src/share/classes/java/awt/Cursor.java

Print this page


   1 /*
   2  * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 277         }
 278         Cursor c = predefinedPrivate[type];
 279         if (c == null) {
 280             predefinedPrivate[type] = c = new Cursor(type);
 281         }
 282         // fill 'predefined' array for backwards compatibility.
 283         if (predefined[type] == null) {
 284             predefined[type] = c;
 285         }
 286         return c;
 287     }
 288 
 289     /**
 290      * Returns a system-specific custom cursor object matching the
 291      * specified name.  Cursor names are, for example: "Invalid.16x16"
 292      *
 293      * @param name a string describing the desired system-specific custom cursor
 294      * @return the system specific custom cursor named
 295      * @exception HeadlessException if
 296      * <code>GraphicsEnvironment.isHeadless</code> returns true

 297      */
 298     static public Cursor getSystemCustomCursor(final String name)
 299         throws AWTException, HeadlessException {
 300         GraphicsEnvironment.checkHeadless();
 301         Cursor cursor = systemCustomCursors.get(name);
 302 
 303         if (cursor == null) {
 304             synchronized(systemCustomCursors) {
 305                 if (systemCustomCursorProperties == null)
 306                     loadSystemCustomCursorProperties();
 307             }
 308 
 309             String prefix = CursorDotPrefix + name;
 310             String key    = prefix + DotFileSuffix;
 311 
 312             if (!systemCustomCursorProperties.containsKey(key)) {
 313                 if (log.isLoggable(PlatformLogger.Level.FINER)) {
 314                     log.finer("Cursor.getSystemCustomCursor(" + name + ") returned null");
 315                 }
 316                 return null;


 361             } catch (Exception e) {
 362                 throw new AWTException(
 363                     "Exception: " + e.getClass() + " " + e.getMessage() +
 364                     " occurred while creating cursor " + name);
 365             }
 366 
 367             if (cursor == null) {
 368                 if (log.isLoggable(PlatformLogger.Level.FINER)) {
 369                     log.finer("Cursor.getSystemCustomCursor(" + name + ") returned null");
 370                 }
 371             } else {
 372                 systemCustomCursors.put(name, cursor);
 373             }
 374         }
 375 
 376         return cursor;
 377     }
 378 
 379     /**
 380      * Return the system default cursor.

 381      */
 382     static public Cursor getDefaultCursor() {
 383         return getPredefinedCursor(Cursor.DEFAULT_CURSOR);
 384     }
 385 
 386     /**
 387      * Creates a new cursor object with the specified type.
 388      * @param type the type of cursor
 389      * @throws IllegalArgumentException if the specified cursor type
 390      * is invalid
 391      */
 392     @ConstructorProperties({"type"})
 393     public Cursor(int type) {
 394         if (type < Cursor.DEFAULT_CURSOR || type > Cursor.MOVE_CURSOR) {
 395             throw new IllegalArgumentException("illegal cursor type");
 396         }
 397         this.type = type;
 398 
 399         // Lookup localized name.
 400         name = Toolkit.getProperty(cursorProperties[type][0],
 401                                    cursorProperties[type][1]);
 402     }
 403 
 404     /**
 405      * Creates a new custom cursor object with the specified name.<p>
 406      * Note:  this constructor should only be used by AWT implementations
 407      * as part of their support for custom cursors.  Applications should
 408      * use Toolkit.createCustomCursor().
 409      * @param name the user-visible name of the cursor.
 410      * @see java.awt.Toolkit#createCustomCursor
 411      */
 412     protected Cursor(String name) {
 413         this.type = Cursor.CUSTOM_CURSOR;
 414         this.name = name;
 415     }
 416 
 417     /**
 418      * Returns the type for this cursor.

 419      */
 420     public int getType() {
 421         return type;
 422     }
 423 
 424     /**
 425      * Returns the name of this cursor.
 426      * @return    a localized description of this cursor.
 427      * @since     1.2
 428      */
 429     public String getName() {
 430         return name;
 431     }
 432 
 433     /**
 434      * Returns a string representation of this cursor.
 435      * @return    a string representation of this cursor.
 436      * @since     1.2
 437      */
 438     public String toString() {


   1 /*
   2  * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 277         }
 278         Cursor c = predefinedPrivate[type];
 279         if (c == null) {
 280             predefinedPrivate[type] = c = new Cursor(type);
 281         }
 282         // fill 'predefined' array for backwards compatibility.
 283         if (predefined[type] == null) {
 284             predefined[type] = c;
 285         }
 286         return c;
 287     }
 288 
 289     /**
 290      * Returns a system-specific custom cursor object matching the
 291      * specified name.  Cursor names are, for example: "Invalid.16x16"
 292      *
 293      * @param name a string describing the desired system-specific custom cursor
 294      * @return the system specific custom cursor named
 295      * @exception HeadlessException if
 296      * <code>GraphicsEnvironment.isHeadless</code> returns true
 297      * @exception AWTException in case of erroneous retrieving of the cursor
 298      */
 299     static public Cursor getSystemCustomCursor(final String name)
 300         throws AWTException, HeadlessException {
 301         GraphicsEnvironment.checkHeadless();
 302         Cursor cursor = systemCustomCursors.get(name);
 303 
 304         if (cursor == null) {
 305             synchronized(systemCustomCursors) {
 306                 if (systemCustomCursorProperties == null)
 307                     loadSystemCustomCursorProperties();
 308             }
 309 
 310             String prefix = CursorDotPrefix + name;
 311             String key    = prefix + DotFileSuffix;
 312 
 313             if (!systemCustomCursorProperties.containsKey(key)) {
 314                 if (log.isLoggable(PlatformLogger.Level.FINER)) {
 315                     log.finer("Cursor.getSystemCustomCursor(" + name + ") returned null");
 316                 }
 317                 return null;


 362             } catch (Exception e) {
 363                 throw new AWTException(
 364                     "Exception: " + e.getClass() + " " + e.getMessage() +
 365                     " occurred while creating cursor " + name);
 366             }
 367 
 368             if (cursor == null) {
 369                 if (log.isLoggable(PlatformLogger.Level.FINER)) {
 370                     log.finer("Cursor.getSystemCustomCursor(" + name + ") returned null");
 371                 }
 372             } else {
 373                 systemCustomCursors.put(name, cursor);
 374             }
 375         }
 376 
 377         return cursor;
 378     }
 379 
 380     /**
 381      * Return the system default cursor.
 382      * @return  the default cursor
 383      */
 384     static public Cursor getDefaultCursor() {
 385         return getPredefinedCursor(Cursor.DEFAULT_CURSOR);
 386     }
 387 
 388     /**
 389      * Creates a new cursor object with the specified type.
 390      * @param type the type of cursor
 391      * @throws IllegalArgumentException if the specified cursor type
 392      * is invalid
 393      */
 394     @ConstructorProperties({"type"})
 395     public Cursor(int type) {
 396         if (type < Cursor.DEFAULT_CURSOR || type > Cursor.MOVE_CURSOR) {
 397             throw new IllegalArgumentException("illegal cursor type");
 398         }
 399         this.type = type;
 400 
 401         // Lookup localized name.
 402         name = Toolkit.getProperty(cursorProperties[type][0],
 403                                    cursorProperties[type][1]);
 404     }
 405 
 406     /**
 407      * Creates a new custom cursor object with the specified name.<p>
 408      * Note:  this constructor should only be used by AWT implementations
 409      * as part of their support for custom cursors.  Applications should
 410      * use Toolkit.createCustomCursor().
 411      * @param name the user-visible name of the cursor.
 412      * @see java.awt.Toolkit#createCustomCursor
 413      */
 414     protected Cursor(String name) {
 415         this.type = Cursor.CUSTOM_CURSOR;
 416         this.name = name;
 417     }
 418 
 419     /**
 420      * Returns the type for this cursor.
 421      * @return  the cursor type
 422      */
 423     public int getType() {
 424         return type;
 425     }
 426 
 427     /**
 428      * Returns the name of this cursor.
 429      * @return    a localized description of this cursor.
 430      * @since     1.2
 431      */
 432     public String getName() {
 433         return name;
 434     }
 435 
 436     /**
 437      * Returns a string representation of this cursor.
 438      * @return    a string representation of this cursor.
 439      * @since     1.2
 440      */
 441     public String toString() {