Example usage for java.awt GraphicsDevice getConfigurations

List of usage examples for java.awt GraphicsDevice getConfigurations

Introduction

In this page you can find the example usage for java.awt GraphicsDevice getConfigurations.

Prototype

public abstract GraphicsConfiguration[] getConfigurations();

Source Link

Document

Returns all of the GraphicsConfiguration objects associated with this GraphicsDevice .

Usage

From source file:Main.java

/**
 * Get the full screen size recognizing multiple monitor.
 * /*from w ww .  j av a  2s . c o 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

/**
 * Updates {@link #SCREEN_SIZE_PRIMARY } and {@link #SCREEN_SIZE_TOTAL}
 *//*w w  w . j  av  a  2s  .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:GCWrapper.java

public CapabilitiesTest(GraphicsDevice dev) {
    super(dev.getDefaultConfiguration());
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent ev) {
            System.exit(0);//from  www .j  a  va  2s.com
        }
    });
    initComponents(getContentPane());
    GraphicsConfiguration[] gcs = dev.getConfigurations();
    for (int i = 0; i < gcs.length; i++) {
        gcSelection.addItem(new GCWrapper(gcs[i], i));
    }
    gcSelection.addItemListener(this);
    gcChanged();
}

From source file:org.zanata.util.TestEventForScreenshotListener.java

private Rectangle getScreenRectangle() {
    // http://stackoverflow.com/a/13380999/14379
    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);
        }/*from   w ww  . j  a va2  s  . c o m*/
    }
    return new Rectangle((int) result.getWidth(), (int) result.getHeight());
}

From source file:util.ui.UiUtilities.java

/**
 * Centers a window to its parent frame and shows it.
 * <p>//from w ww.j  a  va  2s .c  o  m
 * If the window has no parent frame it will be centered to the screen.
 *
 * @param win
 *          The window to center and show.
 */
public static void centerAndShow(Window win) {
    Dimension wD = win.getSize();
    Dimension frameD;
    Point framePos;
    Frame frame = JOptionPane.getFrameForComponent(win);

    // Should this window be centered to its parent frame?
    boolean centerToParentFrame = (frame != null) && (frame != win) && frame.isShowing();

    // Center to parent frame or to screen
    if (centerToParentFrame) {
        frameD = frame.getSize();
        framePos = frame.getLocation();
    } else {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        // dual head, use first screen
        if (ge.getScreenDevices().length > 1) {
            try {
                GraphicsDevice gd = ge.getDefaultScreenDevice();
                GraphicsConfiguration config = gd.getConfigurations()[0];
                frameD = config.getBounds().getSize();
                framePos = config.getBounds().getLocation();
            } catch (RuntimeException e) {
                frameD = Toolkit.getDefaultToolkit().getScreenSize();
                framePos = new Point(0, 0);
            }
        }
        // single screen only
        else {
            frameD = Toolkit.getDefaultToolkit().getScreenSize();
            framePos = new Point(0, 0);
        }
    }

    Point wPos = new Point(framePos.x + (frameD.width - wD.width) / 2,
            framePos.y + (frameD.height - wD.height) / 2);
    wPos.x = Math.max(0, wPos.x); // Make x > 0
    wPos.y = Math.max(0, wPos.y); // Make y > 0
    win.setLocation(wPos);
    win.setVisible(true);
}