< prev index next >

src/java.desktop/share/classes/java/awt/Cursor.java

Print this page

        

*** 23,35 **** * questions. */ package java.awt; import java.beans.ConstructorProperties; import java.io.InputStream; - import java.net.URL; import java.security.AccessController; import java.security.PrivilegedExceptionAction; import java.util.Hashtable; import java.util.Properties; import java.util.StringTokenizer; --- 23,36 ---- * questions. */ package java.awt; import java.beans.ConstructorProperties; + import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.security.AccessController; + import java.security.PrivilegedAction; import java.security.PrivilegedExceptionAction; import java.util.Hashtable; import java.util.Properties; import java.util.StringTokenizer;
*** 259,269 **** * @param type the type of predefined cursor * @return the specified predefined cursor * @throws IllegalArgumentException if the specified cursor type is * invalid */ ! static public Cursor getPredefinedCursor(int type) { if (type < Cursor.DEFAULT_CURSOR || type > Cursor.MOVE_CURSOR) { throw new IllegalArgumentException("illegal cursor type"); } Cursor c = predefinedPrivate[type]; if (c == null) { --- 260,270 ---- * @param type the type of predefined cursor * @return the specified predefined cursor * @throws IllegalArgumentException if the specified cursor type is * invalid */ ! public static Cursor getPredefinedCursor(int type) { if (type < Cursor.DEFAULT_CURSOR || type > Cursor.MOVE_CURSOR) { throw new IllegalArgumentException("illegal cursor type"); } Cursor c = predefinedPrivate[type]; if (c == null) {
*** 284,294 **** * @return the system specific custom cursor named * @exception HeadlessException if * <code>GraphicsEnvironment.isHeadless</code> returns true * @exception AWTException in case of erroneous retrieving of the cursor */ ! static public Cursor getSystemCustomCursor(final String name) throws AWTException, HeadlessException { GraphicsEnvironment.checkHeadless(); Cursor cursor = systemCustomCursors.get(name); if (cursor == null) { --- 285,295 ---- * @return the system specific custom cursor named * @exception HeadlessException if * <code>GraphicsEnvironment.isHeadless</code> returns true * @exception AWTException in case of erroneous retrieving of the cursor */ ! public static Cursor getSystemCustomCursor(final String name) throws AWTException, HeadlessException { GraphicsEnvironment.checkHeadless(); Cursor cursor = systemCustomCursors.get(name); if (cursor == null) {
*** 328,349 **** hotPoint = new Point(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken())); } 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); }); } catch (Exception e) { throw new AWTException( "Exception: " + e.getClass() + " " + e.getMessage() + " occurred while creating cursor " + name); } --- 329,349 ---- hotPoint = new Point(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken())); } catch (NumberFormatException nfe) { throw new AWTException("failed to parse hotspot property for cursor: " + name); } 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) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + in.transferTo(baos); + Image image = toolkit.createImage(baos.toByteArray()); + cursor = toolkit.createCustomCursor(image, hotPoint, localized); } catch (Exception e) { throw new AWTException( "Exception: " + e.getClass() + " " + e.getMessage() + " occurred while creating cursor " + name); }
*** 363,373 **** /** * Return the system default cursor. * * @return the default cursor */ ! static public Cursor getDefaultCursor() { return getPredefinedCursor(Cursor.DEFAULT_CURSOR); } /** * Creates a new cursor object with the specified type. --- 363,373 ---- /** * Return the system default cursor. * * @return the default cursor */ ! public static Cursor getDefaultCursor() { return getPredefinedCursor(Cursor.DEFAULT_CURSOR); } /** * Creates a new cursor object with the specified type.
< prev index next >