jdk/test/java/awt/dnd/Button2DragTest/Button2DragTest.java
author pchelko
Mon, 20 Jan 2014 14:23:51 +0400
changeset 23263 dcf3b071fc36
parent 5506 202f599c92aa
child 38383 c76fffbf4ef5
permissions -rw-r--r--
8032058: [TEST_BUG] [macosx] java/awt/dnd/Button2DragTest sometimes fail Reviewed-by: anthony, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23263
dcf3b071fc36 8032058: [TEST_BUG] [macosx] java/awt/dnd/Button2DragTest sometimes fail
pchelko
parents: 5506
diff changeset
     2
 * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
  test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
  @bug 4955110
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
  @summary tests that a drag ends on button2 release
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
  @author Alexander.Gerasimov area=dnd
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
  @library    ../../regtesthelpers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
  @build      Util
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
  @run applet/othervm Button2DragTest.html
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * Button2DragTest.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * summary: tests that DragSourceDragEvent.getDropAction() accords to its new spec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *          (does not depend on the user drop action)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.applet.Applet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.awt.datatransfer.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.awt.dnd.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import test.java.awt.regtesthelpers.Util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
public class Button2DragTest extends Applet {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private volatile boolean dropSuccess;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private Frame frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public void init() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        // Set up the environment -- set the layout manager, add
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        // buttons, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        frame = new Frame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        final DragSourceListener dragSourceListener = new DragSourceAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            public void dragDropEnd(DragSourceDropEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                dropSuccess = e.getDropSuccess();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                System.err.println("Drop was successful: " + dropSuccess);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        DragGestureListener dragGestureListener = new DragGestureListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            public void dragGestureRecognized(DragGestureEvent dge) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                dge.startDrag(null, new StringSelection("OK"), dragSourceListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        new DragSource().createDefaultDragGestureRecognizer(frame, DnDConstants.ACTION_MOVE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                                                            dragGestureListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        DropTargetAdapter dropTargetListener = new DropTargetAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            public void drop(DropTargetDropEvent dtde) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                dtde.acceptDrop(DnDConstants.ACTION_MOVE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                dtde.dropComplete(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                System.err.println("Drop");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        new DropTarget(frame, dropTargetListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public void start() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        //Get things going.  Request focus, set size, et cetera
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        setSize(200,200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        //What would normally go into main() will probably go here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        //Use System.out.println for diagnostic messages that you want
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        //to read after the test is done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        frame.setBounds(100, 100, 200, 200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        frame.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        Robot robot = Util.createRobot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        Util.waitForIdle(robot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        Point startPoint = frame.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        Point endPoint = new Point(startPoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        startPoint.translate(50, 50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        endPoint.translate(150, 150);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        Util.drag(robot, startPoint, endPoint, InputEvent.BUTTON2_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        Util.waitForIdle(robot);
23263
dcf3b071fc36 8032058: [TEST_BUG] [macosx] java/awt/dnd/Button2DragTest sometimes fail
pchelko
parents: 5506
diff changeset
   115
        robot.delay(500);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        if (dropSuccess) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            System.err.println("test passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            throw new RuntimeException("test failed: drop was not successful");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
}