Example usage for java.awt GraphicsDevice setFullScreenWindow

List of usage examples for java.awt GraphicsDevice setFullScreenWindow

Introduction

In this page you can find the example usage for java.awt GraphicsDevice setFullScreenWindow.

Prototype

public void setFullScreenWindow(Window w) 

Source Link

Document

Enter full-screen mode, or return to windowed mode.

Usage

From source file:MultiBufferTest.java

public MultiBufferTest(int numBuffers, GraphicsDevice device) {
    try {/*from   ww  w  . j a va 2s . c  o  m*/
        GraphicsConfiguration gc = device.getDefaultConfiguration();
        mainFrame = new Frame(gc);
        mainFrame.setUndecorated(true);
        mainFrame.setIgnoreRepaint(true);
        device.setFullScreenWindow(mainFrame);
        if (device.isDisplayChangeSupported()) {
            chooseBestDisplayMode(device);
        }
        Rectangle bounds = mainFrame.getBounds();
        mainFrame.createBufferStrategy(numBuffers);
        BufferStrategy bufferStrategy = mainFrame.getBufferStrategy();
        for (float lag = 2000.0f; lag > 0.00000006f; lag = lag / 1.33f) {
            for (int i = 0; i < numBuffers; i++) {
                Graphics g = bufferStrategy.getDrawGraphics();
                if (!bufferStrategy.contentsLost()) {
                    g.setColor(COLORS[i]);
                    g.fillRect(0, 0, bounds.width, bounds.height);
                    bufferStrategy.show();
                    g.dispose();
                }
                try {
                    Thread.sleep((int) lag);
                } catch (InterruptedException e) {
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        device.setFullScreenWindow(null);
    }
}

From source file:Main.java

void initUI() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    int i = 1;//www  .j a v  a2s  . co m
    for (GraphicsDevice gd : ge.getScreenDevices()) {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.add(createLabel(String.valueOf(i)));
        frame.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
                .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "exit");
        frame.getRootPane().getActionMap().put("exit", new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
        frame.setLocation(gd.getDefaultConfiguration().getBounds().getLocation());
        frame.setUndecorated(true);
        frame.setExtendedState(frame.getExtendedState() | JFrame.MAXIMIZED_BOTH);
        frame.setVisible(true);
        gd.setFullScreenWindow(frame);
        i++;
    }
}

From source file:dylemator.DylematorUI.java

public void setFullscreen(boolean fullscreen) {
    //get a reference to the device.
    GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    DisplayMode dispMode = device.getDisplayMode();
    //save the old display mode before changing it.
    dispModeOld = device.getDisplayMode();

    if (this.fullscreen != fullscreen) { //are we actually changing modes.
                                         //change modes.
        this.fullscreen = fullscreen;
        // toggle fullscreen mode
        if (!fullscreen) {
            //change to windowed mode.
            //set the display mode back to the what it was when
            //the program was launched.
            device.setDisplayMode(dispModeOld);

            //hide the frame so we can change it.
            setVisible(false);//from w ww .  ja  v  a  2 s  . c  om
            //remove the frame from being displayable.
            dispose();
            //put the borders back on the frame.
            setUndecorated(false);
            //needed to unset this window as the fullscreen window.
            device.setFullScreenWindow(null);
            //recenter window
            setLocationRelativeTo(null);
            setResizable(true);

            //reset the display mode to what it was before
            //we changed it.
            setVisible(true);

        } else { //change to fullscreen.
                 //hide everything
            setVisible(false);
            //remove the frame from being displayable.
            dispose();
            //remove borders around the frame
            setUndecorated(true);
            //make the window fullscreen.
            device.setFullScreenWindow(this);
            //attempt to change the screen resolution.
            device.setDisplayMode(dispMode);
            setResizable(false);
            setAlwaysOnTop(false);
            //show the frame
            setVisible(true);
        }
        //make sure that the screen is refreshed.
        repaint();

    }
    this.requestFocus();
}

From source file:com.freedomotic.jfrontend.MainWindow.java

private void setFullscreenMode() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();

    if (gd.isFullScreenSupported()) {
        frameMap.setVisible(false);//w  w w  .j a  v  a  2s  .c  om
        menuBar.setVisible(false);
        frameMap.dispose();
        frameClient.setVisible(false);
        frameClient.dispose();
        desktopPane.removeAll();
        desktopPane.moveToBack(this);
        setVisible(false);
        dispose();

        setUndecorated(true);
        setResizable(false);
        setLayout(new BorderLayout());

        drawer = master.createRenderer(drawer.getCurrEnv());
        if (drawer != null) {
            setDrawer(drawer);
        } else {
            LOG.error(
                    "Unable to create a drawer to render the environment on the desktop frontend in fullscreen mode");
        }
        add(drawer);

        Rectangle maximumWindowBounds = ge.getMaximumWindowBounds();
        setBounds(maximumWindowBounds);

        drawer.setVisible(true);
        this.setVisible(true);
        gd.setFullScreenWindow(this);
        isFullscreen = true;
        Callout callout = new Callout(this.getClass().getCanonicalName(), "info",
                i18n.msg("esc_to_exit_fullscreen"), 100, 100, 0, 5000);
        drawer.createCallout(callout);

    }

}

From source file:com.igormaznitsa.sciareto.ui.MainFrame.java

private void menuFullScreenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuFullScreenActionPerformed
    final Component currentComponent = this.tabPane.getSelectedComponent();
    if (!(currentComponent instanceof Container)) {
        LOGGER.warn("Detected attempt to full screen not a container : " + currentComponent);
        return;//from   ww w.  ja  v  a  2 s  .com
    }

    final GraphicsConfiguration gconfig = this.getGraphicsConfiguration();
    if (gconfig != null) {
        final GraphicsDevice device = gconfig.getDevice();
        if (device.isFullScreenSupported()) {
            if (device.getFullScreenWindow() == null) {
                final JLabel label = new JLabel("Opened in full screen");
                final int tabIndex = this.tabPane.getSelectedIndex();
                this.tabPane.setComponentAt(tabIndex, label);
                final JWindow window = new JWindow(Main.getApplicationFrame());
                window.setAlwaysOnTop(true);
                window.setContentPane((Container) currentComponent);

                endFullScreenIfActive();

                final KeyEventDispatcher fullScreenEscCatcher = new KeyEventDispatcher() {
                    @Override
                    public boolean dispatchKeyEvent(@Nonnull final KeyEvent e) {
                        if (e.getID() == KeyEvent.KEY_PRESSED && (e.getKeyCode() == KeyEvent.VK_ESCAPE
                                || e.getKeyCode() == KeyEvent.VK_F11)) {
                            endFullScreenIfActive();
                            return true;
                        }
                        return false;
                    }
                };

                if (this.taskToEndFullScreen.compareAndSet(null, new Runnable() {
                    @Override
                    public void run() {
                        try {
                            window.dispose();
                        } finally {
                            tabPane.setComponentAt(tabIndex, currentComponent);
                            device.setFullScreenWindow(null);
                            KeyboardFocusManager.getCurrentKeyboardFocusManager()
                                    .removeKeyEventDispatcher(fullScreenEscCatcher);
                        }
                    }
                })) {
                    try {
                        KeyboardFocusManager.getCurrentKeyboardFocusManager()
                                .addKeyEventDispatcher(fullScreenEscCatcher);
                        device.setFullScreenWindow(window);
                    } catch (Exception ex) {
                        LOGGER.error("Can't turn on full screen", ex);
                        endFullScreenIfActive();
                        KeyboardFocusManager.getCurrentKeyboardFocusManager()
                                .removeKeyEventDispatcher(fullScreenEscCatcher);
                    }
                } else {
                    LOGGER.error("Unexpected state, processor is not null!");
                }
            } else {
                LOGGER.warn("Attempt to full screen device which already in full screen!");
            }
        } else {
            LOGGER.warn("Device doesn's support full screen");
            DialogProviderManager.getInstance().getDialogProvider()
                    .msgWarn("The Device doesn't support full-screen mode!");
        }
    } else {
        LOGGER.warn("Can't find graphics config for the frame");
    }
}

