Search in sources :

Example 11 with GraphicsConfiguration

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

the class bug8016356 method main.

public static void main(String[] args) throws Exception {
    // Windows only test
    if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) {
        // Retrieving top edge of Desktop
        GraphicsConfiguration grConf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
        Rectangle scrRect = grConf.getBounds();
        Insets scrInsets = Toolkit.getDefaultToolkit().getScreenInsets(grConf);
        scrTop = scrRect.y + scrInsets.top;
        color = new Color(0, 255, 0);
        SwingUtilities.invokeAndWait(() -> {
            createAndShowUI();
        });
        try {
            Robot robot = new Robot();
            robot.setAutoDelay(500);
            robot.setAutoWaitForIdle(true);
            robot.delay(1000);
            // Resizing a window to invoke Windows Snap feature
            readFrameInfo();
            robot.mouseMove(frLoc.x + frSize.width / 2, frLoc.y);
            robot.mousePress(InputEvent.BUTTON1_MASK);
            robot.mouseMove(frLoc.x + frSize.width / 2, scrTop);
            robot.mouseRelease(InputEvent.BUTTON1_MASK);
            // Retrieving the color of window expanded area
            readFrameInfo();
            Insets insets = frame.getInsets();
            Color bgColor = robot.getPixelColor(frLoc.x + frSize.width / 2, frLoc.y + frSize.height - insets.bottom - 1);
            frame.dispose();
            if (!bgColor.equals(color)) {
                throw new RuntimeException("TEST FAILED: got " + bgColor + " instead of " + color);
            }
            System.out.println("TEST PASSED!");
        } catch (AWTException ex) {
            throw new RuntimeException("TEST FAILED!");
        }
    }
}
Also used : Insets(java.awt.Insets) Color(java.awt.Color) Rectangle(java.awt.Rectangle) Robot(java.awt.Robot) GraphicsConfiguration(java.awt.GraphicsConfiguration) AWTException(java.awt.AWTException)

Example 12 with GraphicsConfiguration

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

the class DrawImageBilinear method main.

public static void main(String[] args) {
    boolean show = false;
    for (String arg : args) {
        if ("-show".equals(arg)) {
            show = true;
        }
    }
    String arch = System.getProperty("os.arch");
    boolean isOglEnabled = Boolean.getBoolean("sun.java2d.opengl");
    skipOglTextureTest = isOglEnabled && ("sparc".equals(arch));
    System.out.println("Skip OpenGL texture test: " + skipOglTextureTest);
    DrawImageBilinear test = new DrawImageBilinear();
    Frame frame = new Frame();
    frame.add(test);
    frame.pack();
    frame.setVisible(true);
    // Wait until the component's been painted
    synchronized (test) {
        while (!done) {
            try {
                test.wait();
            } catch (InterruptedException e) {
                throw new RuntimeException("Failed: Interrupted");
            }
        }
    }
    GraphicsConfiguration gc = frame.getGraphicsConfiguration();
    if (gc.getColorModel() instanceof IndexColorModel) {
        System.out.println("IndexColorModel detected: " + "test considered PASSED");
        frame.dispose();
        return;
    }
    if (!show) {
        frame.dispose();
    }
    if (capture == null) {
        throw new RuntimeException("Failed: capture is null");
    }
    // Test background color
    int pixel = capture.getRGB(5, 5);
    if (pixel != 0xffffffff) {
        throw new RuntimeException("Failed: Incorrect color for " + "background");
    }
    // Test pixels
    testRegion(capture, new Rectangle(10, 10, 40, 40));
    testRegion(capture, new Rectangle(80, 10, 40, 40));
    testRegion(capture, new Rectangle(150, 10, 40, 40));
}
Also used : Frame(java.awt.Frame) Rectangle(java.awt.Rectangle) Point(java.awt.Point) GraphicsConfiguration(java.awt.GraphicsConfiguration) IndexColorModel(java.awt.image.IndexColorModel)

Example 13 with GraphicsConfiguration

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

