Search in sources :

Example 56 with SunToolkit

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!");
    }
}
Also used : Panel(java.awt.Panel) Frame(java.awt.Frame) FlowLayout(java.awt.FlowLayout) TextField(java.awt.TextField) SunToolkit(sun.awt.SunToolkit) Point(java.awt.Point) Robot(java.awt.Robot) Point(java.awt.Point)

Example 57 with SunToolkit

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();
    }
}
Also used : SunToolkit(sun.awt.SunToolkit) AtomicReference(java.util.concurrent.atomic.AtomicReference) InputMethodEvent(java.awt.event.InputMethodEvent) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 58 with SunToolkit

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;
    }
}
Also used : SunToolkit(sun.awt.SunToolkit)

Example 59 with SunToolkit

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!");
    }
}
Also used : SunToolkit(sun.awt.SunToolkit)

Example 60 with SunToolkit

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();
}
Also used : SunToolkit(sun.awt.SunToolkit)

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