< prev index next >

test/java/awt/dnd/MissingEventsOnModalDialog/MissingEventsOnModalDialogTest.java

Print this page




  59         DragSource defaultDragSource
  60                 = DragSource.getDefaultDragSource();
  61         defaultDragSource.createDefaultDragGestureRecognizer(sourceFrame,
  62                 DnDConstants.ACTION_COPY_OR_MOVE,
  63                 new TestDragGestureListener());
  64         new DropTarget(targetFrame, DnDConstants.ACTION_COPY_OR_MOVE,
  65                 new TestDropTargetListener(targetFrame));
  66 
  67         Robot robot = new Robot();
  68         robot.setAutoDelay(50);
  69 
  70         sourceFrame.toFront();
  71         robot.waitForIdle();
  72 
  73         Point point = getCenterPoint(sourceFrame);
  74         robot.mouseMove(point.x, point.y);
  75         robot.waitForIdle();
  76 
  77         mouseDragAndDrop(robot, point, getCenterPoint(targetFrame));
  78 
  79         long time = System.currentTimeMillis() + 200;
  80 
  81         while (!passed) {
  82             if (time < System.currentTimeMillis()) {
  83                 sourceFrame.dispose();
  84                 targetFrame.dispose();
  85                 throw new RuntimeException("Mouse clicked event is lost!");
  86             }
  87             Thread.sleep(10);
  88         }
  89         sourceFrame.dispose();
  90         targetFrame.dispose();
  91     }
  92 
  93     private static Frame createFrame(String title, int x, int y) {
  94         Frame frame = new Frame();
  95         frame.setSize(200, 200);
  96         frame.setLocation(x, y);
  97         frame.setTitle(title);
  98         frame.setVisible(true);
  99         return frame;


 205         clickOnModalDialog(dialog);
 206         dialog.setVisible(true);
 207     }
 208 
 209     private static void clickOnModalDialog(Dialog dialog) {
 210         new Thread(() -> {
 211             clickOnDialog(dialog);
 212         }).start();
 213     }
 214 
 215     private static void clickOnDialog(Dialog dialog) {
 216         try {
 217             long time = System.currentTimeMillis() + 200;
 218 
 219             while (!dialog.isVisible()) {
 220                 if (time < System.currentTimeMillis()) {
 221                     throw new RuntimeException("Dialog is not visible!");
 222                 }
 223                 Thread.sleep(10);
 224             }
 225 
 226             Point point = getCenterPoint(dialog);
 227             Robot robot = new Robot();
 228             robot.setAutoDelay(50);




 229 
 230             robot.mouseMove(point.x, point.y);
 231             robot.mousePress(InputEvent.BUTTON1_MASK);
 232             robot.mouseRelease(InputEvent.BUTTON1_MASK);
 233 
 234         } catch (Exception e) {
 235             throw new RuntimeException(e);
 236         }
 237     }
 238 }


  59         DragSource defaultDragSource
  60                 = DragSource.getDefaultDragSource();
  61         defaultDragSource.createDefaultDragGestureRecognizer(sourceFrame,
  62                 DnDConstants.ACTION_COPY_OR_MOVE,
  63                 new TestDragGestureListener());
  64         new DropTarget(targetFrame, DnDConstants.ACTION_COPY_OR_MOVE,
  65                 new TestDropTargetListener(targetFrame));
  66 
  67         Robot robot = new Robot();
  68         robot.setAutoDelay(50);
  69 
  70         sourceFrame.toFront();
  71         robot.waitForIdle();
  72 
  73         Point point = getCenterPoint(sourceFrame);
  74         robot.mouseMove(point.x, point.y);
  75         robot.waitForIdle();
  76 
  77         mouseDragAndDrop(robot, point, getCenterPoint(targetFrame));
  78 
  79         long time = System.currentTimeMillis() + 1000;
  80 
  81         while (!passed) {
  82             if (time < System.currentTimeMillis()) {
  83                 sourceFrame.dispose();
  84                 targetFrame.dispose();
  85                 throw new RuntimeException("Mouse clicked event is lost!");
  86             }
  87             Thread.sleep(10);
  88         }
  89         sourceFrame.dispose();
  90         targetFrame.dispose();
  91     }
  92 
  93     private static Frame createFrame(String title, int x, int y) {
  94         Frame frame = new Frame();
  95         frame.setSize(200, 200);
  96         frame.setLocation(x, y);
  97         frame.setTitle(title);
  98         frame.setVisible(true);
  99         return frame;


 205         clickOnModalDialog(dialog);
 206         dialog.setVisible(true);
 207     }
 208 
 209     private static void clickOnModalDialog(Dialog dialog) {
 210         new Thread(() -> {
 211             clickOnDialog(dialog);
 212         }).start();
 213     }
 214 
 215     private static void clickOnDialog(Dialog dialog) {
 216         try {
 217             long time = System.currentTimeMillis() + 200;
 218 
 219             while (!dialog.isVisible()) {
 220                 if (time < System.currentTimeMillis()) {
 221                     throw new RuntimeException("Dialog is not visible!");
 222                 }
 223                 Thread.sleep(10);
 224             }


 225             Robot robot = new Robot();
 226             robot.setAutoDelay(50);
 227             robot.waitForIdle();
 228             robot.delay(200);
 229 
 230             Point point = getCenterPoint(dialog);
 231 
 232             robot.mouseMove(point.x, point.y);
 233             robot.mousePress(InputEvent.BUTTON1_MASK);
 234             robot.mouseRelease(InputEvent.BUTTON1_MASK);
 235 
 236         } catch (Exception e) {
 237             throw new RuntimeException(e);
 238         }
 239     }
 240 }
< prev index next >