Search in sources :

Example 21 with GraphicsEnvironment

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

the class FillTexturePaint method main.

public static void main(final String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    VolatileImage vi = gc.createCompatibleVolatileImage(size, size);
    while (true) {
        vi.validate(gc);
        Graphics2D g2d = vi.createGraphics();
        g2d.setComposite(AlphaComposite.Src);
        g2d.setPaint(shape);
        g2d.fill(new Rectangle(0, 0, size, size));
        g2d.dispose();
        if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ignored) {
            }
            continue;
        }
        BufferedImage bi = vi.getSnapshot();
        if (vi.contentsLost()) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ignored) {
            }
            continue;
        }
        for (int x = 0; x < size; ++x) {
            for (int y = 0; y < size; ++y) {
                if (bi.getRGB(x, y) != Color.GREEN.getRGB()) {
                    throw new RuntimeException("Test failed.");
                }
            }
        }
        break;
    }
}
Also used : VolatileImage(java.awt.image.VolatileImage) Rectangle(java.awt.Rectangle) GraphicsEnvironment(java.awt.GraphicsEnvironment) BufferedImage(java.awt.image.BufferedImage) TexturePaint(java.awt.TexturePaint) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D)

Example 22 with GraphicsEnvironment

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

the class FlipDrawImage method main.

public static void main(final String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    VolatileImage vi = gc.createCompatibleVolatileImage(width, height);
    final BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    while (true) {
        vi.validate(gc);
        Graphics2D g2d = vi.createGraphics();
        g2d.setColor(Color.red);
        g2d.fillRect(0, 0, width, height);
        g2d.setColor(Color.green);
        g2d.fillRect(0, 0, width / 2, height / 2);
        g2d.dispose();
        if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ignored) {
            }
            continue;
        }
        Graphics2D g = bi.createGraphics();
        g.setComposite(AlphaComposite.Src);
        g.setColor(Color.BLUE);
        g.fillRect(0, 0, width, height);
        // destination width and height are flipped and scale is used.
        g.drawImage(vi, width / 2, height / 2, -width / 2, -height / 2, null, null);
        g.dispose();
        if (vi.contentsLost()) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ignored) {
            }
            continue;
        }
        for (int x = 0; x < width; ++x) {
            for (int y = 0; y < height; ++y) {
                if (x < width / 2 && y < height / 2) {
                    if (x >= width / 4 && y >= height / 4) {
                        if (bi.getRGB(x, y) != Color.green.getRGB()) {
                            throw new RuntimeException("Test failed.");
                        }
                    } else if (bi.getRGB(x, y) != Color.red.getRGB()) {
                        throw new RuntimeException("Test failed.");
                    }
                } else {
                    if (bi.getRGB(x, y) != Color.BLUE.getRGB()) {
                        throw new RuntimeException("Test failed.");
                    }
                }
            }
        }
        break;
    }
}
Also used : VolatileImage(java.awt.image.VolatileImage) GraphicsEnvironment(java.awt.GraphicsEnvironment) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D)

Example 23 with GraphicsEnvironment

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

the class TransformSetGet method main.

public static void main(final String[] args) {
    final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    final VolatileImage vi = gc.createCompatibleVolatileImage(200, 200);
    final SunGraphics2D sg2d = (SunGraphics2D) vi.createGraphics();
    sg2d.constrain(0, 61, 100, 100);
    final AffineTransform expected = sg2d.cloneTransform();
    sg2d.setTransform(sg2d.getTransform());
    final AffineTransform actual = sg2d.cloneTransform();
    sg2d.dispose();
    vi.flush();
    if (!expected.equals(actual)) {
        System.out.println("Expected = " + expected);
        System.out.println("Actual = " + actual);
        throw new RuntimeException("Wrong transform");
    }
}
Also used : VolatileImage(java.awt.image.VolatileImage) AffineTransform(java.awt.geom.AffineTransform) SunGraphics2D(sun.java2d.SunGraphics2D) GraphicsEnvironment(java.awt.GraphicsEnvironment) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 24 with GraphicsEnvironment

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

the class CloneConfigsTest method main.

public static void main(String[] args) {
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] devices = env.getScreenDevices();
    GraphicsConfiguration c = new TestConfig();
    for (GraphicsDevice gd : devices) {
        System.out.println("Device: " + gd);
        GraphicsConfiguration[] configs = gd.getConfigurations();
        for (int i = 0; i < configs.length; i++) {
            GraphicsConfiguration gc = configs[i];
            System.out.println("\tConfig: " + gc);
            configs[i] = c;
        }
        // verify whether array of configs was modified
        configs = gd.getConfigurations();
        for (GraphicsConfiguration gc : configs) {
            if (gc == c) {
                throw new RuntimeException("Test failed.");
            }
        }
        System.out.println("Test passed.");
    }
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) GraphicsEnvironment(java.awt.GraphicsEnvironment) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 25 with GraphicsEnvironment

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

the class IncorrectAlphaConversionBicubic method main.

public static void main(final String[] args) {
    final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final GraphicsDevice gd = ge.getDefaultScreenDevice();
    final GraphicsConfiguration gc = gd.getDefaultConfiguration();
    final VolatileImage vi = gc.createCompatibleVolatileImage(SIZE, SIZE, TRANSLUCENT);
    final BufferedImage bi = makeUnmanagedBI(gc, TRANSLUCENT);
    final int expected = bi.getRGB(2, 2);
    int attempt = 0;
    BufferedImage snapshot;
    while (true) {
        if (++attempt > 10) {
            throw new RuntimeException("Too many attempts: " + attempt);
        }
        vi.validate(gc);
        final Graphics2D g2d = vi.createGraphics();
        g2d.setComposite(AlphaComposite.Src);
        g2d.scale(2, 2);
        g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        g2d.drawImage(bi, 0, 0, null);
        g2d.dispose();
        snapshot = vi.getSnapshot();
        if (vi.contentsLost()) {
            continue;
        }
        break;
    }
    final int actual = snapshot.getRGB(2, 2);
    if (actual != expected) {
        System.err.println("Actual: " + Integer.toHexString(actual));
        System.err.println("Expected: " + Integer.toHexString(expected));
        throw new RuntimeException("Test failed");
    }
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) VolatileImage(java.awt.image.VolatileImage) GraphicsEnvironment(java.awt.GraphicsEnvironment) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D)

Aggregations

GraphicsEnvironment (java.awt.GraphicsEnvironment)87 GraphicsDevice (java.awt.GraphicsDevice)44 GraphicsConfiguration (java.awt.GraphicsConfiguration)41 BufferedImage (java.awt.image.BufferedImage)22 VolatileImage (java.awt.image.VolatileImage)21 Dimension (java.awt.Dimension)16 Graphics2D (java.awt.Graphics2D)16 Point (java.awt.Point)11 Font (java.awt.Font)10 Rectangle (java.awt.Rectangle)9 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)4 Color (java.awt.Color)3 Container (java.awt.Container)3 DisplayMode (java.awt.DisplayMode)3 GradientPaint (java.awt.GradientPaint)3