Search in sources :

Example 96 with SunToolkit

use of sun.awt.SunToolkit in project jdk8u_jdk by JetBrains.

the class bug6796710 method main.

public static void main(String[] args) throws Exception {
    robot = new Robot();
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            frame = new JFrame();
            frame.setUndecorated(true);
            pnBottom = new JPanel();
            pnBottom.add(new JLabel("Some label"));
            pnBottom.add(new JButton("A button"));
            JEditorPane editorPane = new JEditorPane();
            editorPane.setContentType("text/html");
            editorPane.setText(TEXT);
            editorPane.setEditable(false);
            JPanel pnContent = new JPanel(new BorderLayout());
            pnContent.add(new JScrollPane(editorPane), BorderLayout.CENTER);
            pnContent.add(pnBottom, BorderLayout.SOUTH);
            frame.setContentPane(pnContent);
            frame.setSize(400, 600);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
        }
    });
    ((SunToolkit) SunToolkit.getDefaultToolkit()).realSync();
    // This delay should be added for MacOSX, realSync is not enough
    Thread.sleep(1000);
    BufferedImage bufferedImage = getPnBottomImage();
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            frame.setSize(400, 150);
        }
    });
    ((SunToolkit) SunToolkit.getDefaultToolkit()).realSync();
    // On Linux platforms realSync doesn't guaranties setSize completion
    Thread.sleep(1000);
    if (!Util.compareBufferedImages(bufferedImage, getPnBottomImage())) {
        throw new RuntimeException("The test failed");
    }
    System.out.println("The test bug6796710 passed.");
}
Also used : SunToolkit(sun.awt.SunToolkit) BufferedImage(java.awt.image.BufferedImage)

Example 97 with SunToolkit

use of sun.awt.SunToolkit in project jdk8u_jdk by JetBrains.

the class bug7189299 method main.

public static void main(String[] args) throws Exception {
    final SunToolkit toolkit = ((SunToolkit) Toolkit.getDefaultToolkit());
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            setup();
        }
    });
    toolkit.realSync();
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            try {
                verifySingleDefaultButtonModelListener();
                doTest();
                verifySingleDefaultButtonModelListener();
            } finally {
                frame.dispose();
            }
        }
    });
}
Also used : SunToolkit(sun.awt.SunToolkit)

Example 98 with SunToolkit

use of sun.awt.SunToolkit in project jdk8u_jdk by JetBrains.

the class bug6989617 method main.

public static void main(String... args) throws Exception {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            panel = new MyPanel();
            button = new JButton("Hello");
            panel.add(button);
            frame.add(panel);
            frame.setSize(200, 300);
            frame.setVisible(true);
        }
    });
    // Testing the panel as a painting origin,
    // the panel.paintImmediately() must be triggered
    // when button.repaint() is called
    toolkit.realSync();
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            panel.resetPaintRectangle();
            button.repaint();
        }
    });
    toolkit.realSync();
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            Rectangle pr = panel.getPaintRectangle();
            if (!pr.getSize().equals(button.getSize())) {
                throw new RuntimeException("wrong size of the dirty area");
            }
            if (!pr.getLocation().equals(button.getLocation())) {
                throw new RuntimeException("wrong location of the dirty area");
            }
        }
    });
    // Testing the panel as NOT a painting origin
    // the panel.paintImmediately() must NOT be triggered
    // when button.repaint() is called
    toolkit.realSync();
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            panel.resetPaintRectangle();
            panel.setPaintingOrigin(false);
            if (panel.getPaintRectangle() != null) {
                throw new RuntimeException("paint rectangle is not null");
            }
            button.repaint();
        }
    });
    toolkit.realSync();
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            if (panel.getPaintRectangle() != null) {
                throw new RuntimeException("paint rectangle is not null");
            }
            System.out.println("Test passed...");
        }
    });
}
Also used : SunToolkit(sun.awt.SunToolkit)

Example 99 with SunToolkit

use of sun.awt.SunToolkit in project jdk8u_jdk by JetBrains.

the class bug7154030 method main.

