Search in sources :

Example 66 with GraphicsEnvironment

use of java.awt.GraphicsEnvironment in project processing by processing.

the class PApplet method displayDensity.

/**
  * @param display the display number to check
  */
public static int displayDensity(int display) {
    if (PApplet.platform == PConstants.MACOSX) {
        // This should probably be reset each time there's a display change.
        // A 5-minute search didn't turn up any such event in the Java 7 API.
        // Also, should we use the Toolkit associated with the editor window?
        final String javaVendor = System.getProperty("java.vendor");
        if (javaVendor.contains("Oracle")) {
            GraphicsDevice device;
            GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
            if (display == -1) {
                device = env.getDefaultScreenDevice();
            } else if (display == SPAN) {
                throw new RuntimeException("displayDensity() only works with specific display numbers");
            } else {
                GraphicsDevice[] devices = env.getScreenDevices();
                if (display > 0 && display <= devices.length) {
                    device = devices[display - 1];
                } else {
                    if (devices.length == 1) {
                        System.err.println("Only one display is currently known, use displayDensity(1).");
                    } else {
                        System.err.format("Your displays are numbered %d through %d, " + "pass one of those numbers to displayDensity()%n", 1, devices.length);
                    }
                    throw new RuntimeException("Display " + display + " does not exist.");
                }
            }
            try {
                Field field = device.getClass().getDeclaredField("scale");
                if (field != null) {
                    field.setAccessible(true);
                    Object scale = field.get(device);
                    if (scale instanceof Integer && ((Integer) scale).intValue() == 2) {
                        return 2;
                    }
                }
            } catch (Exception ignore) {
            }
        }
    }
    return 1;
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) GraphicsEnvironment(java.awt.GraphicsEnvironment) HeadlessException(java.awt.HeadlessException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 67 with GraphicsEnvironment

use of java.awt.GraphicsEnvironment in project screenbird by adamhub.

the class ScreenUtil method isDualScreen.

/**
     * Checks for presence of multiple screens/monitors on the current computer.
     * @return True if more than one screen is detected.
     */
public static boolean isDualScreen() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] screens = ge.getScreenDevices();
    return screens.length > 1;
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) GraphicsEnvironment(java.awt.GraphicsEnvironment)

Example 68 with GraphicsEnvironment

use of java.awt.GraphicsEnvironment in project pcgen by PCGen.

the class Main method initPrintPreviewFonts.

private static void initPrintPreviewFonts() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String fontDir = ConfigurationSettings.getOutputSheetsDir() + File.separator + "fonts" + File.separator + "NotoSans" + File.separator;
    try {
        ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontDir + "NotoSans-Regular.ttf")));
        ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontDir + "NotoSans-Bold.ttf")));
        ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontDir + "NotoSans-Italic.ttf")));
        ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontDir + "NotoSans-BoldItalic.ttf")));
    } catch (IOException | FontFormatException ex) {
        Logging.errorPrint("Unexpected exception loading fonts fo print p", ex);
    }
}
Also used : IOException(java.io.IOException) GraphicsEnvironment(java.awt.GraphicsEnvironment) File(java.io.File) FontFormatException(java.awt.FontFormatException)

Example 69 with GraphicsEnvironment

use of java.awt.GraphicsEnvironment in project jdk8u_jdk by JetBrains.

the class MaximizedToMaximized method main.

