List of usage examples for java.awt GraphicsEnvironment getLocalGraphicsEnvironment
public static GraphicsEnvironment getLocalGraphicsEnvironment()
From source file:Main.java
public static int getMonitor(Component c) { Window w = (c instanceof Window) ? (Window) c : SwingUtilities.windowForComponent(c); GraphicsConfiguration gc = (w == null) ? null : w.getGraphicsConfiguration(); GraphicsDevice gd = (gc == null) ? null : gc.getDevice(); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gs = ge.getScreenDevices(); for (int i = 0; i < gs.length; i++) { if (gs[i].equals(gd)) { return i; }// ww w . jav a2 s . c o m } return -1; }
From source file:DrawStringDemo.java
public void paint(Graphics g) { Graphics2D graphics2D = (Graphics2D) g; GraphicsEnvironment.getLocalGraphicsEnvironment(); Font font = new Font("LucidaSans", Font.PLAIN, 40); graphics2D.setFont(font);/* w w w. j a va 2 s . c o m*/ graphics2D.drawString(message, 50, 75); }
From source file:JTextAreaDemo.java
public JTextAreaDemo() { super("JTextAreaDemo"); GraphicsEnvironment.getLocalGraphicsEnvironment(); Font font = new Font("LucidaSans", Font.PLAIN, 40); JTextArea textArea = new JTextArea(davidMessage + andyMessage); textArea.setFont(font);/*w w w . j av a 2 s . c o m*/ this.getContentPane().add(textArea); textArea.show(); }
From source file:Main.java
public static boolean isLocalDisplay() { boolean isLocal; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); if (ge instanceof SunGraphicsEnvironment) { isLocal = ((SunGraphicsEnvironment) ge).isDisplayLocal(); } else {/*from w w w .ja va2 s. c om*/ isLocal = true; } return isLocal; }
From source file:AllAvailableFontsComboBox.java
public AllAvailableFontsComboBox() { add(new JLabel("Fonts")); GraphicsEnvironment gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment(); String envfonts[] = gEnv.getAvailableFontFamilyNames(); Vector vector = new Vector(); for (int i = 1; i < envfonts.length; i++) { vector.addElement(envfonts[i]);/* w w w . j a v a 2 s .c om*/ } fonts = new JComboBox(vector); add(fonts); }
From source file:Main.java
/** * Takes a snapshot of the target component. * * @param component the component to draw * @param usePrint whether <tt>print()</tt> or <tt>paint()</tt> is used to grab the snapshot * @return a Graphics compatible image of the component *//*from ww w. j av a2 s . c om*/ public static Image takeSnapshot(Component component, boolean usePrint) { BufferedImage image = null; GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = genv.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); if (gc.getColorModel().hasAlpha()) { image = gc.createCompatibleImage((int) component.getSize().getWidth(), (int) component.getSize().getHeight()); } else { image = new BufferedImage((int) component.getSize().getWidth(), (int) component.getSize().getHeight(), BufferedImage.TYPE_INT_ARGB); } Graphics g = image.getGraphics(); if (usePrint) { component.print(g); } else { component.paint(g); } g.dispose(); return image; }
From source file:Main.java
/** * Create a custom cursor out of the specified image, with the specified hotspot. *//* w w w. j a v a2 s .c om*/ 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:PaintAllFontsFromGraphicEvironment.java
public void paint(Graphics g) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); Font[] allFonts = ge.getAllFonts(); for (int i = 0; i < allFonts.length; i++) { Font f = allFonts[i].deriveFont(10.0f); g.setFont(f);/* w w w . jav a 2s . c o m*/ g.setColor(Color.black); g.drawString("Hello!", 10, 20 * i); } }
From source file:TextLayoutLineBreakerMeasurer.java
public void paint(Graphics g) { Graphics2D graphics2D = (Graphics2D) g; GraphicsEnvironment.getLocalGraphicsEnvironment(); Font font = new Font("LucidaSans", Font.PLAIN, 14); AttributedString messageAS = new AttributedString(m); messageAS.addAttribute(TextAttribute.FONT, font); AttributedCharacterIterator messageIterator = messageAS.getIterator(); FontRenderContext messageFRC = graphics2D.getFontRenderContext(); LineBreakMeasurer messageLBM = new LineBreakMeasurer(messageIterator, messageFRC); Insets insets = getInsets();//from w w w . j a va2s .co m float wrappingWidth = getSize().width - insets.left - insets.right; float x = insets.left; float y = insets.top; while (messageLBM.getPosition() < messageIterator.getEndIndex()) { TextLayout textLayout = messageLBM.nextLayout(wrappingWidth); y += textLayout.getAscent(); textLayout.draw(graphics2D, x, y); y += textLayout.getDescent() + textLayout.getLeading(); x = insets.left; } }
From source file:Main.java
public static GraphicsDevice getCurrentScreen(Point location, Dimension size) { GraphicsDevice[] devices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices(); GraphicsDevice bestMatch = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); float bestPercentage = 0; for (GraphicsDevice device : devices) { Rectangle bounds = device.getDefaultConfiguration().getBounds(); float percentage = getPercentageOnScreen(location, size, bounds); if (percentage > bestPercentage) { bestMatch = device;// www . java 2 s. c o m bestPercentage = percentage; } } return bestMatch; }