49 MediaTracker tracker = new MediaTracker(c);
50 tracker.addImage(cursor, 0);
51 try {
52 tracker.waitForAll();
53 } catch (InterruptedException e) {
54 }
55 int width = cursor.getWidth(c);
56 int height = cursor.getHeight(c);
57
58 // Fix for bug 4212593 The Toolkit.createCustomCursor does not
59 // check absence of the image of cursor
60 // If the image is invalid, the cursor will be hidden (made completely
61 // transparent). In this case, getBestCursorSize() will adjust negative w and h,
62 // but we need to set the hotspot inside the image here.
63 if (tracker.isErrorAny() || width < 0 || height < 0) {
64 hotSpot.x = hotSpot.y = 0;
65 }
66
67 // Scale image to nearest supported size.
68 Dimension nativeSize = toolkit.getBestCursorSize(width, height);
69 if (nativeSize.width != width || nativeSize.height != height) {
70 cursor = cursor.getScaledInstance(nativeSize.width,
71 nativeSize.height,
72 Image.SCALE_DEFAULT);
73 width = nativeSize.width;
74 height = nativeSize.height;
75 }
76
77 // Verify that the hotspot is within cursor bounds.
78 if (hotSpot.x >= width || hotSpot.y >= height || hotSpot.x < 0 || hotSpot.y < 0) {
79 throw new IndexOutOfBoundsException("invalid hotSpot");
80 }
81
82 /* Extract ARGB array from image.
83 *
84 * A transparency mask can be created in native code by checking
85 * each pixel's top byte -- a 0 value means the pixel's transparent.
86 * Since each platform's format of the bitmap and mask are likely to
87 * be different, their creation shouldn't be here.
88 */
89 int[] pixels = new int[width * height];
|
49 MediaTracker tracker = new MediaTracker(c);
50 tracker.addImage(cursor, 0);
51 try {
52 tracker.waitForAll();
53 } catch (InterruptedException e) {
54 }
55 int width = cursor.getWidth(c);
56 int height = cursor.getHeight(c);
57
58 // Fix for bug 4212593 The Toolkit.createCustomCursor does not
59 // check absence of the image of cursor
60 // If the image is invalid, the cursor will be hidden (made completely
61 // transparent). In this case, getBestCursorSize() will adjust negative w and h,
62 // but we need to set the hotspot inside the image here.
63 if (tracker.isErrorAny() || width < 0 || height < 0) {
64 hotSpot.x = hotSpot.y = 0;
65 }
66
67 // Scale image to nearest supported size.
68 Dimension nativeSize = toolkit.getBestCursorSize(width, height);
69 if ((nativeSize.width != width || nativeSize.height != height) &&
70 (nativeSize.width != 0 && nativeSize.height != 0)) {
71 cursor = cursor.getScaledInstance(nativeSize.width,
72 nativeSize.height,
73 Image.SCALE_DEFAULT);
74 width = nativeSize.width;
75 height = nativeSize.height;
76 }
77
78 // Verify that the hotspot is within cursor bounds.
79 if (hotSpot.x >= width || hotSpot.y >= height || hotSpot.x < 0 || hotSpot.y < 0) {
80 throw new IndexOutOfBoundsException("invalid hotSpot");
81 }
82
83 /* Extract ARGB array from image.
84 *
85 * A transparency mask can be created in native code by checking
86 * each pixel's top byte -- a 0 value means the pixel's transparent.
87 * Since each platform's format of the bitmap and mask are likely to
88 * be different, their creation shouldn't be here.
89 */
90 int[] pixels = new int[width * height];
|