Example usage for java.awt GraphicsEnvironment getScreenDevices

List of usage examples for java.awt GraphicsEnvironment getScreenDevices

Introduction

In this page you can find the example usage for java.awt GraphicsEnvironment getScreenDevices.

Prototype

public abstract GraphicsDevice[] getScreenDevices() throws HeadlessException;

Source Link

Document

Returns an array of all of the screen GraphicsDevice objects.

Usage

From source file:Main.java

private static void initScreenDevices() {
    final GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    screenDevices = graphicsEnvironment.getScreenDevices();
}

From source file:Main.java

/**
 * returns the virtual screensize in a multimonitor system
 * //w  ww .j av  a2  s.com
 * @return
 */
public static Dimension getVirtualScreenSize() {
    Rectangle virtualBounds = new Rectangle();
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();
    for (int j = 0; j < gs.length; j++) {
        GraphicsDevice gd = gs[j];
        GraphicsConfiguration[] gc = gd.getConfigurations();
        for (int i = 0; i < gc.length; i++) {
            virtualBounds = virtualBounds.union(gc[i].getBounds());
        }
    }
    return virtualBounds.getSize();
}

From source file:Main.java

/**
 *  Check whether GUI present or not./*from   w ww  . ja v  a2  s  . c om*/
 */
public static boolean isGUI() {
    boolean retVal = false;
    try {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice[] gs = ge.getScreenDevices();
        if (gs.length > 0) {
            retVal = true;
        }
    } catch (Throwable t) {
    }
    return retVal;
}

From source file:Main.java

/**
 * Get the full screen size recognizing multiple monitor.
 * //  w w  w  .j  a v a2 s  .  co  m
 * @return full screen size
 */
public static Dimension getFullScreenSize() {
    Rectangle2D result = new Rectangle2D.Double();
    GraphicsEnvironment localGE = GraphicsEnvironment.getLocalGraphicsEnvironment();
    for (GraphicsDevice gd : localGE.getScreenDevices()) {
        for (GraphicsConfiguration graphicsConfiguration : gd.getConfigurations()) {
            Rectangle2D.union(result, graphicsConfiguration.getBounds(), result);
        }
    }
    return new Dimension((int) result.getWidth(), (int) result.getHeight());
}

From source file:Main.java

public static int getMonitor(Component c) {
    Window w = (c instanceof Window) ? (Window) c : SwingUtilities.windowForComponent(c);
    GraphicsConfiguration gc = (w == null) ? null : w.getGraphicsConfiguration();
    GraphicsDevice gd = (gc == null) ? null : gc.getDevice();
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();

    for (int i = 0; i < gs.length; i++) {
        if (gs[i].equals(gd)) {
            return i;
        }//from w  ww  .  j  av a2s . c o  m
    }

    return -1;
}

From source file:Main.java

private static Rectangle getScreenBounds(Window aWindow) {

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] devices = ge.getScreenDevices();

    if (aWindow == null)
        return devices[0].getDefaultConfiguration().getBounds();

    Rectangle bounds = aWindow.getBounds();
    int centerX = (int) bounds.getCenterX();
    int centerY = (int) bounds.getCenterY();

    for (GraphicsDevice device : devices) {
        GraphicsConfiguration gc = device.getDefaultConfiguration();
        Rectangle rect = gc.getBounds();
        if (rect.contains(centerX, centerY))
            return rect;
    }/*from  w  ww.j  ava  2s  .co m*/

    return null;
}

From source file:Main.java

/**
 * Updates {@link #SCREEN_SIZE_PRIMARY } and {@link #SCREEN_SIZE_TOTAL}
 *//*  w  ww .ja v a2s.  c  o m*/
public static void calculateScreenSizes() {

    Rectangle totalBounds = new Rectangle();
    Rectangle primaryBounds = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();
    for (int j = 0; j < gs.length; j++) {
        GraphicsDevice gd = gs[j];
        if (gd == ge.getDefaultScreenDevice()) {
            primaryBounds = new Rectangle();
        }
        GraphicsConfiguration[] gc = gd.getConfigurations();
        for (int i = 0; i < gc.length; i++) {
            Rectangle bounds = gc[i].getBounds();
            Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(gc[i]);
            bounds.x += screenInsets.left;
            bounds.y += screenInsets.top;
            bounds.height -= screenInsets.bottom;
            bounds.width -= screenInsets.right;
            totalBounds = totalBounds.union(bounds);
            if (primaryBounds != null) {
                primaryBounds = primaryBounds.union(bounds);
            }
        }
        if (primaryBounds != null) {
            SCREEN_SIZE_PRIMARY = primaryBounds;
            primaryBounds = null;
        }
    }
    SCREEN_SIZE_TOTAL = totalBounds;
}

From source file:Main.java

public static GraphicsDevice getScreenByLocation(Point p) {
    final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

    final GraphicsDevice[] screens = ge.getScreenDevices();

    for (final GraphicsDevice screen : screens) {
        final Rectangle bounds = screen.getDefaultConfiguration().getBounds();

        if (bounds.contains(p)) {
            return screen;

        }/*w  ww. j  av  a 2  s . c o  m*/

    }
    return null;

}

From source file:Main.java

public static void showOnSameScreenAsMouseCenter(Container frame) {
    Point mouseLocation = MouseInfo.getPointerInfo().getLocation();

    GraphicsDevice device;/*from w  w  w . ja va 2s  .c o  m*/

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice lstGDs[] = ge.getScreenDevices();

    ArrayList<GraphicsDevice> lstDevices = new ArrayList<GraphicsDevice>(lstGDs.length);

    for (GraphicsDevice gd : lstGDs) {
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        Rectangle screenBounds = gc.getBounds();

        if (screenBounds.contains(mouseLocation)) {
            lstDevices.add(gd);
        }
    }

    if (lstDevices.size() > 0) {
        device = lstDevices.get(0);
    } else {
        device = ge.getDefaultScreenDevice();
    }

    Rectangle bounds = device.getDefaultConfiguration().getBounds();
    frame.setLocation(bounds.x + bounds.width / 2 - frame.getWidth() / 2,
            bounds.y + bounds.height / 2 - frame.getHeight() / 2);
}

From source file:SwingUtil.java

/**
 * Verifies if the given point is visible on the screen.
 * /*from w  ww . jav a 2s  .co  m*/
 * @param    location       The given location on the screen.
 * @return                True if the location is on the screen, false otherwise.
 */
public static boolean isLocationInScreenBounds(Point location) {

    // Check if the location is in the bounds of one of the graphics devices.
    GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] graphicsDevices = graphicsEnvironment.getScreenDevices();
    Rectangle graphicsConfigurationBounds = new Rectangle();

    // Iterate over the graphics devices.
    for (int j = 0; j < graphicsDevices.length; j++) {

        // Get the bounds of the device.
        GraphicsDevice graphicsDevice = graphicsDevices[j];
        graphicsConfigurationBounds.setRect(graphicsDevice.getDefaultConfiguration().getBounds());

        // Is the location in this bounds?
        graphicsConfigurationBounds.setRect(graphicsConfigurationBounds.x, graphicsConfigurationBounds.y,
                graphicsConfigurationBounds.width, graphicsConfigurationBounds.height);
        if (graphicsConfigurationBounds.contains(location.x, location.y)) {

            // The location is in this screengraphics.
            return true;

        }

    }

    // We could not find a device that contains the given point.
    return false;

}