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

Print this page




 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.FINER)) {
 314                     log.finer("Cursor.getSystemCustomCursor(" + name + ") returned null");
 315                 }
 316                 return null;
 317             }
 318 
 319             final String fileName =
 320                 systemCustomCursorProperties.getProperty(key);
 321 
 322             String localized = systemCustomCursorProperties.getProperty(prefix + DotNameSuffix);
 323 
 324             if (localized == null) localized = name;
 325 
 326             String hotspot = systemCustomCursorProperties.getProperty(prefix + DotHotspotSuffix);
 327 
 328             if (hotspot == null)
 329                 throw new AWTException("no hotspot property defined for cursor: " + name);
 330 
 331             StringTokenizer st = new StringTokenizer(hotspot, ",");
 332 
 333             if (st.countTokens() != 2)


 348                 final int fy = y;
 349                 final String flocalized = localized;
 350 
 351                 cursor = java.security.AccessController.<Cursor>doPrivileged(
 352                     new java.security.PrivilegedExceptionAction<Cursor>() {
 353                     public Cursor run() throws Exception {
 354                         Toolkit toolkit = Toolkit.getDefaultToolkit();
 355                         Image image = toolkit.getImage(
 356                            systemCustomCursorDirPrefix + fileName);
 357                         return toolkit.createCustomCursor(
 358                                     image, new Point(fx,fy), flocalized);
 359                     }
 360                 });
 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.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




 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;
 317             }
 318 
 319             final String fileName =
 320                 systemCustomCursorProperties.getProperty(key);
 321 
 322             String localized = systemCustomCursorProperties.getProperty(prefix + DotNameSuffix);
 323 
 324             if (localized == null) localized = name;
 325 
 326             String hotspot = systemCustomCursorProperties.getProperty(prefix + DotHotspotSuffix);
 327 
 328             if (hotspot == null)
 329                 throw new AWTException("no hotspot property defined for cursor: " + name);
 330 
 331             StringTokenizer st = new StringTokenizer(hotspot, ",");
 332 
 333             if (st.countTokens() != 2)


 348                 final int fy = y;
 349                 final String flocalized = localized;
 350 
 351                 cursor = java.security.AccessController.<Cursor>doPrivileged(
 352                     new java.security.PrivilegedExceptionAction<Cursor>() {
 353                     public Cursor run() throws Exception {
 354                         Toolkit toolkit = Toolkit.getDefaultToolkit();
 355                         Image image = toolkit.getImage(
 356                            systemCustomCursorDirPrefix + fileName);
 357                         return toolkit.createCustomCursor(
 358                                     image, new Point(fx,fy), flocalized);
 359                     }
 360                 });
 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