public static void main(String[] args) throws Exception {
    Frame frame = new Frame();
    final Toolkit toolkit = Toolkit.getDefaultToolkit();
    final GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final GraphicsDevice graphicsDevice = graphicsEnvironment.getDefaultScreenDevice();
    final Dimension screenSize = toolkit.getScreenSize();
    final Insets screenInsets = toolkit.getScreenInsets(graphicsDevice.getDefaultConfiguration());
    final Rectangle availableScreenBounds = new Rectangle(screenSize);
    availableScreenBounds.x += screenInsets.left;
    availableScreenBounds.y += screenInsets.top;
    availableScreenBounds.width -= (screenInsets.left + screenInsets.right);
    availableScreenBounds.height -= (screenInsets.top + screenInsets.bottom);
    frame.setBounds(availableScreenBounds.x, availableScreenBounds.y, availableScreenBounds.width, availableScreenBounds.height);
    frame.setVisible(true);
    Rectangle frameBounds = frame.getBounds();
    frame.setExtendedState(Frame.MAXIMIZED_BOTH);
    ((SunToolkit) toolkit).realSync();
    Rectangle maximizedFrameBounds = frame.getBounds();
    if (maximizedFrameBounds.width < frameBounds.width || maximizedFrameBounds.height < frameBounds.height) {
        throw new RuntimeException("Maximized frame is smaller than non maximized");
    }
}
Also used : Frame(java.awt.Frame) GraphicsDevice(java.awt.GraphicsDevice) Insets(java.awt.Insets) Rectangle(java.awt.Rectangle) SunToolkit(sun.awt.SunToolkit) SunToolkit(sun.awt.SunToolkit) Toolkit(java.awt.Toolkit) Dimension(java.awt.Dimension) GraphicsEnvironment(java.awt.GraphicsEnvironment)

Example 70 with GraphicsEnvironment

use of java.awt.GraphicsEnvironment in project jdk8u_jdk by JetBrains.

the class TextRenderingTest method main.

public static void main(final String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    VolatileImage vi = gc.createCompatibleVolatileImage(width, height);
    while (true) {
        vi.validate(gc);
        Graphics2D g2d = vi.createGraphics();
        g2d.setColor(Color.white);
        g2d.fillRect(0, 0, width, height);
        g2d.setPaint(new GradientPaint(new Point2D.Float(0, height / 2), Color.white, new Point2D.Float(width, height / 2), Color.black));
        g2d.fillRect(0, 0, width, height);
        String fnt = g2d.getFont().getFamily();
        g2d.setFont(new Font(fnt, Font.PLAIN, 100));
        // draw text with offset
        g2d.drawString("IIIIIIIIII", 100, 100);
        g2d.dispose();
        if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
            }
            continue;
        }
        if (vi.contentsLost()) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
            }
            continue;
        }
        break;
    }
    BufferedImage bi = vi.getSnapshot();
    // the text shifted shouldn't be visible onto a painted rectangle!
    // so the check: color component (blue) must decrease monotonously
    int prev = Integer.MAX_VALUE;
    for (int x = 0; x < width; ++x) {
        int color = bi.getRGB(x, height / 2);
        int b = color & 0xFF;
        if (b > prev) {
            throw new RuntimeException("test failed: can see the text rendered!");
        }
        prev = b;
    }
}
Also used : VolatileImage(java.awt.image.VolatileImage) GradientPaint(java.awt.GradientPaint) GraphicsEnvironment(java.awt.GraphicsEnvironment) Font(java.awt.Font) BufferedImage(java.awt.image.BufferedImage) GradientPaint(java.awt.GradientPaint) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D)

Aggregations

GraphicsEnvironment (java.awt.GraphicsEnvironment)93 GraphicsDevice (java.awt.GraphicsDevice)46 GraphicsConfiguration (java.awt.GraphicsConfiguration)44 BufferedImage (java.awt.image.BufferedImage)24 VolatileImage (java.awt.image.VolatileImage)21 Dimension (java.awt.Dimension)17 Graphics2D (java.awt.Graphics2D)17 Point (java.awt.Point)12 Font (java.awt.Font)11 Rectangle (java.awt.Rectangle)11 Insets (java.awt.Insets)7 File (java.io.File)7 Frame (java.awt.Frame)6 Toolkit (java.awt.Toolkit)6 AffineTransform (java.awt.geom.AffineTransform)6 HeadlessException (java.awt.HeadlessException)5 Color (java.awt.Color)3 Container (java.awt.Container)3 DisplayMode (java.awt.DisplayMode)3 GradientPaint (java.awt.GradientPaint)3