Search in sources :

Example 61 with SunToolkit

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

the class bug8007006 method main.

public static void main(String[] args) throws Exception {
    if (sun.awt.OSInfo.getOSType() != sun.awt.OSInfo.OSType.MACOSX) {
        System.out.println("This test is for MacOS only. Automatically passed on other platforms.");
        return;
    }
    System.setProperty("apple.laf.useScreenMenuBar", "true");
    createAndShowGUI();
    sleep(1500);
    frame2.dispose();
    sleep(1500);
    SunToolkit tk = (SunToolkit) Toolkit.getDefaultToolkit();
    Robot robot = new Robot();
    robot.setAutoDelay(50);
    // open "Apple" menu (the leftmost one)
    robot.keyPress(KeyEvent.VK_META);
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(KeyEvent.VK_SLASH);
    robot.keyRelease(KeyEvent.VK_SLASH);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.keyRelease(KeyEvent.VK_META);
    // Select our menu
    robot.keyPress(KeyEvent.VK_LEFT);
    robot.keyRelease(KeyEvent.VK_LEFT);
    // Select menu item
    robot.keyPress(KeyEvent.VK_DOWN);
    robot.keyRelease(KeyEvent.VK_DOWN);
    robot.keyPress(KeyEvent.VK_ENTER);
    robot.keyRelease(KeyEvent.VK_ENTER);
    sleep(0);
    MenuBar mbar = frame1.getMenuBar();
    Menu menu = mbar.getMenu(0);
    CheckboxMenuItem item = (CheckboxMenuItem) menu.getItem(0);
    boolean isChecked = item.getState();
    frame1.dispose();
    if (isChecked) {
        throw new Exception("Test failed: menu item remained checked");
    }
}
Also used : SunToolkit(sun.awt.SunToolkit)

Example 62 with SunToolkit

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

the class bug8007006 method sleep.

private static void sleep(int ms) {
    SunToolkit tk = (SunToolkit) Toolkit.getDefaultToolkit();
    tk.realSync();
    try {
        Thread.sleep(ms);
    } catch (Exception ignore) {
    }
}
Also used : SunToolkit(sun.awt.SunToolkit)

Example 63 with SunToolkit

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

the class HiDPIRobotMouseClick method main.

public static void main(String[] args) throws Exception {
    try {
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception e) {
        return;
    }
    Frame frame = new Frame();
    frame.setBounds(30, 20, 400, 300);
    frame.setUndecorated(true);
    frame.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            mouseX = e.getXOnScreen();
            mouseY = e.getYOnScreen();
        }
    });
    frame.setVisible(true);
    Robot robot = new Robot();
    robot.waitForIdle();
    Thread.sleep(200);
    Rectangle rect = frame.getBounds();
    rect.setLocation(frame.getLocationOnScreen());
    int x = (int) rect.getCenterX();
    int y = (int) rect.getCenterY();
    robot.mouseMove(x, y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();
    if (x != mouseX || y != mouseY) {
        throw new RuntimeException("Wrong mouse click point!");
    }
}
Also used : Frame(java.awt.Frame) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) Rectangle(java.awt.Rectangle) SunToolkit(sun.awt.SunToolkit) Robot(java.awt.Robot)

Example 64 with SunToolkit

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

the class ExtendedKeyCodeTest method main.

public static void main(String[] args) throws Exception {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    Robot robot = new Robot();
    robot.setAutoDelay(50);
    Frame frame = new Frame();
    frame.setSize(300, 300);
    frame.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            eventsCount++;
            setExtendedKeyCode = setExtendedKeyCode && (e.getExtendedKeyCode() == ExtendedKeyCodes.getExtendedKeyCodeForChar(e.getKeyChar()));
        }

        @Override
        public void keyReleased(KeyEvent e) {
            eventsCount++;
            setExtendedKeyCode = setExtendedKeyCode && (e.getExtendedKeyCode() == ExtendedKeyCodes.getExtendedKeyCodeForChar(e.getKeyChar()));
        }
    });
    frame.setVisible(true);
    toolkit.realSync();
    robot.keyPress(KeyEvent.VK_D);
    robot.keyRelease(KeyEvent.VK_D);
    toolkit.realSync();
    frame.dispose();
    if (eventsCount != 2 || !setExtendedKeyCode) {
        throw new RuntimeException("Wrong extended key code");
    }
    frame = new Frame();
    frame.setSize(300, 300);
    setExtendedKeyCode = false;
    frame.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            setExtendedKeyCode = e.getExtendedKeyCode() == KeyEvent.VK_LEFT;
        }
    });
    frame.setVisible(true);
    toolkit.realSync();
    robot.keyPress(KeyEvent.VK_LEFT);
    robot.keyRelease(KeyEvent.VK_LEFT);
    toolkit.realSync();
    frame.dispose();
    if (!setExtendedKeyCode) {
        throw new RuntimeException("Wrong extended key code!");
    }
}
Also used : KeyEvent(java.awt.event.KeyEvent) Frame(java.awt.Frame) KeyAdapter(java.awt.event.KeyAdapter) SunToolkit(sun.awt.SunToolkit) Robot(java.awt.Robot)

Example 65 with SunToolkit

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

the class KeyCharTest method main.

public static void main(String[] args) throws Exception {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    Frame frame = new Frame();
    frame.setSize(300, 300);
    frame.setVisible(true);
    toolkit.realSync();
    Robot robot = new Robot();
    robot.keyPress(KeyEvent.VK_DELETE);
    robot.keyRelease(KeyEvent.VK_DELETE);
    toolkit.realSync();
    frame.dispose();
    if (eventsCount != 3) {
        throw new RuntimeException("Wrong number of key events: " + eventsCount);
    }
}
Also used : Frame(java.awt.Frame) SunToolkit(sun.awt.SunToolkit) Robot(java.awt.Robot)

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