Search in sources :

Example 81 with GraphicsEnvironment

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

the class IncorrectClipXorModeSurface2Surface method main.

public static void main(final String[] args) throws IOException {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    AffineTransform at;
    for (int size : SIZES) {
        at = AffineTransform.getScaleInstance(size, size);
        for (Shape clip : SHAPES) {
            clip = at.createTransformedShape(clip);
            for (Shape to : SHAPES) {
                to = at.createTransformedShape(to);
                // Prepare test images
                BufferedImage snapshot;
                VolatileImage source = getVolatileImage(gc, size);
                VolatileImage target = getVolatileImage(gc, size);
                int attempt = 0;
                while (true) {
                    if (++attempt > 10) {
                        throw new RuntimeException("Too many attempts: " + attempt);
                    }
                    // Prepare source images
                    source.validate(gc);
                    Graphics2D g2d = source.createGraphics();
                    g2d.setColor(Color.RED);
                    g2d.fillRect(0, 0, size, size);
                    g2d.dispose();
                    if (source.validate(gc) != VolatileImage.IMAGE_OK) {
                        continue;
                    }
                    // Prepare target images
                    target.validate(gc);
                    g2d = target.createGraphics();
                    g2d.setColor(Color.GREEN);
                    g2d.fillRect(0, 0, size, size);
                    g2d.dispose();
                    if (target.validate(gc) != VolatileImage.IMAGE_OK) {
                        continue;
                    }
                    draw(clip, to, source, target);
                    snapshot = target.getSnapshot();
                    if (source.contentsLost() || target.contentsLost()) {
                        continue;
                    }
                    break;
                }
                // Prepare gold images
                BufferedImage goldS = getSourceGold(gc, size);
                BufferedImage goldT = getTargetGold(gc, size);
                draw(clip, to, goldS, goldT);
                validate(snapshot, goldT);
                source.flush();
                target.flush();
            }
        }
    }
}
Also used : Shape(java.awt.Shape) VolatileImage(java.awt.image.VolatileImage) AffineTransform(java.awt.geom.AffineTransform) GraphicsEnvironment(java.awt.GraphicsEnvironment) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D)

Example 82 with GraphicsEnvironment

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

the class IncorrectSourceOffset method main.

public static void main(final String[] args) throws IOException {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    VolatileImage vi = gc.createCompatibleVolatileImage(511, 255);
    BufferedImage bi = new BufferedImage(511, 255, BufferedImage.TYPE_INT_ARGB);
    BufferedImage gold = new BufferedImage(511, 255, BufferedImage.TYPE_INT_ARGB);
    fill(gold);
    while (true) {
        vi.validate(gc);
        fill(vi);
        if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
            try {
                Thread.sleep(100);
            } catch (final InterruptedException ignored) {
            }
            continue;
        }
        Graphics2D big = bi.createGraphics();
        big.drawImage(vi, 7, 11, 127, 111, 7, 11, 127, 111, null);
        big.dispose();
        if (vi.contentsLost()) {
            try {
                Thread.sleep(100);
            } catch (final InterruptedException ignored) {
            }
            continue;
        }
        break;
    }
    for (int x = 7; x < 127; ++x) {
        for (int y = 11; y < 111; ++y) {
            if (gold.getRGB(x, y) != bi.getRGB(x, y)) {
                ImageIO.write(gold, "png", new File("gold.png"));
                ImageIO.write(bi, "png", new File("bi.png"));
                throw new RuntimeException("Test failed.");
            }
        }
    }
}
Also used : VolatileImage(java.awt.image.VolatileImage) GraphicsEnvironment(java.awt.GraphicsEnvironment) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D)

Example 83 with GraphicsEnvironment

use of java.awt.GraphicsEnvironment in project karaf by apache.

the class ScreenshotDumpProvider method createDump.

/**
	 * {@inheritDoc}
	 */
public void createDump(DumpDestination destination) throws Exception {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    // get all graphic devices attached to computer
    GraphicsDevice[] gs = ge.getScreenDevices();
    // create dump entry for each device  
    for (int i = 0; i < gs.length; i++) {
        DisplayMode mode = gs[i].getDisplayMode();
        Rectangle bounds = new Rectangle(0, 0, mode.getWidth(), mode.getHeight());
        BufferedImage screenshot = new Robot(gs[i]).createScreenCapture(bounds);
        // to attach your entry to destination you have to execute this line
        OutputStream outputStream = destination.add("screenshot/display_" + i + ".png");
        ImageIO.write(screenshot, "PNG", outputStream);
        outputStream.close();
    }
}
Also used : DisplayMode(java.awt.DisplayMode) GraphicsDevice(java.awt.GraphicsDevice) OutputStream(java.io.OutputStream) Rectangle(java.awt.Rectangle) GraphicsEnvironment(java.awt.GraphicsEnvironment) Robot(java.awt.Robot) BufferedImage(java.awt.image.BufferedImage)

Example 84 with GraphicsEnvironment