From source file:org.rdv.datapanel.AbstractDataPanel.java

/**
 * Undock the UI component and display fullscreen.
 * /*www .  j  av  a 2 s  . c o m*/
 * @since  1.1
 */
void maximizePanel() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] devices = ge.getScreenDevices();
    for (int i = 0; i < devices.length; i++) {
        GraphicsDevice device = devices[i];
        if (device.isFullScreenSupported() && device.getFullScreenWindow() == null) {
            maximized = true;
            dataPanelContainer.removeDataPanel(component);

            frame = new JFrame(getTitle());
            frame.setUndecorated(true);
            frame.getContentPane().add(component);

            try {
                device.setFullScreenWindow(frame);
            } catch (InternalError e) {
                log.error("Failed to switch to full screen mode: " + e.getMessage() + ".");
                restorePanel(true);
                return;
            }

            frame.setVisible(true);
            frame.requestFocus();

            return;
        }
    }

    log.warn("No screens available or full screen exclusive mode is unsupported on your platform.");
}

From source file:org.rdv.datapanel.AbstractDataPanel.java

/**
 * Leave fullscreen mode and dock the UI component if addToContainer is true.
 * //from   w  w  w . j a  v a 2  s .  co m
 * @param addToContainer  whether to dock the UI component
 * @since                 1.1
 */
