Search in sources :

Example 66 with GraphicsDevice

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

the class CheckDisplayModes method main.

public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice graphicDevice = ge.getDefaultScreenDevice();
    if (!graphicDevice.isDisplayChangeSupported()) {
        System.err.println("Display mode change is not supported on this host. Test is considered passed.");
        return;
    }
    DisplayMode defaultDisplayMode = graphicDevice.getDisplayMode();
    checkDisplayMode(defaultDisplayMode);
    graphicDevice.setDisplayMode(defaultDisplayMode);
    DisplayMode[] displayModes = graphicDevice.getDisplayModes();
    boolean isDefaultDisplayModeIncluded = false;
    for (DisplayMode displayMode : displayModes) {
        checkDisplayMode(displayMode);
        graphicDevice.setDisplayMode(displayMode);
        if (defaultDisplayMode.equals(displayMode)) {
            isDefaultDisplayModeIncluded = true;
        }
    }
    if (!isDefaultDisplayModeIncluded) {
        throw new RuntimeException("Default display mode is not included");
    }
}
Also used : DisplayMode(java.awt.DisplayMode) GraphicsDevice(java.awt.GraphicsDevice) GraphicsEnvironment(java.awt.GraphicsEnvironment)

Example 67 with GraphicsDevice

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

the class WindowGCInFullScreen method main.

public static void main(final String[] args) throws InvocationTargetException, InterruptedException {
    SwingUtilities.invokeAndWait(() -> {
        final GraphicsDevice[] devices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
        final Frame frame = new Frame();
        frame.setBackground(Color.GREEN);
        frame.setUndecorated(true);
        frame.setSize(100, 100);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        sleep();
        for (final GraphicsDevice gd : devices) {
            try {
                gd.setFullScreenWindow(frame);
                if (gd.getFullScreenWindow() != frame) {
                    throw new RuntimeException("Wrong window");
                }
                if (frame.getGraphicsConfiguration().getDevice() != gd) {
                    throw new RuntimeException("Wrong new GraphicsDevice");
                }
            } finally {
                // cleaning up
                gd.setFullScreenWindow(null);
            }
        }
        frame.dispose();
    });
}
Also used : Frame(java.awt.Frame) GraphicsDevice(java.awt.GraphicsDevice)

Example 68 with GraphicsDevice

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

the class X11GraphicsEnvironment method getXineramaWindowBounds.

/**
     * Return the bounds for a centered Window on a system running in Xinerama
     * mode.
     *
     * Calculations are based on the assumption of a perfectly rectangular
     * display area (display edges line up with one another, and displays
     * have consistent width and/or height).
     *
     * The bounds to return depend on the arrangement of displays and on where
     * Windows are to be centered.  There are two common situations:
     *
     * 1) The center point lies at the center of the combined area of all the
     *    displays.  In this case, the combined area of all displays is
     *    returned.
     *
     * 2) The center point lies at the center of a single display.  In this case
     *    the user most likely wants centered Windows to be constrained to that
     *    single display.  The boundaries of the one display are returned.
     *
     * It is possible for the center point to be at both the center of the
     * entire display space AND at the center of a single monitor (a square of
     * 9 monitors, for instance).  In this case, the entire display area is
     * returned.
     *
     * Because the center point is arbitrarily settable by the user, it could
     * fit neither of the cases above.  The fallback case is to simply return
     * the combined area for all screens.
     */
protected Rectangle getXineramaWindowBounds() {
    Point center = getCenterPoint();
    Rectangle unionRect, tempRect;
    GraphicsDevice[] gds = getScreenDevices();
    Rectangle centerMonitorRect = null;
    int i;
    // if center point is at the center of all monitors
    // return union of all bounds
    //
    //  MM*MM     MMM       M
    //            M*M       *
    //            MMM       M
    // if center point is at center of a single monitor (but not of all
    // monitors)
    // return bounds of single monitor
    //
    // MMM         MM
    // MM*         *M
    // else, center is in some strange spot (such as on the border between
    // monitors), and we should just return the union of all monitors
    //
    // MM          MMM
    // MM          MMM
    unionRect = getUsableBounds(gds[0]);
    for (i = 0; i < gds.length; i++) {
        tempRect = getUsableBounds(gds[i]);
        if (centerMonitorRect == null && // add a pixel or two for fudge-factor
        (tempRect.width / 2) + tempRect.x > center.x - 1 && (tempRect.height / 2) + tempRect.y > center.y - 1 && (tempRect.width / 2) + tempRect.x < center.x + 1 && (tempRect.height / 2) + tempRect.y < center.y + 1) {
            centerMonitorRect = tempRect;
        }
        unionRect = unionRect.union(tempRect);
    }
    // add a pixel or two for fudge-factor
    if ((unionRect.width / 2) + unionRect.x > center.x - 1 && (unionRect.height / 2) + unionRect.y > center.y - 1 && (unionRect.width / 2) + unionRect.x < center.x + 1 && (unionRect.height / 2) + unionRect.y < center.y + 1) {
        if (screenLog.isLoggable(PlatformLogger.Level.FINER)) {
            screenLog.finer("Video Wall: center point is at center of all displays.");
        }
        return unionRect;
    }
    // next, check if at center of one monitor
    if (centerMonitorRect != null) {
        if (screenLog.isLoggable(PlatformLogger.Level.FINER)) {
            screenLog.finer("Center point at center of a particular " + "monitor, but not of the entire virtual display.");
        }
        return centerMonitorRect;
    }
    // otherwise, the center is at some weird spot: return unionRect
    if (screenLog.isLoggable(PlatformLogger.Level.FINER)) {
        screenLog.finer("Center point is somewhere strange - return union of all bounds.");
    }
    return unionRect;
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) Rectangle(java.awt.Rectangle) Point(java.awt.Point) Point(java.awt.Point)

Example 69 with GraphicsDevice

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

the class WGLSurfaceData method getGC.

public static WGLGraphicsConfig getGC(WComponentPeer peer) {
    if (peer != null) {
        return (WGLGraphicsConfig) peer.getGraphicsConfiguration();
    } else {
        // REMIND: this should rarely (never?) happen, but what if
        //         default config is not WGL?
        GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gd = env.getDefaultScreenDevice();
        return (WGLGraphicsConfig) gd.getDefaultConfiguration();
    }
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) Win32GraphicsDevice(sun.awt.Win32GraphicsDevice) GraphicsEnvironment(java.awt.GraphicsEnvironment)

Example 70 with GraphicsDevice

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

the class D3DSurfaceData method getGC.

private static D3DGraphicsConfig getGC(WComponentPeer peer) {
    GraphicsConfiguration gc;
    if (peer != null) {
        gc = peer.getGraphicsConfiguration();
    } else {
        GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gd = env.getDefaultScreenDevice();
        gc = gd.getDefaultConfiguration();
    }
    return (gc instanceof D3DGraphicsConfig) ? (D3DGraphicsConfig) gc : null;
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) GraphicsEnvironment(java.awt.GraphicsEnvironment) GraphicsConfiguration(java.awt.GraphicsConfiguration)

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