src/macosx/classes/sun/lwawt/macosx/CCustomCursor.java

Print this page

        

*** 34,43 **** --- 34,44 ---- final Rectangle bounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getBounds(); return sMaxCursorSize = new Dimension(bounds.width / 2, bounds.height / 2); } Image fImage; + private boolean isImageOk = false; Point fHotspot; public CCustomCursor(final Image cursor, final Point hotSpot, final String name) throws IndexOutOfBoundsException, HeadlessException { super(name); fImage = cursor;
*** 62,71 **** --- 63,75 ---- // If the image is invalid, the cursor will be hidden (made completely // transparent). In this case, getBestCursorSize() will adjust negative w and h, // but we need to set the hotspot inside the image here. if (tracker.isErrorAny() || width < 0 || height < 0) { fHotspot.x = fHotspot.y = 0; + isImageOk = false; + } else { + isImageOk = true; } // Scale image to nearest supported size final Dimension nativeSize = toolkit.getBestCursorSize(width, height); if (nativeSize.width != width || nativeSize.height != height) {
*** 108,128 **** // Called from native when the cursor is set // Returns long array of [NSImage ptr, x hotspot, y hotspot] CImage fCImage; long getImageData() { ! if (fCImage == null) { try { fCImage = CImage.getCreator().createFromImage(fImage); } catch (IllegalArgumentException iae) { // Silently return null - we want to hide cursor by providing an empty // ByteArray or just null return 0L; } } ! return fCImage.ptr; } Point getHotSpot() { return fHotspot; } --- 112,143 ---- // Called from native when the cursor is set // Returns long array of [NSImage ptr, x hotspot, y hotspot] CImage fCImage; long getImageData() { ! if (fCImage != null) { ! return fCImage.ptr; ! } ! ! if (isImageOk) { try { fCImage = CImage.getCreator().createFromImage(fImage); + + if (fCImage == null) { + isImageOk = false; + return 0L; + } else { + return fCImage.ptr; + } } catch (IllegalArgumentException iae) { // Silently return null - we want to hide cursor by providing an empty // ByteArray or just null return 0L; } } ! return 0L; } Point getHotSpot() { return fHotspot; }