Search in sources :

Example 1 with SunToolkit

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

the class bug8020708 method testInternalFrameMnemonic.

static void testInternalFrameMnemonic() throws Exception {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    Robot robot = new Robot();
    robot.setAutoDelay(50);
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            frame = new JFrame("Test");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(300, 200);
            JDesktopPane desktop = new JDesktopPane();
            internalFrame = new JInternalFrame("Test");
            internalFrame.setSize(200, 100);
            internalFrame.setClosable(true);
            desktop.add(internalFrame);
            internalFrame.setVisible(true);
            internalFrame.setMaximizable(true);
            frame.getContentPane().add(desktop);
            frame.setVisible(true);
        }
    });
    toolkit.realSync();
    Point clickPoint = Util.getCenterPoint(internalFrame);
    robot.mouseMove(clickPoint.x, clickPoint.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    toolkit.realSync();
    Util.hitKeys(robot, KeyEvent.VK_CONTROL, KeyEvent.VK_SPACE);
    toolkit.realSync();
    Util.hitKeys(robot, KeyEvent.VK_C);
    toolkit.realSync();
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            if (internalFrame.isVisible()) {
                throw new RuntimeException("Close mnemonic does not work");
            }
            frame.dispose();
        }
    });
}
Also used : JDesktopPane(javax.swing.JDesktopPane) JFrame(javax.swing.JFrame) SunToolkit(sun.awt.SunToolkit) Point(java.awt.Point) Robot(java.awt.Robot) JInternalFrame(javax.swing.JInternalFrame)

Example 2 with SunToolkit

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

the class InternalFrameIsNotCollectedTest method sync.

public static void sync() {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    toolkit.realSync();
}
Also used : SunToolkit(sun.awt.SunToolkit)

Example 3 with SunToolkit

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

the class bug8002077 method runTest.

private static void runTest() throws Exception {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    Robot robot = new Robot();
    robot.setAutoDelay(50);
    SwingUtilities.invokeLater(() -> fileChooserState = new JFileChooser().showSaveDialog(null));
    toolkit.realSync();
    Util.hitMnemonics(robot, KeyEvent.VK_N);
    toolkit.realSync();
    Util.hitKeys(robot, KeyEvent.VK_A);
    toolkit.realSync();
    Util.hitMnemonics(robot, KeyEvent.VK_S);
    toolkit.realSync();
    if (fileChooserState != JFileChooser.APPROVE_OPTION) {
        // Close the dialog
        Util.hitKeys(robot, KeyEvent.VK_ESCAPE);
        toolkit.realSync();
        throw new RuntimeException("Save button is not pressed!");
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) SunToolkit(sun.awt.SunToolkit) Robot(java.awt.Robot)

Example 4 with SunToolkit

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

the class bug5074573 method test.

static boolean test(final Class<? extends JTextComponent> textComponentClass) throws Exception {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    Robot robot = new Robot();
    robot.setAutoWaitForIdle(true);
    robot.setAutoDelay(50);
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            initialize(textComponentClass);
        }
    });
    toolkit.realSync();
    // Remove selection from JTextField components for the Aqua Look & Feel
    if (textComponent instanceof JTextField && "Aqua".equals(UIManager.getLookAndFeel().getID())) {
        SwingUtilities.invokeAndWait(new Runnable() {

            @Override
            public void run() {
                Caret caret = textComponent.getCaret();
                int dot = caret.getDot();
                textComponent.select(dot, dot);
            }
        });
        toolkit.realSync();
    }
    robot.keyPress(getCtrlKey());
    robot.keyPress(KeyEvent.VK_BACK_SPACE);
    robot.keyRelease(KeyEvent.VK_BACK_SPACE);
    robot.keyRelease(getCtrlKey());
    toolkit.realSync();
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            Caret caret = textComponent.getCaret();
            caret.setDot(0);
        }
    });
    toolkit.realSync();
    robot.keyPress(getCtrlKey());
    robot.keyPress(KeyEvent.VK_DELETE);
    robot.keyRelease(KeyEvent.VK_DELETE);
    robot.keyRelease(getCtrlKey());
    toolkit.realSync();
    return resultString.equals(getText());
}
Also used : SunToolkit(sun.awt.SunToolkit) Robot(java.awt.Robot)

Example 5 with SunToolkit

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

the class bug7158712 method main.

public static void main(String[] args) throws Exception {
    Robot robot = new Robot();
    robot.setAutoDelay(500);
    SynthLookAndFeel laf = new SynthLookAndFeel();
    laf.load(new ByteArrayInputStream(SYNTH_XML.getBytes("UTF8")), bug7158712.class);
    UIManager.setLookAndFeel(laf);
    EventQueue.invokeAndWait(new Runnable() {

        public void run() {
            comboBox = new JComboBox<>(new String[] { "Very Looooooooooooooooooooong Text Item 1", "Item 2" });
            JFrame frame = new JFrame();
            frame.add(comboBox, BorderLayout.NORTH);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(new Dimension(400, 300));
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();
    Point comboBoxLocation = Util.invokeOnEDT(new Callable<Point>() {

        @Override
        public Point call() throws Exception {
            return comboBox.getLocationOnScreen();
        }
    });
    robot.mouseMove(comboBoxLocation.x, comboBoxLocation.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            BasicComboPopup popup = (BasicComboPopup) comboBox.getAccessibleContext().getAccessibleChild(0);
            Point popupPoint = popup.getLocationOnScreen();
            Point comboBoxPoint = comboBox.getLocationOnScreen();
            if (comboBoxPoint.x - 5 != popupPoint.x || comboBoxPoint.y + comboBox.getHeight() - 5 != popupPoint.y) {
                throw new RuntimeException("Invalid popup coordinates. Popup location: " + popupPoint + ", comboBox location: " + comboBoxPoint);
            }
            System.out.println("Test bug7158712 passed");
        }
    });
}
Also used : SynthLookAndFeel(javax.swing.plaf.synth.SynthLookAndFeel) SunToolkit(sun.awt.SunToolkit) ByteArrayInputStream(java.io.ByteArrayInputStream) BasicComboPopup(javax.swing.plaf.basic.BasicComboPopup)

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