Search in sources :

Example 1 with GraphicsDevice

use of java.awt.GraphicsDevice in project screenbird by adamhub.

the class ScreenUtil method isMultipleScreen.

/**
     * Checks for presence of multiple screens/monitors on the current computer.
     * @return True if more than one screen is detected.
     */
public static boolean isMultipleScreen() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] screens = ge.getScreenDevices();
    return screens.length > 1;
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) GraphicsEnvironment(java.awt.GraphicsEnvironment)

Example 2 with GraphicsDevice

use of java.awt.GraphicsDevice in project screenbird by adamhub.

the class RecorderPanelTest method testGetScreen.

/**
     * Test of getScreen method, of class RecorderPanel.
     */
@Test
public void testGetScreen() {
    System.out.println("getScreen");
    GraphicsConfiguration gd = instance.getGraphicsConfiguration();
    GraphicsDevice expResult = gd.getDevice();
    GraphicsDevice result = instance.getScreen();
    assertNotNull(result);
    assertEquals(expResult, result);
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) GraphicsConfiguration(java.awt.GraphicsConfiguration) Test(org.junit.Test)

Example 3 with GraphicsDevice

use of java.awt.GraphicsDevice in project screenbird by adamhub.

the class RecorderTest method testGetScreen.

/**
     * Test of getScreen method, of class Recorder.
     */
@Test
public void testGetScreen() {
    log("getScreen");
    Recorder instance = new Recorder(null);
    GraphicsDevice expResult = null;
    GraphicsDevice result = instance.getScreen();
    assertEquals(expResult, result);
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) Test(org.junit.Test)

Example 4 with GraphicsDevice

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

the class VRAppState method stateAttached.

@Override
public void stateAttached(AppStateManager stateManager) {
    //To change body of generated methods, choose Tools | Templates.
    super.stateAttached(stateManager);
    if (settings == null) {
        settings = new AppSettings(true);
        logger.config("Using default settings.");
    } else {
        logger.config("Using given settings.");
    }
    // Attach VR environment to the application
    if (!environment.isInitialized()) {
        environment.initialize();
    }
    if (environment.isInitialized()) {
        environment.atttach(this, stateManager.getApplication());
    } else {
        logger.severe("Cannot attach VR environment to the VR app state as its not initialized.");
    }
    GraphicsDevice defDev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    if (environment.isInVR() && !environment.compositorAllowed()) {
        // "easy extended" mode
        // setup experimental JFrame on external device
        // first, find the VR device
        GraphicsDevice VRdev = null;
        GraphicsDevice[] devs = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
        // pick the display that isn't the default one
        for (GraphicsDevice gd : devs) {
            if (gd != defDev) {
                VRdev = gd;
                break;
            }
        }
        // did we get the VR device?
        if (VRdev != null) {
            // set properties for VR acceleration
            try {
                java.awt.DisplayMode useDM = null;
                int max = 0;
                for (java.awt.DisplayMode dm : VRdev.getDisplayModes()) {
                    int check = dm.getHeight() + dm.getWidth() + dm.getRefreshRate() + dm.getBitDepth();
                    if (check > max) {
                        max = check;
                        useDM = dm;
                    }
                }
                // create a window for the VR device
                settings.setWidth(useDM.getWidth());
                settings.setHeight(useDM.getHeight());
                settings.setBitsPerPixel(useDM.getBitDepth());
                settings.setFrequency(useDM.getRefreshRate());
                settings.setSwapBuffers(true);
                // allow vsync on this display
                settings.setVSync(true);
                stateManager.getApplication().setSettings(settings);
                logger.config("Updated underlying application settings.");
                // make sure we are in the right display mode
                if (VRdev.getDisplayMode().equals(useDM) == false) {
                    VRdev.setDisplayMode(useDM);
                }
                return;
            } catch (Exception e) {
                logger.log(Level.SEVERE, e.getMessage(), e);
            }
        } else {
            logger.config("Cannot access to external screen.");
        }
    } else {
        if (!environment.isInVR()) {
            logger.config("Cannot switch to VR mode (VR disabled by user).");
        } else if (!environment.compositorAllowed()) {
            logger.warning("Cannot switch to VR mode (VR not supported).");
        }
    }
    if (!environment.isInVR()) {
        //FIXME: Handling GLFW workaround on MacOS
        boolean macOs = false;
        if (macOs) {
            // GLFW workaround on macs
            settings.setFrequency(defDev.getDisplayMode().getRefreshRate());
            settings.setDepthBits(24);
            settings.setVSync(true);
            // try and read resolution from file in local dir
            File resfile = new File("resolution.txt");
            if (resfile.exists()) {
                try {
                    BufferedReader br = new BufferedReader(new FileReader(resfile));
                    settings.setWidth(Integer.parseInt(br.readLine()));
                    settings.setHeight(Integer.parseInt(br.readLine()));
                    try {
                        settings.setFullscreen(br.readLine().toLowerCase(Locale.ENGLISH).contains("full"));
                    } catch (Exception e) {
                        settings.setFullscreen(false);
                    }
                    br.close();
                } catch (Exception e) {
                    settings.setWidth(1280);
                    settings.setHeight(720);
                }
            } else {
                settings.setWidth(1280);
                settings.setHeight(720);
                settings.setFullscreen(false);
            }
            settings.setResizable(false);
        }
        settings.setSwapBuffers(true);
    } else {
        // use basic mirroring window, skip settings window
        settings.setSamples(1);
        settings.setWidth(xWin);
        settings.setHeight(yWin);
        settings.setBitsPerPixel(32);
        settings.setFrameRate(0);
        settings.setFrequency(environment.getVRHardware().getDisplayFrequency());
        settings.setFullscreen(false);
        // stop vsyncing on primary monitor!
        settings.setVSync(false);
        settings.setSwapBuffers(environment.isSwapBuffers());
    }
    // Updating application settings
    stateManager.getApplication().setSettings(settings);
    logger.config("Updated underlying application settings.");
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) AppSettings(com.jme3.system.AppSettings) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File)

Example 5 with GraphicsDevice

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

the class EditorState method defaultConfig.

GraphicsConfiguration defaultConfig() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice device = ge.getDefaultScreenDevice();
    GraphicsConfiguration config = device.getDefaultConfiguration();
    //      deviceName = device.getIDstring();
    deviceBounds = config.getBounds();
    return config;
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) GraphicsEnvironment(java.awt.GraphicsEnvironment) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Aggregations

GraphicsDevice (java.awt.GraphicsDevice)75 GraphicsEnvironment (java.awt.GraphicsEnvironment)44 GraphicsConfiguration (java.awt.GraphicsConfiguration)23 Point (java.awt.Point)15 Frame (java.awt.Frame)13 Dimension (java.awt.Dimension)12 DisplayMode (java.awt.DisplayMode)12 Rectangle (java.awt.Rectangle)11 Insets (java.awt.Insets)7 Toolkit (java.awt.Toolkit)7 Graphics (java.awt.Graphics)6 BufferedImage (java.awt.image.BufferedImage)6 HeadlessException (java.awt.HeadlessException)4 Window (java.awt.Window)4 JFrame (javax.swing.JFrame)4 Test (org.junit.Test)4 MouseAdapter (java.awt.event.MouseAdapter)3 MouseEvent (java.awt.event.MouseEvent)3 WindowAdapter (java.awt.event.WindowAdapter)3 WindowEvent (java.awt.event.WindowEvent)3