Search in sources :

Example 21 with SunToolkit

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

the class bug7156657 method main.

public static void main(String[] args) throws Exception {
    final Robot robot = new Robot();
    final SunToolkit toolkit = ((SunToolkit) Toolkit.getDefaultToolkit());
    Boolean skipTest = Util.invokeOnEDT(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            frame = createFrame();
            if (!AWTUtilities.isTranslucencyCapable(frame.getGraphicsConfiguration())) {
                System.out.println("Translucency is not supported, the test skipped");
                return true;
            }
            lowerFrame = createFrame();
            lowerFrame.getContentPane().setBackground(Color.RED);
            lowerFrame.setVisible(true);
            popupMenu = new JPopupMenu();
            popupMenu.setOpaque(false);
            popupMenu.add(new TransparentMenuItem("1111"));
            popupMenu.add(new TransparentMenuItem("2222"));
            popupMenu.add(new TransparentMenuItem("3333"));
            AWTUtilities.setWindowOpaque(frame, false);
            JPanel pnContent = new JPanel();
            pnContent.setBackground(new Color(255, 255, 255, 128));
            frame.add(pnContent);
            frame.setVisible(true);
            return false;
        }
    });
    if (skipTest) {
        return;
    }
    toolkit.realSync();
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            popupMenu.show(frame, 0, 0);
        }
    });
    toolkit.realSync();
    Rectangle popupRectangle = Util.invokeOnEDT(new Callable<Rectangle>() {

        @Override
        public Rectangle call() throws Exception {
            return popupMenu.getBounds();
        }
    });
    BufferedImage redBackgroundCapture = robot.createScreenCapture(popupRectangle);
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            lowerFrame.getContentPane().setBackground(Color.GREEN);
        }
    });
    toolkit.realSync();
    BufferedImage greenBackgroundCapture = robot.createScreenCapture(popupRectangle);
    if (Util.compareBufferedImages(redBackgroundCapture, greenBackgroundCapture)) {
        throw new RuntimeException("The test failed");
    }
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            popupMenu.setVisible(false);
            frame.dispose();
            lowerFrame.dispose();
        }
    });
    System.out.println("The test passed");
}
Also used : SunToolkit(sun.awt.SunToolkit) BufferedImage(java.awt.image.BufferedImage)

Example 22 with SunToolkit

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

the class bug6987844 method main.

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

        public void run() {
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JMenuBar bar = new JMenuBar();
            menu1 = new JMenu("Menu1");
            menu1.add(new JMenuItem("item"));
            bar.add(menu1);
            menu2 = new JMenu("Menu2");
            menu2.add(new JMenuItem("item"));
            menu2.add(new JMenuItem("item"));
            bar.add(menu2);
            frame.setJMenuBar(bar);
            frame.pack();
            frame.setVisible(true);
        }
    });
    toolkit.realSync();
    Point point1 = menu1.getLocationOnScreen();
    Point point2 = menu2.getLocationOnScreen();
    robot.mouseMove(point1.x + 1, point1.y + 1);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.mouseMove(point2.x + 1, point2.y + 1);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.mouseMove(point1.x + 1, point1.y + 1);
    toolkit.realSync();
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            Dimension popupSize1 = menu1.getPopupMenu().getSize();
            Dimension popupSize2 = menu2.getPopupMenu().getSize();
            if (popupSize1.equals(popupSize2)) {
                throw new RuntimeException("First popup unexpedetly changed its size");
            }
        }
    });
}
Also used : SunToolkit(sun.awt.SunToolkit)

Example 23 with SunToolkit

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

the class bug4692443 method main.

public static void main(String[] args) throws Throwable {
    fail = new FailedListener();
    pass = new PassedListener();
    passed = false;
    Robot robo = new Robot();
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            createAndShowGUI();
        }
    });
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    toolkit.realSync();
    try {
        robo = new Robot();
    } catch (AWTException e) {
        throw new RuntimeException("Robot could not be created");
    }
    int altKey = java.awt.event.KeyEvent.VK_ALT;
    robo.setAutoDelay(100);
    // Enter File menu
    Util.hitMnemonics(robo, KeyEvent.VK_F);
    // Enter submenu
    robo.keyPress(KeyEvent.VK_S);
    robo.keyRelease(KeyEvent.VK_S);
    // Launch "One" action
    robo.keyPress(KeyEvent.VK_O);
    robo.keyRelease(KeyEvent.VK_O);
    // Launch "One" action
    robo.keyPress(KeyEvent.VK_M);
    robo.keyRelease(KeyEvent.VK_M);
    toolkit.realSync();
    if (!passed) {
        throw new RuntimeException("Test failed.");
    }
}
Also used : SunToolkit(sun.awt.SunToolkit)

Example 24 with SunToolkit

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

the class bug4458079 method main.

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

        public void run() {
            new bug4458079().createAndShowGUI();
        }
    });
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    toolkit.realSync();
    Robot robot = new Robot();
    robot.setAutoDelay(50);
    Util.hitMnemonics(robot, KeyEvent.VK_M);
    toolkit.realSync();
    Thread.sleep(1000);
    Util.hitKeys(robot, KeyEvent.VK_DOWN);
    Util.hitKeys(robot, KeyEvent.VK_ENTER);
    toolkit.realSync();
    Thread.sleep(1000);
    if (!itemASelected) {
        throw new RuntimeException("Test failed: arrow key traversal in JMenu broken!");
    }
}
Also used : SunToolkit(sun.awt.SunToolkit) Robot(java.awt.Robot)

Example 25 with SunToolkit

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

the class bug7146377 method main.

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

        public void run() {
            frame = new JFrame();
            label = new JLabel("A label");
            label.addMouseListener(new MouseListener() {

                @Override
                public void mouseClicked(MouseEvent e) {
                    checkEvent(e);
                }

                @Override
                public void mousePressed(MouseEvent e) {
                    checkEvent(e);
                }

                @Override
                public void mouseReleased(MouseEvent e) {
                    checkEvent(e);
                }

                @Override
                public void mouseEntered(MouseEvent e) {
                    checkEvent(e);
                }

                @Override
                public void mouseExited(MouseEvent e) {
                    checkEvent(e);
                }
            });
            frame.add(label);
            frame.setSize(200, 100);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
        }
    });
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    toolkit.realSync();
    // On Linux platforms realSync doesn't guaranties setSize completion
    Thread.sleep(1000);
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            point = label.getLocationOnScreen();
        }
    });
    Robot robot = new Robot();
    robot.setAutoDelay(200);
    // Move mouse
    for (int i = 0; i < 20; i++) {
        robot.mouseMove(point.x + i, point.y + i);
    }
    for (int button : new int[] { InputEvent.BUTTON1_MASK, InputEvent.BUTTON2_MASK, InputEvent.BUTTON3_MASK }) {
        robot.mouseMove(point.x, point.y);
        // Mouse Drag
        robot.mousePress(button);
        for (int i = 0; i < 20; i++) {
            robot.mouseMove(point.x + i, point.y + i);
        }
        robot.mouseRelease(button);
    }
    toolkit.realSync();
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            frame.dispose();
        }
    });
    System.out.println("Test passed");
}
Also used : MouseListener(java.awt.event.MouseListener) MouseEvent(java.awt.event.MouseEvent) SunToolkit(sun.awt.SunToolkit)

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