21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 7154048 27 * @summary Window created under a mouse does not receive mouse enter event. 28 * Mouse Entered/Exited events are wrongly generated during dragging the window 29 * from one component to another 30 * @library ../../regtesthelpers 31 * @build Util 32 * @author alexandr.scherbatiy area=awt.event 33 * @run main DragWindowTest 34 */ 35 36 import java.awt.*; 37 import java.awt.event.*; 38 import javax.swing.*; 39 40 import java.util.concurrent.*; 41 import sun.awt.SunToolkit; 42 43 import test.java.awt.regtesthelpers.Util; 44 45 public class DragWindowTest { 46 47 private static volatile int dragWindowMouseEnteredCount = 0; 48 private static volatile int dragWindowMouseReleasedCount = 0; 49 private static volatile int buttonMouseEnteredCount = 0; 50 private static volatile int labelMouseReleasedCount = 0; 51 private static MyDragWindow dragWindow; 52 private static JLabel label; 53 private static JButton button; 54 55 public static void main(String[] args) throws Exception { 56 57 SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); 58 Robot robot = new Robot(); 59 robot.setAutoDelay(50); 60 61 SwingUtilities.invokeAndWait(new Runnable() { 62 63 @Override 64 public void run() { 65 createAndShowGUI(); 66 } 67 }); 68 69 toolkit.realSync(); 70 71 Point pointToClick = Util.invokeOnEDT(new Callable<Point>() { 72 73 @Override 74 public Point call() throws Exception { 75 return getCenterPoint(label); 76 } 77 }); 78 79 80 robot.mouseMove(pointToClick.x, pointToClick.y); 81 robot.mousePress(InputEvent.BUTTON1_MASK); 82 toolkit.realSync(); 83 84 if (dragWindowMouseEnteredCount != 1) { 85 throw new RuntimeException("No MouseEntered event on Drag Window!"); 86 } 87 88 Point pointToDrag = Util.invokeOnEDT(new Callable<Point>() { 89 90 @Override 91 public Point call() throws Exception { 92 button.addMouseListener(new ButtonMouseListener()); 93 return getCenterPoint(button); 94 } 95 }); 96 97 robot.mouseMove(pointToDrag.x, pointToDrag.y); 98 toolkit.realSync(); 99 100 if (buttonMouseEnteredCount != 0) { 101 throw new RuntimeException("Extra MouseEntered event on button!"); 102 } 103 104 robot.mouseRelease(InputEvent.BUTTON1_MASK); 105 toolkit.realSync(); 106 107 if (labelMouseReleasedCount != 1) { 108 throw new RuntimeException("No MouseReleased event on label!"); 109 } 110 111 } 112 113 private static Point getCenterPoint(Component comp) { 114 Point p = comp.getLocationOnScreen(); 115 Rectangle rect = comp.getBounds(); 116 return new Point(p.x + rect.width / 2, p.y + rect.height / 2); 117 } 118 119 private static void createAndShowGUI() { 120 121 JFrame frame = new JFrame("Main Frame"); 122 frame.setSize(300, 200); 123 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 124 125 label = new JLabel("Label"); | 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 7154048 27 * @summary Window created under a mouse does not receive mouse enter event. 28 * Mouse Entered/Exited events are wrongly generated during dragging the window 29 * from one component to another 30 * @library ../../regtesthelpers 31 * @build Util 32 * @author alexandr.scherbatiy area=awt.event 33 * @run main DragWindowTest 34 */ 35 36 import java.awt.*; 37 import java.awt.event.*; 38 import javax.swing.*; 39 40 import java.util.concurrent.*; 41 42 import test.java.awt.regtesthelpers.Util; 43 44 public class DragWindowTest { 45 46 private static volatile int dragWindowMouseEnteredCount = 0; 47 private static volatile int dragWindowMouseReleasedCount = 0; 48 private static volatile int buttonMouseEnteredCount = 0; 49 private static volatile int labelMouseReleasedCount = 0; 50 private static MyDragWindow dragWindow; 51 private static JLabel label; 52 private static JButton button; 53 54 public static void main(String[] args) throws Exception { 55 56 Robot robot = new Robot(); 57 robot.setAutoDelay(50); 58 59 SwingUtilities.invokeAndWait(new Runnable() { 60 61 @Override 62 public void run() { 63 createAndShowGUI(); 64 } 65 }); 66 67 robot.waitForIdle(); 68 69 Point pointToClick = Util.invokeOnEDT(new Callable<Point>() { 70 71 @Override 72 public Point call() throws Exception { 73 return getCenterPoint(label); 74 } 75 }); 76 77 78 robot.mouseMove(pointToClick.x, pointToClick.y); 79 robot.mousePress(InputEvent.BUTTON1_MASK); 80 robot.waitForIdle(); 81 82 if (dragWindowMouseEnteredCount != 1) { 83 throw new RuntimeException("No MouseEntered event on Drag Window!"); 84 } 85 86 Point pointToDrag = Util.invokeOnEDT(new Callable<Point>() { 87 88 @Override 89 public Point call() throws Exception { 90 button.addMouseListener(new ButtonMouseListener()); 91 return getCenterPoint(button); 92 } 93 }); 94 95 robot.mouseMove(pointToDrag.x, pointToDrag.y); 96 robot.waitForIdle(); 97 98 if (buttonMouseEnteredCount != 0) { 99 throw new RuntimeException("Extra MouseEntered event on button!"); 100 } 101 102 robot.mouseRelease(InputEvent.BUTTON1_MASK); 103 robot.waitForIdle(); 104 105 if (labelMouseReleasedCount != 1) { 106 throw new RuntimeException("No MouseReleased event on label!"); 107 } 108 109 } 110 111 private static Point getCenterPoint(Component comp) { 112 Point p = comp.getLocationOnScreen(); 113 Rectangle rect = comp.getBounds(); 114 return new Point(p.x + rect.width / 2, p.y + rect.height / 2); 115 } 116 117 private static void createAndShowGUI() { 118 119 JFrame frame = new JFrame("Main Frame"); 120 frame.setSize(300, 200); 121 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 122 123 label = new JLabel("Label"); |