diff options
Diffstat (limited to 'src/nativewindow/classes/jogamp')
-rw-r--r-- | src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java b/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java index 0fa5006cc..31de84137 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java +++ b/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java @@ -27,21 +27,31 @@ */ package jogamp.nativewindow.awt; +import java.awt.Cursor; import java.awt.FocusTraversalPolicy; import java.awt.Insets; +import java.awt.Point; +import java.awt.Toolkit; import java.awt.Window; import java.awt.Component; import java.awt.Container; import java.awt.Frame; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.net.URLConnection; +import java.util.HashMap; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JRootPane; import javax.swing.WindowConstants; +import javax.imageio.ImageIO; import javax.media.nativewindow.NativeWindowException; import javax.media.nativewindow.WindowClosingProtocol; import javax.swing.MenuSelectionManager; +import com.jogamp.common.util.IOUtil; + public class AWTMisc { public static JFrame getJFrame(Component c) { @@ -163,6 +173,33 @@ public class AWTMisc { MenuSelectionManager.defaultManager().clearSelectedPath(); } + static final HashMap<String, Cursor> cursorMap = new HashMap<String, Cursor>(); + static final Cursor nulCursor; + static { + final Toolkit toolkit = Toolkit.getDefaultToolkit(); + BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_4BYTE_ABGR); + nulCursor = toolkit.createCustomCursor(img, new Point(0,0), "nullCursor"); + } + + public static synchronized Cursor getNullCursor() { return nulCursor; } + + public static synchronized Cursor getCursor(IOUtil.ClassResources resources, Point hotSpot) throws IOException { + final String key = resources.getClass().getName()+":"+resources.resourcePaths[0]; + Cursor cursor = cursorMap.get(key); + if( null == cursor ) { + cursor = createAWTCursor(resources, hotSpot); + cursorMap.put(key, cursor); + } + return cursor; + } + private static synchronized Cursor createAWTCursor(IOUtil.ClassResources resources, Point hotSpot) throws IOException { + final URLConnection urlConn = resources.resolve(0); + BufferedImage img = ImageIO.read(urlConn.getInputStream()); + + final Toolkit toolkit = Toolkit.getDefaultToolkit(); + return toolkit.createCustomCursor(img, hotSpot, resources.resourcePaths[0]); + } + public static WindowClosingProtocol.WindowClosingMode AWT2NWClosingOperation(int awtClosingOperation) { switch (awtClosingOperation) { case WindowConstants.DISPOSE_ON_CLOSE: |