use of java.awt.GraphicsEnvironment in project JMRI by JMRI.

the class ReportContext method addScreenSize.

/**
     * Provide screen - size information. This is based on the
     * jmri.util.JmriJFrame calculation, but isn't refactored to there because
     * we also want diagnostic info
     */
public void addScreenSize() {
    try {
        // Find screen size. This throws null-pointer exceptions on
        // some Java installs, however, for unknown reasons, so be
        // prepared to fall back.
        JFrame dummy = new JFrame();
        try {
            Insets insets = dummy.getToolkit().getScreenInsets(dummy.getGraphicsConfiguration());
            Dimension screen = dummy.getToolkit().getScreenSize();
            addString("Screen size h:" + screen.height + ", w:" + screen.width + " Inset t:" + insets.top + ", b:" + insets.bottom + "; l:" + insets.left + ", r:" + insets.right);
        } catch (NoSuchMethodError ex) {
            Dimension screen = dummy.getToolkit().getScreenSize();
            addString("Screen size h:" + screen.height + ", w:" + screen.width + " (No Inset method available)");
        }
    } catch (HeadlessException ex) {
        // failed, fall back to standard method
        addString("(Cannot sense screen size due to " + ex.toString() + ")");
    }
    try {
        // Find screen resolution. Not expected to fail, but just in case....
        int dpi = Toolkit.getDefaultToolkit().getScreenResolution();
        addString("Screen resolution: " + dpi);
    } catch (HeadlessException ex) {
        addString("Screen resolution not available");
    }
    //Rectangle virtualBounds = new Rectangle();
    try {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        addString("Environment max bounds: " + ge.getMaximumWindowBounds());
        try {
            GraphicsDevice[] gs = ge.getScreenDevices();
            for (GraphicsDevice gd : gs) {
                GraphicsConfiguration[] gc = gd.getConfigurations();
                for (int i = 0; i < gc.length; i++) {
                    addString("bounds[" + i + "] = " + gc[i].getBounds());
                // virtualBounds = virtualBounds.union(gc[i].getBounds());
                }
                addString("Device: " + gd.getIDstring() + " bounds = " + gd.getDefaultConfiguration().getBounds() + " " + gd.getDefaultConfiguration().toString());
            }
        } catch (HeadlessException ex) {
            addString("Exception getting device bounds " + ex.getMessage());
        }
    } catch (HeadlessException ex) {
        addString("Exception getting max window bounds " + ex.getMessage());
    }
    // various Linux window managers
    try {
        Insets jmriInsets = JmriInsets.getInsets();
        addString("JmriInsets t:" + jmriInsets.top + ", b:" + jmriInsets.bottom + "; l:" + jmriInsets.left + ", r:" + jmriInsets.right);
    } catch (Exception ex) {
        addString("Exception getting JmriInsets" + ex.getMessage());
    }
}
Also used : Insets(java.awt.Insets) JmriInsets(jmri.util.JmriInsets) GraphicsDevice(java.awt.GraphicsDevice) HeadlessException(java.awt.HeadlessException) JFrame(javax.swing.JFrame) Dimension(java.awt.Dimension) GraphicsEnvironment(java.awt.GraphicsEnvironment) SocketException(java.net.SocketException) HeadlessException(java.awt.HeadlessException) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 85 with GraphicsEnvironment

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

the class CustomCompositeTest method main.

public static void main(String[] args) {
    paintLatch = new CountDownLatch(1);
    paintError = null;
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            initGUI();
        }
    });
    try {
        paintLatch.await();
    } catch (InterruptedException e) {
    }
    ;
    System.out.println("Paint is done!");
    if (paintError != null) {
        frame.dispose();
        throw new RuntimeException("Test FAILED.", paintError);
    }
    System.out.println("Phase 1: PASSED.");
    // now resise the frame in order to cause re-paint with accelerated
    // source images.
    paintError = null;
    paintLatch = new CountDownLatch(1);
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            Dimension size = frame.getSize();
            size.width += 50;
            size.height += 50;
            frame.setSize(size);
        }
    });
    try {
        paintLatch.await();
    } catch (InterruptedException e) {
    }
    ;
    if (paintError != null) {
        frame.dispose();
        throw new RuntimeException("Resize test FAILED.", paintError);
    }
    frame.dispose();
    System.out.println("Phase 2: PASSED.");
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration cfg = env.getDefaultScreenDevice().getDefaultConfiguration();
    // test rendering to accelerated volatile image
    testVolatileImage(cfg, true);
    System.out.println("Phase 3: PASSED.");
    // test rendering to unaccelerated volatile image
    testVolatileImage(cfg, false);
    System.out.println("Phase 4: PASSED.");
}
Also used : Dimension(java.awt.Dimension) CountDownLatch(java.util.concurrent.CountDownLatch) GraphicsEnvironment(java.awt.GraphicsEnvironment) GraphicsConfiguration(java.awt.GraphicsConfiguration)

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