Search in sources :

Example 1 with DisplayMode

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

the class MultimonFullscreenTest method actionPerformed.

public void actionPerformed(ActionEvent ae) {
    GraphicsDevice dev = deviceMap.get(ae.getSource());
    System.err.println("Setting FS on device:" + dev);
    final Window fsWindow;
    if (useFSWindow) {
        fsWindow = new Window(this, dev.getDefaultConfiguration()) {

            public void paint(Graphics g) {
                renderDimensions(g, getBounds(), this.getGraphicsConfiguration());
            }
        };
    } else if (useFSDialog) {
        fsWindow = new Dialog((Frame) null, "FS Dialog on device " + dev, false, dev.getDefaultConfiguration());
        fsWindow.add(new Component() {

            public void paint(Graphics g) {
                renderDimensions(g, getBounds(), this.getGraphicsConfiguration());
            }
        });
    } else {
        fsWindow = new Frame("FS Frame on device " + dev, dev.getDefaultConfiguration()) {

            public void paint(Graphics g) {
                renderDimensions(g, getBounds(), this.getGraphicsConfiguration());
            }
        };
        if (addHWChildren) {
            fsWindow.add("South", new Panel() {

                public void paint(Graphics g) {
                    g.setColor(Color.red);
                    g.fillRect(0, 0, getWidth(), getHeight());
                }
            });
            fsWindow.add("North", new Button("Button, sucka!"));
        }
    }
    fsWindow.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() > 1) {
                done = true;
                fsWindow.dispose();
            }
        }
    });
    fsWindow.addWindowListener(new WindowHandler());
    dev.setFullScreenWindow(fsWindow);
    if (dmChange && dev.isDisplayChangeSupported()) {
        DisplayMode[] dms = dev.getDisplayModes();
        DisplayMode myDM = null;
        for (DisplayMode dm : dms) {
            if (dm.getWidth() == 800 && dm.getHeight() == 600 && (dm.getBitDepth() >= 16 || dm.getBitDepth() == DisplayMode.BIT_DEPTH_MULTI) && (dm.getRefreshRate() >= 60 || dm.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN)) {
                myDM = dm;
                break;
            }
        }
        if (myDM != null) {
            System.err.println("Setting Display Mode: " + myDM.getWidth() + "x" + myDM.getHeight() + "x" + myDM.getBitDepth() + "@" + myDM.getRefreshRate() + "Hz on device" + dev);
            dev.setDisplayMode(myDM);
        } else {
            System.err.println("Can't find suitable display mode.");
        }
    }
    done = false;
    if (runRenderLoop) {
        Thread updateThread = new Thread(new Runnable() {

            public void run() {
                BufferStrategy bs = null;
                if (useBS) {
                    fsWindow.createBufferStrategy(2);
                    bs = fsWindow.getBufferStrategy();
                }
                while (!done) {
                    if (useBS) {
                        Graphics g = bs.getDrawGraphics();
                        renderDimensions(g, fsWindow.getBounds(), fsWindow.getGraphicsConfiguration());
                        bs.show();
                    } else {
                        fsWindow.repaint();
                    }
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                    }
                }
                if (useBS) {
                    bs.dispose();
                }
            }
        });
        updateThread.start();
    }
}
Also used : Window(java.awt.Window) Frame(java.awt.Frame) MouseEvent(java.awt.event.MouseEvent) BufferStrategy(java.awt.image.BufferStrategy) MouseAdapter(java.awt.event.MouseAdapter) Graphics(java.awt.Graphics) DisplayMode(java.awt.DisplayMode) Panel(java.awt.Panel) GraphicsDevice(java.awt.GraphicsDevice) Button(java.awt.Button) Dialog(java.awt.Dialog) Component(java.awt.Component)

Example 2 with DisplayMode

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

the class NoResizeEventOnDMChangeTest method testFSWindow.