public static void main(String[] args) throws Exception {
    BufferedImage imageInit = null;
    BufferedImage imageShow = null;
    BufferedImage imageHide = null;
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    Robot robot = new Robot();
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            JDesktopPane desktop = new JDesktopPane();
            button = new JButton("button");
            JFrame frame = new JFrame();
            button.setSize(200, 200);
            button.setLocation(100, 100);
            button.setForeground(Color.RED);
            button.setBackground(Color.RED);
            button.setOpaque(true);
            button.setVisible(false);
            desktop.add(button);
            frame.setContentPane(desktop);
            frame.setSize(300, 300);
            frame.setLocation(0, 0);
            frame.setVisible(true);
            frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        }
    });
    toolkit.realSync();
    imageInit = robot.createScreenCapture(new Rectangle(0, 0, 300, 300));
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            button.show();
        }
    });
    toolkit.realSync();
    imageShow = robot.createScreenCapture(new Rectangle(0, 0, 300, 300));
    if (Util.compareBufferedImages(imageInit, imageShow)) {
        throw new Exception("Failed to show opaque button");
    }
    toolkit.realSync();
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            button.hide();
        }
    });
    toolkit.realSync();
    imageHide = robot.createScreenCapture(new Rectangle(0, 0, 300, 300));
    if (!Util.compareBufferedImages(imageInit, imageHide)) {
        throw new Exception("Failed to hide opaque button");
    }
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            button.setOpaque(false);
            button.setBackground(new Color(128, 128, 0));
            button.setVisible(false);
        }
    });
    toolkit.realSync();
    imageInit = robot.createScreenCapture(new Rectangle(0, 0, 300, 300));
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            button.show();
        }
    });
    toolkit.realSync();
    imageShow = robot.createScreenCapture(new Rectangle(0, 0, 300, 300));
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            button.hide();
        }
    });
    if (Util.compareBufferedImages(imageInit, imageShow)) {
        throw new Exception("Failed to show non-opaque button");
    }
    toolkit.realSync();
    imageHide = robot.createScreenCapture(new Rectangle(0, 0, 300, 300));
    if (!Util.compareBufferedImages(imageInit, imageHide)) {
        throw new Exception("Failed to hide non-opaque button");
    }
}
Also used : JDesktopPane(javax.swing.JDesktopPane) JFrame(javax.swing.JFrame) Color(java.awt.Color) JButton(javax.swing.JButton) Rectangle(java.awt.Rectangle) SunToolkit(sun.awt.SunToolkit) Robot(java.awt.Robot) BufferedImage(java.awt.image.BufferedImage) AWTException(java.awt.AWTException)

Example 100 with SunToolkit

use of sun.awt.SunToolkit in project jdk8u_jdk by JetBrains.

the class bug6683775 method main.

public static void main(String[] args) throws Exception {
    GraphicsConfiguration gc = getGC();
    if (!AWTUtilities.isTranslucencySupported(AWTUtilities.Translucency.PERPIXEL_TRANSLUCENT) || gc == null) {
        return;
    }
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    Robot robot = new Robot();
    final JFrame testFrame = new JFrame(gc);
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            JFrame backgroundFrame = new JFrame("Background frame");
            backgroundFrame.setUndecorated(true);
            JPanel panel = new JPanel();
            panel.setBackground(Color.RED);
            backgroundFrame.add(panel);
            backgroundFrame.setSize(200, 200);
            backgroundFrame.setVisible(true);
            testFrame.setUndecorated(true);
            JPanel p = new JPanel();
            p.setOpaque(false);
            testFrame.add(p);
            AWTUtilities.setWindowOpaque(testFrame, false);
            testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            testFrame.setSize(400, 400);
            testFrame.setLocation(0, 0);
            testFrame.setVisible(true);
        }
    });
    toolkit.realSync();
    //robot.getPixelColor() didn't work right for some reason
    BufferedImage capture = robot.createScreenCapture(new Rectangle(100, 100));
    int redRGB = Color.RED.getRGB();
    if (redRGB != capture.getRGB(10, 10)) {
        throw new RuntimeException("Transparent frame is not transparent!");
    }
}
Also used : SunToolkit(sun.awt.SunToolkit) BufferedImage(java.awt.image.BufferedImage)

Aggregations

SunToolkit (sun.awt.SunToolkit)120 Robot (java.awt.Robot)26 Point (java.awt.Point)9 Frame (java.awt.Frame)7 JFrame (javax.swing.JFrame)7 BufferedImage (java.awt.image.BufferedImage)5 Rectangle (java.awt.Rectangle)4 FlowLayout (java.awt.FlowLayout)3 TextField (java.awt.TextField)3 Toolkit (java.awt.Toolkit)3 MouseEvent (java.awt.event.MouseEvent)3 JTableHeader (javax.swing.table.JTableHeader)3 Component (java.awt.Component)2 KeyEvent (java.awt.event.KeyEvent)2 VolatileImage (java.awt.image.VolatileImage)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 IOException (java.io.IOException)2 Field (java.lang.reflect.Field)2 URL (java.net.URL)2