Search in sources :

Example 21 with DisplayMode

use of java.awt.DisplayMode 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 22 with DisplayMode

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

the class NoResizeEventOnDMChangeTest method main.

public static void main(String[] args) {
    final GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    if (!gd.isFullScreenSupported()) {
        System.out.println("Full screen not supported, test passed");
        return;
    }
    DisplayMode dm = gd.getDisplayMode();
    final DisplayMode[] dms = new DisplayMode[2];
    for (DisplayMode dm1 : gd.getDisplayModes()) {
        if (dm1.getWidth() != dm.getWidth() || dm1.getHeight() != dm.getHeight()) {
            dms[0] = dm1;
            break;
        }
    }
    if (dms[0] == null) {
        System.out.println("Test Passed: all DMs have same dimensions");
        return;
    }
    dms[1] = dm;
    Frame f = new Frame() {

        @Override
        public void paint(Graphics g) {
            g.setColor(Color.red);
            g.fillRect(0, 0, getWidth(), getHeight());
            g.setColor(Color.green);
            g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
        }
    };
    f.setUndecorated(true);
    testFSWindow(gd, dms, f);
    Window w = new Window(f) {

        @Override
        public void paint(Graphics g) {
            g.setColor(Color.magenta);
            g.fillRect(0, 0, getWidth(), getHeight());
            g.setColor(Color.cyan);
            g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
        }
    };
    testFSWindow(gd, dms, w);
    System.out.println("Test Passed.");
}
Also used : DisplayMode(java.awt.DisplayMode) Graphics(java.awt.Graphics) Window(java.awt.Window) Frame(java.awt.Frame) GraphicsDevice(java.awt.GraphicsDevice)

Example 23 with DisplayMode

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

the class DisplayChangeVITest method run.

public void run() {
    GraphicsDevice gd = getGraphicsConfiguration().getDevice();
    if (gd.isDisplayChangeSupported() && dms.size() > 0) {
        while (!done && reps++ < TEST_REPS) {
            for (DisplayMode dm : dms) {
                System.err.printf("Entering DisplayMode[%dx%dx%d]\n", dm.getWidth(), dm.getHeight(), dm.getBitDepth());
                gd.setDisplayMode(dm);
                initBackbuffer();
                for (int i = 0; i < 10; i++) {
                    // render to the screen
                    render(getGraphics());
                    // ask Swing to repaint
                    repaint();
                    sleep(100);
                }
                sleep(1500);
            }
        }
    } else {
        System.err.println("Display mode change " + "not supported. Test passed.");
    }
    dispose();
    synchronized (lock) {
        done = true;
        lock.notify();
    }
}
Also used : DisplayMode(java.awt.DisplayMode) GraphicsDevice(java.awt.GraphicsDevice)

Example 24 with DisplayMode

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

the class Win32GraphicsDevice method getDisplayModes.

@Override
public synchronized DisplayMode[] getDisplayModes() {
    ArrayList modes = new ArrayList();
    enumDisplayModes(screen, modes);
    int listSize = modes.size();
    DisplayMode[] retArray = new DisplayMode[listSize];
    for (int i = 0; i < listSize; i++) {
        retArray[i] = (DisplayMode) modes.get(i);
    }
    return retArray;
}
Also used : DisplayMode(java.awt.DisplayMode) ArrayList(java.util.ArrayList)

Example 25 with DisplayMode

use of java.awt.DisplayMode 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)

Aggregations

DisplayMode (java.awt.DisplayMode)31 GraphicsDevice (java.awt.GraphicsDevice)20 GraphicsEnvironment (java.awt.GraphicsEnvironment)9 Dimension (java.awt.Dimension)6 Frame (java.awt.Frame)4 ArrayList (java.util.ArrayList)4 LionEngineException (com.b3dgs.lionengine.LionEngineException)3 Graphics (java.awt.Graphics)3 Rectangle (java.awt.Rectangle)3 Component (java.awt.Component)2 Point (java.awt.Point)2 Robot (java.awt.Robot)2 Window (java.awt.Window)2 WindowAdapter (java.awt.event.WindowAdapter)2 WindowEvent (java.awt.event.WindowEvent)2 BufferedImage (java.awt.image.BufferedImage)2 Config (com.b3dgs.lionengine.Config)1 Resolution (com.b3dgs.lionengine.Resolution)1 AWTException (java.awt.AWTException)1 Button (java.awt.Button)1