Search in sources :

Example 26 with SunToolkit

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

the class bug7107099 method main.

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

        @Override
        public void run() {
            textarea = new JTextArea("before###1###\nbefore###2###\nbefore###3###\nbefore###4###\nbefore###5###\n");
            scrollPane = new JScrollPane(textarea);
            scrollPane.setPreferredSize(new Dimension(100, 50));
            frame = new JFrame();
            frame.setLayout(new BorderLayout());
            frame.setSize(200, 200);
            frame.add(scrollPane, BorderLayout.SOUTH);
            frame.setVisible(true);
        }
    });
    toolkit.realSync();
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            BoundedRangeModel model = scrollPane.getVerticalScrollBar().getModel();
            value = model.getValue();
            min = model.getMinimum();
            max = model.getMaximum();
            extent = model.getExtent();
            // Do tricky manipulation for testing purpose
            textarea.setText(null);
            scrollPane.setViewportView(textarea);
            textarea.setText("after###1###\nafter###1###\nafter###1###\nafter###1###\nafter###1###\n");
            textarea.setCaretPosition(0);
        }
    });
    toolkit.realSync();
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            BoundedRangeModel model = scrollPane.getVerticalScrollBar().getModel();
            if (value != model.getValue() || min != model.getMinimum() || max != model.getMaximum() || extent != model.getExtent()) {
                throw new RuntimeException("Test bug7107099 failed");
            }
            System.out.println("Test bug7107099 passed");
            frame.dispose();
        }
    });
}
Also used : SunToolkit(sun.awt.SunToolkit)

Example 27 with SunToolkit

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

the class NonOpaquePopupMenuTest method main.

public static void main(String[] args) throws Throwable {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    Robot robot = new Robot();
    robot.setAutoDelay(250);
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            new NonOpaquePopupMenuTest();
        }
    });
    toolkit.realSync();
    Point p = getMenuClickPoint();
    robot.mouseMove(p.x, p.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    toolkit.realSync();
    if (isParentOpaque()) {
        throw new RuntimeException("Popup menu parent is opaque");
    }
}
Also used : SunToolkit(sun.awt.SunToolkit)

Example 28 with SunToolkit

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

the class SwingTest method start.

private void start() throws Throwable {
    do {
        if ((this.method != null) && Modifier.isStatic(this.method.getModifiers())) {
            // invoke static method on the current thread
            run();
        } else {
            // invoke on the event dispatch thread
            SwingUtilities.invokeLater(this);
        }
        Toolkit tk = Toolkit.getDefaultToolkit();
        if (tk instanceof SunToolkit) {
            SunToolkit stk = (SunToolkit) tk;
            // wait until done
            stk.realSync();
        }
    } while (this.frame != null);
    if (this.error != null) {
        throw this.error;
    }
}
Also used : SunToolkit(sun.awt.SunToolkit) SunToolkit(sun.awt.SunToolkit) Toolkit(java.awt.Toolkit)

Example 29 with SunToolkit

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

the class OwnedWindowsSerialization method main.

public static void main(String[] args) throws Exception {
    SwingUtilities.invokeAndWait(() -> {
        topFrame = new Frame(TOP_FRAME_LABEL);
        topFrame.setAlwaysOnTop(true);
        dialog = new Dialog(topFrame, DIALOG_LABEL);
        subDialog = new Dialog(dialog, SUBDIALOG_LABEL);
    });
    ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();
    if (!topFrame.isAlwaysOnTop() || !dialog.isAlwaysOnTop() || !subDialog.isAlwaysOnTop()) {
        throw new RuntimeException("TEST FAILED: AlwaysOnTop was not set properly");
    }
    //Serialize
    byte[] serializedObject;
    try (ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        ObjectOutputStream outputStream = new ObjectOutputStream(bytes)) {
        outputStream.writeObject(topFrame);
        outputStream.flush();
        serializedObject = bytes.toByteArray();
    }
    if (serializedObject == null) {
        throw new RuntimeException("FAILED: Serialized byte array in null");
    }
    //Deserialize
    Frame deserializedFrame;
    try (ObjectInputStream inputStream = new ObjectInputStream(new ByteArrayInputStream(serializedObject))) {
        deserializedFrame = (Frame) inputStream.readObject();
    }
    //Check the state of the deserialized objects
    if (!TOP_FRAME_LABEL.equals(deserializedFrame.getTitle())) {
        throw new RuntimeException("FAILED: Top frame deserialized incorrectly");
    }
    if (!deserializedFrame.isAlwaysOnTop()) {
        throw new RuntimeException("FAILED: Top frame alwaysOnTop not set after deserialization");
    }
    Window[] topOwnedWindows = topFrame.getOwnedWindows();
    if (topOwnedWindows.length != 1 || !DIALOG_LABEL.equals(((Dialog) topOwnedWindows[0]).getTitle())) {
        throw new RuntimeException("FAILED: Dialog deserialized incorrectly");
    }
    if (!topOwnedWindows[0].isAlwaysOnTop()) {
        throw new RuntimeException("FAILED: Dialog alwaysOnTop not set after deserialization");
    }
    Window dialog = topOwnedWindows[0];
    Window[] dialogOwnedWindows = dialog.getOwnedWindows();
    if (dialogOwnedWindows.length != 1 || !SUBDIALOG_LABEL.equals(((Dialog) dialogOwnedWindows[0]).getTitle())) {
        throw new RuntimeException("FAILED: Subdialog deserialized incorrectly");
    }
    if (!dialogOwnedWindows[0].isAlwaysOnTop()) {
        throw new RuntimeException("FAILED: Subdialog alwaysOnTop not set after deserialization");
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SunToolkit(sun.awt.SunToolkit) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 30 with SunToolkit

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

the class Test6817933 method main.

public static void main(String[] args) throws Exception {
    try {
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception exception) {
        exception.printStackTrace();
        // ignore test on non-Windows machines
        return;
    }
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            StyleSheet css = new StyleSheet();
            css.addRule(STYLE);
            HTMLEditorKit kit = new HTMLEditorKit();
            kit.setStyleSheet(css);
            JFrame frame = new JFrame(STYLE);
            frame.add(chooser = new JFileChooser());
            frame.setSize(640, 480);
            frame.setVisible(true);
        }
    });
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    toolkit.realSync(500);
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            try {
                JToggleButton button = get(JToggleButton.class, get(WindowsPlacesBar.class, chooser));
                int width = button.getWidth();
                int height = button.getHeight() / 3;
                Point point = new Point(0, height * 2);
                SwingUtilities.convertPointToScreen(point, button);
                width += point.x;
                height += point.y;
                int count = 0;
                Robot robot = new Robot();
                for (int x = point.x; x < width; x++) {
                    for (int y = point.y; y < height; y++) {
                        count += COLOR.equals(robot.getPixelColor(x, y)) ? -2 : 1;
                    }
                }
                if (count < 0) {
                    throw new Exception("TEST ERROR: a lot of red pixels");
                }
            } catch (Exception exception) {
                throw new Error(exception);
            } finally {
                SwingUtilities.getWindowAncestor(chooser).dispose();
            }
        }
    });
}
Also used : StyleSheet(javax.swing.text.html.StyleSheet) JFileChooser(javax.swing.JFileChooser) JToggleButton(javax.swing.JToggleButton) JFrame(javax.swing.JFrame) SunToolkit(sun.awt.SunToolkit) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) Point(java.awt.Point) 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