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 *
383 * @return the default cursor
384 */
385 static public Cursor getDefaultCursor() {
386 return getPredefinedCursor(Cursor.DEFAULT_CURSOR);
387 }
388
389 /**
390 * Creates a new cursor object with the specified type.
391 * @param type the type of cursor
392 * @throws IllegalArgumentException if the specified cursor type
393 * is invalid
394 */
395 @ConstructorProperties({"type"})
396 public Cursor(int type) {
397 if (type < Cursor.DEFAULT_CURSOR || type > Cursor.MOVE_CURSOR) {
398 throw new IllegalArgumentException("illegal cursor type");
399 }
400 this.type = type;
401
402 // Lookup localized name.
403 name = Toolkit.getProperty(cursorProperties[type][0],
404 cursorProperties[type][1]);
405 }
406
407 /**
408 * Creates a new custom cursor object with the specified name.<p>
409 * Note: this constructor should only be used by AWT implementations
410 * as part of their support for custom cursors. Applications should
411 * use Toolkit.createCustomCursor().
412 * @param name the user-visible name of the cursor.
413 * @see java.awt.Toolkit#createCustomCursor
414 */
415 protected Cursor(String name) {
416 this.type = Cursor.CUSTOM_CURSOR;
417 this.name = name;
418 }
419
420 /**
421 * Returns the type for this cursor.
422 *
423 * @return the cursor type
424 */
425 public int getType() {
426 return type;
427 }
428
429 /**
430 * Returns the name of this cursor.
431 * @return a localized description of this cursor.
432 * @since 1.2
433 */
434 public String getName() {
435 return name;
436 }
437
438 /**
439 * Returns a string representation of this cursor.
440 * @return a string representation of this cursor.
441 * @since 1.2
442 */
443 public String toString() {
|