Search in sources :

Example 6 with DisplayMode

use of java.awt.DisplayMode in project TeachingInSimulation by ScOrPiOzzy.

the class SettingDialog method initResolution.

private void initResolution() {
    GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice sd = g.getDefaultScreenDevice();
    DisplayMode[] modes = sd.getDisplayModes();
    List<Resolution> resolutions = new ArrayList<Resolution>();
    for (DisplayMode mode : modes) {
        int width = mode.getWidth();
        int height = mode.getHeight();
        if (mode.getRefreshRate() != 60 || mode.getBitDepth() != 32) {
            continue;
        }
        if (width == 1366 && height == 768) {
            resolutions.add(new Resolution(width, height));
        } else if (width == 1600 && height == 900) {
            resolutions.add(new Resolution(width, height));
        } else if (width == 1920 && height == 1080) {
            resolutions.add(new Resolution(width, height));
        }
    }
    resolutions.sort(new Comparator<Resolution>() {

        @Override
        public int compare(Resolution o1, Resolution o2) {
            int width1 = o1.getWidth();
            int width2 = o2.getWidth();
            if (width1 == width2) {
                return 0;
            }
            return width1 > width2 ? 1 : -1;
        }
    });
    resolution.getItems().addAll(resolutions);
    Preferences prefs = Preferences.userRoot().node(SettingConsts.REG_APP_PATH);
    // 分辨率
    int width = prefs.getInt(SettingConsts.RESOLUTION_WIDTH, 1366);
    if (width < 1366) {
        width = 1366;
    }
    int height = prefs.getInt(SettingConsts.RESOLUTION_HEIGHT, 768);
    if (height < 768) {
        height = 768;
    }
    resolution.getSelectionModel().select(new Resolution(width, height));
    boolean fullscreen = prefs.getBoolean(SettingConsts.SCREEN_MODE, false);
    full.setSelected(fullscreen);
}
Also used : DisplayMode(java.awt.DisplayMode) GraphicsDevice(java.awt.GraphicsDevice) ArrayList(java.util.ArrayList) GraphicsEnvironment(java.awt.GraphicsEnvironment) Preferences(java.util.prefs.Preferences)

Example 7 with DisplayMode

use of java.awt.DisplayMode in project TeachingInSimulation by ScOrPiOzzy.

the class TestReslution2 method display.

private void display() {
    GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice sd = g.getDefaultScreenDevice();
    DisplayMode[] dm = sd.getDisplayModes();
    List<String> resolution = new ArrayList<>();
    for (int i = 0; i < dm.length; i++) {
        String res = String.format("%sx%s", dm[i].getWidth(), dm[i].getHeight());
        if (resolution.indexOf(res) == -1) {
            resolution.add(res);
        }
    }
    resolution.forEach(System.out::println);
}
Also used : DisplayMode(java.awt.DisplayMode) GraphicsDevice(java.awt.GraphicsDevice) ArrayList(java.util.ArrayList) GraphicsEnvironment(java.awt.GraphicsEnvironment)

Example 8 with DisplayMode

use of java.awt.DisplayMode in project TeachingInSimulation by ScOrPiOzzy.

the class TestReslution2 method doSnap.

protected void doSnap(final ImageView iv) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();
    Robot robot = null;
    try {
        robot = new Robot(gs[gs.length - 1]);
    } catch (AWTException e) {
        e.printStackTrace();
        return;
    }
    DisplayMode mode = gs[0].getDisplayMode();
    Rectangle bounds = new Rectangle(0, 0, mode.getWidth(), mode.getHeight());
    final BufferedImage bi = robot.createScreenCapture(bounds);
    Platform.runLater(new Runnable() {

        @Override
        public void run() {
            Image im = SwingFXUtils.toFXImage(bi, null);
            iv.setImage(im);
        }
    });
}
Also used : DisplayMode(java.awt.DisplayMode) GraphicsDevice(java.awt.GraphicsDevice) Rectangle(java.awt.Rectangle) GraphicsEnvironment(java.awt.GraphicsEnvironment) BufferedImage(java.awt.image.BufferedImage) Image(javafx.scene.image.Image) Robot(java.awt.Robot) BufferedImage(java.awt.image.BufferedImage) AWTException(java.awt.AWTException)

Example 9 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());
    }
    if (!dev.isDisplayChangeSupported()) {
        throw new LionEngineException(ScreenFullAwt.ERROR_SWITCH);
    }
    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 10 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)

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