jdk/test/java/awt/dnd/ImageDecoratedDnDInOut/ImageDecoratedDnDInOut.java
author serb
Tue, 12 Nov 2013 20:24:25 +0400
changeset 21596 0e3a39f29dbc
parent 5506 202f599c92aa
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: 5506
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%
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    26
  @bug 4874070
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 ImageDecoratedDnDInOut.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.dnd.DragSource;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    37
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
public class ImageDecoratedDnDInOut extends Applet {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    40
    //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
    41
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    42
    public void init() {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    43
        //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
    44
        // 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
    45
        // etc.
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    46
        this.setLayout(new BorderLayout());
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    47
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    48
        String[] instructions =
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    49
                {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    50
                        "Automatic test.",
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    51
                        "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
    52
                        "a red panel, will appear below. ",
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    53
                        "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
    54
                        "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
    55
                        "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
    56
                        "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
    57
                        "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
    58
                        "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
    59
                        "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
    60
                        "the desktop and IE ).",
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    61
                        "3. The mouse would be released.",
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    62
                        "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
    63
                        "\"Drag ME!\" should appear inside the panel. "
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    64
                };
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    65
        Sysout.createDialogWithInstructions(instructions);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    66
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    67
    }//End  init()
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    68
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    69
    public void start() {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    70
        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
    71
        Panel mainPanel;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    72
        Component dragSource, dropTarget;
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
        f.setBounds(0, 400, 200, 200);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    75
        f.setLayout(new BorderLayout());
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    76
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    77
        mainPanel = new Panel();
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    78
        mainPanel.setLayout(new BorderLayout());
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    79
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    80
        mainPanel.setBackground(Color.blue);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    81
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    82
        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
    83
        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
    84
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    85
        mainPanel.add(dragSource, "North");
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    86
        mainPanel.add(dropTarget, "Center");
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    87
        f.add(mainPanel, BorderLayout.CENTER);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    88
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    89
        f.setVisible(true);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    90
        try {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    91
            Point sourcePoint = dragSource.getLocationOnScreen();
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    92
            Dimension d = dragSource.getSize();
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    93
            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
    94
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    95
            Robot robot = new Robot();
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    96
            robot.mouseMove(sourcePoint.x, sourcePoint.y);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    97
            robot.mousePress(InputEvent.BUTTON1_MASK);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    98
            Thread.sleep(2000);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    99
            for(int i = 0; i <100; ++i) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   100
                robot.mouseMove(
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   101
                    sourcePoint.x + d.width / 2 + 10,
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   102
                    sourcePoint.y + d.height);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   103
                Thread.sleep(100);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   104
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   105
                robot.mouseMove(sourcePoint.x, sourcePoint.y);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   106
                Thread.sleep(100);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   107
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   108
                robot.mouseMove(
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   109
                    sourcePoint.x,
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   110
                    sourcePoint.y + d.height);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   111
                Thread.sleep(100);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   112
            }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   113
            sourcePoint.y += d.height;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   114
            robot.mouseMove(sourcePoint.x, sourcePoint.y);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   115
            Thread.sleep(100);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   116
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   117
            robot.mouseRelease(InputEvent.BUTTON1_MASK);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   118
            Thread.sleep(4000);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   119
        } catch( Exception e){
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   120
        e.printStackTrace();
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   121
            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
   122
        }
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
    }// start()
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   125
}// class DnDAcceptanceTest
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   126
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   127
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   128
/**
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   129
 * *************************************************
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   130
 * Standard Test Machinery
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   131
 * 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
   132
 * 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
   133
 * 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
   134
 * 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
   135
 * **************************************************
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   136
 */
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   137
class Sysout {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   138
    private static TestDialog dialog;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   139
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   140
    public static void createDialogWithInstructions(String[] instructions) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   141
        dialog = new TestDialog(new Frame(), "Instructions");
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   142
        dialog.printInstructions(instructions);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   143
        dialog.show();
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   144
        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
   145
    }
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
    public static void createDialog() {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   148
        dialog = new TestDialog(new Frame(), "Instructions");
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   149
        String[] defInstr = {"Instructions will appear here. ", ""};
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   150
        dialog.printInstructions(defInstr);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   151
        dialog.show();
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   152
        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
   153
    }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   154
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   155
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   156
    public static void printInstructions(String[] instructions) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   157
        dialog.printInstructions(instructions);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   158
    }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   159
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
    public static void println(String messageIn) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   162
        dialog.displayMessage(messageIn);
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
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   165
}// Sysout  class
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   166
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   167
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   168
class TestDialog extends Dialog {
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
    TextArea instructionsText;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   171
    TextArea messageText;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   172
    int maxStringLength = 80;
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
    //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
   175
    public TestDialog(Frame frame, String name) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   176
        super(frame, name);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   177
        int scrollBoth = TextArea.SCROLLBARS_BOTH;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   178
        instructionsText = new TextArea("", 15, maxStringLength, scrollBoth);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   179
        add("North", instructionsText);
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
        messageText = new TextArea("", 5, maxStringLength, scrollBoth);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   182
        add("South", messageText);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   183
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   184
        pack();
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   185
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   186
        show();
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   187
    }// TestDialog()
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
    //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
   190
    public void printInstructions(String[] instructions) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   191
        //Clear out any current instructions
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   192
        instructionsText.setText("");
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
        //Go down array of instruction strings
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   195
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   196
        String printStr, remainingStr;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   197
        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
   198
            //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
   199
            remainingStr = instructions[i];
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   200
            while (remainingStr.length() > 0) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   201
                //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
   202
                if (remainingStr.length() >= maxStringLength) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   203
                    //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
   204
                    int posOfSpace = remainingStr.
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   205
                            lastIndexOf(' ', maxStringLength - 1);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   206
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   207
                    if (posOfSpace <= 0) posOfSpace = maxStringLength - 1;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   208
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   209
                    printStr = remainingStr.substring(0, posOfSpace + 1);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   210
                    remainingStr = remainingStr.substring(posOfSpace + 1);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   211
                }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   212
                //else just print
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   213
                else {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   214
                    printStr = remainingStr;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   215
                    remainingStr = "";
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   216
                }
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
                instructionsText.append(printStr + "\n");
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
            }// while
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   221
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   222
        }// for
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   223
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   224
    }//printInstructions()
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   225
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   226
    //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
   227
    public void displayMessage(String messageIn) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   228
        messageText.append(messageIn + "\n");
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
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   231
}// TestDialog  class
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   232