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 * @key headful 27 * @bug 4955110 28 * @summary tests that a drag ends on button2 release 29 * @author Alexander.Gerasimov area=dnd 30 * @library ../../regtesthelpers 31 * @build Util 32 * @run applet/othervm Button2DragTest.html 33 */ 34 35 36 /** 37 * Button2DragTest.java 38 * 39 * summary: tests that DragSourceDragEvent.getDropAction() accords to its new spec 40 * (does not depend on the user drop action) 41 * 42 */ 43 44 import java.applet.Applet; 45 import java.awt.*; 46 import java.awt.event.*; 47 import java.awt.datatransfer.*; 48 import java.awt.dnd.*; 49 import test.java.awt.regtesthelpers.Util; 50 51 52 public class Button2DragTest extends Applet { 53 54 private volatile boolean dropSuccess; 55 56 private Frame frame; 57 58 59 public void init() { 60 // Set up the environment -- set the layout manager, add 61 // buttons, etc. 62 setLayout(new BorderLayout()); 63 64 frame = new Frame(); 65 66 final DragSourceListener dragSourceListener = new DragSourceAdapter() { 67 public void dragDropEnd(DragSourceDropEvent e) { 68 dropSuccess = e.getDropSuccess(); 69 System.err.println("Drop was successful: " + dropSuccess); 70 } 71 }; 72 DragGestureListener dragGestureListener = new DragGestureListener() { 73 public void dragGestureRecognized(DragGestureEvent dge) { 74 dge.startDrag(null, new StringSelection("OK"), dragSourceListener); 75 } 76 }; 77 new DragSource().createDefaultDragGestureRecognizer(frame, DnDConstants.ACTION_MOVE, 78 dragGestureListener); 79 80 DropTargetAdapter dropTargetListener = new DropTargetAdapter() { 81 public void drop(DropTargetDropEvent dtde) { 82 dtde.acceptDrop(DnDConstants.ACTION_MOVE); 83 dtde.dropComplete(true); 84 System.err.println("Drop"); 85 } 86 }; 87 new DropTarget(frame, dropTargetListener); 88 } 89 90 91 public void start() { 92 //Get things going. Request focus, set size, et cetera 93 setSize(200,200); 94 setVisible(true); 95 validate(); 96 97 //What would normally go into main() will probably go here. 98 //Use System.out.println for diagnostic messages that you want 99 //to read after the test is done. 100 101 frame.setBounds(100, 100, 200, 200); 102 frame.setVisible(true); 103 104 Robot robot = Util.createRobot(); 105 106 Util.waitForIdle(robot); 107 108 Point startPoint = frame.getLocationOnScreen(); 109 Point endPoint = new Point(startPoint); 110 startPoint.translate(50, 50); 111 endPoint.translate(150, 150); 112 113 Util.drag(robot, startPoint, endPoint, InputEvent.BUTTON2_MASK); 114 115 Util.waitForIdle(robot); 116 robot.delay(500); 117 118 if (dropSuccess) { 119 System.err.println("test passed"); 120 } else { 121 throw new RuntimeException("test failed: drop was not successful"); 122 } 123 } 124 125 }