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

/**
 * Gets the insets of the screen.// w  w  w.j  a  va 2  s  .  c  om
 * <p>
 * <b>Attention: </b>Due to <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6899304">Java bug 6899304</a>
 * this method only returns correct insets values for the primary screen device. For other screen devices empty insets
 * will be returned. In Windows environments these circumstances (task bar on a none primary screen) will be very rare
 * and therefore ignored until the bug will be fixed in a future Java version.
 * </p>
 *
 * @param screenDevice
 *          a screen thats {@link GraphicsConfiguration} will be used to determine the insets
 * @return the insets of this toolkit's screen, in pixels, if the given screen device is the primary screen, otherwise
 *         empty insets
 * @see Toolkit#getScreenInsets(GraphicsConfiguration)
 */
public static Insets getScreenInsets(GraphicsDevice screenDevice) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    // <bko 2012-02-29>
    // "Fix" for Sun bug 6899304 ("java.awt.Toolkit.getScreenInsets(GraphicsConfiguration) returns incorrect values")
    // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6699851
    if (screenDevice == ge.getDefaultScreenDevice()) {
        // only return Toolkit.getScreenInsets for primary screen device
        return Toolkit.getDefaultToolkit().getScreenInsets(screenDevice.getDefaultConfiguration());
    } else {
        // return empty insets for other screen devices
        return new Insets(0, 0, 0, 0);
    }
    // </bko>
}

From source file:com.seleniumtests.driver.CustomEventFiringWebDriver.java

/**
 * Returns the rectangle of all screens on the system
 * @return/*w w w.  j a va  2  s . co m*/
 */
private static Rectangle getScreensRectangle() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

    Rectangle screenRect = new Rectangle(0, 0, 0, 0);
    for (GraphicsDevice gd : ge.getScreenDevices()) {
        screenRect = screenRect.union(gd.getDefaultConfiguration().getBounds());
    }
    return screenRect;
}

From source file:org.github.jipsg.sanselan.ManagedImageBufferedImageFactory.java

public BufferedImage getColorBufferedImage(final int width, final int height, final boolean hasAlpha) {
    final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final GraphicsDevice gd = ge.getDefaultScreenDevice();
    final GraphicsConfiguration gc = gd.getDefaultConfiguration();
    return gc.createCompatibleImage(width, height, Transparency.TRANSLUCENT);
}

From source file:MultiBufferTest.java

public MultiBufferTest(int numBuffers, GraphicsDevice device) {
    try {/*w  w w .  j a  va2  s. c o  m*/
        GraphicsConfiguration gc = device.getDefaultConfiguration();
        mainFrame = new Frame(gc);
        mainFrame.setUndecorated(true);
        mainFrame.setIgnoreRepaint(true);
        device.setFullScreenWindow(mainFrame);
        if (device.isDisplayChangeSupported()) {
            chooseBestDisplayMode(device);
        }
        Rectangle bounds = mainFrame.getBounds();
        mainFrame.createBufferStrategy(numBuffers);
        BufferStrategy bufferStrategy = mainFrame.getBufferStrategy();
        for (float lag = 2000.0f; lag > 0.00000006f; lag = lag / 1.33f) {
            for (int i = 0; i < numBuffers; i++) {
                Graphics g = bufferStrategy.getDrawGraphics();
                if (!bufferStrategy.contentsLost()) {
                    g.setColor(COLORS[i]);
                    g.fillRect(0, 0, bounds.width, bounds.height);
                    bufferStrategy.show();
                    g.dispose();
                }
                try {
                    Thread.sleep((int) lag);
                } catch (InterruptedException e) {
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        device.setFullScreenWindow(null);
    }
}

From source file:GCWrapper.java

public CapabilitiesTest(GraphicsDevice dev) {
    super(dev.getDefaultConfiguration());
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent ev) {
            System.exit(0);/*from  w  ww  . j  a  v  a  2 s  . c o  m*/
        }
    });
    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:DisplayModeModel.java

public DisplayModeTest(GraphicsDevice device) {
    super(device.getDefaultConfiguration());
    this.device = device;
    setTitle("Display Mode Test");
    originalDM = device.getDisplayMode();
    setDMLabel(originalDM);//w  w w  . j  a  v  a2 s. c  om
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    // Make sure a DM is always selected in the list
    exit.addActionListener(this);
    changeDM.addActionListener(this);
    changeDM.setEnabled(device.isDisplayChangeSupported());
}

From source file:eu.novait.imagerenamer.model.ImageFile.java

private BufferedImage getCompatibleImage(int w, int h) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    GraphicsConfiguration gc = gd.getDefaultConfiguration();
    BufferedImage image = gc.createCompatibleImage(w, h);
    return image;
}

From source file:com.mightypocket.ashot.AndroDemon.java

public AndroDemon(final Mediator mediator) {
    super(mediator.getApplication());
    this.mediator = mediator;

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    gc = gd.getDefaultConfiguration();
}

From source file:net.pms.medialibrary.commons.helpers.FileImportHelper.java

/**
 * Creates a buffered image from an image
 * @param image the image/*from  ww w .  j  av a  2s  . c  o  m*/
 * @return the buffered image
 */
public static BufferedImage getBufferedImage(Image image) {
    if (image instanceof BufferedImage) {
        return (BufferedImage) image;
    }

    // This code ensures that all the pixels in the image are loaded
    image = new ImageIcon(image).getImage();

    // Determine if the image has transparent pixels; for this method's
    // implementation, see Determining If an Image Has Transparent Pixels
    boolean hasAlpha = hasAlpha(image);

    // Create a buffered image with a format that's compatible with the screen
    BufferedImage bimage = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    try {
        // Determine the type of transparency of the new buffered image
        int transparency = Transparency.OPAQUE;
        if (hasAlpha) {
            transparency = Transparency.BITMASK;
        }

        // Create the buffered image
        GraphicsDevice gs = ge.getDefaultScreenDevice();
        GraphicsConfiguration gc = gs.getDefaultConfiguration();
        bimage = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), transparency);
    } catch (HeadlessException e) {
        // The system does not have a screen
    }

    if (bimage == null) {
        // Create a buffered image using the default color model
        int type = BufferedImage.TYPE_INT_RGB;
        if (hasAlpha) {
            type = BufferedImage.TYPE_INT_ARGB;
        }
        bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
    }

    // Copy image to buffered image
    Graphics g = bimage.createGraphics();

    // Paint the image onto the buffered image
    g.drawImage(image, 0, 0, null);
    g.dispose();

    return bimage;
}

From source file:com.tag.FramePreferences.java

public final Rectangle getGraphicsBounds() {
    GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Rectangle r = null;/*from   ww  w . java2 s.co m*/
    for (GraphicsDevice device : environment.getScreenDevices()) {
        GraphicsConfiguration config = device.getDefaultConfiguration();
        if (r == null) {
            r = config.getBounds();
        } else {
            r.add(config.getBounds());
        }
    }
    return r;
}