use of sun.awt.SunToolkit in project jdk8u_jdk by JetBrains.
the class SelectionInvisibleTest method main.
public static void main(String[] args) throws Exception {
Frame frame = new Frame();
frame.setSize(300, 200);
TextField textField = new TextField(TEXT + LAST_WORD, 30);
Panel panel = new Panel(new FlowLayout());
panel.add(textField);
frame.add(panel);
frame.setVisible(true);
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
toolkit.realSync();
Robot robot = new Robot();
robot.setAutoDelay(50);
Point point = textField.getLocationOnScreen();
int x = point.x + textField.getWidth() / 2;
int y = point.y + textField.getHeight() / 2;
robot.mouseMove(x, y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
toolkit.realSync();
robot.mousePress(InputEvent.BUTTON1_MASK);
int N = 10;
int dx = textField.getWidth() / N;
for (int i = 0; i < N; i++) {
x += dx;
robot.mouseMove(x, y);
}
robot.mouseRelease(InputEvent.BUTTON1_MASK);
toolkit.realSync();
if (!textField.getSelectedText().endsWith(LAST_WORD)) {
throw new RuntimeException("Last word is not selected!");
}
}
use of sun.awt.SunToolkit in project jdk8u_jdk by JetBrains.
the class bug8041990 method main.
public static void main(String[] args) throws Exception {
ThreadGroup stubTG = new ThreadGroup(getRootThreadGroup(), "Stub Thread Group");
ThreadGroup swingTG = new ThreadGroup(getRootThreadGroup(), "SwingTG");
try {
Thread stubThread = new Thread(stubTG, SunToolkit::createNewAppContext);
stubThread.start();
stubThread.join();
CountDownLatch startSwingLatch = new CountDownLatch(1);
new Thread(swingTG, () -> {
SunToolkit.createNewAppContext();
SwingUtilities.invokeLater(() -> {
frame = new JFrame();
component = new JLabel("Test Text");
frame.add(component);
frame.setBounds(100, 100, 100, 100);
frame.setVisible(true);
startSwingLatch.countDown();
});
}).start();
startSwingLatch.await();
AtomicReference<Exception> caughtException = new AtomicReference<>();
Thread checkThread = new Thread(getRootThreadGroup(), () -> {
try {
// If the bug is present this will throw exception
new InputMethodEvent(component, InputMethodEvent.CARET_POSITION_CHANGED, TextHitInfo.leading(0), TextHitInfo.trailing(0));
} catch (Exception e) {
caughtException.set(e);
}
});
checkThread.start();
checkThread.join();
if (caughtException.get() != null) {
throw new RuntimeException("Failed. Caught exception!", caughtException.get());
}
} finally {
new Thread(swingTG, () -> SwingUtilities.invokeLater(() -> {
if (frame != null) {
frame.dispose();
}
})).start();
}
}
use of sun.awt.SunToolkit in project jdk8u_jdk by JetBrains.
the class bug8016551 method main.
public static void main(String[] args) throws Exception {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception e) {
// We intentionally allow the test to run with other l&f
}
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
try {
Icon icon = UIManager.getIcon("InternalFrame.closeIcon");
if (icon == null) {
return;
}
JMenuItem item = new TestMenuItem(icon);
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(item);
f.pack();
f.setVisible(true);
} catch (ClassCastException e) {
throw new RuntimeException(e);
}
}
});
SunToolkit tk = (SunToolkit) Toolkit.getDefaultToolkit();
tk.realSync();
if (exception != null) {
throw exception;
}
}
use of sun.awt.SunToolkit in project jdk8u_jdk by JetBrains.
the class ResizingFrameTest method main.
public static void main(String[] args) throws Exception {
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
Robot robot = new Robot();
robot.setAutoDelay(50);
robot.mouseMove(100, 100);
// create a frame under the mouse cursor
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
createAndShowGUI();
}
});
toolkit.realSync();
if (mouseEnteredCount != 1 || mouseExitedCount != 0) {
throw new RuntimeException("No Mouse Entered/Exited events!");
}
// iconify frame
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame.setExtendedState(Frame.ICONIFIED);
}
});
toolkit.realSync();
robot.delay(200);
if (mouseEnteredCount != 1 || mouseExitedCount != 1) {
throw new RuntimeException("No Mouse Entered/Exited events!");
}
// deiconify frame
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame.setExtendedState(Frame.NORMAL);
}
});
toolkit.realSync();
robot.delay(200);
if (mouseEnteredCount != 2 || mouseExitedCount != 1) {
throw new RuntimeException("No Mouse Entered/Exited events!");
}
// move the mouse out of the frame
robot.mouseMove(500, 500);
toolkit.realSync();
robot.delay(200);
if (mouseEnteredCount != 2 || mouseExitedCount != 2) {
throw new RuntimeException("No Mouse Entered/Exited events!");
}
// maximize the frame
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
}
});
toolkit.realSync();
robot.delay(200);
if (mouseEnteredCount != 3 || mouseExitedCount != 2) {
throw new RuntimeException("No Mouse Entered/Exited events!");
}
// demaximize the frame
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame.setExtendedState(Frame.NORMAL);
}
});
toolkit.realSync();
robot.delay(200);
if (mouseEnteredCount != 3 || mouseExitedCount != 3) {
throw new RuntimeException("No Mouse Entered/Exited events!");
}
// move the frame under the mouse
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame.setLocation(400, 400);
}
});
toolkit.realSync();
robot.delay(200);
if (mouseEnteredCount != 4 || mouseExitedCount != 3) {
throw new RuntimeException("No Mouse Entered/Exited events!");
}
// move the frame out of the mouse
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame.setLocation(100, 100);
}
});
toolkit.realSync();
robot.delay(400);
if (mouseEnteredCount != 4 || mouseExitedCount != 4) {
throw new RuntimeException("No Mouse Entered/Exited events!");
}
// enlarge the frame bounds
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame.setBounds(100, 100, 800, 800);
}
});
toolkit.realSync();
robot.delay(200);
if (mouseEnteredCount != 5 || mouseExitedCount != 4) {
throw new RuntimeException("No Mouse Entered/Exited events!");
}
// make the frame bounds smaller
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame.setBounds(100, 100, 200, 300);
}
});
toolkit.realSync();
robot.delay(400);
if (mouseEnteredCount != 5 || mouseExitedCount != 5) {
throw new RuntimeException("No Mouse Entered/Exited events!");
}
}
use of sun.awt.SunToolkit in project jdk8u_jdk by JetBrains.
the class EmptyListEventTest 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() {
@Override
public void run() {
createAndShowGUI();
}
});
toolkit.realSync();
// press mouse -> ItemEvent
Point point = getClickPoint();
robot.mouseMove(point.x, point.y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
toolkit.realSync();
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
list.requestFocusInWindow();
}
});
toolkit.realSync();
if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() != list) {
throw new RuntimeException("Test failed - list isn't focus owner.");
}
// press key ENTER -> ActionEvent
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
toolkit.realSync();
// press key SPACE -> ItemEvent
robot.keyPress(KeyEvent.VK_SPACE);
robot.keyRelease(KeyEvent.VK_SPACE);
toolkit.realSync();
// mouse double click -> ActionEvent
robot.setAutoDelay(10);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
toolkit.realSync();
}
Aggregations