Search in sources :

Example 71 with GraphicsDevice

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

the class bug8071705 method checkConfigs.

private static GraphicsDevice checkConfigs(GraphicsDevice[] devices) {
    GraphicsDevice correctDevice = null;
    if (devices.length < 2) {
        return correctDevice;
    }
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Rectangle screenBounds = new Rectangle(toolkit.getScreenSize());
    int halfScreen = screenBounds.height / 2;
    for (int i = 0; i < devices.length; i++) {
        if (devices[i].getType() == GraphicsDevice.TYPE_RASTER_SCREEN) {
            GraphicsConfiguration conf = devices[i].getDefaultConfiguration();
            Rectangle bounds = conf.getBounds();
            if (bounds.y >= halfScreen) {
                // found
                correctDevice = devices[i];
                break;
            }
        }
    }
    return correctDevice;
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) Rectangle(java.awt.Rectangle) Toolkit(java.awt.Toolkit) Point(java.awt.Point) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 72 with GraphicsDevice

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

the class StrikeDisposalCrashTest method main.

public static void main(String[] args) {
    System.setProperty("sun.java2d.font.reftype", "weak");
    GraphicsDevice[] gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
    Frame[] frames = new Frame[gd.length];
    for (int i = 0; i < frames.length; i++) {
        GraphicsConfiguration gc = gd[i].getDefaultConfiguration();
        Frame f = new Frame("Frame on " + gc, gc);
        f.setSize(100, 100);
        f.setLocation(gc.getBounds().x, gc.getBounds().y);
        f.pack();
        frames[i] = f;
    }
    Font f1 = new Font("Dialog", Font.PLAIN, 10);
    Font f2 = new Font("Dialog", Font.ITALIC, 12);
    for (int i = 0; i < frames.length / 2; i++) {
        // making sure the glyphs are cached in the accel. cache on
        // one frame, then the other
        renderText(frames[i], f1);
        renderText(frames[frames.length - 1 - i], f1);
        // and now the other way around, with different glyphs
        renderText(frames[frames.length - 1 - i], f2);
        renderText(frames[i], f2);
    }
    // try to force strike disposal (note that we have to use
    // -Dsun.java2d.font.reftype=weak to facilitate the disposal)
    System.gc();
    System.runFinalization();
    System.gc();
    System.runFinalization();
    for (Frame f : frames) {
        f.dispose();
    }
    System.err.println("Exiting. If the test crashed after this it FAILED");
}
Also used : Frame(java.awt.Frame) GraphicsDevice(java.awt.GraphicsDevice) Font(java.awt.Font) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 73 with GraphicsDevice

use of java.awt.GraphicsDevice in project JMRI by JMRI.

the class ReportContext method addScreenSize.

/**
     * Provide screen - size information. This is based on the
     * jmri.util.JmriJFrame calculation, but isn't refactored to there because
     * we also want diagnostic info
     */
