Search in sources :

Example 41 with GraphicsEnvironment

use of java.awt.GraphicsEnvironment in project jdk8u_jdk by JetBrains.

the class RSLAPITest method main.

public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    GraphicsConfiguration gc = gd.getDefaultConfiguration();
    testGC(gc);
    if (failed) {
        throw new RuntimeException("Test FAILED. See err output for more");
    }
    System.out.println("Test PASSED.");
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) GraphicsEnvironment(java.awt.GraphicsEnvironment) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 42 with GraphicsEnvironment

use of java.awt.GraphicsEnvironment in project jdk8u_jdk by JetBrains.

the class OpaqueImageToSurfaceBlitTest method main.

public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    GraphicsConfiguration gc = gd.getDefaultConfiguration();
    VolatileImage vi = gc.createCompatibleVolatileImage(16, 16);
    vi.validate(gc);
    BufferedImage bi = new BufferedImage(2, 2, BufferedImage.TYPE_INT_RGB);
    int[] data = ((DataBufferInt) bi.getRaster().getDataBuffer()).getData();
    data[0] = 0x0000007f;
    data[1] = 0x0000007f;
    data[2] = 0xff00007f;
    data[3] = 0xff00007f;
    Graphics2D g = vi.createGraphics();
    g.setComposite(AlphaComposite.SrcOver.derive(0.999f));
    g.drawImage(bi, 0, 0, null);
    bi = vi.getSnapshot();
    if (bi.getRGB(0, 0) != bi.getRGB(1, 1)) {
        throw new RuntimeException("Test FAILED: color at 0x0 =" + Integer.toHexString(bi.getRGB(0, 0)) + " differs from 1x1 =" + Integer.toHexString(bi.getRGB(1, 1)));
    }
    System.out.println("Test PASSED.");
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) VolatileImage(java.awt.image.VolatileImage) DataBufferInt(java.awt.image.DataBufferInt) GraphicsEnvironment(java.awt.GraphicsEnvironment) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D)

Example 43 with GraphicsEnvironment

use of java.awt.GraphicsEnvironment in project sulky by huxi.

the class Windows method showWindow.

public static void showWindow(Window window, Window centerParent, boolean pack) {
    final Logger logger = LoggerFactory.getLogger(Windows.class);
    if (pack) {
        window.pack();
    }
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Rectangle maxBounds = ge.getMaximumWindowBounds();
    if (logger.isDebugEnabled())
        logger.debug("MaximumWindowBounds: {}", maxBounds);
    Rectangle windowBounds = window.getBounds();
    if (logger.isDebugEnabled())
        logger.debug("Original windowBounds: {}", windowBounds);
    if (windowBounds.width > maxBounds.width) {
        windowBounds.width = maxBounds.width;
    }
    if (windowBounds.height > maxBounds.height) {
        windowBounds.height = maxBounds.height;
    }
    if (logger.isDebugEnabled())
        logger.debug("Corrected windowBounds: {}", windowBounds);
    Rectangle centerBounds = maxBounds;
    if (centerParent != null && centerParent.isVisible()) {
        centerBounds = centerParent.getBounds();
        if (logger.isDebugEnabled())
            logger.debug("Retrieved parent container bounds...");
    }
    if (logger.isDebugEnabled())
        logger.debug("centerBounds: {}", centerBounds);
    windowBounds.x = centerBounds.x + (centerBounds.width - windowBounds.width) / 2;
    windowBounds.y = centerBounds.y + (centerBounds.height - windowBounds.height) / 2;
    if (logger.isDebugEnabled())
        logger.debug("centered bounds: {}", windowBounds);
    // first, correct upper left corner
    if (windowBounds.x < maxBounds.x) {
        windowBounds.x = maxBounds.x;
    }
    if (windowBounds.y < maxBounds.y) {
        windowBounds.y = maxBounds.y;
    }
    if (logger.isDebugEnabled())
        logger.debug("corrected1: {}", windowBounds);
    // second, check bottom right
    if (windowBounds.x + windowBounds.width > maxBounds.x + maxBounds.width) {
        windowBounds.x = maxBounds.width - windowBounds.width;
    }
    if (windowBounds.y + windowBounds.height > maxBounds.y + maxBounds.height) {
        windowBounds.y = maxBounds.height - windowBounds.height;
    }
    if (logger.isDebugEnabled())
        logger.debug("corrected1: {}", windowBounds);
    // if window/window is simply too large.
    if (windowBounds.x < maxBounds.x) {
        windowBounds.x = maxBounds.x;
    }
    if (windowBounds.y < maxBounds.y) {
        windowBounds.y = maxBounds.y;
    }
    if (logger.isDebugEnabled())
        logger.debug("changed bounds: {}", windowBounds);
    window.setBounds(windowBounds);
    window.setVisible(true);
}
Also used : Rectangle(java.awt.Rectangle) Logger(org.slf4j.Logger) GraphicsEnvironment(java.awt.GraphicsEnvironment)