private static void testFSWindow(final GraphicsDevice gd, final DisplayMode[] dms, final Window fsWin) {
    System.out.println("Testing FS window: " + fsWin);
    Component c = new Canvas() {

        @Override
        public void paint(Graphics g) {
            g.setColor(Color.blue);
            g.fillRect(0, 0, getWidth(), getHeight());
            g.setColor(Color.magenta);
            g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
            g.setColor(Color.red);
            g.drawString("FS Window   : " + fsWin, 50, 50);
            DisplayMode dm = getGraphicsConfiguration().getDevice().getDisplayMode();
            g.drawString("Display Mode: " + dm.getWidth() + "x" + dm.getHeight(), 50, 75);
        }
    };
    fsWin.add("Center", c);
    fsWin.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            fsWin.dispose();
            if (fsWin.getOwner() != null) {
                fsWin.getOwner().dispose();
            }
        }
    });
    try {
        EventQueue.invokeAndWait(new Runnable() {

            public void run() {
                gd.setFullScreenWindow(fsWin);
            }
        });
    } catch (Exception ex) {
    }
    sleep(1000);
    final ResizeEventChecker r1 = new ResizeEventChecker();
    final ResizeEventChecker r2 = new ResizeEventChecker();
    if (gd.isDisplayChangeSupported()) {
        fsWin.addComponentListener(r1);
        c.addComponentListener(r2);
        for (final DisplayMode dm1 : dms) {
            try {
                EventQueue.invokeAndWait(new Runnable() {

                    public void run() {
                        System.err.printf("----------- Setting DM %dx%d:\n", dm1.getWidth(), dm1.getHeight());
                        try {
                            gd.setDisplayMode(dm1);
                            r1.incDmChanges();
                            r2.incDmChanges();
                        } catch (IllegalArgumentException iae) {
                        }
                    }
                });
            } catch (Exception ex) {
            }
            for (int i = 0; i < 3; i++) {
                fsWin.repaint();
                sleep(1000);
            }
        }
        fsWin.removeComponentListener(r1);
        c.removeComponentListener(r2);
    }
    try {
        EventQueue.invokeAndWait(new Runnable() {

            public void run() {
                gd.setFullScreenWindow(null);
                fsWin.dispose();
                if (fsWin.getOwner() != null) {
                    fsWin.getOwner().dispose();
                }
            }
        });
    } catch (Exception ex) {
    }
    System.out.printf("FS Window: resizes=%d, dm changes=%d\n", r1.getResizes(), r1.getDmChanges());
    System.out.printf("Component: resizes=%d, dm changes=%d\n", r2.getResizes(), r2.getDmChanges());
    if (r1.getResizes() < r1.getDmChanges()) {
        throw new RuntimeException("FS Window didn't receive all resizes!");
    }
    if (r2.getResizes() < r2.getDmChanges()) {
        throw new RuntimeException("Component didn't receive all resizes!");
    }
}
Also used : Canvas(java.awt.Canvas) WindowAdapter(java.awt.event.WindowAdapter) Graphics(java.awt.Graphics) DisplayMode(java.awt.DisplayMode) WindowEvent(java.awt.event.WindowEvent) Component(java.awt.Component)

Example 3 with DisplayMode

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

the class DisplayModeChanger method main.

public static void main(String[] args) throws InterruptedException, InvocationTargetException {
    final GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    EventQueue.invokeAndWait(new Runnable() {

        public void run() {
            Frame f = null;
            if (gd.isFullScreenSupported()) {
                try {
                    f = new Frame("DisplayChanger Frame");
                    gd.setFullScreenWindow(f);
                    if (gd.isDisplayChangeSupported()) {
                        DisplayMode dm = findDisplayMode(gd);
                        if (gd != null) {
                            gd.setDisplayMode(dm);
                        }
                    }
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException ex) {
                        ex.printStackTrace();
                    }
                    gd.setFullScreenWindow(null);
                } finally {
                    if (f != null) {
                        f.dispose();
                    }
                }
            }
        }
    });
}
Also used : DisplayMode(java.awt.DisplayMode) Frame(java.awt.Frame) GraphicsDevice(java.awt.GraphicsDevice)

Example 4 with DisplayMode

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

the class DisplayModeChanger method findDisplayMode.

/**
     * Finds a display mode that is different from the current display
     * mode and is likely to cause a display change event.
     */
private static DisplayMode findDisplayMode(GraphicsDevice gd) {
    DisplayMode[] dms = gd.getDisplayModes();
    DisplayMode currentDM = gd.getDisplayMode();
    for (DisplayMode dm : dms) {
        if (!dm.equals(currentDM) && dm.getRefreshRate() == currentDM.getRefreshRate()) {
            // cause a DM change event
            return dm;
        }
    }
    return null;
}
Also used : DisplayMode(java.awt.DisplayMode)

Example 5 with DisplayMode

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

the class IncorrectDisplayModeExitFullscreen method main.

public static void main(final String[] args) {
    final GraphicsDevice[] devices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
    if (devices.length < 2 || devices[0].getDisplayModes().length < 2 || !devices[0].isFullScreenSupported() || !devices[1].isFullScreenSupported()) {
        System.err.println("Testcase is not applicable");
        return;
    }
    final DisplayMode defaultDM = devices[0].getDisplayMode();
    final DisplayMode[] dms = devices[0].getDisplayModes();
    DisplayMode nonDefaultDM = null;
    for (final DisplayMode dm : dms) {
        if (!dm.equals(defaultDM)) {
            nonDefaultDM = dm;
            break;
        }
    }
    if (nonDefaultDM == null) {
        System.err.println("Testcase is not applicable");
        return;
    }
    final Frame frame = new Frame();
    frame.setBackground(Color.GREEN);
    frame.setUndecorated(true);
    try {
        devices[0].setFullScreenWindow(frame);
        sleep();
        devices[0].setDisplayMode(nonDefaultDM);
        sleep();
        devices[1].setFullScreenWindow(frame);
        sleep();
        if (!defaultDM.equals(devices[0].getDisplayMode())) {
            throw new RuntimeException("DisplayMode is not restored");
        }
    } finally {
        // cleaning up
        devices[0].setFullScreenWindow(null);
        devices[1].setFullScreenWindow(null);
        frame.dispose();
    }
}
Also used : DisplayMode(java.awt.DisplayMode) Frame(java.awt.Frame) GraphicsDevice(java.awt.GraphicsDevice)

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