List of usage examples for java.awt Toolkit createCustomCursor
public Cursor createCustomCursor(Image cursor, Point hotSpot, String name) throws IndexOutOfBoundsException, HeadlessException
From source file:CursorUtil.java
public static Cursor createCursor(BufferedImage img, Point hotspot, String name) throws IndexOutOfBoundsException, Exception { Toolkit tk = Toolkit.getDefaultToolkit(); Dimension d = tk.getBestCursorSize(img.getWidth(), img.getHeight()); if ((d.width == img.getWidth()) && (d.height == img.getHeight())) return tk.createCustomCursor(img, hotspot, name); if ((d.width + d.height) < 2) throw new Exception("Invalid Size"); BufferedImage newImg = GraphicsUtil.createImage(d.width, d.height); Graphics2D g2 = newImg.createGraphics(); g2.drawImage(img, // what to draw 0, // dest left 0, // dest top newImg.getWidth(), // dest right newImg.getHeight(), // dest bottom 0, // src left 0, // src top img.getWidth(), // src right img.getHeight(), // src bottom null // to notify of image updates );// w w w .j a va2s. co m return tk.createCustomCursor(newImg, hotspot, name); }
From source file:Main.java
public static Cursor buildCursorByTrimming(Toolkit toolkit, Image image, int x, int y, String name, Cursor defaultCursor) {/*ww w. j ava 2 s . co m*/ Dimension d = toolkit.getBestCursorSize(image.getWidth(null), image.getHeight(null)); if (d == null || d.getWidth() <= 0 || d.getHeight() <= 0) return defaultCursor; BufferedImage out = new BufferedImage((int) d.getWidth(), (int) d.getHeight(), BufferedImage.TYPE_INT_ARGB); out.getGraphics().drawImage(image, 0, 0, null); return toolkit.createCustomCursor(out, new Point(x, y), name); }
From source file:net.sf.nmedit.jtheme.JTCursor.java
private static Cursor createCursor(int id) { Toolkit tk = Toolkit.getDefaultToolkit(); URL res = getResource(id);/*ww w.j a va 2 s .c om*/ if (res == null) { Log log = LogFactory.getLog(JTCursor.class); if (log.isWarnEnabled()) { log.warn("Could not find cursor: id=" + id + ", url=" + res); } return Cursor.getDefaultCursor(); } Image img; try { img = ImageIO.read(res); } catch (IOException e) { Log log = LogFactory.getLog(JTCursor.class); if (log.isWarnEnabled()) { log.warn("Could not find cursor: id=" + id + ", url=" + res, e); } return Cursor.getDefaultCursor(); } return tk.createCustomCursor(img, new Point(4, 16), names[id]); }
From source file:es.emergya.ui.base.BasicWindow.java
/** * Initialize the window with default values. *//* w ww . jav a 2 s . c o m*/ private void inicializar() { frame = new JFrame(i18n.getString("title")); //$NON-NLS-1$ getFrame().setBackground(Color.WHITE); getFrame().setIconImage(ICON_IMAGE); //$NON-NLS-1$ getFrame().addWindowListener(new RemoveClientesConectadosListener()); getFrame().setMinimumSize(new Dimension(900, 600)); getFrame().addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { resize(); } }); busyCursor = new Cursor(Cursor.WAIT_CURSOR); defaultCursor = new Cursor(Cursor.DEFAULT_CURSOR); Toolkit toolkit = Toolkit.getDefaultToolkit(); Image image = getImageIcon("/images/hand.gif"); if (image != null) handCursor = toolkit.createCustomCursor(image, new Point(0, 0), "hand"); //$NON-NLS-1$ }
From source file:Main.java
/** * Create a custom cursor out of the specified image, with the specified hotspot. *//*from w w w . j a va 2 s.co m*/ public static Cursor createImageCursor(Image img, Point hotspot) { Toolkit tk = Toolkit.getDefaultToolkit(); // for now, just report the cursor restrictions, then blindly create int w = img.getWidth(null); int h = img.getHeight(null); Dimension d = tk.getBestCursorSize(w, h); // int colors = tk.getMaximumCursorColors(); // Log.debug("Creating custom cursor [desiredSize=" + w + "x" + h + // ", bestSize=" + d.width + "x" + d.height + // ", maxcolors=" + colors + "]."); // if the passed-in image is smaller, pad it with transparent pixels and use it anyway. if (((w < d.width) && (h <= d.height)) || ((w <= d.width) && (h < d.height))) { Image padder = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration().createCompatibleImage(d.width, d.height, Transparency.BITMASK); Graphics g = padder.getGraphics(); g.drawImage(img, 0, 0, null); g.dispose(); // and reassign the image to the padded image img = padder; // and adjust the 'best' to cheat the hotspot checking code d.width = w; d.height = h; } // make sure the hotspot is valid if (hotspot == null) { hotspot = new Point(d.width / 2, d.height / 2); } else { hotspot.x = Math.min(d.width - 1, Math.max(0, hotspot.x)); hotspot.y = Math.min(d.height - 1, Math.max(0, hotspot.y)); } // and create the cursor return tk.createCustomCursor(img, hotspot, "samskivertDnDCursor"); }
From source file:org.colombbus.tangara.commons.resinject.ClassResourceImpl.java
private Cursor loadCursor(String key) { String imageKey = key + ".image"; //$NON-NLS-1$ String nameKey = key + ".name"; //$NON-NLS-1$ String xKey = key + ".hotspot.x"; //$NON-NLS-1$ String yKey = key + ".hotspot.y"; //$NON-NLS-1$ Image image = getImage(imageKey); String name = getString(nameKey); Integer hotSpotX = getInteger(xKey); Integer hotSpotY = getInteger(yKey); Point hotSpot = new Point(hotSpotX.intValue(), hotSpotY.intValue()); Toolkit toolkit = Toolkit.getDefaultToolkit(); return toolkit.createCustomCursor(image, hotSpot, name); }
From source file:org.dishevelled.brainstorm.BrainStorm.java
/** * Create and return a new hidden cursor, that is a fully transparent one pixel custom cursor. * * @return a new hidden cursor// w w w . ja v a2s.com */ private Cursor createHiddenCursor() { Toolkit toolkit = Toolkit.getDefaultToolkit(); Dimension size = toolkit.getBestCursorSize(1, 1); BufferedImage image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = image.createGraphics(); graphics.setBackground(new Color(0.0f, 0.0f, 0.0f, 0.0f)); graphics.clearRect(0, 0, size.width, size.height); graphics.dispose(); return toolkit.createCustomCursor(image, new Point(0, 0), "hiddenCursor"); }
From source file:pl.edu.icm.visnow.geometries.viewer3d.Display3DPanel.java
private void initializeOnceCrosshairCursor() { if (crosshairCursor == null) { Toolkit toolkit = Toolkit.getDefaultToolkit(); BufferedImage crosshairCursorImage = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB); int[] crosshairCursorRaster = new int[32 * 32]; for (int i = 0; i < crosshairCursorRaster.length; i++) { crosshairCursorRaster[i] = 0; }//w ww .jav a2s. c o m for (int i = 0; i < 14; i++) { crosshairCursorRaster[15 * 32 + i] = crosshairCursorRaster[15 * 32 + 31 - i] = 0xff888888; crosshairCursorRaster[15 + 32 * i] = crosshairCursorRaster[15 + 32 * (31 - i)] = 0xff888888; } crosshairCursorImage.setRGB(0, 0, 32, 32, crosshairCursorRaster, 0, 32); crosshairCursor = toolkit.createCustomCursor(crosshairCursorImage, new Point(15, 15), "crosshairCursor"); } }