Search in sources :

Example 71 with SunToolkit

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

the class bug4743225 method main.

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

        public void run() {
            new bug4743225().setVisible(true);
        }
    });
    toolkit.realSync();
    // calling this method from main thread is ok
    Point point = cb.getLocationOnScreen();
    robot.mouseMove(point.x + 10, point.y + 10);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    toolkit.realSync();
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            if (getPopup().getList().getLastVisibleIndex() == 3) {
                flag = true;
            }
        }
    });
    if (!flag) {
        throw new RuntimeException("The ComboBox popup wasn't correctly updated");
    }
}
Also used : SunToolkit(sun.awt.SunToolkit) Point(java.awt.Point) Robot(java.awt.Robot)

Example 72 with SunToolkit

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

the class ConsumedKeyTest method test.

private static void test(final int key) throws Exception {
    passed = false;
    try {
        SwingUtilities.invokeAndWait(() -> {
            frame = new JFrame();
            JComboBox<String> combo = new JComboBox<>(new String[] { "one", "two", "three" });
            JPanel panel = new JPanel();
            panel.add(combo);
            combo.requestFocusInWindow();
            frame.setBounds(100, 150, 300, 100);
            addAction(panel, key);
            frame.add(panel);
            frame.setVisible(true);
        });
        Robot robot = new Robot();
        robot.waitForIdle();
        ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();
        robot.keyPress(key);
        robot.waitForIdle();
        ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();
        robot.keyRelease(key);
        robot.waitForIdle();
        ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();
        if (!passed) {
            throw new RuntimeException("FAILED: " + KeyEvent.getKeyText(key) + " was consumed by combo box");
        }
    } finally {
        if (frame != null) {
            frame.dispose();
        }
    }
}
Also used : SunToolkit(sun.awt.SunToolkit) Robot(java.awt.Robot)

Example 73 with SunToolkit

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

the class bug7199708 method main.

public static void main(String[] args) throws Exception {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    Robot robot = new Robot();
    robot.setAutoDelay(50);
    final File folder = createLargeFolder();
    UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            fileChooser = new JFileChooser(folder);
            fileChooser.showSaveDialog(null);
        }
    });
    toolkit.realSync();
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            final String detailsTooltip = UIManager.getString("FileChooser." + "detailsViewButtonToolTipText", fileChooser.getLocale());
            doAction(fileChooser, new ComponentAction() {

                @Override
                public boolean accept(Component component) {
                    return (component instanceof AbstractButton) && detailsTooltip.equals(((AbstractButton) component).getToolTipText());
                }

                @Override
                public void perform(Component component) {
                    ((AbstractButton) component).doClick();
                }
            });
            doAction(fileChooser, new ComponentAction() {

                @Override
                public boolean accept(Component component) {
                    return (component instanceof JTable);
                }

                @Override
                public void perform(Component component) {
                    Point tableLocation = component.getLocationOnScreen();
                    locationX = (int) tableLocation.getX();
                    locationY = (int) tableLocation.getY();
                    width = (int) fileChooser.getBounds().getWidth();
                }
            });
        }
    });
    toolkit.realSync();
    int d = 25;
    for (int i = 0; i < width / d; i++) {
        robot.mouseMove(locationX + i * d, locationY + 5);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        toolkit.realSync();
    }
    robot.keyPress(KeyEvent.VK_ESCAPE);
    robot.keyRelease(KeyEvent.VK_ESCAPE);
}
Also used : AbstractButton(javax.swing.AbstractButton) JFileChooser(javax.swing.JFileChooser) JTable(javax.swing.JTable) SunToolkit(sun.awt.SunToolkit) Point(java.awt.Point) Component(java.awt.Component) Robot(java.awt.Robot) File(java.io.File) Point(java.awt.Point)

Example 74 with SunToolkit

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

the class bug8021253 method main.

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

        public void run() {
            createAndShowGUI();
        }
    });
    toolkit.realSync();
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            fileChooser.setSelectedFile(file);
        }
    });
    toolkit.realSync();
    robot.keyPress(KeyEvent.VK_ENTER);
    robot.keyRelease(KeyEvent.VK_ENTER);
    toolkit.realSync();
    if (!defaultKeyPressed) {
        throw new RuntimeException("Default button is not pressed");
    }
}
Also used : SunToolkit(sun.awt.SunToolkit) Robot(java.awt.Robot)

Example 75 with SunToolkit

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

the class bug6596966 method main.

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

        public void run() {
            button = new JButton("Button");
            comboBox = new JComboBox();
            label = new JLabel("Label");
            label.setDisplayedMnemonic('L');
            label.setLabelFor(comboBox);
            JPanel pnContent = new JPanel();
            pnContent.add(button);
            pnContent.add(label);
            pnContent.add(comboBox);
            frame = new JFrame();
            frame.add(pnContent);
            frame.pack();
            frame.setVisible(true);
        }
    });
    toolkit.realSync();
    ArrayList<Integer> keys = Util.getSystemMnemonicKeyCodes();
    for (int i = 0; i < keys.size(); ++i) {
        robot.keyPress(keys.get(i));
    }
    robot.keyPress(KeyEvent.VK_L);
    toolkit.realSync();
    toolkit.getSystemEventQueue().postEvent(new KeyEvent(label, KeyEvent.KEY_RELEASED, EventQueue.getMostRecentEventTime(), 0, KeyEvent.VK_L, 'L'));
    toolkit.realSync();
    try {
        SwingUtilities.invokeAndWait(new Runnable() {

            public void run() {
                if (!comboBox.isFocusOwner()) {
                    throw new RuntimeException("comboBox isn't focus owner");
                }
            }
        });
    } finally {
        robot.keyRelease(KeyEvent.VK_L);
        for (int i = 0; i < keys.size(); ++i) {
            robot.keyRelease(keys.get(i));
        }
        toolkit.realSync();
    }
}
Also used : SunToolkit(sun.awt.SunToolkit) KeyEvent(java.awt.event.KeyEvent)

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