Search in sources :

Example 26 with DisplayMode

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

the class X11GraphicsDevice method getDefaultDisplayMode.

private DisplayMode getDefaultDisplayMode() {
    GraphicsConfiguration gc = getDefaultConfiguration();
    Rectangle r = gc.getBounds();
    return new DisplayMode(r.width, r.height, DisplayMode.BIT_DEPTH_MULTI, DisplayMode.REFRESH_RATE_UNKNOWN);
}
Also used : DisplayMode(java.awt.DisplayMode) Rectangle(java.awt.Rectangle) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 27 with DisplayMode

use of java.awt.DisplayMode in project karaf by apache.

the class ScreenshotDumpProvider method createDump.

/**
 * {@inheritDoc}
 */
public void createDump(DumpDestination destination) throws Exception {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    // get all graphic devices attached to computer
    GraphicsDevice[] gs = ge.getScreenDevices();
    // create dump entry for each device
    for (int i = 0; i < gs.length; i++) {
        DisplayMode mode = gs[i].getDisplayMode();
        Rectangle bounds = new Rectangle(0, 0, mode.getWidth(), mode.getHeight());
        BufferedImage screenshot = new Robot(gs[i]).createScreenCapture(bounds);
        // to attach your entry to destination you have to execute this line
        OutputStream outputStream = destination.add("screenshot/display_" + i + ".png");
        ImageIO.write(screenshot, "PNG", outputStream);
        outputStream.close();
    }
}
Also used : DisplayMode(java.awt.DisplayMode) GraphicsDevice(java.awt.GraphicsDevice) OutputStream(java.io.OutputStream) Rectangle(java.awt.Rectangle) GraphicsEnvironment(java.awt.GraphicsEnvironment) Robot(java.awt.Robot) BufferedImage(java.awt.image.BufferedImage)

Example 28 with DisplayMode

use of java.awt.DisplayMode in project javacv by bytedeco.

the class CanvasFrame method init.

private void init(final boolean fullScreen, final DisplayMode displayMode, final double gamma) {
    Runnable r = new Runnable() {

        public void run() {
            KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(keyEventDispatch);
            GraphicsDevice gd = getGraphicsConfiguration().getDevice();
            DisplayMode d = gd.getDisplayMode(), d2 = null;
            if (displayMode != null && d != null) {
                int w = displayMode.getWidth();
                int h = displayMode.getHeight();
                int b = displayMode.getBitDepth();
                int r = displayMode.getRefreshRate();
                d2 = new DisplayMode(w > 0 ? w : d.getWidth(), h > 0 ? h : d.getHeight(), b > 0 ? b : d.getBitDepth(), r > 0 ? r : d.getRefreshRate());
            }
            if (fullScreen) {
                setUndecorated(true);
                getRootPane().setWindowDecorationStyle(JRootPane.NONE);
                setResizable(false);
                gd.setFullScreenWindow(CanvasFrame.this);
            } else {
                setLocationByPlatform(true);
            }
            if (d2 != null && !d2.equals(d)) {
                gd.setDisplayMode(d2);
            }
            double g = gamma == 0.0 ? getGamma(gd) : gamma;
            inverseGamma = g == 0.0 ? 1.0 : 1.0 / g;
            // Must be called after the fullscreen stuff, but before
            // getting our BufferStrategy or even creating our Canvas
            setVisible(true);
            initCanvas(fullScreen, displayMode, gamma);
        }
    };
    if (EventQueue.isDispatchThread()) {
        r.run();
    } else {
        try {
            EventQueue.invokeAndWait(r);
        } catch (java.lang.Exception ex) {
        }
    }
}
Also used : DisplayMode(java.awt.DisplayMode) GraphicsDevice(java.awt.GraphicsDevice)

Example 29 with DisplayMode

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

the class TestReslution method display1.

@Test
public void display1() {
    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) Test(org.junit.Test)

Example 30 with DisplayMode

use of java.awt.DisplayMode in project vft-capture by videofirst.

the class HideToSystemTray method getCentredLocation.

public static Point getCentredLocation(Window window, Dimension componentSize) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < gs.length; i++) {
        DisplayMode dm = gs[i].getDisplayMode();
        sb.append(i + ", width: " + dm.getWidth() + ", height: " + dm.getHeight() + "\n");
    }
    System.out.println(sb.toString());
    // int currentScreenWidth = gs[0].getDisplayMode().getWidth();
    // //int currentScreenHeight = gs[0].getDisplayMode().getWidth();
    Dimension screenSize = window.getToolkit().getScreenSize();
    Point p = new Point((int) (screenSize.getWidth() / 2 - componentSize.getWidth() / 2), (int) (screenSize.getHeight() / 2 - componentSize.getHeight() / 2));
    return p;
}
Also used : DisplayMode(java.awt.DisplayMode) GraphicsDevice(java.awt.GraphicsDevice) Dimension(java.awt.Dimension) Point(java.awt.Point) GraphicsEnvironment(java.awt.GraphicsEnvironment) Point(java.awt.Point)

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