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:tvbrowser.ui.mainframe.MainFrame.java

/**
 * Switch the fullscreen mode of TV-Browser
 */// w ww  .  j a  v  a  2s.  com
public void switchFullscreenMode() {
    dispose();

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();

            if (isFullScreenMode()) {
                // switch back from fullscreen
                device.setFullScreenWindow(null);
                setUndecorated(false);
                setBounds(mXPos, mYPos, mWidth, mHeight);

                if (mMenuBar != null) {
                    mMenuBar.setFullscreenItemChecked(false);
                    mMenuBar.setVisible(true);
                }

                if (mToolBarPanel != null) {
                    mToolBarPanel.setVisible(Settings.propIsToolbarVisible.getBoolean());
                }

                if (mStatusBar != null) {
                    mStatusBar.setVisible(Settings.propIsStatusbarVisible.getBoolean());
                }

                if (mChannelChooser != null) {
                    mChannelChooser.setVisible(Settings.propShowChannels.getBoolean());
                }

                if (mFinderPanel != null) {
                    mFinderPanel.getComponent().setVisible(Settings.propShowDatelist.getBoolean());
                }

                setVisible(true);

                setShowPluginOverview(Settings.propShowPluginView.getBoolean(), false);
                setShowTimeButtons(Settings.propShowTimeButtons.getBoolean(), false);
                setShowDatelist(Settings.propShowDatelist.getBoolean(), false);
                setShowChannellist(Settings.propShowChannels.getBoolean(), false);
            } else {
                // switch into fullscreen
                mXPos = getX();
                mYPos = getY();
                mWidth = getWidth();
                mHeight = getHeight();

                setShowPluginOverview(false, false);
                setShowTimeButtons(false, false);
                setShowDatelist(false, false);
                setShowChannellist(false, false);

                if (mStatusBar != null) {
                    mMenuBar.setFullscreenItemChecked(true);
                    mStatusBar.setVisible(false);
                }

                if (mChannelChooser != null) {
                    mChannelChooser.setVisible(false);
                }

                if (mMenuBar != null) {
                    mMenuBar.setVisible(false);
                }

                if (mToolBarPanel != null) {
                    mToolBarPanel.setVisible(false);
                }

                if (mFinderPanel != null) {
                    mFinderPanel.getComponent().setVisible(false);
                }

                setUndecorated(true);
                final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();

                if (device.isFullScreenSupported() && OperatingSystem.isMacOs()) {
                    device.setFullScreenWindow(MainFrame.getInstance());
                } else {
                    setLocation(0, 0);
                    setSize(screen);
                }

                setVisible(true);
                mProgramTableScrollPane.requestFocusInWindow();

                new Thread("Fullscreen border detection") {
                    public void run() {
                        setPriority(Thread.MIN_PRIORITY);

                        while (isFullScreenMode()) {
                            final Point p = MouseInfo.getPointerInfo().getLocation();
                            SwingUtilities.convertPointFromScreen(p, MainFrame.this);

                            if (isActive()) {

                                // mouse pointer is at top
                                if (p.y <= 10) {
                                    if (mToolBarPanel != null && mToolBar.getToolbarLocation()
                                            .compareTo(BorderLayout.NORTH) == 0) {
                                        if (!mToolBarPanel.isVisible()) {
                                            mToolBarPanel
                                                    .setVisible(Settings.propIsToolbarVisible.getBoolean());
                                        }
                                    }

                                    if (p.y <= 0) {
                                        mMenuBar.setVisible(true);
                                    }
                                } else if (p.y > (mMenuBar != null && mMenuBar.isVisible()
                                        ? mMenuBar.getHeight()
                                        : 0)
                                        + (Settings.propIsToolbarVisible.getBoolean()
                                                ? mToolBarPanel.getHeight()
                                                : 0)) {
                                    if (mMenuBar.isVisible()) {
                                        mMenuBar.setVisible(!isFullScreenMode());
                                    }

                                    if (mToolBarPanel != null && mToolBarPanel.isVisible() && mToolBar
                                            .getToolbarLocation().compareTo(BorderLayout.NORTH) == 0) {
                                        mToolBarPanel.setVisible(!isFullScreenMode());
                                    }
                                }

                                // mouse pointer is at the bottom
                                if (p.y >= screen.height - 1) {
                                    if (mStatusBar != null && !mStatusBar.isVisible()) {
                                        mStatusBar.setVisible(Settings.propIsStatusbarVisible.getBoolean());
                                    }
                                } else if (mStatusBar != null && mStatusBar.isVisible()
                                        && p.y < screen.height - mStatusBar.getHeight()) {
                                    mStatusBar.setVisible(!isFullScreenMode());
                                }

                                // mouse pointer is on the left side
                                if (p.x <= 5) {
                                    if (p.x == 0 && mToolBarPanel != null && mToolBar.getToolbarLocation()
                                            .compareTo(BorderLayout.WEST) == 0) {
                                        if (!mToolBarPanel.isVisible()) {
                                            mToolBarPanel
                                                    .setVisible(Settings.propIsToolbarVisible.getBoolean());
                                        }
                                    }

                                    if (Settings.propPluginViewIsLeft.getBoolean()) {
                                        if (Settings.propShowPluginView.getBoolean()) {
                                            SwingUtilities.invokeLater(new Runnable() {
                                                public void run() {
                                                    setShowPluginOverview(true, false);
                                                }
                                            });
                                        }
                                    } else {
                                        checkIfToShowTimeDateChannelList();
                                    }
                                } else {
                                    int toolBarWidth = (mToolBarPanel != null && mToolBarPanel.isVisible()
                                            && mToolBar.getToolbarLocation().compareTo(BorderLayout.WEST) == 0)
                                                    ? mToolBarPanel.getWidth()
                                                    : 0;

                                    if (p.x > toolBarWidth && toolBarWidth != 0) {
                                        mToolBarPanel.setVisible(!isFullScreenMode());
                                    }

                                    if (Settings.propPluginViewIsLeft.getBoolean()) {
                                        if (Settings.propShowPluginView.getBoolean() && mPluginView != null
                                                && mPluginView.isVisible()
                                                && p.x > mPluginView.getWidth() + toolBarWidth + 25) {
                                            SwingUtilities.invokeLater(new Runnable() {
                                                public void run() {
                                                    setShowPluginOverview(!isFullScreenMode(), false);
                                                }
                                            });
                                        }
                                    } else if (Settings.propShowChannels.getBoolean()
                                            || Settings.propShowDatelist.getBoolean()
                                            || Settings.propShowTimeButtons.getBoolean()) {
                                        SwingUtilities.invokeLater(new Runnable() {
                                            public void run() {
                                                if (mChannelChooser != null && mChannelChooser.isVisible()
                                                        && p.x > mChannelChooser.getWidth()) {
                                                    setShowChannellist(!isFullScreenMode(), false);
                                                }

                                                if (mFinderPanel != null
                                                        && mFinderPanel.getComponent().isVisible()
                                                        && p.x > mFinderPanel.getComponent().getWidth()) {
                                                    setShowDatelist(!isFullScreenMode(), false);
                                                }

                                                if (mTimeChooserPanel != null && mTimeChooserPanel.isVisible()
                                                        && p.x > mTimeChooserPanel.getWidth()) {
                                                    setShowTimeButtons(!isFullScreenMode(), false);
                                                }
                                            }
                                        });
                                    }
                                }

                                // mouse pointer is on the right side
                                if (p.x >= screen.width - 1) {
                                    if (!Settings.propPluginViewIsLeft.getBoolean()) {
                                        if (Settings.propShowPluginView.getBoolean()) {
                                            SwingUtilities.invokeLater(new Runnable() {
                                                public void run() {
                                                    setShowPluginOverview(true, false);
                                                }
                                            });
                                        }
                                    } else {
                                        checkIfToShowTimeDateChannelList();
                                    }
                                } else {
                                    if (!Settings.propPluginViewIsLeft.getBoolean()) {
                                        if (Settings.propShowPluginView.getBoolean() && mPluginView != null
                                                && mPluginView.isVisible()
                                                && p.x < screen.width - mPluginView.getWidth()) {
                                            SwingUtilities.invokeLater(new Runnable() {
                                                public void run() {
                                                    setShowPluginOverview(!isFullScreenMode(), false);
                                                }
                                            });
                                        }
                                    } else if (Settings.propShowChannels.getBoolean()
                                            || Settings.propShowDatelist.getBoolean()
                                            || Settings.propShowTimeButtons.getBoolean()) {
                                        SwingUtilities.invokeLater(new Runnable() {
                                            public void run() {
                                                if (mChannelChooser != null && mChannelChooser.isVisible()
                                                        && p.x < screen.width - mChannelChooser.getWidth()) {
                                                    setShowChannellist(!isFullScreenMode(), false);
                                                }

                                                if (mFinderPanel != null
                                                        && mFinderPanel.getComponent().isVisible()
                                                        && p.x < screen.width
                                                                - mFinderPanel.getComponent().getWidth()) {
                                                    setShowDatelist(!isFullScreenMode(), false);
                                                }

                                                if (mTimeChooserPanel != null && mTimeChooserPanel.isVisible()
                                                        && p.x < screen.width - mTimeChooserPanel.getWidth()) {
                                                    setShowTimeButtons(!isFullScreenMode(), false);
                                                }
                                            }
                                        });
                                    }
                                }
                            }
                            try {
                                Thread.sleep(200);
                            } catch (Exception e) {
                            }
                        }
                    }
                }.start();
            }
        }
    });
}