Search in sources :

Example 11 with SunToolkit

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

the class bug6889007 method main.

public static void main(String[] args) throws Exception {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    Robot robot = new Robot();
    robot.setAutoDelay(20);
    final JFrame frame = new JFrame();
    frame.setUndecorated(true);
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JTableHeader th = new JTableHeader();
            th.setColumnModel(new JTable(20, 5).getColumnModel());
            th.setUI(new MyTableHeaderUI());
            frame.add(th);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    toolkit.realSync();
    Point point = frame.getLocationOnScreen();
    int shift = 10;
    int x = point.x;
    int y = point.y + frame.getHeight() / 2;
    for (int i = -shift; i < frame.getWidth() + 2 * shift; i++) {
        robot.mouseMove(x++, y);
    }
    toolkit.realSync();
    // 9 is a magic test number
    if (MyTableHeaderUI.getTestValue() != 9) {
        throw new RuntimeException("Unexpected test number " + MyTableHeaderUI.getTestValue());
    }
    System.out.println("ok");
}
Also used : SunToolkit(sun.awt.SunToolkit) JTableHeader(javax.swing.table.JTableHeader)

Example 12 with SunToolkit

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

the class bug7049024 method main.

public static void main(String[] args) throws Exception {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            frame = new JFrame("Test");
            textField = new JTextField("test selection for textfield");
            button = new JButton("To compete the focus");
            frame.setLayout(new FlowLayout());
            frame.getContentPane().add(textField);
            frame.getContentPane().add(button);
            frame.pack();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
        }
    });
    toolkit.realSync();
    clipboard = textField.getToolkit().getSystemSelection();
    if (null == clipboard) {
        return;
    }
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            textField.requestFocusInWindow();
        }
    });
    toolkit.realSync();
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            caret = (DefaultCaret) textField.getCaret();
            caret.setDot(2);
            caret.moveDot(4);
        }
    });
    toolkit.realSync();
    String oldSelection = (String) clipboard.getData(DataFlavor.stringFlavor);
    System.out.println("oldSelection is " + oldSelection);
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            button.requestFocusInWindow();
        }
    });
    // So JTextField loses the focus.
    toolkit.realSync();
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            caret.setDot(4);
            caret.moveDot(6);
        }
    });
    toolkit.realSync();
    String newSelection = (String) clipboard.getData(DataFlavor.stringFlavor);
    System.out.println("newSelection is " + newSelection);
    boolean passed = newSelection.equals(oldSelection);
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            frame.dispose();
        }
    });
    if (!passed) {
        throw new RuntimeException("The test for bug 7049024 failed");
    }
}
Also used : DefaultCaret(javax.swing.text.DefaultCaret) SunToolkit(sun.awt.SunToolkit)

Example 13 with SunToolkit

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

the class bug4846413 method main.

public static void main(String[] args) throws Exception {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    Robot robot = new Robot();
    robot.setAutoDelay(50);
    UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
    javax.swing.SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            createAndShowGUI();
        }
    });
    toolkit.realSync();
    Point movePoint = getButtonPoint();
    robot.mouseMove(movePoint.x, movePoint.y);
    toolkit.realSync();
    long timeout = System.currentTimeMillis() + 9000;
    while (!isTooltipAdded && (System.currentTimeMillis() < timeout)) {
        try {
            Thread.sleep(500);
        } catch (Exception e) {
        }
    }
    checkToolTip();
}
Also used : SunToolkit(sun.awt.SunToolkit) Point(java.awt.Point) Robot(java.awt.Robot)

Example 14 with SunToolkit

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

the class bug4330357 method main.

public static void main(String[] args) throws Exception {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    robot = new Robot();
    robot.setAutoDelay(50);
    UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
    javax.swing.SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            createAndShowGUI();
        }
    });
    toolkit.realSync();
    clickMouse(getTreeRowClickPoint(1));
    Util.hitKeys(robot, KeyEvent.VK_F2);
    Util.hitKeys(robot, KeyEvent.VK_A, KeyEvent.VK_B, KeyEvent.VK_C);
    toolkit.realSync();
    if (!hasComponent(JTextField.class)) {
        throw new RuntimeException("Cell editor is missed for path: color");
    }
    clickMouse(getButtonClickPoint());
    toolkit.realSync();
    clickMouse(getTreeRowClickPoint(2));
    Util.hitKeys(robot, KeyEvent.VK_F2);
    toolkit.realSync();
    if (!hasComponent(JComboBox.class)) {
        throw new RuntimeException("Cell editor is missed for path: sports");
    }
    if (hasComponent(JTextField.class)) {
        throw new RuntimeException("Cell editor is wrongly shown for path: color");
    }
}
Also used : SunToolkit(sun.awt.SunToolkit)

Example 15 with SunToolkit

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

the class bug8024061 method main.

public static void main(String[] args) throws AWTException, InvocationTargetException, InterruptedException {
    OSType type = OSInfo.getOSType();
    if (type != OSType.LINUX && type != OSType.SOLARIS) {
        System.out.println("This test is for Linux and Solaris only... " + "skipping!");
        return;
    }
    final bug8024061[] dnd = { null };
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            dnd[0] = new bug8024061();
        }
    });
    final Robot robot = new Robot();
    robot.setAutoDelay(10);
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    toolkit.realSync();
    JFrame frame = dnd[0].frame;
    Point point = frame.getLocationOnScreen();
    Point here = new Point(point.x + 35, point.y + 45);
    Point there = new Point(point.x + 120, point.y + 45);
    here.x += 25;
    robot.mouseMove(here.x, here.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    while (here.x < there.x) {
        here.x += 20;
        robot.mouseMove(here.x, here.y);
        System.out.println("x = " + here.x);
    }
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    toolkit.realSync();
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    System.out.println("finished");
    try {
        if (lock.await(5, TimeUnit.SECONDS)) {
            if (dragEnterException == null) {
                System.out.println("Test passed.");
            } else {
                System.out.println("Test failed.");
                dragEnterException.printStackTrace();
                throw new RuntimeException(dragEnterException);
            }
        } else {
            System.out.println("Test failed. Timeout reached");
            throw new RuntimeException("Timed out waiting for dragEnter()");
        }
    } finally {
        frame.dispose();
    }
}
Also used : OSType(sun.awt.OSInfo.OSType) 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