Search in sources :

Example 16 with GraphicsDevice

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

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

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

Example 19 with GraphicsDevice

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

the class CloneConfigsTest method main.

public static void main(String[] args) {
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] devices = env.getScreenDevices();
    GraphicsConfiguration c = new TestConfig();
    for (GraphicsDevice gd : devices) {
        System.out.println("Device: " + gd);
        GraphicsConfiguration[] configs = gd.getConfigurations();
        for (int i = 0; i < configs.length; i++) {
            GraphicsConfiguration gc = configs[i];
            System.out.println("\tConfig: " + gc);
            configs[i] = c;
        }
        // verify whether array of configs was modified
        configs = gd.getConfigurations();
        for (GraphicsConfiguration gc : configs) {
            if (gc == c) {
                throw new RuntimeException("Test failed.");
            }
        }
        System.out.println("Test passed.");
    }
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) GraphicsEnvironment(java.awt.GraphicsEnvironment) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 20 with GraphicsDevice

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

the class IncorrectAlphaConversionBicubic method main.

public static void main(final String[] args) {
    final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final GraphicsDevice gd = ge.getDefaultScreenDevice();
    final GraphicsConfiguration gc = gd.getDefaultConfiguration();
    final VolatileImage vi = gc.createCompatibleVolatileImage(SIZE, SIZE, TRANSLUCENT);
    final BufferedImage bi = makeUnmanagedBI(gc, TRANSLUCENT);
    final int expected = bi.getRGB(2, 2);
    int attempt = 0;
    BufferedImage snapshot;
    while (true) {
        if (++attempt > 10) {
            throw new RuntimeException("Too many attempts: " + attempt);
        }
        vi.validate(gc);
        final Graphics2D g2d = vi.createGraphics();
        g2d.setComposite(AlphaComposite.Src);
        g2d.scale(2, 2);
        g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        g2d.drawImage(bi, 0, 0, null);
        g2d.dispose();
        snapshot = vi.getSnapshot();
        if (vi.contentsLost()) {
            continue;
        }
        break;
    }
    final int actual = snapshot.getRGB(2, 2);
    if (actual != expected) {
        System.err.println("Actual: " + Integer.toHexString(actual));
        System.err.println("Expected: " + Integer.toHexString(expected));
        throw new RuntimeException("Test failed");
    }
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) VolatileImage(java.awt.image.VolatileImage) GraphicsEnvironment(java.awt.GraphicsEnvironment) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D)

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