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");
}
}
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) {
}
}
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!");
}
}
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!");
}
}
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);
}
}
Aggregations