public static Cursor getSystemCustomCursor(String name) throws AWTException, HeadlessException {
GraphicsEnvironment.checkHeadless();
Cursor cursor = (Cursor)systemCustomCursors.get(name);
if (cursor == null) {
synchronized(systemCustomCursors) {
if (systemCustomCursorProperties == null)
loadSystemCustomCursorProperties();
}
String prefix = CursorDotPrefix + name;
String key = prefix + DotFileSuffix;
if (!systemCustomCursorProperties.containsKey(key)) {
if (log.isLoggable(PlatformLogger.FINER)) {
log.finer("Cursor.getSystemCustomCursor(" + name + ") returned null");
}
return null;
}
final String fileName =
systemCustomCursorProperties.getProperty(key);
String localized = (String)systemCustomCursorProperties.getProperty(prefix + DotNameSuffix);
if (localized == null) localized = name;
String hotspot = (String)systemCustomCursorProperties.getProperty(prefix + DotHotspotSuffix);
if (hotspot == null)
throw new AWTException("no hotspot property defined for cursor: " + name);
StringTokenizer st = new StringTokenizer(hotspot, ",");
if (st.countTokens() != 2)
throw new AWTException("failed to parse hotspot property for cursor: " + name);
int x = 0;
int y = 0;
try {
x = Integer.parseInt(st.nextToken());
y = Integer.parseInt(st.nextToken());
} catch (NumberFormatException nfe) {
throw new AWTException("failed to parse hotspot property for cursor: " + name);
}
try {
final int fx = x;
final int fy = y;
final String flocalized = localized;
cursor = (Cursor) java.security.AccessController.doPrivileged(
new java.security.PrivilegedExceptionAction() {
public Object run() throws Exception {
Toolkit toolkit = Toolkit.getDefaultToolkit();
Image image = toolkit.getImage(
systemCustomCursorDirPrefix + fileName);
return toolkit.createCustomCursor(
image, new Point(fx,fy), flocalized);
}
});
} catch (Exception e) {
throw new AWTException(
"Exception: " + e.getClass() + " " + e.getMessage() +
" occurred while creating cursor " + name);
}
if (cursor == null) {
if (log.isLoggable(PlatformLogger.FINER)) {
log.finer("Cursor.getSystemCustomCursor(" + name + ") returned null");
}
} else {
systemCustomCursors.put(name, cursor);
}
}
return cursor;
}
Returns a system-specific custom cursor object matching the
specified name. Cursor names are, for example: "Invalid.16x16" |