< prev index next >

test/java/awt/dnd/Button2DragTest/Button2DragTest.java

Print this page
rev 14294 : 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
Reviewed-by: xxx
rev 8985 : 8032058: [TEST_BUG] [macosx] java/awt/dnd/Button2DragTest sometimes fail
Reviewed-by: anthony, serb
rev 2362 : 6943119: Rebrand source copyright notices
Reviewed-by: darcy, weijun
rev 0 : Initial load
   1 /*
   2  * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25   test
  26   @bug 4955110
  27   @summary tests that a drag ends on button2 release
  28   @author Alexander.Gerasimov area=dnd
  29   @library    ../../regtesthelpers
  30   @build      Util
  31   @run applet/othervm Button2DragTest.html
  32 */






  33 

  34 
  35 /**
  36  * Button2DragTest.java
  37  *
  38  * summary: tests that DragSourceDragEvent.getDropAction() accords to its new spec
  39  *          (does not depend on the user drop action)
  40  *



  41  */
  42 
  43 import java.applet.Applet;
  44 import java.awt.*;
  45 import java.awt.event.*;
  46 import java.awt.datatransfer.*;
  47 import java.awt.dnd.*;
  48 import test.java.awt.regtesthelpers.Util;
  49 
  50 
  51 public class Button2DragTest extends Applet {
  52 
  53     private volatile boolean dropSuccess;
  54 
  55     private Frame frame;
  56 
  57 
  58     public void init() {
  59         // Set up the environment -- set the layout manager, add
  60         // buttons, etc.
  61         setLayout(new BorderLayout());






  62 

  63         frame = new Frame();
  64 
  65         final DragSourceListener dragSourceListener = new DragSourceAdapter() {
  66             public void dragDropEnd(DragSourceDropEvent e) {
  67                 dropSuccess = e.getDropSuccess();
  68                 System.err.println("Drop was successful: " + dropSuccess);
  69             }
  70         };
  71         DragGestureListener dragGestureListener = new DragGestureListener() {
  72             public void dragGestureRecognized(DragGestureEvent dge) {
  73                 dge.startDrag(null, new StringSelection("OK"), dragSourceListener);
  74             }
  75         };
  76         new DragSource().createDefaultDragGestureRecognizer(frame, DnDConstants.ACTION_MOVE,
  77                                                             dragGestureListener);
  78 
  79         DropTargetAdapter dropTargetListener = new DropTargetAdapter() {
  80             public void drop(DropTargetDropEvent dtde) {
  81                 dtde.acceptDrop(DnDConstants.ACTION_MOVE);
  82                 dtde.dropComplete(true);
  83                 System.err.println("Drop");
  84             }
  85         };
  86         new DropTarget(frame, dropTargetListener);
  87     }
  88 
  89 
  90     public void start() {
  91         //Get things going.  Request focus, set size, et cetera
  92         setSize(200,200);
  93         setVisible(true);
  94         validate();
  95 
  96         //What would normally go into main() will probably go here.
  97         //Use System.out.println for diagnostic messages that you want
  98         //to read after the test is done.
  99 
 100         frame.setBounds(100, 100, 200, 200);

 101         frame.setVisible(true);
 102 
 103         Robot robot = Util.createRobot();
 104 
 105         Util.waitForIdle(robot);
 106 
 107         Point startPoint = frame.getLocationOnScreen();
 108         Point endPoint = new Point(startPoint);
 109         startPoint.translate(50, 50);
 110         endPoint.translate(150, 150);
 111 
 112         Util.drag(robot, startPoint, endPoint, InputEvent.BUTTON2_MASK);
 113 
 114         Util.waitForIdle(robot);
 115         robot.delay(500);
 116 
 117         if (dropSuccess) {
 118             System.err.println("test passed");
 119         } else {
 120             throw new RuntimeException("test failed: drop was not successful");
   1 /*
   2  * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.awt.Frame;
  25 import java.awt.Point;
  26 import java.awt.Robot;
  27 import java.awt.datatransfer.StringSelection;
  28 import java.awt.dnd.DnDConstants;
  29 import java.awt.dnd.DragGestureEvent;
  30 import java.awt.dnd.DragGestureListener;
  31 import java.awt.dnd.DragSource;
  32 import java.awt.dnd.DragSourceAdapter;
  33 import java.awt.dnd.DragSourceDropEvent;
  34 import java.awt.dnd.DragSourceListener;
  35 import java.awt.dnd.DropTarget;
  36 import java.awt.dnd.DropTargetAdapter;
  37 import java.awt.dnd.DropTargetDropEvent;
  38 import java.awt.event.InputEvent;
  39 
  40 import test.java.awt.regtesthelpers.Util;
  41 
  42 /**
  43  * @test
  44  * @bug 4955110
  45  * @summary tests that DragSourceDragEvent.getDropAction() accords to its new
  46  *          spec (does not depend on the user drop action)
  47  * @library ../../regtesthelpers
  48  * @build Util
  49  * @run main/othervm Button2DragTest
  50  * @author Alexander.Gerasimov area=dnd
  51  */
  52 public final class Button2DragTest {









  53 
  54     private volatile boolean dropSuccess;
  55 
  56     private static Frame frame;

  57 
  58     public static void main(final String[] args) {
  59         Button2DragTest test = new Button2DragTest();
  60         try {
  61             test.run();
  62         } finally {
  63             if (frame != null) {
  64                 frame.dispose();
  65             }
  66         }
  67     }
  68 
  69     public void run() {
  70         frame = new Frame();
  71 
  72         final DragSourceListener dragSourceListener = new DragSourceAdapter() {
  73             public void dragDropEnd(DragSourceDropEvent e) {
  74                 dropSuccess = e.getDropSuccess();
  75                 System.err.println("Drop was successful: " + dropSuccess);
  76             }
  77         };
  78         DragGestureListener dragGestureListener = new DragGestureListener() {
  79             public void dragGestureRecognized(DragGestureEvent dge) {
  80                 dge.startDrag(null, new StringSelection("OK"), dragSourceListener);
  81             }
  82         };
  83         new DragSource().createDefaultDragGestureRecognizer(frame, DnDConstants.ACTION_MOVE,
  84                                                             dragGestureListener);
  85 
  86         DropTargetAdapter dropTargetListener = new DropTargetAdapter() {
  87             public void drop(DropTargetDropEvent dtde) {
  88                 dtde.acceptDrop(DnDConstants.ACTION_MOVE);
  89                 dtde.dropComplete(true);
  90                 System.err.println("Drop");
  91             }
  92         };
  93         new DropTarget(frame, dropTargetListener);








  94 
  95         //What would normally go into main() will probably go here.
  96         //Use System.out.println for diagnostic messages that you want
  97         //to read after the test is done.
  98         frame.setUndecorated(true);
  99         frame.setBounds(100, 100, 200, 200);
 100         frame.setLocationRelativeTo(null);
 101         frame.setVisible(true);
 102 
 103         Robot robot = Util.createRobot();
 104 
 105         Util.waitForIdle(robot);
 106 
 107         Point startPoint = frame.getLocationOnScreen();
 108         Point endPoint = new Point(startPoint);
 109         startPoint.translate(50, 50);
 110         endPoint.translate(150, 150);
 111 
 112         Util.drag(robot, startPoint, endPoint, InputEvent.BUTTON2_MASK);
 113 
 114         Util.waitForIdle(robot);
 115         robot.delay(500);
 116 
 117         if (dropSuccess) {
 118             System.err.println("test passed");
 119         } else {
 120             throw new RuntimeException("test failed: drop was not successful");
< prev index next >