the class SourceClippingBlitTest method runTests.

public void runTests() {
    GraphicsConfiguration gc = getGraphicsConfiguration();
    for (Image srcIm : new Image[] { getBufferedImage(gc, IMAGEW, IMAGEH, BufferedImage.TYPE_INT_RGB, true), getBufferedImage(gc, IMAGEW, IMAGEH, BufferedImage.TYPE_INT_RGB, false), //                        BufferedImage.TYPE_INT_ARGB, false),
    getVImage(gc, IMAGEW, IMAGEH) }) {
        System.out.println("Testing source: " + srcIm);
        // wiggle the source and dest rectangles
        try {
            for (int locationVar = -10; locationVar < 20; locationVar += 10) {
                for (int sizeVar = -10; sizeVar < 20; sizeVar += 10) {
                    Rectangle srcRect = (Rectangle) IMAGE_BOUNDS.clone();
                    srcRect.translate(locationVar, locationVar);
                    srcRect.grow(sizeVar, sizeVar);
                    Rectangle dstRect = new Rectangle(sizeVar, sizeVar, srcRect.width, srcRect.height);
                    System.out.println("testing blit rect src: " + srcRect);
                    System.out.println("                  dst: " + dstRect);
                    render(getGraphics(), srcIm, srcRect, dstRect);
                    test(srcRect, dstRect);
                }
            }
            System.out.println("Test passed.");
        } finally {
            synchronized (lock) {
                done = true;
                lock.notifyAll();
            }
        }
    }
}
Also used : Rectangle(java.awt.Rectangle) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) VolatileImage(java.awt.image.VolatileImage) Point(java.awt.Point) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 14 with GraphicsConfiguration

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

the class SourceClippingBlitTest method render.

public void render(Graphics g, Image image, Rectangle srcRect, Rectangle dstRect) {
    int w = getWidth();
    int h = getHeight();
    g.setColor(Color.green);
    g.fillRect(0, 0, w, h);
    int bltWidth = srcRect.width;
    int bltHeight = srcRect.height;
    VolatileImage vi = null;
    if (image instanceof VolatileImage) {
        vi = (VolatileImage) image;
    }
    do {
        if (vi != null) {
            GraphicsConfiguration gc = getGraphicsConfiguration();
            if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
                initImage(gc, vi);
            }
        }
        g.drawImage(image, dstRect.x, dstRect.y, dstRect.x + bltWidth, dstRect.y + bltHeight, srcRect.x, srcRect.y, srcRect.x + bltWidth, srcRect.y + bltHeight, Color.red, null);
    } while (vi != null && vi.contentsLost());
}
Also used : VolatileImage(java.awt.image.VolatileImage) Point(java.awt.Point) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 15 with GraphicsConfiguration

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

the class bug7181438 method createVolatileImage.

private static VolatileImage createVolatileImage() {
    final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    return gc.createCompatibleVolatileImage(SIZE, SIZE, Transparency.TRANSLUCENT);
}
Also used : GraphicsEnvironment(java.awt.GraphicsEnvironment) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Aggregations

GraphicsConfiguration (java.awt.GraphicsConfiguration)136 GraphicsEnvironment (java.awt.GraphicsEnvironment)55 BufferedImage (java.awt.image.BufferedImage)46 Rectangle (java.awt.Rectangle)44 GraphicsDevice (java.awt.GraphicsDevice)38 Graphics2D (java.awt.Graphics2D)34 VolatileImage (java.awt.image.VolatileImage)31 Point (java.awt.Point)30 Dimension (java.awt.Dimension)21 Insets (java.awt.Insets)17 File (java.io.File)16 Graphics (java.awt.Graphics)13 IOException (java.io.IOException)13 Frame (java.awt.Frame)11 JFrame (javax.swing.JFrame)8 HeadlessException (java.awt.HeadlessException)7 Window (java.awt.Window)7 ImageIcon (javax.swing.ImageIcon)7 Color (java.awt.Color)6 AffineTransform (java.awt.geom.AffineTransform)6