Search in sources :

Example 16 with DisplayMode

use of java.awt.DisplayMode in project lionengine by b3dgs.

the class ScreenFullAwt method initFullscreen.

/**
 * Prepare fullscreen mode.
 *
 * @param output The output resolution
 * @param depth The bit depth color.
 * @throws LionEngineException If unsupported resolution.
 */
private void initFullscreen(Resolution output, int depth) {
    final java.awt.Window window = new java.awt.Window(frame, conf);
    window.setBackground(Color.BLACK);
    window.setIgnoreRepaint(true);
    window.setPreferredSize(new Dimension(output.getWidth(), output.getHeight()));
    dev.setFullScreenWindow(window);
    final DisplayMode disp = isSupported(new DisplayMode(output.getWidth(), output.getHeight(), depth, output.getRate()));
    if (disp == null) {
        throw new LionEngineException(ScreenFullAwt.ERROR_UNSUPPORTED_FULLSCREEN + formatResolution(output, depth) + getSupportedResolutions());
    }
    checkDisplayChangeSupport();
    dev.setDisplayMode(disp);
    window.validate();
    ToolsAwt.createBufferStrategy(window, conf);
    buf = window.getBufferStrategy();
    // Set input listeners
    componentForKeyboard = frame;
    componentForMouse = window;
    componentForCursor = window;
    frame.validate();
}
Also used : DisplayMode(java.awt.DisplayMode) LionEngineException(com.b3dgs.lionengine.LionEngineException) Dimension(java.awt.Dimension)

Example 17 with DisplayMode

use of java.awt.DisplayMode in project lionengine by b3dgs.

the class ScreenFullAwt method getSupportedResolutions.

/**
 * Get the supported resolution information.
 *
 * @return The supported resolutions.
 */
private String getSupportedResolutions() {
    final StringBuilder builder = new StringBuilder(Constant.HUNDRED);
    int i = 0;
    for (final DisplayMode display : dev.getDisplayModes()) {
        final StringBuilder widthSpace = new StringBuilder();
        final int width = display.getWidth();
        if (width < Constant.THOUSAND) {
            widthSpace.append(Constant.SPACE);
        }
        final StringBuilder heightSpace = new StringBuilder();
        final int height = display.getHeight();
        if (height < Constant.THOUSAND) {
            heightSpace.append(System.lineSeparator());
        }
        final StringBuilder freqSpace = new StringBuilder();
        final int freq = display.getRefreshRate();
        if (freq < Constant.HUNDRED) {
            freqSpace.append(Constant.SPACE);
        }
        builder.append("Supported display mode:").append(System.lineSeparator()).append('[').append(widthSpace).append(width).append(Constant.STAR).append(heightSpace).append(height).append(Constant.STAR).append(display.getBitDepth()).append(Constant.SPACE).append(Constant.AT).append(freqSpace).append(freq).append(Constant.UNIT_RATE).append(']').append(Constant.SPACE);
        i++;
        final int linesPerDisplay = 5;
        if (i % linesPerDisplay == 0) {
            builder.append(System.lineSeparator());
        }
    }
    return builder.toString();
}
Also used : DisplayMode(java.awt.DisplayMode)

Example 18 with DisplayMode

use of java.awt.DisplayMode in project jmonkeyengine by jMonkeyEngine.

the class JoglDisplay method applySettings.

