jdk/test/java/awt/dnd/ImageDecoratedDnDNegative/ImageDecoratedDnDNegative.java
author serb
Tue, 12 Nov 2013 20:24:25 +0400
changeset 21596 0e3a39f29dbc
parent 12808 20329ff2140c
child 23010 6dadb192ad81
permissions -rw-r--r--
8027696: Incorrect copyright header in the tests Reviewed-by: alanb, malenkov, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4831
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4831
diff changeset
     2
 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
4831
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
     4
 *
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
21596
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 12808
diff changeset
     7
 * published by the Free Software Foundation.
4831
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
     8
 *
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    13
 * accompanied this code).
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    14
 *
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4831
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4831
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4831
diff changeset
    21
 * questions.
4831
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    22
 */
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    23
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    24
/*
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    25
  test %W% %E%
12808
20329ff2140c 7146550: [macosx] DnD test failure in createCompatibleWritableRaster()
bae
parents: 5506
diff changeset
    26
  @bug 4874070 7146550
4831
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    27
  @summary Tests basic DnD functionality
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    28
  @author Your Name: Alexey Utkin area=dnd
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    29
  @run applet ImageDecoratedDnDNegative.html
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    30
*/
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    31
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    32
import java.applet.Applet;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    33
import java.awt.*;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    34
import java.awt.Robot;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    35
import java.awt.event.InputEvent;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    36
import java.awt.event.KeyEvent;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    37
import java.awt.geom.Point2D;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    38
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    39
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    40
import java.awt.dnd.DragSource;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    41
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    42
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    43
public class ImageDecoratedDnDNegative extends Applet {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    44
    //Declare things used in the test, like buttons and labels here
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    45
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    46
    public void init() {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    47
        //Create instructions for the user here, as well as set up
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    48
        // the environment -- set the layout manager, add buttons,
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    49
        // etc.
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    50
        this.setLayout(new BorderLayout());
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    51
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    52
        String[] instructions =
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    53
                {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    54
                        "Automatic test.",
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    55
                        "A Frame, which contains a yellow button labeled \"Drag ME!\" and ",
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    56
                        "a red panel, will appear below. ",
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    57
                        "1. The button would be clicked and dragged to the red panel. ",
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    58
                        "2. When the mouse enters the red panel during the drag, the panel ",
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    59
                        "should turn yellow. On the systems that supports pictured drag, ",
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    60
                        "the image under the drag-cursor should appear (ancor is shifted ",
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    61
                        "from top-left corner of the picture inside the picture to 10pt in both dimensions ). ",
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    62
                        "In WIN32 systems the image under cursor would be visible ONLY over ",
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    63
                        "the drop targets with activated extended OLE D\'n\'D support (that are ",
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    64
                        "the desktop and IE ).",
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    65
                        "3. The mouse would be released.",
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    66
                        "The panel should turn red again and a yellow button labeled ",
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    67
                        "\"Drag ME!\" should appear inside the panel. You should be able ",
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    68
                        "to repeat this operation multiple times."
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    69
                };
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    70
        Sysout.createDialogWithInstructions(instructions);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    71
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    72
    }//End  init()
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    73
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    74
    public void moveTo(
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    75
        Robot r,
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    76
        Point b,
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    77
        Point e)
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    78
    {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    79
        Point2D.Double ee = new Point2D.Double(e.getX(), e.getY());
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    80
        Point2D.Double bb = new Point2D.Double(b.getX(), b.getY());
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    81
        final int count = (int)(ee.distance(bb));
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    82
        Point2D.Double c = new Point2D.Double(bb.getX(), bb.getY());
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    83
        for(int i=0; i<count; ++i){
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    84
            c.setLocation(
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    85
                    bb.getX() + (ee.getX()-bb.getX())*i/count,
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    86
                    bb.getY() + (ee.getY()-bb.getY())*i/count);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    87
            r.mouseMove(
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    88
                    (int)c.getX(),
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    89
                    (int)c.getY());
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    90
            r.delay(5);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    91
        }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    92
        r.mouseMove(
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    93
                (int)ee.getX(),
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    94
                (int)ee.getY());
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    95
        r.delay(5);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    96
    }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    97
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    98
    public void start() {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    99
        Frame f = new Frame("Use keyboard for DnD change");
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   100
        Panel mainPanel;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   101
        Component dragSource, dropTarget;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   102
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   103
        f.setBounds(0, 400, 200, 200);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   104
        f.setLayout(new BorderLayout());
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   105
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   106
        mainPanel = new Panel();
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   107
        mainPanel.setLayout(new BorderLayout());
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   108
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   109
        mainPanel.setBackground(Color.blue);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   110
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   111
        dropTarget = new DnDTarget(Color.red, Color.yellow);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   112
        dragSource = new DnDSource("Drag ME! (" + (DragSource.isDragImageSupported()?"with ":"without") + " image)" );
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   113
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   114
        mainPanel.add(dragSource, "North");
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   115
        mainPanel.add(dropTarget, "Center");
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   116
        f.add(mainPanel, BorderLayout.CENTER);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   117
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   118
        f.setVisible(true);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   119
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   120
        Point sourcePoint = dragSource.getLocationOnScreen();
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   121
        Dimension d = dragSource.getSize();
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   122
        sourcePoint.translate(d.width / 2, d.height / 2);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   123
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   124
        try {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   125
            Robot robot = new Robot();
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   126
            robot.mouseMove(sourcePoint.x, sourcePoint.y);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   127
            Point start = new Point(
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   128
                    sourcePoint.x,
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   129
                    sourcePoint.y);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   130
            Point out = new Point(
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   131
                    sourcePoint.x + d.width / 2 + 10,
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   132
                    sourcePoint.y + d.height);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   133
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   134
            Point cur = start;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   135
            for(int i = 2; i < 5; ++i){
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   136
                moveTo(robot, cur, start);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   137
                robot.delay(500);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   138
                robot.mousePress(InputEvent.BUTTON1_MASK);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   139
                robot.delay(500);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   140
                moveTo(robot, start, out);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   141
                robot.keyPress(KeyEvent.VK_CONTROL);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   142
                Point drop = new Point(
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   143
                        (int)start.getX(),
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   144
                        (int)start.getY() + (d.height + 5) * i );
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   145
                moveTo(robot, out, drop);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   146
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   147
                robot.mouseRelease(InputEvent.BUTTON1_MASK);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   148
                robot.delay(10);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   149
                robot.keyRelease(KeyEvent.VK_CONTROL);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   150
                robot.delay(1000);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   151
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   152
                cur = drop;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   153
            }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   154
        } catch( Exception e){
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   155
            e.printStackTrace();
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   156
            throw new RuntimeException("test failed: drop was not successful with exception " + e);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   157
        }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   158
    }// start()
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   159
}// class DnDAcceptanceTest
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   160
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   161
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   162
/**
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   163
 * *************************************************
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   164
 * Standard Test Machinery
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   165
 * DO NOT modify anything below -- it's a standard
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   166
 * chunk of code whose purpose is to make user
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   167
 * interaction uniform, and thereby make it simpler
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   168
 * to read and understand someone else's test.
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   169
 * **************************************************
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   170
 */
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   171
class Sysout {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   172
    private static TestDialog dialog;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   173
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   174
    public static void createDialogWithInstructions(String[] instructions) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   175
        dialog = new TestDialog(new Frame(), "Instructions");
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   176
        dialog.printInstructions(instructions);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   177
        dialog.show();
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   178
        println("Any messages for the tester will display here.");
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   179
    }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   180
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   181
    public static void createDialog() {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   182
        dialog = new TestDialog(new Frame(), "Instructions");
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   183
        String[] defInstr = {"Instructions will appear here. ", ""};
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   184
        dialog.printInstructions(defInstr);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   185
        dialog.show();
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   186
        println("Any messages for the tester will display here.");
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   187
    }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   188
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   189
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   190
    public static void printInstructions(String[] instructions) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   191
        dialog.printInstructions(instructions);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   192
    }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   193
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   194
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   195
    public static void println(String messageIn) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   196
        dialog.displayMessage(messageIn);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   197
    }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   198
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   199
}// Sysout  class
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   200
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   201
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   202
class TestDialog extends Dialog {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   203
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   204
    TextArea instructionsText;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   205
    TextArea messageText;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   206
    int maxStringLength = 80;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   207
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   208
    //DO NOT call this directly, go through Sysout
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   209
    public TestDialog(Frame frame, String name) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   210
        super(frame, name);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   211
        int scrollBoth = TextArea.SCROLLBARS_BOTH;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   212
        instructionsText = new TextArea("", 15, maxStringLength, scrollBoth);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   213
        add("North", instructionsText);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   214
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   215
        messageText = new TextArea("", 5, maxStringLength, scrollBoth);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   216
        add("South", messageText);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   217
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   218
        pack();
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   219
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   220
        show();
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   221
    }// TestDialog()
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   222
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   223
    //DO NOT call this directly, go through Sysout
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   224
    public void printInstructions(String[] instructions) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   225
        //Clear out any current instructions
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   226
        instructionsText.setText("");
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   227
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   228
        //Go down array of instruction strings
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   229
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   230
        String printStr, remainingStr;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   231
        for (int i = 0; i < instructions.length; i++) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   232
            //chop up each into pieces maxSringLength long
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   233
            remainingStr = instructions[i];
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   234
            while (remainingStr.length() > 0) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   235
                //if longer than max then chop off first max chars to print
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   236
                if (remainingStr.length() >= maxStringLength) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   237
                    //Try to chop on a word boundary
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   238
                    int posOfSpace = remainingStr.
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   239
                            lastIndexOf(' ', maxStringLength - 1);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   240
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   241
                    if (posOfSpace <= 0) posOfSpace = maxStringLength - 1;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   242
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   243
                    printStr = remainingStr.substring(0, posOfSpace + 1);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   244
                    remainingStr = remainingStr.substring(posOfSpace + 1);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   245
                }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   246
                //else just print
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   247
                else {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   248
                    printStr = remainingStr;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   249
                    remainingStr = "";
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   250
                }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   251
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   252
                instructionsText.append(printStr + "\n");
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   253
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   254
            }// while
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   255
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   256
        }// for
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   257
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   258
    }//printInstructions()
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   259
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   260
    //DO NOT call this directly, go through Sysout
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   261
    public void displayMessage(String messageIn) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   262
        messageText.append(messageIn + "\n");
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   263
    }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   264
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   265
}// TestDialog  class
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   266