void restorePanel(boolean addToContainer) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] devices = ge.getScreenDevices();
    for (int i = 0; i < devices.length; i++) {
        GraphicsDevice device = devices[i];
        if (device.isFullScreenSupported() && device.getFullScreenWindow() == frame) {
            if (frame != null) {
                frame.setVisible(false);
                device.setFullScreenWindow(null);
                frame.getContentPane().remove(component);
                frame.dispose();
                frame = null;
            }

            maximized = false;

            if (addToContainer) {
                dataPanelContainer.addDataPanel(component);
            }

            break;
        }
    }
}

From source file:org.rdv.ui.MainPanel.java

private boolean enterFullScreenMode() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] devices = ge.getScreenDevices();
    for (int i = 0; i < devices.length; i++) {
        GraphicsDevice device = devices[i];
        if (device.isFullScreenSupported() && device.getFullScreenWindow() == null) {
            log.info("Switching to full screen mode.");

            frame.setVisible(false);//from w  w w .j  a  va 2 s. c om

            try {
                device.setFullScreenWindow(frame);
            } catch (InternalError e) {
                log.error("Failed to switch to full screen exclusive mode.");
                e.printStackTrace();

                frame.setVisible(true);
                return false;
            }

            frame.dispose();
            frame.setUndecorated(true);
            frame.setVisible(true);
            frame.requestFocusInWindow();

            return true;
        }
    }

    log.warn("No screens available or full screen exclusive mode is unsupported on your platform.");

    postError("Full screen mode is not supported on your platform.");

    return false;
}

From source file:org.rdv.ui.MainPanel.java

private void leaveFullScreenMode() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] devices = ge.getScreenDevices();
    for (int i = 0; i < devices.length; i++) {
        GraphicsDevice device = devices[i];
        if (device.isFullScreenSupported() && device.getFullScreenWindow() == frame) {
            log.info("Leaving full screen mode.");

            frame.setVisible(false);/*from ww w  .  ja va 2 s .  c  om*/
            device.setFullScreenWindow(null);
            frame.dispose();
            frame.setUndecorated(false);
            frame.setVisible(true);

            break;
        }
    }
}

From source file:org.simmi.GeneSetHead.java

License:asdf

public void initFSKeyListener(final Window window) {
    keylistener = new KeyListener() {
        @Override/*from  w ww . j av a2 s  .c o m*/
        public void keyTyped(KeyEvent e) {

        }

        @Override
        public void keyReleased(KeyEvent e) {

        }

        @Override
        public void keyPressed(KeyEvent e) {
            GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
            if (e.getKeyCode() == KeyEvent.VK_F11 && gd.isFullScreenSupported()) {
                Window w = gd.getFullScreenWindow();
                if (w != null) {
                    gd.setFullScreenWindow(null);
                } else {
                    gd.setFullScreenWindow(window);
                }
            }
        }
    };
}