protected void applySettings(AppSettings settings) {
    final boolean isDisplayModeModified;
    final GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    // Get the current display mode
    final DisplayMode previousDisplayMode = gd.getDisplayMode();
    // Handle full screen mode if requested.
    if (settings.isFullscreen()) {
        frame.setUndecorated(true);
        // Check if the full-screen mode is supported by the OS
        boolean isFullScreenSupported = gd.isFullScreenSupported();
        if (isFullScreenSupported) {
            gd.setFullScreenWindow(frame);
            // Check if display mode changes are supported by the OS
            if (gd.isDisplayChangeSupported()) {
                // Get all available display modes
                final DisplayMode[] displayModes = gd.getDisplayModes();
                DisplayMode multiBitsDepthSupportedDisplayMode = null;
                DisplayMode refreshRateUnknownDisplayMode = null;
                DisplayMode multiBitsDepthSupportedAndRefreshRateUnknownDisplayMode = null;
                DisplayMode matchingDisplayMode = null;
                DisplayMode currentDisplayMode;
                // that matches exactly with your parameters
                for (int i = 0; i < displayModes.length && matchingDisplayMode == null; i++) {
                    currentDisplayMode = displayModes[i];
                    if (currentDisplayMode.getWidth() == settings.getWidth() && currentDisplayMode.getHeight() == settings.getHeight()) {
                        if (currentDisplayMode.getBitDepth() == settings.getBitsPerPixel()) {
                            if (currentDisplayMode.getRefreshRate() == settings.getFrequency()) {
                                matchingDisplayMode = currentDisplayMode;
                            } else if (currentDisplayMode.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN) {
                                refreshRateUnknownDisplayMode = currentDisplayMode;
                            }
                        } else if (currentDisplayMode.getBitDepth() == DisplayMode.BIT_DEPTH_MULTI) {
                            if (currentDisplayMode.getRefreshRate() == settings.getFrequency()) {
                                multiBitsDepthSupportedDisplayMode = currentDisplayMode;
                            } else if (currentDisplayMode.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN) {
                                multiBitsDepthSupportedAndRefreshRateUnknownDisplayMode = currentDisplayMode;
                            }
                        }
                    }
                }
                DisplayMode nextDisplayMode = null;
                if (matchingDisplayMode != null) {
                    nextDisplayMode = matchingDisplayMode;
                } else if (multiBitsDepthSupportedDisplayMode != null) {
                    nextDisplayMode = multiBitsDepthSupportedDisplayMode;
                } else if (refreshRateUnknownDisplayMode != null) {
                    nextDisplayMode = refreshRateUnknownDisplayMode;
                } else if (multiBitsDepthSupportedAndRefreshRateUnknownDisplayMode != null) {
                    nextDisplayMode = multiBitsDepthSupportedAndRefreshRateUnknownDisplayMode;
                } else {
                    isFullScreenSupported = false;
                }
                // with the input parameters, use it
                if (nextDisplayMode != null) {
                    gd.setDisplayMode(nextDisplayMode);
                    isDisplayModeModified = true;
                } else {
                    isDisplayModeModified = false;
                }
            } else {
                isDisplayModeModified = false;
                // Resize the canvas if the display mode cannot be changed
                // and the screen size is not equal to the canvas size
                final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
                if (screenSize.width != settings.getWidth() || screenSize.height != settings.getHeight()) {
                    canvas.setSize(screenSize);
                }
            }
        } else {
            isDisplayModeModified = false;
        }
        // Software windowed full-screen mode
        if (!isFullScreenSupported) {
            final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            // Resize the canvas
            canvas.setSize(screenSize);
            // Resize the frame so that it occupies the whole screen
            frame.setSize(screenSize);
            // Set its location at the top left corner
            frame.setLocation(0, 0);
        }
    } else // Otherwise, center the window on the screen.
    {
        isDisplayModeModified = false;
        frame.pack();
        int x, y;
        x = (Toolkit.getDefaultToolkit().getScreenSize().width - settings.getWidth()) / 2;
        y = (Toolkit.getDefaultToolkit().getScreenSize().height - settings.getHeight()) / 2;
        frame.setLocation(x, y);
    }
    frame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent evt) {
            // If required, restore the previous display mode
            if (isDisplayModeModified) {
                gd.setDisplayMode(previousDisplayMode);
            }
            // If required, get back to the windowed mode
            if (gd.getFullScreenWindow() == frame) {
                gd.setFullScreenWindow(null);
            }
            windowCloseRequest.set(true);
        }

        @Override
        public void windowActivated(WindowEvent evt) {
            active.set(true);
        }

        @Override
        public void windowDeactivated(WindowEvent evt) {
            active.set(false);
        }
    });
    logger.log(Level.FINE, "Selected display mode: {0}x{1}x{2} @{3}", new Object[] { gd.getDisplayMode().getWidth(), gd.getDisplayMode().getHeight(), gd.getDisplayMode().getBitDepth(), gd.getDisplayMode().getRefreshRate() });
}
Also used : DisplayMode(java.awt.DisplayMode) GraphicsDevice(java.awt.GraphicsDevice) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) Dimension(java.awt.Dimension)

