changeset 26344:68c0e8209883

8053657: [TEST_BUG] move some 5 tests related to undecorated Frame/JFrame to JDK Reviewed-by: serb
author yan
date Tue, 12 Aug 2014 18:26:30 +0400
parents cf09debe8a4b
children 3586cdbe1c58
files jdk/test/java/awt/Frame/MiscUndecorated/ActiveAWTWindowTest.java jdk/test/java/awt/Frame/MiscUndecorated/ActiveSwingWindowTest.java jdk/test/java/awt/Frame/MiscUndecorated/FrameCloseTest.java jdk/test/java/awt/Frame/MiscUndecorated/RepaintTest.java jdk/test/java/awt/Frame/MiscUndecorated/UndecoratedInitiallyIconified.java jdk/test/java/awt/Mixing/AWT_Mixing/Util.java
diffstat 6 files changed, 1004 insertions(+), 601 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Frame/MiscUndecorated/ActiveAWTWindowTest.java	Tue Aug 12 18:26:30 2014 +0400
@@ -0,0 +1,215 @@
+/*
+ * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+* @test
+* @summary To check proper WINDOW_EVENTS are triggered when Frame gains or losses the focus
+* @author Jitender(jitender.singh@eng.sun.com) area=AWT
+* @author yan
+* @library ../../../../lib/testlibrary
+* @build ExtendedRobot
+* @run main ActiveAWTWindowTest
+*/
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class ActiveAWTWindowTest {
+
+    private Frame frame, frame2;
+    private Button button, button2;
+    private TextField textField, textField2;
+    private int eventType, eventType1;
+    private ExtendedRobot robot;
+    private Object lock1 = new Object();
+    private Object lock2 = new Object();
+    private Object lock3 = new Object();
+    private boolean passed = true;
+    private int delay = 150;
+
+    public static void main(String[] args) {
+        ActiveAWTWindowTest test = new ActiveAWTWindowTest();
+        test.doTest();
+    }
+
+    public ActiveAWTWindowTest() {
+        try{
+            EventQueue.invokeAndWait( () -> {
+                    initializeGUI();
+            });
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new RuntimeException("Interrupted or unexpected Exception occured");
+        }
+    }
+
+    private void initializeGUI() {
+        frame = new Frame();
+        frame.setLayout(new FlowLayout());
+
+        frame.setLocation(5, 20);
+        frame.setSize(200, 200);
+        frame.setUndecorated(true);
+        frame.addWindowFocusListener(new WindowFocusListener() {
+            public void windowGainedFocus(WindowEvent event) {
+                System.out.println("Frame Focus gained");
+                synchronized (lock3) {
+                    try {
+                        lock3.notifyAll();
+                    } catch (Exception ex) {
+                        ex.printStackTrace();
+                    }
+                }
+            }
+
+            public void windowLostFocus(WindowEvent event) {
+                    System.out.println("Frame Focus lost");
+            }
+        });
+        frame.addWindowListener(new WindowAdapter() {
+            public void windowActivated(WindowEvent e) {
+                eventType = WindowEvent.WINDOW_ACTIVATED;
+                System.out.println("Undecorated Frame is activated\n");
+                synchronized (lock1) {
+                    try {
+                        lock1.notifyAll();
+                    } catch (Exception ex) {
+                        ex.printStackTrace();
+                    }
+                }
+            }
+
+            public void windowDeactivated(WindowEvent e) {
+                eventType = WindowEvent.WINDOW_DEACTIVATED;
+                System.out.println("Undecorated Frame got Deactivated\n");
+                synchronized (lock2) {
+                    try {
+                            lock2.notifyAll();
+                    } catch (Exception ex) {
+                        ex.printStackTrace();
+                    }
+                }
+            }
+        });
+        textField = new TextField("TextField");
+        button = new Button("Click me");
+        button.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                textField.setText("Focus gained");
+            }
+        });
+
+        frame.setBackground(Color.green);
+        frame.add(button);
+        frame.add(textField);
+        frame.setVisible(true);
+
+        frame2 = new Frame();
+        frame2.setLayout(new FlowLayout());
+        frame2.setLocation(5, 250);
+        frame2.setSize(200, 200);
+        frame2.setBackground(Color.green);
+        button2 = new Button("Click me");
+        textField2 = new TextField("TextField");
+        button2.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                textField2.setText("Got the focus");
+            }
+        });
+
+        frame2.add(button2, BorderLayout.SOUTH);
+        frame2.add(textField2, BorderLayout.NORTH);
+        frame2.setVisible(true);
+
+        frame.toFront();
+    }
+
+    public void doTest() {
+        try {
+            robot = new ExtendedRobot();
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new RuntimeException("Cannot create robot");
+        }
+
+        robot.waitForIdle(5*delay);
+        robot.mouseMove(button.getLocationOnScreen().x + button.getSize().width / 2,
+                        button.getLocationOnScreen().y + button.getSize().height / 2);
+        robot.waitForIdle(delay);
+        robot.mousePress(InputEvent.BUTTON1_MASK);
+        robot.waitForIdle(delay);
+        robot.mouseRelease(InputEvent.BUTTON1_MASK);
+
+        if (eventType != WindowEvent.WINDOW_ACTIVATED) {
+            synchronized (lock1) {
+                try {
+                    lock1.wait(delay * 10);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        if (eventType != WindowEvent.WINDOW_ACTIVATED) {
+            passed = false;
+            System.err.println("WINDOW_ACTIVATED event did not occur when the " +
+                    "undecorated frame is activated!");
+        }
+
+        eventType1 = -1;
+        eventType = -1;
+
+        robot.mouseMove(button2.getLocationOnScreen().x + button2.getSize().width / 2,
+                        button2.getLocationOnScreen().y + button2.getSize().height / 2);
+        robot.waitForIdle(delay);
+        robot.mousePress(InputEvent.BUTTON1_MASK);
+        robot.waitForIdle(delay);
+        robot.mouseRelease(InputEvent.BUTTON1_MASK);
+
+        if (eventType != WindowEvent.WINDOW_DEACTIVATED) {
+            synchronized (lock2) {
+                try {
+                    lock2.wait(delay * 10);
+                } catch (Exception e) {
+                }
+            }
+        }
+        if (eventType != WindowEvent.WINDOW_DEACTIVATED) {
+            passed = false;
+            System.err.println("FAIL: WINDOW_DEACTIVATED event did not occur for the " +
+                    "undecorated frame when another frame gains focus!");
+        }
+        if (frame.hasFocus()) {
+            passed = false;
+            System.err.println("FAIL: The undecorated frame has focus even when " +
+                        "another frame is clicked!");
+        }
+
+        if (!passed) {
+            //captureScreenAndSave();
+            System.err.println("Test failed!");
+            throw new RuntimeException("Test failed.");
+        } else {
+            System.out.println("Test passed");
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Frame/MiscUndecorated/ActiveSwingWindowTest.java	Tue Aug 12 18:26:30 2014 +0400
@@ -0,0 +1,219 @@
+/*
+ * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+* @test
+* @summary To check proper WINDOW_EVENTS are triggered when JFrame gains or losses the focus
+* @author Jitender(jitender.singh@eng.sun.com) area=AWT
+* @author yan
+* @library ../../../../lib/testlibrary
+* @build ExtendedRobot
+* @run main ActiveSwingWindowTest
+*/
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.JFrame;
+import javax.swing.JTextField;
+import javax.swing.JButton;
+
+
+public class ActiveSwingWindowTest {
+
+    private JFrame frame, frame2;
+    private JButton button, button2;
+    private JTextField textField, textField2;
+    private int eventType, eventType1;
+    private ExtendedRobot robot;
+    private Object lock1 = new Object();
+    private Object lock2 = new Object();
+    private Object lock3 = new Object();
+    private boolean passed = true;
+    private int delay = 150;
+
+    public static void main(String[] args) {
+        ActiveSwingWindowTest test = new ActiveSwingWindowTest();
+        test.doTest();
+    }
+
+    public ActiveSwingWindowTest() {
+        try{
+            EventQueue.invokeAndWait( () -> {
+                    initializeGUI();
+            });
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new RuntimeException("Interrupted or unexpected Exception occured");
+        }
+    }
+
+    private void initializeGUI() {
+        frame = new JFrame();
+        frame.setLayout(new FlowLayout());
+
+        frame.setLocation(5, 20);
+        frame.setSize(200, 200);
+        frame.setUndecorated(true);
+        frame.addWindowFocusListener(new WindowFocusListener() {
+            public void windowGainedFocus(WindowEvent event) {
+                System.out.println("Frame Focus gained");
+                synchronized (lock3) {
+                    try {
+                        lock3.notifyAll();
+                    } catch (Exception ex) {
+                        ex.printStackTrace();
+                    }
+                }
+            }
+
+            public void windowLostFocus(WindowEvent event) {
+                    System.out.println("Frame Focus lost");
+            }
+        });
+        frame.addWindowListener(new WindowAdapter() {
+            public void windowActivated(WindowEvent e) {
+                eventType = WindowEvent.WINDOW_ACTIVATED;
+                System.out.println("Undecorated Frame is activated\n");
+                synchronized (lock1) {
+                    try {
+                        lock1.notifyAll();
+                    } catch (Exception ex) {
+                        ex.printStackTrace();
+                    }
+                }
+            }
+
+            public void windowDeactivated(WindowEvent e) {
+                eventType = WindowEvent.WINDOW_DEACTIVATED;
+                System.out.println("Undecorated Frame got Deactivated\n");
+                synchronized (lock2) {
+                    try {
+                            lock2.notifyAll();
+                    } catch (Exception ex) {
+                        ex.printStackTrace();
+                    }
+                }
+            }
+        });
+        textField = new JTextField("TextField");
+        button = new JButton("Click me");
+        button.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                textField.setText("Focus gained");
+            }
+        });
+
+        frame.setBackground(Color.green);
+        frame.add(button);
+        frame.add(textField);
+        frame.setVisible(true);
+
+        frame2 = new JFrame();
+        frame2.setLayout(new FlowLayout());
+        frame2.setLocation(5, 250);
+        frame2.setSize(200, 200);
+        frame2.setBackground(Color.green);
+        button2 = new JButton("Click me");
+        textField2 = new JTextField("TextField");
+        button2.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                textField2.setText("Got the focus");
+            }
+        });
+
+        frame2.add(button2, BorderLayout.SOUTH);
+        frame2.add(textField2, BorderLayout.NORTH);
+        frame2.setVisible(true);
+
+        frame.toFront();
+    }
+
+    public void doTest() {
+        try {
+            robot = new ExtendedRobot();
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new RuntimeException("Cannot create robot");
+        }
+
+        robot.waitForIdle(5*delay);
+        robot.mouseMove(button.getLocationOnScreen().x + button.getSize().width / 2,
+                        button.getLocationOnScreen().y + button.getSize().height / 2);
+        robot.waitForIdle(delay);
+        robot.mousePress(InputEvent.BUTTON1_MASK);
+        robot.waitForIdle(delay);
+        robot.mouseRelease(InputEvent.BUTTON1_MASK);
+
+        if (eventType != WindowEvent.WINDOW_ACTIVATED) {
+            synchronized (lock1) {
+                try {
+                    lock1.wait(delay * 10);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        if (eventType != WindowEvent.WINDOW_ACTIVATED) {
+            passed = false;
+            System.err.println("WINDOW_ACTIVATED event did not occur when the " +
+                    "undecorated frame is activated!");
+        }
+
+        eventType1 = -1;
+        eventType = -1;
+
+        robot.mouseMove(button2.getLocationOnScreen().x + button2.getSize().width / 2,
+                        button2.getLocationOnScreen().y + button2.getSize().height / 2);
+        robot.waitForIdle(delay);
+        robot.mousePress(InputEvent.BUTTON1_MASK);
+        robot.waitForIdle(delay);
+        robot.mouseRelease(InputEvent.BUTTON1_MASK);
+
+        if (eventType != WindowEvent.WINDOW_DEACTIVATED) {
+            synchronized (lock2) {
+                try {
+                    lock2.wait(delay * 10);
+                } catch (Exception e) {
+                }
+            }
+        }
+        if (eventType != WindowEvent.WINDOW_DEACTIVATED) {
+            passed = false;
+            System.err.println("FAIL: WINDOW_DEACTIVATED event did not occur for the " +
+                    "undecorated frame when another frame gains focus!");
+        }
+        if (frame.hasFocus()) {
+            passed = false;
+            System.err.println("FAIL: The undecorated frame has focus even when " +
+                        "another frame is clicked!");
+        }
+
+        if (!passed) {
+            //captureScreenAndSave();
+            System.err.println("Test failed!");
+            throw new RuntimeException("Test failed.");
+        } else {
+            System.out.println("Test passed");
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Frame/MiscUndecorated/FrameCloseTest.java	Tue Aug 12 18:26:30 2014 +0400
@@ -0,0 +1,212 @@
+/*
+ * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+* @test
+* @summary To make sure Undecorated Frame triggers correct windows events while closing
+* @author Jitender(jitender.singh@eng.sun.com) area=AWT*
+* @author yan
+* @library ../../../../lib/testlibrary
+* @build ExtendedRobot
+* @run main FrameCloseTest
+*/
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.JFrame;
+import javax.swing.JButton;
+
+public class FrameCloseTest {
+    private static int delay = 150;
+
+    private Frame frame, frame2;
+    private Component button, dummyButton;
+    private int eventType, eventType1, eventType2;
+    private ExtendedRobot robot;
+    private Object lock1 = new Object();
+    private Object lock2 = new Object();
+    private Object lock3 = new Object();
+    private Object lock4 = new Object();
+    private boolean passed = true;
+
+    public static void main(String[] args) {
+        FrameCloseTest test = new FrameCloseTest();
+        test.doTest(false);
+        test.doTest(true);
+    }
+
+    private void initializeGUI(boolean swingFrame) {
+        frame = swingFrame? new Frame() : new JFrame();
+        frame.setLayout(new FlowLayout());
+
+        frame.setLocation(5, 20);
+        frame.setSize(200, 200);
+        frame.setUndecorated(true);
+        frame.addWindowFocusListener(new WindowFocusListener() {
+            public void windowGainedFocus(WindowEvent event) {
+                System.out.println("Frame Focus gained");
+                synchronized (lock4) {
+                    try {
+                        lock4.notifyAll();
+                    } catch (Exception ex) {
+                        ex.printStackTrace();
+                    }
+                }
+            }
+
+            public void windowLostFocus(WindowEvent event) {
+                System.out.println("Frame Focus lost");
+            }
+        });
+        frame.addWindowListener(new WindowAdapter() {
+            public void windowActivated(WindowEvent e) {
+                eventType = WindowEvent.WINDOW_ACTIVATED;
+                System.out.println("Undecorated Frame is activated");
+                synchronized (lock1) {
+                    try {
+                        lock1.notifyAll();
+                    } catch (Exception ex) {
+                        ex.printStackTrace();
+                    }
+                }
+            }
+
+            public void windowDeactivated(WindowEvent e) {
+                eventType1 = WindowEvent.WINDOW_DEACTIVATED;
+                System.out.println("Undecorated Frame got Deactivated");
+                synchronized (lock2) {
+                    try {
+                        lock2.notifyAll();
+                    } catch (Exception ex) {
+                        ex.printStackTrace();
+                    }
+                }
+            }
+
+            public void windowClosed(WindowEvent e) {
+                eventType2 = WindowEvent.WINDOW_CLOSED;
+                System.out.println("Undecorated Frame got closed");
+                synchronized (lock3) {
+                    try {
+                        lock3.notifyAll();
+                    } catch (Exception ex) {
+                        ex.printStackTrace();
+                    }
+                }
+            }
+        });
+        dummyButton = swingFrame? new JButton("Click me") : new Button("Click me");
+
+        frame.setBackground(Color.green);
+        frame.add((button = createButton(swingFrame, "Close me")));
+        frame.add(dummyButton);
+        frame.setVisible(true);
+        frame.toFront();
+    }
+    private Component createButton(boolean swingControl, String txt) {
+        if(swingControl) {
+            JButton jbtn = new JButton(txt);
+            jbtn.addActionListener(new ActionListener() {
+                public void actionPerformed(ActionEvent e) {
+                    frame.dispose();
+                }
+            });
+            return jbtn;
+        }else {
+            Button btn = new Button(txt);
+            btn.addActionListener(new ActionListener() {
+                public void actionPerformed(ActionEvent e) {
+                    frame.dispose();
+                }
+            });
+            return btn;
+        }
+    }
+
+    public void doTest(boolean swingControl) {
+        try {
+            Toolkit.getDefaultToolkit().getSystemEventQueue().invokeAndWait(new Runnable() {
+                public void run() {
+                    initializeGUI(swingControl);
+                }
+            });
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new RuntimeException("Interrupted or unexpected Exception occured");
+        }
+        try {
+            robot = new ExtendedRobot();
+            robot.waitForIdle(1000);
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new RuntimeException("Cannot create robot");
+        }
+
+        robot.mouseMove(dummyButton.getLocationOnScreen().x + dummyButton.getSize().width / 2,
+                        dummyButton.getLocationOnScreen().y + dummyButton.getSize().height / 2);
+        robot.waitForIdle(delay);
+        robot.mousePress(InputEvent.BUTTON1_MASK);
+        robot.waitForIdle(delay);
+        robot.mouseRelease(InputEvent.BUTTON1_MASK);
+        robot.waitForIdle(delay);
+
+        eventType1 = -1;
+        eventType = -1;
+        eventType2 = -1;
+
+        robot.mouseMove(button.getLocationOnScreen().x + button.getSize().width / 2,
+                        button.getLocationOnScreen().y + button.getSize().height / 2);
+        robot.waitForIdle(delay);
+        robot.mousePress(InputEvent.BUTTON1_MASK);
+        robot.waitForIdle(delay);
+        robot.mouseRelease(InputEvent.BUTTON1_MASK);
+        robot.waitForIdle(delay * 10);
+
+        if (eventType2 != WindowEvent.WINDOW_CLOSED) {
+            synchronized (lock3) {
+                try {
+                    lock3.wait(delay * 10);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        if (eventType2 != WindowEvent.WINDOW_CLOSED) {
+            passed = false;
+            System.err.println("WINDOW_CLOSED event did not occur when the " +
+                    "undecorated frame is closed!");
+        }
+        if (eventType == WindowEvent.WINDOW_ACTIVATED) {
+            passed = false;
+            System.err.println("WINDOW_ACTIVATED event occured when the " +
+                    "undecorated frame is closed!");
+        }
+
+        if (!passed) {
+            System.err.println("Test failed!");
+            throw new RuntimeException("Test failed");
+        } else {
+            System.out.println("Test passed");
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Frame/MiscUndecorated/RepaintTest.java	Tue Aug 12 18:26:30 2014 +0400
@@ -0,0 +1,302 @@
+/*
+ * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+/*
+* @test
+* @summary Make sure that on changing state of Undecorated Frame,
+*          all the components on it are repainted correctly
+* @author Jitender(jitender.singh@eng.sun.com) area=AWT
+* @author yan
+* @library ../../../../lib/testlibrary
+* @build ExtendedRobot
+* @run main RepaintTest
+*/
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.JFrame;
+import javax.swing.JButton;
+import javax.swing.JTextField;
+import javax.swing.JPanel;
+import java.io.*;
+import java.awt.image.*;
+
+public class RepaintTest {
+    private static int delay = 150;
+
+    private Frame frame;
+    private Container panel1, panel2;
+    private Component button;
+    private Component textField;
+    private ExtendedRobot robot;
+    private Object buttonLock = new Object();
+    private boolean passed = true;
+    private boolean buttonClicked = false;
+    private int MAX_TOLERANCE_LEVEL = 10;
+
+    public static void main(String[] args) {
+        RepaintTest test = new RepaintTest();
+        test.doTest(false);
+        try {
+            Toolkit.getDefaultToolkit().getSystemEventQueue().invokeAndWait(new Runnable() {
+                public void run() {
+                    test.frame.dispose();
+                }
+            });
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new RuntimeException("Unexpected Exception occured");
+        }
+        test.doTest(true);
+        try {
+            Toolkit.getDefaultToolkit().getSystemEventQueue().invokeAndWait(new Runnable() {
+                public void run() {
+                    test.frame.dispose();
+                }
+            });
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new RuntimeException("Unexpected Exception occured");
+        }
+    }
+
+    /**
+     * Do screen capture and save it as image
+     */
+    private static void captureScreenAndSave() {
+
+        try {
+            Robot robot = new Robot();
+            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+            Rectangle rectangle = new Rectangle(0, 0, screenSize.width, screenSize.height);
+            System.out.println("About to screen capture - " + rectangle);
+            BufferedImage image = robot.createScreenCapture(rectangle);
+            javax.imageio.ImageIO.write(image, "jpg", new File("ScreenImage.jpg"));
+            robot.delay(3000);
+        } catch (Throwable t) {
+            System.out.println("WARNING: Exception thrown while screen capture!");
+            t.printStackTrace();
+        }
+    }
+
+    private void initializeGUI(boolean swingControl) {
+        frame = swingControl ? new JFrame() : new Frame();
+        frame.setLayout(new BorderLayout());
+
+        frame.setSize(300, 300);
+        frame.setUndecorated(true);
+
+        button = createButton(swingControl, (swingControl ? "Swing Button" : "AWT Button"));
+        textField = swingControl ? new JTextField("TextField") : new TextField("TextField");
+        panel1 = swingControl ? new JPanel() : new Panel();
+        panel2 = swingControl ? new JPanel() : new Panel();
+        panel1.add(button);
+        panel2.add(textField);
+        frame.add(panel2, BorderLayout.SOUTH);
+        frame.add(panel1, BorderLayout.NORTH);
+
+        frame.setBackground(Color.green);
+        frame.setVisible(true);
+        frame.toFront();
+    }
+    private Component createButton(boolean swingControl, String txt) {
+        if(swingControl) {
+            JButton jbtn = new JButton(txt);
+            jbtn.addActionListener(new ActionListener() {
+                public void actionPerformed(ActionEvent e) {
+                    buttonClicked = true;
+                    synchronized (buttonLock) {
+                        try {
+                            buttonLock.notifyAll();
+                        } catch (Exception ex) {
+                            ex.printStackTrace();
+                        }
+                    }
+                }
+            });
+            return jbtn;
+        }else {
+            Button btn = new Button(txt);
+            btn.addActionListener(new ActionListener() {
+                public void actionPerformed(ActionEvent e) {
+                    buttonClicked = true;
+                    synchronized (buttonLock) {
+                        try {
+                            buttonLock.notifyAll();
+                        } catch (Exception ex) {
+                            ex.printStackTrace();
+                        }
+                    }
+                }
+            });
+            return btn;
+        }
+    }
+
+    public void doTest(boolean swingControl) {
+        try {
+            Toolkit.getDefaultToolkit().getSystemEventQueue().invokeAndWait(new Runnable() {
+                public void run() {
+                    initializeGUI(swingControl);
+                }
+            });
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new RuntimeException("Interrupted or unexpected Exception occured");
+        }
+        try {
+            robot = new ExtendedRobot();
+            robot.waitForIdle(1000);
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new RuntimeException("Cannot create robot");
+        }
+
+        robot.mouseMove(button.getLocationOnScreen().x + button.getSize().width / 2,
+                        button.getLocationOnScreen().y + button.getSize().height / 2);
+        robot.waitForIdle(delay);
+        robot.mousePress(InputEvent.BUTTON1_MASK);
+        robot.waitForIdle(delay);
+        robot.mouseRelease(InputEvent.BUTTON1_MASK);
+
+        if (! buttonClicked) {
+            synchronized (buttonLock) {
+                try {
+                    buttonLock.wait(delay * 10);
+                } catch (Exception e) {
+                }
+            }
+        }
+        if (! buttonClicked) {
+            passed = false;
+            System.err.println("ActionEvent not triggered when " +
+                    "button is clicked!");
+            throw new RuntimeException("ActionEvent not triggered");
+        }
+
+        robot.waitForIdle(delay * 5); // Need to wait until look of the button
+                                      // returns to normal undepressed
+        passed = paintAndRepaint(button, (swingControl? "J": "")+"Button");
+        if( !paintAndRepaint(button, (swingControl? "J": "")+"TextField") ) {
+            passed = false;
+        }
+        if(!passed) {
+            throw new RuntimeException("Test failed");
+        }
+    }
+    private boolean paintAndRepaint(Component comp, String prefix) {
+        //Capture the component & compare it's dimensions
+        //before iconifying & after frame comes back from
+        //iconified to normal state
+        System.out.println("paintAndRepaint "+prefix);
+        Point p = comp.getLocationOnScreen();
+        Rectangle bRect = new Rectangle((int)p.getX(), (int)p.getY(),
+                                                comp.getWidth(), comp.getHeight());
+        BufferedImage capturedImage = robot.createScreenCapture(bRect);
+
+        try {
+            Toolkit.getDefaultToolkit().getSystemEventQueue().invokeAndWait(new Runnable() {
+                public void run() {
+                    frame.setExtendedState(Frame.ICONIFIED);
+                }
+            });
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new RuntimeException("Exception while setting extended state ICONIFIED");
+        }
+        robot.waitForIdle(delay * 5);
+        try {
+            Toolkit.getDefaultToolkit().getSystemEventQueue().invokeAndWait(new Runnable() {
+                public void run() {
+                    frame.setExtendedState(Frame.NORMAL);
+                    frame.toFront();
+                }
+            });
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new RuntimeException("Exception while setting extended state NORMAL");
+        }
+        robot.waitForIdle(delay * 5);
+
+        if (! p.equals(comp.getLocationOnScreen())) {
+            passed = false;
+            System.err.println("FAIL: Frame or component did not get positioned in the same place");
+        }
+
+        p = comp.getLocationOnScreen();
+        bRect = new Rectangle((int)p.getX(), (int)p.getY(),
+                                  comp.getWidth(), comp.getHeight());
+        BufferedImage capturedImage2 = robot.createScreenCapture(bRect);
+
+        if (! compareImages(capturedImage, capturedImage2)) {
+            passed = false;
+            try {
+                javax.imageio.ImageIO.write(capturedImage, "jpg", new File(
+                                   prefix+"BeforeMinimize.jpg"));
+                javax.imageio.ImageIO.write(capturedImage2, "jpg", new File(
+                                   prefix+"AfterMinimize.jpg"));
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+
+            System.err.println("FAIL: The frame or component did not get repainted correctly");
+        }
+        return passed;
+    }
+
+    //method for comparing two images
+    public boolean compareImages(BufferedImage capturedImg, BufferedImage realImg) {
+        int capturedPixels[], realPixels[];
+        int imgWidth, imgHeight;
+        boolean comparison = true;
+        int toleranceLevel = 0;
+
+        imgWidth = capturedImg.getWidth(null);
+        imgHeight = capturedImg.getHeight(null);
+        capturedPixels = new int[imgWidth * imgHeight];
+        realPixels = new int[imgWidth * imgHeight];
+
+        try {
+            PixelGrabber pgCapturedImg = new PixelGrabber(capturedImg, 0, 0,
+                              imgWidth, imgHeight, capturedPixels, 0, imgWidth);
+            pgCapturedImg.grabPixels();
+
+            PixelGrabber pgRealImg = new PixelGrabber(realImg, 0, 0,
+                              imgWidth, imgHeight, realPixels, 0, imgWidth);
+            pgRealImg.grabPixels();
+
+            for(int i=0; i<(imgWidth * imgHeight); i++) {
+                if(capturedPixels[i] != realPixels[i]) {
+                    toleranceLevel++;
+                }
+            }
+
+            if (toleranceLevel > MAX_TOLERANCE_LEVEL) {
+                comparison = false;
+            }
+        } catch(Exception ie) {
+            ie.printStackTrace();
+            comparison = false;
+        }
+        return comparison;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Frame/MiscUndecorated/UndecoratedInitiallyIconified.java	Tue Aug 12 18:26:30 2014 +0400
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.Frame;
+import java.awt.Toolkit;
+import javax.swing.JFrame;
+import java.awt.EventQueue;
+import java.awt.FlowLayout;
+/*
+ * @test
+ * @bug 4464710 7102299
+ * @summary Recurring bug is, an undecorated JFrame cannot be set iconified
+ *          before setVisible(true)
+ *
+ * @run main UndecoratedInitiallyIconified
+ */
+
+
+public class UndecoratedInitiallyIconified {
+    private static JFrame frame;
+    public static void main(String args[]) throws Exception {
+        if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.ICONIFIED)) {
+            return;
+        }
+        EventQueue.invokeAndWait( () -> {
+            frame = new JFrame("Test Frame");
+            frame.setLayout(new FlowLayout());
+            frame.setBounds(50,50,300,300);
+            frame.setUndecorated(true);
+            frame.setExtendedState(Frame.ICONIFIED);
+            if(frame.getExtendedState() != Frame.ICONIFIED) {
+                throw new RuntimeException("getExtendedState is not Frame.ICONIFIED as expected");
+            }
+        });
+    }
+}
--- a/jdk/test/java/awt/Mixing/AWT_Mixing/Util.java	Tue Aug 12 14:38:38 2014 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,601 +0,0 @@
-/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-import java.awt.Component;
-import java.awt.Frame;
-import java.awt.Dialog;
-import java.awt.Window;
-import java.awt.Button;
-import java.awt.Point;
-import java.awt.Dimension;
-import java.awt.Rectangle;
-import java.awt.Robot;
-import java.awt.Toolkit;
-import java.awt.IllegalComponentStateException;
-import java.awt.AWTException;
-import java.awt.AWTEvent;
-
-import java.awt.event.InputEvent;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
-import java.awt.event.ActionEvent;
-import java.awt.event.FocusEvent;
-import java.awt.event.WindowListener;
-import java.awt.event.WindowFocusListener;
-import java.awt.event.FocusListener;
-import java.awt.event.ActionListener;
-
-import java.awt.peer.FramePeer;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-import java.security.PrivilegedAction;
-import java.security.AccessController;
-
-import java.util.concurrent.atomic.AtomicBoolean;
-
-/**
- * <p>This class contains utilities useful for regression testing.
- * <p>When using jtreg you would include this class into the build
- * list via something like:
- * <pre>
-     &amp;library ../../../../share/lib/AWT_Mixing/src/regtesthelpers/
-     &amp;build Util
-     &amp;run main YourTest
-   </pre>
- * Note that if you are about to create a test based on
- * Applet-template, then put those lines into html-file, not in java-file.
- * <p> And put an
- * import regtesthelpers.Util;
- * into the java source of test.
-*/
-public final class Util {
-    private Util() {} // this is a helper class with static methods :)
-
-    /*
-     * @throws RuntimeException when creation failed
-     */
-    public static Robot createRobot() {
-        try {
-            return new Robot();
-        } catch (AWTException e) {
-            throw new RuntimeException("Error: unable to create robot", e);
-        }
-    }
-
-    public static Frame createEmbeddedFrame(final Frame embedder)
-        throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException,
-               InstantiationException, InvocationTargetException
-    {
-        Toolkit tk = Toolkit.getDefaultToolkit();
-        FramePeer frame_peer = (FramePeer) embedder.getPeer();
-        System.out.println("frame's peer = " + frame_peer);
-        if ("sun.awt.windows.WToolkit".equals(tk.getClass().getName())) {
-            Class comp_peer_class =
-                Class.forName("sun.awt.windows.WComponentPeer");
-            System.out.println("comp peer class = " + comp_peer_class);
-            Field hwnd_field = comp_peer_class.getDeclaredField("hwnd");
-            hwnd_field.setAccessible(true);
-            System.out.println("hwnd_field =" + hwnd_field);
-            long hwnd = hwnd_field.getLong(frame_peer);
-            System.out.println("hwnd = " + hwnd);
-
-            Class clazz = Class.forName("sun.awt.windows.WEmbeddedFrame");
-            Constructor constructor = clazz.getConstructor (new Class [] {Long.TYPE});
-            return (Frame) constructor.newInstance (new Object[] {hwnd});
-        } else if ("sun.awt.X11.XToolkit".equals(tk.getClass().getName())) {
-            Class x_base_window_class = Class.forName("sun.awt.X11.XBaseWindow");
-            System.out.println("x_base_window_class = " + x_base_window_class);
-            Method get_window = x_base_window_class.getMethod("getWindow", new Class[0]);
-            System.out.println("get_window = " + get_window);
-            long window = (Long) get_window.invoke(frame_peer, new Object[0]);
-            System.out.println("window = " + window);
-            Class clazz = Class.forName("sun.awt.X11.XEmbeddedFrame");
-            Constructor constructor = clazz.getConstructor (new Class [] {Long.TYPE, Boolean.TYPE});
-            return (Frame) constructor.newInstance (new Object[] {window, true});
-        }
-
-        throw new RuntimeException("Unexpected toolkit - " + tk);
-    }
-
-    /**
-     * Makes the window visible and waits until it's shown.
-     */
-    public static void showWindowWait(Window win) {
-        win.setVisible(true);
-        waitTillShown(win);
-    }
-
-    /**
-     * Moves mouse pointer in the center of given {@code comp} component
-     * using {@code robot} parameter.
-     */
-    public static void pointOnComp(final Component comp, final Robot robot) {
-        Rectangle bounds = new Rectangle(comp.getLocationOnScreen(), comp.getSize());
-        robot.mouseMove(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
-    }
-
-    /**
-     * Moves mouse pointer in the center of a given {@code comp} component
-     * and performs a left mouse button click using the {@code robot} parameter
-     * with the {@code delay} delay between press and release.
-     */
-    public static void clickOnComp(final Component comp, final Robot robot, int delay) {
-        pointOnComp(comp, robot);
-        robot.delay(delay);
-        robot.mousePress(InputEvent.BUTTON1_MASK);
-        robot.delay(delay);
-        robot.mouseRelease(InputEvent.BUTTON1_MASK);
-    }
-
-    /**
-     * Moves mouse pointer in the center of a given {@code comp} component
-     * and performs a left mouse button click using the {@code robot} parameter
-     * with the default delay between press and release.
-     */
-    public static void clickOnComp(final Component comp, final Robot robot) {
-        clickOnComp(comp, robot, 50);
-    }
-
-    /*
-     * Clicks on a title of Frame/Dialog.
-     * WARNING: it may fail on some platforms when the window is not wide enough.
-     */
-    public static void clickOnTitle(final Window decoratedWindow, final Robot robot) {
-        Point p = decoratedWindow.getLocationOnScreen();
-        Dimension d = decoratedWindow.getSize();
-
-        if (decoratedWindow instanceof Frame || decoratedWindow instanceof Dialog) {
-            robot.mouseMove(p.x + (int)(d.getWidth()/2), p.y + (int)decoratedWindow.getInsets().top/2);
-            robot.delay(50);
-            robot.mousePress(InputEvent.BUTTON1_MASK);
-            robot.delay(50);
-            robot.mouseRelease(InputEvent.BUTTON1_MASK);
-        }
-    }
-
-    public static void waitForIdle(final Robot robot) {
-        // we do not use robot for now, use SunToolkit.realSync() instead
-        ((sun.awt.SunToolkit)Toolkit.getDefaultToolkit()).realSync();
-    }
-
-    public static Field getField(final Class klass, final String fieldName) {
-        return AccessController.doPrivileged(new PrivilegedAction<Field>() {
-            public Field run() {
-                try {
-                    Field field = klass.getDeclaredField(fieldName);
-                    assert (field != null);
-                    field.setAccessible(true);
-                    return field;
-                } catch (SecurityException se) {
-                    throw new RuntimeException("Error: unexpected exception caught!", se);
-                } catch (NoSuchFieldException nsfe) {
-                    throw new RuntimeException("Error: unexpected exception caught!", nsfe);
-                }
-            }
-        });
-    }
-
-    /*
-     * Waits for a notification and for a boolean condition to become true.
-     * The method returns when the above conditions are fullfilled or when the timeout
-     * occurs.
-     *
-     * @param condition the object to be notified and the booelan condition to wait for
-     * @param timeout the maximum time to wait in milliseconds
-     * @param catchExceptions if {@code true} the method catches InterruptedException
-     * @return the final boolean value of the {@code condition}
-     * @throws InterruptedException if the awaiting proccess has been interrupted
-     */
-    public static boolean waitForConditionEx(final AtomicBoolean condition, long timeout)
-      throws InterruptedException
-        {
-            synchronized (condition) {
-                long startTime = System.currentTimeMillis();
-                while (!condition.get()) {
-                    condition.wait(timeout);
-                    if (System.currentTimeMillis() - startTime >= timeout ) {
-                        break;
-                    }
-                }
-            }
-            return condition.get();
-        }
-
-    /*
-     * The same as {@code waitForConditionEx(AtomicBoolean, long)} except that it
-     * doesn't throw InterruptedException.
-     */
-    public static boolean waitForCondition(final AtomicBoolean condition, long timeout) {
-        try {
-            return waitForConditionEx(condition, timeout);
-        } catch (InterruptedException e) {
-            throw new RuntimeException("Error: unexpected exception caught!", e);
-        }
-    }
-
-    /*
-     * The same as {@code waitForConditionEx(AtomicBoolean, long)} but without a timeout.
-     */
-    public static void waitForConditionEx(final AtomicBoolean condition)
-      throws InterruptedException
-        {
-            synchronized (condition) {
-                while (!condition.get()) {
-                    condition.wait();
-                }
-            }
-        }
-
-    /*
-     * The same as {@code waitForConditionEx(AtomicBoolean)} except that it
-     * doesn't throw InterruptedException.
-     */
-    public static void waitForCondition(final AtomicBoolean condition) {
-        try {
-            waitForConditionEx(condition);
-        } catch (InterruptedException e) {
-            throw new RuntimeException("Error: unexpected exception caught!", e);
-        }
-    }
-
-    public static void waitTillShownEx(final Component comp) throws InterruptedException {
-        while (true) {
-            try {
-                Thread.sleep(100);
-                comp.getLocationOnScreen();
-                break;
-            } catch (IllegalComponentStateException e) {}
-        }
-    }
-    public static void waitTillShown(final Component comp) {
-        try {
-            waitTillShownEx(comp);
-        } catch (InterruptedException e) {
-            throw new RuntimeException("Error: unexpected exception caught!", e);
-        }
-    }
-
-    /**
-     * Drags from one point to another with the specified mouse button pressed.
-     *
-     * @param robot a robot to use for moving the mouse, etc.
-     * @param startPoint a start point of the drag
-     * @param endPoint an end point of the drag
-     * @param button one of {@code InputEvent.BUTTON1_MASK},
-     *     {@code InputEvent.BUTTON2_MASK}, {@code InputEvent.BUTTON3_MASK}
-     *
-     * @throws IllegalArgumentException if {@code button} is not one of
-     *     {@code InputEvent.BUTTON1_MASK}, {@code InputEvent.BUTTON2_MASK},
-     *     {@code InputEvent.BUTTON3_MASK}
-     */
-    public static void drag(Robot robot, Point startPoint, Point endPoint, int button) {
-        if (!(button == InputEvent.BUTTON1_MASK || button == InputEvent.BUTTON2_MASK
-                || button == InputEvent.BUTTON3_MASK))
-        {
-            throw new IllegalArgumentException("invalid mouse button");
-        }
-
-        robot.mouseMove(startPoint.x, startPoint.y);
-        robot.mousePress(button);
-        try {
-            mouseMove(robot, startPoint, endPoint);
-        } finally {
-            robot.mouseRelease(button);
-        }
-    }
-
-    /**
-     * Moves the mouse pointer from one point to another.
-     * Uses Bresenham's algorithm.
-     *
-     * @param robot a robot to use for moving the mouse
-     * @param startPoint a start point of the drag
-     * @param endPoint an end point of the drag
-     */
-    public static void mouseMove(Robot robot, Point startPoint, Point endPoint) {
-        int dx = endPoint.x - startPoint.x;
-        int dy = endPoint.y - startPoint.y;
-
-        int ax = Math.abs(dx) * 2;
-        int ay = Math.abs(dy) * 2;
-
-        int sx = signWOZero(dx);
-        int sy = signWOZero(dy);
-
-        int x = startPoint.x;
-        int y = startPoint.y;
-
-        int d = 0;
-
-        if (ax > ay) {
-            d = ay - ax/2;
-            while (true){
-                robot.mouseMove(x, y);
-                robot.delay(50);
-
-                if (x == endPoint.x){
-                    return;
-                }
-                if (d >= 0){
-                    y = y + sy;
-                    d = d - ax;
-                }
-                x = x + sx;
-                d = d + ay;
-            }
-        } else {
-            d = ax - ay/2;
-            while (true){
-                robot.mouseMove(x, y);
-                robot.delay(50);
-
-                if (y == endPoint.y){
-                    return;
-                }
-                if (d >= 0){
-                    x = x + sx;
-                    d = d - ay;
-                }
-                y = y + sy;
-                d = d + ax;
-            }
-        }
-    }
-
-    private static int signWOZero(int i){
-        return (i > 0)? 1: -1;
-    }
-
-    private static int sign(int n) {
-        return n < 0 ? -1 : n == 0 ? 0 : 1;
-    }
-
-    /** Returns {@code WindowListener} instance that diposes {@code Window} on
-     *  "window closing" event.
-     *
-     * @return    the {@code WindowListener} instance that could be set
-     *            on a {@code Window}. After that
-     *            the {@code Window} is disposed when "window closed"
-     *            event is sent to the {@code Window}
-     */
-    public static WindowListener getClosingWindowAdapter() {
-        return new WindowAdapter () {
-            public void windowClosing(WindowEvent e) {
-                e.getWindow().dispose();
-            }
-        };
-    }
-
-    /*
-     * The values directly map to the ones of
-     * sun.awt.X11.XWM & sun.awt.motif.MToolkit classes.
-     */
-    public final static int
-        UNDETERMINED_WM = 1,
-        NO_WM = 2,
-        OTHER_WM = 3,
-        OPENLOOK_WM = 4,
-        MOTIF_WM = 5,
-        CDE_WM = 6,
-        ENLIGHTEN_WM = 7,
-        KDE2_WM = 8,
-        SAWFISH_WM = 9,
-        ICE_WM = 10,
-        METACITY_WM = 11,
-        COMPIZ_WM = 12,
-        LG3D_WM = 13;
-
-    /*
-     * Returns -1 in case of not X Window or any problems.
-     */
-    public static int getWMID() {
-        Class clazz = null;
-        try {
-            if ("sun.awt.X11.XToolkit".equals(Toolkit.getDefaultToolkit().getClass().getName())) {
-                clazz = Class.forName("sun.awt.X11.XWM");
-            } else if ("sun.awt.motif.MToolkit".equals(Toolkit.getDefaultToolkit().getClass().getName())) {
-                clazz = Class.forName("sun.awt.motif.MToolkit");
-            }
-        } catch (ClassNotFoundException cnfe) {
-            cnfe.printStackTrace();
-        }
-        if (clazz == null) {
-            return -1;
-        }
-
-        try {
-            final Class _clazz = clazz;
-            Method m_getWMID = (Method)AccessController.doPrivileged(new PrivilegedAction() {
-                    public Object run() {
-                        try {
-                            Method method = _clazz.getDeclaredMethod("getWMID", new Class[] {});
-                            if (method != null) {
-                                method.setAccessible(true);
-                            }
-                            return method;
-                        } catch (NoSuchMethodException e) {
-                            assert false;
-                        } catch (SecurityException e) {
-                            assert false;
-                        }
-                        return null;
-                    }
-                });
-            return ((Integer)m_getWMID.invoke(null, new Object[] {})).intValue();
-        } catch (IllegalAccessException iae) {
-            iae.printStackTrace();
-        } catch (InvocationTargetException ite) {
-            ite.printStackTrace();
-        }
-        return -1;
-    }
-
-
-    ////////////////////////////
-    // Some stuff to test focus.
-    ////////////////////////////
-
-    private static WindowGainedFocusListener wgfListener = new WindowGainedFocusListener();
-    private static FocusGainedListener fgListener = new FocusGainedListener();
-    private static ActionPerformedListener apListener = new ActionPerformedListener();
-
-    private abstract static class EventListener {
-        AtomicBoolean notifier = new AtomicBoolean(false);
-        Component comp;
-        boolean printEvent;
-
-        public void listen(Component comp, boolean printEvent) {
-            this.comp = comp;
-            this.printEvent = printEvent;
-            notifier.set(false);
-            setListener(comp);
-        }
-
-        public AtomicBoolean getNotifier() {
-            return notifier;
-        }
-
-        abstract void setListener(Component comp);
-
-        void printAndNotify(AWTEvent e) {
-            if (printEvent) {
-                System.err.println(e);
-            }
-            synchronized (notifier) {
-                notifier.set(true);
-                notifier.notifyAll();
-            }
-        }
-    }
-
-    private static class WindowGainedFocusListener extends EventListener implements WindowFocusListener {
-
-        void setListener(Component comp) {
-            ((Window)comp).addWindowFocusListener(this);
-        }
-
-        public void windowGainedFocus(WindowEvent e) {
-
-            ((Window)comp).removeWindowFocusListener(this);
-            printAndNotify(e);
-        }
-
-        public void windowLostFocus(WindowEvent e) {}
-    }
-
-    private static class FocusGainedListener extends EventListener implements FocusListener {
-
-        void setListener(Component comp) {
-            comp.addFocusListener(this);
-        }
-
-        public void focusGained(FocusEvent e) {
-            comp.removeFocusListener(this);
-            printAndNotify(e);
-        }
-
-        public void focusLost(FocusEvent e) {}
-    }
-
-    private static class ActionPerformedListener extends EventListener implements ActionListener {
-
-        void setListener(Component comp) {
-            ((Button)comp).addActionListener(this);
-        }
-
-        public void actionPerformed(ActionEvent e) {
-            ((Button)comp).removeActionListener(this);
-            printAndNotify(e);
-        }
-    }
-
-    private static boolean trackEvent(int eventID, Component comp, Runnable action, int time, boolean printEvent) {
-        EventListener listener = null;
-
-        switch (eventID) {
-        case WindowEvent.WINDOW_GAINED_FOCUS:
-            listener = wgfListener;
-            break;
-        case FocusEvent.FOCUS_GAINED:
-            listener = fgListener;
-            break;
-        case ActionEvent.ACTION_PERFORMED:
-            listener = apListener;
-            break;
-        }
-
-        listener.listen(comp, printEvent);
-        action.run();
-        return Util.waitForCondition(listener.getNotifier(), time);
-    }
-
-    /*
-     * Tracks WINDOW_GAINED_FOCUS event for a window caused by an action.
-     * @param window the window to track the event for
-     * @param action the action to perform
-     * @param time the max time to wait for the event
-     * @param printEvent should the event received be printed or doesn't
-     * @return true if the event has been received, otherwise false
-     */
-    public static boolean trackWindowGainedFocus(Window window, Runnable action, int time, boolean printEvent) {
-        return trackEvent(WindowEvent.WINDOW_GAINED_FOCUS, window, action, time, printEvent);
-    }
-
-    /*
-     * Tracks FOCUS_GAINED event for a component caused by an action.
-     * @see #trackWindowGainedFocus
-     */
-    public static boolean trackFocusGained(Component comp, Runnable action, int time, boolean printEvent) {
-        return trackEvent(FocusEvent.FOCUS_GAINED, comp, action, time, printEvent);
-    }
-
-    /*
-     * Tracks ACTION_PERFORMED event for a button caused by an action.
-     * @see #trackWindowGainedFocus
-     */
-    public static boolean trackActionPerformed(Button button, Runnable action, int time, boolean printEvent) {
-        return trackEvent(ActionEvent.ACTION_PERFORMED, button, action, time, printEvent);
-    }
-
-    /*
-     * Requests focus on the component provided and waits for the result.
-     * @return true if the component has been focused, false otherwise.
-     */
-    public static boolean focusComponent(Component comp, int time) {
-        return focusComponent(comp, time, false);
-    }
-    public static boolean focusComponent(final Component comp, int time, boolean printEvent) {
-        return trackFocusGained(comp,
-                                new Runnable() {
-                                    public void run() {
-                                        comp.requestFocus();
-                                    }
-                                },
-                                time, printEvent);
-
-    }
-}