Example 44 with GraphicsEnvironment

use of java.awt.GraphicsEnvironment in project vcell by virtualcell.

the class BeanUtils method centerOnScreen.

public static void centerOnScreen(Window window) {
    if (window != null) {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        final Rectangle maxBounds = ge.getMaximumWindowBounds();
        Dimension screenSize = maxBounds.getSize();
        Dimension size = window.getSize();
        if (size.height > screenSize.height)
            size.height = screenSize.height;
        if (size.width > screenSize.width)
            size.width = screenSize.width;
        window.setLocation((screenSize.width - size.width) / 2, (screenSize.height - size.height) / 2);
    }
}
Also used : Rectangle(java.awt.Rectangle) Dimension(java.awt.Dimension) GraphicsEnvironment(java.awt.GraphicsEnvironment)

Example 45 with GraphicsEnvironment

use of java.awt.GraphicsEnvironment in project jdk8u_jdk by JetBrains.

the class OffScreenImage method createGraphics.

public Graphics2D createGraphics() {
    if (c == null) {
        GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
        return env.createGraphics(this);
    }
    Color bg = c.getBackground();
    if (bg == null) {
        bg = SystemColor.window;
    }
    Color fg = c.getForeground();
    if (fg == null) {
        fg = SystemColor.windowText;
    }
    Font font = c.getFont();
    if (font == null) {
        if (defaultFont == null) {
            defaultFont = new Font("Dialog", Font.PLAIN, 12);
        }
        font = defaultFont;
    }
    return new SunGraphics2D(SurfaceData.getPrimarySurfaceData(this), fg, bg, font);
}
Also used : Color(java.awt.Color) SystemColor(java.awt.SystemColor) SunGraphics2D(sun.java2d.SunGraphics2D) GraphicsEnvironment(java.awt.GraphicsEnvironment) Font(java.awt.Font)

Aggregations

GraphicsEnvironment (java.awt.GraphicsEnvironment)93 GraphicsDevice (java.awt.GraphicsDevice)46 GraphicsConfiguration (java.awt.GraphicsConfiguration)44 BufferedImage (java.awt.image.BufferedImage)24 VolatileImage (java.awt.image.VolatileImage)21 Dimension (java.awt.Dimension)17 Graphics2D (java.awt.Graphics2D)17 Point (java.awt.Point)12 Font (java.awt.Font)11 Rectangle (java.awt.Rectangle)11 Insets (java.awt.Insets)7 File (java.io.File)7 Frame (java.awt.Frame)6 Toolkit (java.awt.Toolkit)6 AffineTransform (java.awt.geom.AffineTransform)6 HeadlessException (java.awt.HeadlessException)5 Color (java.awt.Color)3 Container (java.awt.Container)3 DisplayMode (java.awt.DisplayMode)3 GradientPaint (java.awt.GradientPaint)3