Search in sources :

Example 21 with AWTException

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

the class SourceClippingBlitTest method main.

public static void main(String[] args) {
    // allow user to override the properties if needed
    if (System.getProperty("sun.java2d.pmoffscreen") == null) {
        System.setProperty("sun.java2d.pmoffscreen", "true");
    }
    if (args.length > 0 && args[0].equals("-showerrors")) {
        showErrors = true;
    }
    try {
        robot = new Robot();
    } catch (AWTException e) {
        throw new RuntimeException(e);
    }
    Frame f = new Frame(SourceClippingBlitTest.class.getName());
    final SourceClippingBlitTest test = new SourceClippingBlitTest();
    f.add(test);
    f.addWindowListener(new WindowAdapter() {

        public void windowActivated(WindowEvent e) {
            if (!done) {
                test.runTests();
            }
        }
    });
    f.pack();
    f.setLocation(100, 100);
    f.setVisible(true);
    synchronized (lock) {
        while (!done) {
            try {
                lock.wait();
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
        }
    }
    if (!showErrors) {
        f.dispose();
    }
}
Also used : Frame(java.awt.Frame) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) Robot(java.awt.Robot) AWTException(java.awt.AWTException)

Example 22 with AWTException

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

the class SwingOnScreenScrollingTest method main.

public static void main(String[] args) {
    int size = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getColorModel().getPixelSize();
    if (size < 16) {
        System.err.println("<16 bit display mode detected. Test PASSED");
        return;
    }
    final JFrame f = new JFrame("SwingOnScreenScrollingTest");
    try {
        EventQueue.invokeAndWait(new Runnable() {

            public void run() {
                test = new SwingOnScreenScrollingTest();
                pane = new JScrollPane(test);
                f.add(pane);
                f.pack();
                f.setSize(100, 200);
                f.setVisible(true);
            }
        });
    } catch (InvocationTargetException ex) {
        ex.printStackTrace();
    } catch (InterruptedException ex) {
        ex.printStackTrace();
    }
    try {
        Thread.sleep(500);
    } catch (InterruptedException ex) {
        ex.printStackTrace();
    }
    EventQueue.invokeLater(new Runnable() {

        public void run() {
            BufferedImage bi;
            bi = new BufferedImage(100, 300, BufferedImage.TYPE_INT_RGB);
            Graphics gg = bi.getGraphics();
            test.paint(gg);
            for (int y = 80; y < 200; y += 10) {
                test.scrollRectToVisible(new Rectangle(0, y, 100, 100));
                try {
                    Thread.sleep(200);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
            }
            Point p = pane.getViewport().getLocationOnScreen();
            Robot r = null;
            try {
                r = new Robot();
            } catch (AWTException ex) {
                throw new RuntimeException(ex);
            }
            bi = r.createScreenCapture(new Rectangle(p.x + 5, p.y + 5, 30, 30));
            for (int y = 0; y < bi.getHeight(); y++) {
                for (int x = 0; x < bi.getHeight(); x++) {
                    int rgb = bi.getRGB(x, y);
                    if (bi.getRGB(x, y) != Color.red.getRGB()) {
                        System.err.printf("Test Failed at (%d,%d) c=0x%x\n", x, y, rgb);
                        try {
                            String name = "SwingOnScreenScrollingTest_out.png";
                            ImageIO.write(bi, "png", new File(name));
                            System.err.println("Wrote grabbed image to " + name);
                        } catch (Throwable ex) {
                        }
                        throw new RuntimeException("Test failed");
                    }
                }
            }
            System.out.println("Test PASSED.");
            f.dispose();
        }
    });
}
Also used : JScrollPane(javax.swing.JScrollPane) Rectangle(java.awt.Rectangle) Point(java.awt.Point) Point(java.awt.Point) InvocationTargetException(java.lang.reflect.InvocationTargetException) BufferedImage(java.awt.image.BufferedImage) Graphics(java.awt.Graphics) JFrame(javax.swing.JFrame) Robot(java.awt.Robot) File(java.io.File) AWTException(java.awt.AWTException)

Aggregations

AWTException (java.awt.AWTException)22 Robot (java.awt.Robot)13 BufferedImage (java.awt.image.BufferedImage)7 Point (java.awt.Point)5 Rectangle (java.awt.Rectangle)5 Frame (java.awt.Frame)4 IOException (java.io.IOException)4 Image (java.awt.Image)3 MenuItem (java.awt.MenuItem)3 PopupMenu (java.awt.PopupMenu)3 TrayIcon (java.awt.TrayIcon)3 ActionEvent (java.awt.event.ActionEvent)3 WindowEvent (java.awt.event.WindowEvent)3 File (java.io.File)3 BufferCapabilities (java.awt.BufferCapabilities)2 Dimension (java.awt.Dimension)2 Graphics (java.awt.Graphics)2 GraphicsConfiguration (java.awt.GraphicsConfiguration)2 ImageCapabilities (java.awt.ImageCapabilities)2 Insets (java.awt.Insets)2