Search in sources :

Example 56 with GraphicsDevice

use of java.awt.GraphicsDevice 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 57 with GraphicsDevice

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

the class AltTabCrashTest method findDisplayMode.

private DisplayMode findDisplayMode() {
    GraphicsDevice gd = getGraphicsConfiguration().getDevice();
    DisplayMode[] dms = gd.getDisplayModes();
    DisplayMode currentDM = gd.getDisplayMode();
    for (DisplayMode dm : dms) {
        if (dm.getBitDepth() > 8 && dm.getBitDepth() != DisplayMode.BIT_DEPTH_MULTI && dm.getBitDepth() != currentDM.getBitDepth() && dm.getWidth() == currentDM.getWidth() && dm.getHeight() == currentDM.getHeight()) {
            // depth
            return dm;
        }
        if (dm.getBitDepth() == DisplayMode.BIT_DEPTH_MULTI && (dm.getWidth() != currentDM.getWidth() || dm.getHeight() != currentDM.getHeight())) {
            // dimensions
            return dm;
        }
    }
    return null;
}
Also used : DisplayMode(java.awt.DisplayMode) GraphicsDevice(java.awt.GraphicsDevice)

Example 58 with GraphicsDevice

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

the class BufferStrategyExceptionTest method main.

public static void main(String[] args) {
    GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    for (int i = 0; i < TEST_REPS; i++) {
        TestFrame f = new TestFrame();
        f.pack();
        f.setSize(400, 400);
        f.setVisible(true);
        if (i % 2 == 0) {
            gd.setFullScreenWindow(f);
        }
        // generate a resize event which will invalidate the peer's
        // surface data and hopefully cause an exception during
        // BufferStrategy creation in TestFrame.render()
        Dimension d = f.getSize();
        d.width -= 5;
        d.height -= 5;
        f.setSize(d);
        f.render();
        gd.setFullScreenWindow(null);
        sleep(100);
        f.dispose();
    }
    System.out.println("Test passed.");
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) Dimension(java.awt.Dimension)

Example 59 with GraphicsDevice

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

the class DisplayChangeVITest method selectDisplayModes.

private void selectDisplayModes() {
    GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    dms = new ArrayList<DisplayMode>();
    DisplayMode[] dmArray = gd.getDisplayModes();
    boolean found8 = false, found16 = false, found24 = false, found32 = false;
    for (DisplayMode dm : dmArray) {
        if (!found8 && (dm.getBitDepth() == 8 || dm.getBitDepth() == DisplayMode.BIT_DEPTH_MULTI) && (dm.getWidth() >= 800 && dm.getWidth() < 1024)) {
            dms.add(dm);
            found8 = true;
            continue;
        }
        if (!found32 && (dm.getBitDepth() == 32 || dm.getBitDepth() == DisplayMode.BIT_DEPTH_MULTI) && dm.getWidth() >= 1280) {
            dms.add(dm);
            found32 = true;
            continue;
        }
        if (!found16 && dm.getBitDepth() == 16 && (dm.getWidth() >= 1024 && dm.getWidth() < 1280)) {
            dms.add(dm);
            found16 = true;
            continue;
        }
        if (found8 && found16 && found32) {
            break;
        }
    }
    System.err.println("Found display modes:");
    for (DisplayMode dm : dms) {
        System.err.printf("DisplayMode[%dx%dx%d]\n", dm.getWidth(), dm.getHeight(), dm.getBitDepth());
    }
}
Also used : DisplayMode(java.awt.DisplayMode) GraphicsDevice(java.awt.GraphicsDevice)

Example 60 with GraphicsDevice

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

the class DisplayChangeVITest method main.

public static void main(String[] args) throws Exception {
    DisplayChangeVITest test = new DisplayChangeVITest();
    GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    if (gd.isFullScreenSupported()) {
        gd.setFullScreenWindow(test);
        Thread t = new Thread(test);
        t.run();
        synchronized (lock) {
            while (!done) {
                try {
                    lock.wait(50);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
            }
        }
        System.err.println("Test Passed.");
    } else {
        System.err.println("Full screen not supported. Test passed.");
    }
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) Thread(java.lang.Thread)

Aggregations

GraphicsDevice (java.awt.GraphicsDevice)80 GraphicsEnvironment (java.awt.GraphicsEnvironment)46 GraphicsConfiguration (java.awt.GraphicsConfiguration)25 Point (java.awt.Point)17 Dimension (java.awt.Dimension)15 Frame (java.awt.Frame)13 DisplayMode (java.awt.DisplayMode)12 Rectangle (java.awt.Rectangle)11 Graphics (java.awt.Graphics)7 Insets (java.awt.Insets)7 Toolkit (java.awt.Toolkit)7 BufferedImage (java.awt.image.BufferedImage)7 HeadlessException (java.awt.HeadlessException)5 Window (java.awt.Window)4 JFrame (javax.swing.JFrame)4 Test (org.junit.Test)4 MouseAdapter (java.awt.event.MouseAdapter)3 WindowAdapter (java.awt.event.WindowAdapter)3 WindowEvent (java.awt.event.WindowEvent)3 VolatileImage (java.awt.image.VolatileImage)3