Example usage for java.awt GraphicsDevice getDefaultConfiguration

List of usage examples for java.awt GraphicsDevice getDefaultConfiguration

Introduction

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

Prototype

public abstract GraphicsConfiguration getDefaultConfiguration();

Source Link

Document

Returns the default GraphicsConfiguration associated with this GraphicsDevice .

Usage

From source file:Main.java

public static boolean isPointOnScreen(Point p) {
    GraphicsDevice[] devices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
    for (GraphicsDevice device : devices) {
        if (device.getDefaultConfiguration().getBounds().contains(p)) {
            return true;
        }//from  w  w  w .  ja va2s  .co  m
    }
    return false;
}

From source file:Main.java

public static Rectangle computeVirtualGraphicsBounds() {
    Rectangle virtualBounds = new Rectangle();
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();
    for (GraphicsDevice gd : gs) {
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        virtualBounds = virtualBounds.union(gc.getBounds());
    }/*from ww  w .j  a  va  2s.  c om*/
    return virtualBounds;
}

From source file:Main.java

public static boolean isXOnScreen(int x) {
    GraphicsDevice[] devices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
    for (GraphicsDevice device : devices) {
        int boundA = device.getDefaultConfiguration().getBounds().x;
        int boundB = boundA + device.getDefaultConfiguration().getBounds().width;
        if (inBounds(x, boundA, boundB)) {
            return true;
        }/*from www  .ja  v  a2  s  .  com*/
    }
    return false;
}

From source file:Main.java

public static boolean isYOnScreen(int y) {
    GraphicsDevice[] devices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
    for (GraphicsDevice device : devices) {
        int boundA = device.getDefaultConfiguration().getBounds().y;
        int boundB = boundA + device.getDefaultConfiguration().getBounds().height;
        if (inBounds(y, boundA, boundB)) {
            return true;
        }//from   ww  w  .  j a v  a 2  s . c  o  m
    }
    return false;
}

From source file:Main.java

/**
 * @param screen// w ww  . j a  v a 2 s. com
 * @return
 */
public static Rectangle getUsableScreenBounds(GraphicsDevice screen) {
    final Rectangle bounds = screen.getDefaultConfiguration().getBounds();
    Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(screen.getDefaultConfiguration());
    bounds.x += insets.left;
    bounds.y += insets.top;
    bounds.width -= insets.left + insets.right;
    bounds.height -= insets.top + insets.bottom;
    return bounds;
}

From source file:Main.java

public static Image getImage(Component c) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    GraphicsConfiguration gc = gd.getDefaultConfiguration();

    // Create an image that supports transparent pixels
    BufferedImage bImage = gc.createCompatibleImage(c.getWidth(), c.getHeight(), Transparency.BITMASK);

    /*//from w w w  .java  2 s  . c o m
     * And now this is how we get an image of the component
     */
    Graphics2D g = bImage.createGraphics();

    // Then use the current component we're in and call paint on this
    // graphics object
    c.paint(g);
    return bImage;
}

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;
    }/*w  ww .j  av  a 2 s .  co m*/

    return null;
}

From source file:Main.java

public static BufferedImage toBufferedImage(Image image) {
    if (image instanceof BufferedImage) {
        return (BufferedImage) image;
    }/*from ww w  . j a va2 s. c  o m*/

    // This code ensures that all the pixels in the image are loaded
    image = new ImageIcon(image).getImage();
    // Create a buffered image with a format that's compatible with the screen
    BufferedImage bimage = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    try {
        GraphicsDevice gs = ge.getDefaultScreenDevice();
        GraphicsConfiguration gc = gs.getDefaultConfiguration();
        VolatileImage vbimage = gc.createCompatibleVolatileImage(200, 200, gc.getImageCapabilities());
    } catch (Exception e) {
        // The system does not have a screen
    }
    return bimage;
}

From source file:Main.java

public static BufferedImage toBufferedImage(Image image) {
    if (image instanceof BufferedImage) {
        return (BufferedImage) image;
    }/*from   w  w  w .j  a  v a 2 s  .  co  m*/

    // This code ensures that all the pixels in the image are loaded
    image = new ImageIcon(image).getImage();
    // Create a buffered image with a format that's compatible with the screen
    BufferedImage bimage = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    try {
        GraphicsDevice gs = ge.getDefaultScreenDevice();
        GraphicsConfiguration gc = gs.getDefaultConfiguration();
        VolatileImage vbimage = gc.createCompatibleVolatileImage(200, 200);
    } catch (HeadlessException e) {
        // The system does not have a screen
    }
    return bimage;
}

From source file:Main.java

public static BufferedImage toBufferedImage(Image image) {
    if (image instanceof BufferedImage) {
        return (BufferedImage) image;
    }/*from  www  .j a  v a 2 s .co  m*/

    // This code ensures that all the pixels in the image are loaded
    image = new ImageIcon(image).getImage();
    // Create a buffered image with a format that's compatible with the screen
    BufferedImage bimage = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    try {
        GraphicsDevice gs = ge.getDefaultScreenDevice();
        GraphicsConfiguration gc = gs.getDefaultConfiguration();
        VolatileImage vbimage = gc.createCompatibleVolatileImage(200, 200, gc.getImageCapabilities(),
                Transparency.BITMASK);
    } catch (Exception e) {
        // The system does not have a screen
    }
    return bimage;
}