Example 19 with DisplayMode

use of java.awt.DisplayMode in project processing by processing.

the class PApplet method handleSettings.

void handleSettings() {
    insideSettings = true;
    // Need the list of display devices to be queried already for usage below.
    // https://github.com/processing/processing/issues/3295
    // https://github.com/processing/processing/issues/3296
    // Not doing this from a static initializer because it may cause
    // PApplet to cache and the values to stick through subsequent runs.
    // Instead make it a runtime thing and a local variable.
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice device = ge.getDefaultScreenDevice();
    displayDevices = ge.getScreenDevices();
    // be numbered from 1 because it's too weird to say "display 0" in prefs.
    if (display > 0 && display <= displayDevices.length) {
        device = displayDevices[display - 1];
    }
    // Set displayWidth and displayHeight for people still using those.
    DisplayMode displayMode = device.getDisplayMode();
    displayWidth = displayMode.getWidth();
    displayHeight = displayMode.getHeight();
    // Here's where size(), fullScreen(), smooth(N) and noSmooth() might
    // be called, conjuring up the demons of various rendering configurations.
    settings();
    if (display == SPAN && platform == MACOSX) {
        // Make sure "Displays have separate Spaces" is unchecked
        // in System Preferences > Mission Control
        Process p = exec("defaults", "read", "com.apple.spaces", "spans-displays");
        BufferedReader outReader = createReader(p.getInputStream());
        BufferedReader errReader = createReader(p.getErrorStream());
        StringBuilder stdout = new StringBuilder();
        StringBuilder stderr = new StringBuilder();
        String line = null;
        try {
            while ((line = outReader.readLine()) != null) {
                stdout.append(line);
            }
            while ((line = errReader.readLine()) != null) {
                stderr.append(line);
            }
        } catch (IOException e) {
            printStackTrace(e);
        }
        int resultCode = -1;
        try {
            resultCode = p.waitFor();
        } catch (InterruptedException e) {
        }
        String result = trim(stdout.toString());
        if ("0".equals(result)) {
            EventQueue.invokeLater(new Runnable() {

                public void run() {
                    checkLookAndFeel();
                    final String msg = "To use fullScreen(SPAN), first turn off “Displays have separate spaces”\n" + "in System Preferences → Mission Control. Then log out and log back in.";
                    JOptionPane.showMessageDialog(null, msg, "Apple's Defaults Stink", JOptionPane.WARNING_MESSAGE);
                }
            });
        } else if (!"1".equals(result)) {
            System.err.println("Could not check the status of “Displays have separate spaces.”");
            System.err.format("Received message '%s' and result code %d.%n", trim(stderr.toString()), resultCode);
        }
    }
    insideSettings = false;
}
Also used : DisplayMode(java.awt.DisplayMode) GraphicsDevice(java.awt.GraphicsDevice) GraphicsEnvironment(java.awt.GraphicsEnvironment)

Example 20 with DisplayMode

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

the class AltTabCrashTest method findDisplayMode.

private DisplayMode findDisplayMode() {
    GraphicsDevice gd = getGraphicsConfiguration().getDevice();
    DisplayMode[] dms = gd.getDisplayModes();
    DisplayMode currentDM = gd.getDisplayMode();
    for (DisplayMode dm : dms) {
        if (dm.getBitDepth() > 8 && dm.getBitDepth() != DisplayMode.BIT_DEPTH_MULTI && dm.getBitDepth() != currentDM.getBitDepth() && dm.getWidth() == currentDM.getWidth() && dm.getHeight() == currentDM.getHeight()) {
            // depth
            return dm;
        }
        if (dm.getBitDepth() == DisplayMode.BIT_DEPTH_MULTI && (dm.getWidth() != currentDM.getWidth() || dm.getHeight() != currentDM.getHeight())) {
            // dimensions
            return dm;
        }
    }
    return null;
}
Also used : DisplayMode(java.awt.DisplayMode) 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