public static Cursor createCustomCursor(Component component, Image icon, String name) { Toolkit t = component.getToolkit(); Dimension d = t.getBestCursorSize(16, 16); Image i = icon; if (d.width != icon.getWidth(null)) { if (((d.width) == 0) && (d.height == 0)) { // system doesn't support custom cursors, falling back return Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR); } // need to resize the icon Image empty = ImageUtilities.createBufferedImage(d.width, d.height); i = ImageUtilities.mergeImages(icon, empty, 0, 0); } return t.createCustomCursor(i, new Point(1, 1), name); }
public static Cursor createCustomCursor(Component component, Image icon, String name) { Toolkit t = component.getToolkit(); Dimension d = t.getBestCursorSize(16, 16); Image i = icon; if (d.width != icon.getWidth(null)) { if (((d.width) == 0) && (d.height == 0)) { // system doesn't support custom cursors, falling back return Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR); } // need to resize the icon Image empty = ImageUtilities.createBufferedImage(d.width, d.height); i = ImageUtilities.mergeImages(icon, empty, 0, 0); } return t.createCustomCursor(i, new Point(1, 1), name); }
Toolkit toolkit = Toolkit.getDefaultToolkit(); Dimension dim = toolkit.getBestCursorSize(1,1); transCursor = toolkit.createCustomCursor(gc.createCompatibleImage(dim.width, dim.height), new Point(0, 0), "transCursor"); ((Component)mainFrame).setCursor(transCursor);
Toolkit kit = Toolkit.getDefaultToolkit(); Dimension dim = kit.getBestCursorSize(48, 48); BufferedImage buffered = GraphicsUtilities.createCompatibleTranslucentImage(dim.width, dim.height); Shape circle = new Ellipse2D.Float(0, 0, dim.width - 1, dim.height - 1); Graphics2D g = buffered.createGraphics(); g.setColor(Color.BLUE); g.draw(circle); g.setColor(Color.RED); int centerX = (dim.width - 1) /2; int centerY = (dim.height - 1) / 2; g.drawLine(centerX, 0, centerX, dim.height - 1); g.drawLine(0, centerY, dim.height - 1, centerY); g.dispose(); Cursor cursor = kit.createCustomCursor(buffered, new Point(centerX, centerY), "myCursor");
Toolkit toolkit = Toolkit.getDefaultToolkit(); // get the smallest valid cursor size Dimension dim = toolkit.getBestCursorSize(1, 1); // create a new image of that size with an alpha channel BufferedImage cursorImg = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_ARGB); // get a Graphics2D object to draw to the image Graphics2D g2d = cursorImg.createGraphics(); // set the background 'color' with 0 alpha and clear the image g2d.setBackground(new Color(0.0f, 0.0f, 0.0f, 0.0f)); g2d.clearRect(0, 0, dim.width, dim.height); // dispose the Graphics2D object g2d.dispose(); // now create your cursor using that transparent image hiddenCursor = toolkit.createCustomCursor(cursorImg, new Point(0,0), "hiddenCursor");
Toolkit kit = Toolkit.getDefaultToolkit(); Dimension dim = kit.getBestCursorSize(48, 48); BufferedImage buffered = GraphicsUtilities.createCompatibleTranslucentImage(dim.width, dim.height); Shape circle = new Ellipse2D.Float(0, 0, dim.width - 1, dim.height - 1); Graphics2D g = buffered.createGraphics(); g.setColor(Color.BLUE); g.draw(circle); g.setColor(Color.RED); int centerX = (dim.width - 1) /2; int centerY = (dim.height - 1) / 2; g.drawLine(centerX, 0, centerX, dim.height - 1); g.drawLine(0, centerY, dim.height - 1, centerY); g.dispose(); Cursor cursor = kit.createCustomCursor(buffered, new Point(centerX, centerY), "myCursor");
public Dimension getBestCursorSize(int preferredWidth, int preferredHeight) throws HeadlessException { return getUnderlyingToolkit().getBestCursorSize(preferredWidth, preferredHeight); }
/** * Create a hidden cursor. * * @return Hidden cursor, or default cursor if not able to create it. */ public static Cursor createHiddenCursor() { final Toolkit toolkit = Toolkit.getDefaultToolkit(); final Dimension dim = toolkit.getBestCursorSize(1, 1); final BufferedImage c = createImage(Math.max(1, dim.width), Math.max(1, dim.height), java.awt.Transparency.BITMASK); final BufferedImage buffer = applyMask(c, Color.BLACK.getRGB()); return toolkit.createCustomCursor(buffer, new Point(0, 0), "hiddenCursor"); }
/** * Returns cursor created from given icon. */ private static Cursor createCustomCursor(Image icon, String name) { Toolkit t = Toolkit.getDefaultToolkit(); Dimension d = t.getBestCursorSize(16, 16); Image i = icon; if (d.width != icon.getWidth(null)) { // need to resize the icon Image empty = createBufferedImage(d.width, d.height); i = Utilities.mergeImages(icon, empty, 0, 0); } return t.createCustomCursor(i, new Point(11,9), name); }
/** * Returns cursor created from given icon. */ private static Cursor createCustomCursor(Image icon, String name) { Toolkit t = Toolkit.getDefaultToolkit(); Dimension d = t.getBestCursorSize(16, 16); Image i = icon; if (d.width != icon.getWidth(null)) { // need to resize the icon Image empty = createBufferedImage(d.width, d.height); i = Utilities.mergeImages(icon, empty, 0, 0); } return t.createCustomCursor(i, new Point(11,9), name); }
public static Cursor getCustomCursor(String filename, String cursorName, int hotSpotX, int hotSpotY) { Toolkit defaultToolkit = Toolkit.getDefaultToolkit(); ImageIcon icon = new ImageIcon(DefaultView2d.class.getResource("/icon/cursor/" + filename)); //$NON-NLS-1$ Dimension bestCursorSize = defaultToolkit.getBestCursorSize(icon.getIconWidth(), icon.getIconHeight()); Point hotSpot = new Point((hotSpotX * bestCursorSize.width) / icon.getIconWidth(), (hotSpotY * bestCursorSize.height) / icon.getIconHeight()); return defaultToolkit.createCustomCursor(icon.getImage(), hotSpot, cursorName); }
public static Cursor getCustomCursor(String filename, String cursorName, int hotSpotX, int hotSpotY) { Toolkit defaultToolkit = Toolkit.getDefaultToolkit(); URL path = ActionW.class.getResource("/icon/cursor/" + filename); //$NON-NLS-1$ if (path == null) { return null; } ImageIcon icon = new ImageIcon(path); Dimension bestCursorSize = defaultToolkit.getBestCursorSize(icon.getIconWidth(), icon.getIconHeight()); Point hotSpot = new Point((hotSpotX * bestCursorSize.width) / icon.getIconWidth(), (hotSpotY * bestCursorSize.height) / icon.getIconHeight()); return defaultToolkit.createCustomCursor(icon.getImage(), hotSpot, cursorName); }
private static Cursor loadCursor() { ImageIcon img = null; Cursor c = null; Dimension size = Toolkit.getDefaultToolkit().getBestCursorSize(16, 16); if(size.width == 32) { img = loadImageIcon("/net/sf/tinylaf/cp_icons/cs32.gif"); c = Toolkit.getDefaultToolkit().createCustomCursor( img.getImage(), new Point(15, 15), "cs_cursor"); } else if(size.width == 16) { img = loadImageIcon("/net/sf/tinylaf/cp_icons/cs16.gif"); c = Toolkit.getDefaultToolkit().createCustomCursor( img.getImage(), new Point(7, 7), "cs_cursor"); } return c; }
private static Cursor createCustomCursor(Component component, Image icon, String name) { Toolkit t = component.getToolkit(); Dimension d = t.getBestCursorSize(16, 16); Image i = icon; if (d.width != icon.getWidth(null)) { if ((d.width) == 0 && (d.height == 0)) { // system doesn't support custom cursors, falling back return Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR); } // need to resize the icon Image empty = IconManager.createBufferedImage(d.width, d.height); i = Utilities.mergeImages(icon, empty, 0, 0); } return t.createCustomCursor(i, new Point(1,1), name); }
public static Cursor createCustomCursor(Component component, Image icon, String name) { Toolkit t = component.getToolkit(); Dimension d = t.getBestCursorSize(16, 16); Image i = icon; if (d.width != icon.getWidth(null)) { if (((d.width) == 0) && (d.height == 0)) { // system doesn't support custom cursors, falling back return Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR); } // need to resize the icon Image empty = ImageUtilities.createBufferedImage(d.width, d.height); i = Utilities.mergeImages(icon, empty, 0, 0); } return t.createCustomCursor(i, new Point(1, 1), name); }
private static Cursor createCustomCursor(Component component, Image icon, String name) { Toolkit t = component.getToolkit(); Dimension d = t.getBestCursorSize(16, 16); Image i = icon; if (d.width != icon.getWidth(null)) { if ((d.width) == 0 && (d.height == 0)) { // system doesn't support custom cursors, falling back return Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR); } // need to resize the icon Image empty = IconManager.createBufferedImage(d.width, d.height); i = Utilities.mergeImages(icon, empty, 0, 0); } return t.createCustomCursor(i, new Point(1,1), name); }
private static Cursor createRangeFinderCursor(ImageIcon cursorIcon) { Toolkit defaultToolkit = Toolkit.getDefaultToolkit(); final String cursorName = "rangeFinder"; // this is necessary because on some systems the cursor is scaled but not the 'hot spot' Dimension bestCursorSize = defaultToolkit.getBestCursorSize(cursorIcon.getIconWidth(), cursorIcon.getIconHeight()); Point hotSpot = new Point((7 * bestCursorSize.width) / cursorIcon.getIconWidth(), (7 * bestCursorSize.height) / cursorIcon.getIconHeight()); return defaultToolkit.createCustomCursor(cursorIcon.getImage(), hotSpot, cursorName); }
public static Cursor createCustomCursor(Component component, Image icon, String name) { Toolkit t = component.getToolkit(); Dimension d = t.getBestCursorSize(16, 16); Image i = icon; if (d.width != icon.getWidth(null)) { if (((d.width) == 0) && (d.height == 0)) { // system doesn't support custom cursors, falling back return Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR); } // need to resize the icon Image empty = ImageUtilities.createBufferedImage(d.width, d.height); i = ImageUtilities.mergeImages(icon, empty, 0, 0); } return t.createCustomCursor(i, new Point(1, 1), name); }
private static Cursor createRangeFinderCursor(ImageIcon cursorIcon) { Toolkit defaultToolkit = Toolkit.getDefaultToolkit(); final String cursorName = "rangeFinder"; // this is necessary because on some systems the cursor is scaled but not the 'hot spot' Dimension bestCursorSize = defaultToolkit.getBestCursorSize(cursorIcon.getIconWidth(), cursorIcon.getIconHeight()); Point hotSpot = new Point((7 * bestCursorSize.width) / cursorIcon.getIconWidth(), (7 * bestCursorSize.height) / cursorIcon.getIconHeight()); return defaultToolkit.createCustomCursor(cursorIcon.getImage(), hotSpot, cursorName); }
@Override public void setCursor(PImage img, int x, int y) { // Don't set cursorType, instead use cursorType to save the last // regular cursor type used for when cursor() is called. //cursor_type = Cursor.CUSTOM_CURSOR; // this is a temporary workaround for the CHIP, will be removed Dimension cursorSize = Toolkit.getDefaultToolkit().getBestCursorSize(img.width, img.height); if (cursorSize.width == 0 || cursorSize.height == 0) { return; } Cursor cursor = canvas.getToolkit().createCustomCursor((Image) img.getNative(), new Point(x, y), "custom"); canvas.setCursor(cursor); cursorVisible = true; }