public void addScreenSize() {
    try {
        // Find screen size. This throws null-pointer exceptions on
        // some Java installs, however, for unknown reasons, so be
        // prepared to fall back.
        JFrame dummy = new JFrame();
        try {
            Insets insets = dummy.getToolkit().getScreenInsets(dummy.getGraphicsConfiguration());
            Dimension screen = dummy.getToolkit().getScreenSize();
            addString("Screen size h:" + screen.height + ", w:" + screen.width + " Inset t:" + insets.top + ", b:" + insets.bottom + "; l:" + insets.left + ", r:" + insets.right);
        } catch (NoSuchMethodError ex) {
            Dimension screen = dummy.getToolkit().getScreenSize();
            addString("Screen size h:" + screen.height + ", w:" + screen.width + " (No Inset method available)");
        }
    } catch (HeadlessException ex) {
        // failed, fall back to standard method
        addString("(Cannot sense screen size due to " + ex.toString() + ")");
    }
    try {
        // Find screen resolution. Not expected to fail, but just in case....
        int dpi = Toolkit.getDefaultToolkit().getScreenResolution();
        addString("Screen resolution: " + dpi);
    } catch (HeadlessException ex) {
        addString("Screen resolution not available");
    }
    //Rectangle virtualBounds = new Rectangle();
    try {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        addString("Environment max bounds: " + ge.getMaximumWindowBounds());
        try {
            GraphicsDevice[] gs = ge.getScreenDevices();
            for (GraphicsDevice gd : gs) {
                GraphicsConfiguration[] gc = gd.getConfigurations();
                for (int i = 0; i < gc.length; i++) {
                    addString("bounds[" + i + "] = " + gc[i].getBounds());
                // virtualBounds = virtualBounds.union(gc[i].getBounds());
                }
                addString("Device: " + gd.getIDstring() + " bounds = " + gd.getDefaultConfiguration().getBounds() + " " + gd.getDefaultConfiguration().toString());
            }
        } catch (HeadlessException ex) {
            addString("Exception getting device bounds " + ex.getMessage());
        }
    } catch (HeadlessException ex) {
        addString("Exception getting max window bounds " + ex.getMessage());
    }
    // various Linux window managers
    try {
        Insets jmriInsets = JmriInsets.getInsets();
        addString("JmriInsets t:" + jmriInsets.top + ", b:" + jmriInsets.bottom + "; l:" + jmriInsets.left + ", r:" + jmriInsets.right);
    } catch (Exception ex) {
        addString("Exception getting JmriInsets" + ex.getMessage());
    }
}
Also used : Insets(java.awt.Insets) JmriInsets(jmri.util.JmriInsets) GraphicsDevice(java.awt.GraphicsDevice) HeadlessException(java.awt.HeadlessException) JFrame(javax.swing.JFrame) Dimension(java.awt.Dimension) GraphicsEnvironment(java.awt.GraphicsEnvironment) SocketException(java.net.SocketException) HeadlessException(java.awt.HeadlessException) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 74 with GraphicsDevice

use of java.awt.GraphicsDevice in project jabref by JabRef.

the class WindowLocation method getVirtualBounds.

private Rectangle getVirtualBounds() {
    Rectangle bounds = new Rectangle(0, 0, 0, 0);
    GraphicsDevice[] devices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
    for (GraphicsDevice device : devices) {
        bounds.add(device.getDefaultConfiguration().getBounds());
    }
    return bounds;
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) Rectangle(java.awt.Rectangle)

Example 75 with GraphicsDevice

use of java.awt.GraphicsDevice in project karaf by apache.

the class ScreenshotDumpProvider method createDump.

/**
	 * {@inheritDoc}
	 */
public void createDump(DumpDestination destination) throws Exception {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    // get all graphic devices attached to computer
    GraphicsDevice[] gs = ge.getScreenDevices();
    // create dump entry for each device  
    for (int i = 0; i < gs.length; i++) {
        DisplayMode mode = gs[i].getDisplayMode();
        Rectangle bounds = new Rectangle(0, 0, mode.getWidth(), mode.getHeight());
        BufferedImage screenshot = new Robot(gs[i]).createScreenCapture(bounds);
        // to attach your entry to destination you have to execute this line
        OutputStream outputStream = destination.add("screenshot/display_" + i + ".png");
        ImageIO.write(screenshot, "PNG", outputStream);
        outputStream.close();
    }
}
Also used : DisplayMode(java.awt.DisplayMode) GraphicsDevice(java.awt.GraphicsDevice) OutputStream(java.io.OutputStream) Rectangle(java.awt.Rectangle) GraphicsEnvironment(java.awt.GraphicsEnvironment) Robot(java.awt.Robot) BufferedImage(java.awt.image.BufferedImage)

Aggregations

GraphicsDevice (java.awt.GraphicsDevice)75 GraphicsEnvironment (java.awt.GraphicsEnvironment)44 GraphicsConfiguration (java.awt.GraphicsConfiguration)23 Point (java.awt.Point)15 Frame (java.awt.Frame)13 Dimension (java.awt.Dimension)12 DisplayMode (java.awt.DisplayMode)12 Rectangle (java.awt.Rectangle)11 Insets (java.awt.Insets)7 Toolkit (java.awt.Toolkit)7 Graphics (java.awt.Graphics)6 BufferedImage (java.awt.image.BufferedImage)6 HeadlessException (java.awt.HeadlessException)4 Window (java.awt.Window)4 JFrame (javax.swing.JFrame)4 Test (org.junit.Test)4 MouseAdapter (java.awt.event.MouseAdapter)3 MouseEvent (java.awt.event.MouseEvent)3 WindowAdapter (java.awt.event.WindowAdapter)3 WindowEvent (java.awt.event.WindowEvent)3