8078658: Make custom Cursors available for modular build
authorserb
Thu, 18 Jun 2015 14:56:45 +0300
changeset 31443 272f4e5cbb14
parent 31442 5f0b1f795848
child 31444 9d3d98a1adcb
8078658: Make custom Cursors available for modular build Reviewed-by: alanb, chegar
jdk/src/java.desktop/share/classes/java/awt/Cursor.java
--- a/jdk/src/java.desktop/share/classes/java/awt/Cursor.java	Thu Jun 18 11:05:33 2015 +0300
+++ b/jdk/src/java.desktop/share/classes/java/awt/Cursor.java	Thu Jun 18 14:56:45 2015 +0300
@@ -26,8 +26,8 @@
 
 import java.beans.ConstructorProperties;
 import java.io.InputStream;
-import java.net.URL;
 import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.security.PrivilegedExceptionAction;
 import java.util.Hashtable;
 import java.util.Properties;
@@ -261,7 +261,7 @@
      * @throws IllegalArgumentException if the specified cursor type is
      *         invalid
      */
-    static public Cursor getPredefinedCursor(int type) {
+    public static Cursor getPredefinedCursor(int type) {
         if (type < Cursor.DEFAULT_CURSOR || type > Cursor.MOVE_CURSOR) {
             throw new IllegalArgumentException("illegal cursor type");
         }
@@ -286,7 +286,7 @@
      * <code>GraphicsEnvironment.isHeadless</code> returns true
      * @exception AWTException in case of erroneous retrieving of the cursor
      */
-    static public Cursor getSystemCustomCursor(final String name)
+    public static Cursor getSystemCustomCursor(final String name)
         throws AWTException, HeadlessException {
         GraphicsEnvironment.checkHeadless();
         Cursor cursor = systemCustomCursors.get(name);
@@ -330,18 +330,15 @@
             } catch (NumberFormatException nfe) {
                 throw new AWTException("failed to parse hotspot property for cursor: " + name);
             }
-
-            try {
-                final Toolkit toolkit = Toolkit.getDefaultToolkit();
-                final String file = RESOURCE_PREFIX + fileName;
-
-                cursor = AccessController.doPrivileged(
-                        (PrivilegedExceptionAction<Cursor>) () -> {
-                            URL url = Cursor.class.getResource(file);
-                            Image image = toolkit.getImage(url);
-                            return toolkit.createCustomCursor(image, hotPoint,
-                                                              localized);
-                        });
+            final Toolkit toolkit = Toolkit.getDefaultToolkit();
+            final String file = RESOURCE_PREFIX + fileName;
+            final InputStream in = AccessController.doPrivileged(
+                    (PrivilegedAction<InputStream>) () -> {
+                        return Cursor.class.getResourceAsStream(file);
+                    });
+            try (in) {
+                Image image = toolkit.createImage(in.readAllBytes());
+                cursor = toolkit.createCustomCursor(image, hotPoint, localized);
             } catch (Exception e) {
                 throw new AWTException(
                     "Exception: " + e.getClass() + " " + e.getMessage() +
@@ -365,7 +362,7 @@
      *
      * @return the default cursor
      */
-    static public Cursor getDefaultCursor() {
+    public static Cursor getDefaultCursor() {
         return getPredefinedCursor(Cursor.DEFAULT_CURSOR);
     }