jdk/test/java/awt/Robot/ManualInstructions/ManualInstructions.java
author dav
Tue, 16 Sep 2008 12:17:02 +0400
changeset 1962 6c293d33645b
child 21596 0e3a39f29dbc
permissions -rw-r--r--
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons Summary: implementation of the more mouse buttons support Reviewed-by: art, dcherepanov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
     1
/*
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
     2
  test %W% %E%  %I%, %G%
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
     3
  @bug 6315717
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
     4
  @summary  manual control over the Robot
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
     5
  @author Andrei Dmitriev : area=awt.robot
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
     6
  @run applet/manual=yesno ManualInstructions.html
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
     7
*/
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
     8
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
     9
import java.applet.Applet;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    10
import java.awt.*;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    11
import java.awt.event.*;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    12
import java.util.Timer;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    13
import java.util.TimerTask;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    14
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    15
public class ManualInstructions extends Applet
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    16
{
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    17
    final static long SEND_DELAY = 1000;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    18
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    19
    public static void main(String s[]){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    20
        ManualInstructions mi = new ManualInstructions();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    21
        mi.init();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    22
        mi.start();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    23
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    24
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    25
    static Robot robot;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    26
    Point mouseLocation; //where mouse should be pressed each time
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    27
    Panel target = new Panel();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    28
    Button pressOn = new Button("press on ...");
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    29
    Button releaseOn = new Button("release on ...");
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    30
    Button clickOn = new Button("click on ...");
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    31
    Choice buttonNumber = new Choice();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    32
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    33
    public void init()
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    34
    {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    35
        try {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    36
            robot = new Robot();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    37
        } catch (AWTException ex) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    38
            ex.printStackTrace();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    39
            throw new RuntimeException(ex);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    40
        }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    41
        this.setLayout (new BorderLayout ());
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    42
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    43
        target.setBackground(Color.green);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    44
        target.setName("GreenBox");//for the ease of debug
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    45
        target.setPreferredSize(new Dimension(100, 100));
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    46
        String toolkit = Toolkit.getDefaultToolkit().getClass().getName();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    47
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    48
        // on X systems two buttons are reserved for wheel though they are countable by MouseInfo.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    49
        int buttonsNumber = toolkit.equals("sun.awt.windows.WToolkit")?MouseInfo.getNumberOfButtons():MouseInfo.getNumberOfButtons()-2;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    50
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    51
        for (int i = 0; i < 8; i++){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    52
            buttonNumber.add("BUTTON"+(i+1)+"_MASK");
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    53
        }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    54
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    55
        pressOn.addActionListener(new ActionListener(){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    56
                public void actionPerformed(ActionEvent e){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    57
                    System.out.println("Now pressing : " + (buttonNumber.getSelectedIndex()+1));
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    58
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    59
                    Timer timer = new Timer();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    60
                    TimerTask robotInteraction = new TimerTask(){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    61
                            public void run(){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    62
                                robot.mouseMove(updateTargetLocation().x, updateTargetLocation().y);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    63
                                robot.mousePress(getMask(buttonNumber.getSelectedIndex()+1));
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    64
                            }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    65
                        };
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    66
                    timer.schedule(robotInteraction, SEND_DELAY);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    67
                }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    68
            });
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    69
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    70
        releaseOn.addActionListener(new ActionListener(){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    71
            public void actionPerformed(ActionEvent e){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    72
                System.out.println("Now releasing : " + (buttonNumber.getSelectedIndex()+1));
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    73
                Timer timer = new Timer();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    74
                TimerTask robotInteraction = new TimerTask(){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    75
                        public void run(){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    76
                            robot.mouseMove(updateTargetLocation().x, updateTargetLocation().y);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    77
                            robot.mouseRelease(getMask(buttonNumber.getSelectedIndex()+1));
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    78
                        }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    79
                    };
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    80
                timer.schedule(robotInteraction, SEND_DELAY);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    81
            }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    82
        });
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    83
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    84
        clickOn.addActionListener(new ActionListener(){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    85
            public void actionPerformed(ActionEvent e){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    86
                System.out.println("Now clicking : " + (buttonNumber.getSelectedIndex()+1));
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    87
                Timer timer = new Timer();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    88
                TimerTask robotInteraction = new TimerTask(){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    89
                        public void run(){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    90
                            robot.mouseMove(updateTargetLocation().x, updateTargetLocation().y);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    91
                            robot.mousePress(getMask(buttonNumber.getSelectedIndex()+1));
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    92
                            robot.mouseRelease(getMask(buttonNumber.getSelectedIndex()+1));
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    93
                        }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    94
                    };
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    95
                timer.schedule(robotInteraction, SEND_DELAY);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    96
            }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    97
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    98
        });
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    99
        target.addMouseListener(new MouseAdapter(){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   100
           public void mousePressed(MouseEvent e){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   101
                Sysout.println(""+e);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   102
           }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   103
           public void mouseReleased(MouseEvent e){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   104
                Sysout.println(""+e);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   105
           }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   106
           public void mouseClicked(MouseEvent e){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   107
                Sysout.println(""+e);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   108
           }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   109
        });
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   110
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   111
        String[] instructions =
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   112
        {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   113
            "Do provide an instruction to the robot by",
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   114
            "choosing the button number to act and ",
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   115
            "pressing appropriate java.awt.Button on the left.",
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   116
            "Inspect an output in the TextArea below.",
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   117
            "Please don't generate non-natural sequences like Release-Release, etc.",
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   118
            "If you use keyboard be sure that you released the keyboard shortly.",
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   119
            "If events are generated well press Pass, otherwise Fail."
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   120
        };
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   121
        Sysout.createDialogWithInstructions( instructions );
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   122
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   123
    }//End  init()
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   124
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   125
    private int getMask(int button){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   126
        return InputEvent.getMaskForButton(button);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   127
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   128
        /*
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   129
            //this only works for standard buttons and for old JDK builds
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   130
        int mask = 0;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   131
        switch (button){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   132
        case 1: {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   133
            mask = InputEvent.BUTTON1_MASK;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   134
            break;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   135
        }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   136
        case 2: {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   137
            mask = InputEvent.BUTTON2_MASK;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   138
            break;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   139
        }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   140
        case 3: {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   141
            mask = InputEvent.BUTTON3_MASK;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   142
            break;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   143
        }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   144
        }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   145
        return mask;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   146
        */
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   147
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   148
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   149
    private Point updateTargetLocation() {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   150
        return new Point(target.getLocationOnScreen().x + target.getWidth()/2, target.getLocationOnScreen().y + target.getHeight()/2);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   151
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   152
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   153
    public void start ()
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   154
    {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   155
        //Get things going.  Request focus, set size, et cetera
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   156
        setSize (200,200);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   157
        setVisible(true);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   158
        validate();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   159
        Frame f = new Frame ("Set action for Robot here.");
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   160
        f.setLayout(new FlowLayout());
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   161
        f.add(buttonNumber);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   162
        f.add(pressOn);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   163
        f.add(releaseOn);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   164
        f.add(clickOn);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   165
        f.add(target);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   166
        f.pack();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   167
        f.setVisible(true);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   168
     }// start()
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   169
}// class
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   170
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   171
/* Place other classes related to the test after this line */
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   172
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   173
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   174
/****************************************************
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   175
 Standard Test Machinery
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   176
 DO NOT modify anything below -- it's a standard
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   177
  chunk of code whose purpose is to make user
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   178
  interaction uniform, and thereby make it simpler
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   179
  to read and understand someone else's test.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   180
 ****************************************************/
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   181
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   182
/**
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   183
 This is part of the standard test machinery.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   184
 It creates a dialog (with the instructions), and is the interface
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   185
  for sending text messages to the user.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   186
 To print the instructions, send an array of strings to Sysout.createDialog
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   187
  WithInstructions method.  Put one line of instructions per array entry.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   188
 To display a message for the tester to see, simply call Sysout.println
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   189
  with the string to be displayed.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   190
 This mimics System.out.println but works within the test harness as well
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   191
  as standalone.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   192
 */
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   193
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   194
class Sysout
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   195
{
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   196
    private static TestDialog dialog;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   197
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   198
    public static void createDialogWithInstructions( String[] instructions )
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   199
    {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   200
        dialog = new TestDialog( new Frame(), "Instructions" );
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   201
        dialog.printInstructions( instructions );
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   202
        dialog.setVisible(true);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   203
        println( "Any messages for the tester will display here." );
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   204
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   205
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   206
    public static void createDialog( )
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   207
    {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   208
        dialog = new TestDialog( new Frame(), "Instructions" );
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   209
        String[] defInstr = { "Instructions will appear here. ", "" } ;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   210
        dialog.printInstructions( defInstr );
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   211
        dialog.setVisible(true);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   212
        println( "Any messages for the tester will display here." );
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   213
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   214
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   215
    public static void printInstructions( String[] instructions )
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   216
    {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   217
        dialog.printInstructions( instructions );
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   218
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   219
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   220
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   221
    public static void println( String messageIn )
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   222
    {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   223
        dialog.displayMessage( messageIn );
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   224
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   225
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   226
}// Sysout  class
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   227
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   228
/**
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   229
  This is part of the standard test machinery.  It provides a place for the
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   230
   test instructions to be displayed, and a place for interactive messages
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   231
   to the user to be displayed.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   232
  To have the test instructions displayed, see Sysout.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   233
  To have a message to the user be displayed, see Sysout.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   234
  Do not call anything in this dialog directly.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   235
  */
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   236
class TestDialog extends Dialog
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   237
{
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   238
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   239
    TextArea instructionsText;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   240
    TextArea messageText;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   241
    int maxStringLength = 120;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   242
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   243
    //DO NOT call this directly, go through Sysout
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   244
    public TestDialog( Frame frame, String name )
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   245
    {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   246
        super( frame, name );
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   247
        int scrollBoth = TextArea.SCROLLBARS_BOTH;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   248
        instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   249
        add( "North", instructionsText );
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   250
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   251
        messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   252
        add("Center", messageText);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   253
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   254
        pack();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   255
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   256
        setVisible(true);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   257
    }// TestDialog()
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   258
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   259
    //DO NOT call this directly, go through Sysout
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   260
    public void printInstructions( String[] instructions )
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   261
    {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   262
        //Clear out any current instructions
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   263
        instructionsText.setText( "" );
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   264
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   265
        //Go down array of instruction strings
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   266
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   267
        String printStr, remainingStr;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   268
        for( int i=0; i < instructions.length; i++ )
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   269
        {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   270
            //chop up each into pieces maxSringLength long
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   271
            remainingStr = instructions[ i ];
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   272
            while( remainingStr.length() > 0 )
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   273
            {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   274
                //if longer than max then chop off first max chars to print
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   275
                if( remainingStr.length() >= maxStringLength )
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   276
                {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   277
                    //Try to chop on a word boundary
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   278
                    int posOfSpace = remainingStr.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   279
                        lastIndexOf( ' ', maxStringLength - 1 );
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   280
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   281
                    if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   282
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   283
                    printStr = remainingStr.substring( 0, posOfSpace + 1 );
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   284
                    remainingStr = remainingStr.substring( posOfSpace + 1 );
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   285
                }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   286
                //else just print
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   287
                else
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   288
                {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   289
                    printStr = remainingStr;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   290
                    remainingStr = "";
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   291
                }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   292
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   293
                instructionsText.append( printStr + "\n" );
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   294
            }// while
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   295
        }// for
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   296
    }//printInstructions()
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   297
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   298
    //DO NOT call this directly, go through Sysout
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   299
    public void displayMessage( String messageIn )
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   300
    {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   301
        messageText.append( messageIn + "\n" );
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   302
        System.out.println(messageIn);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   303
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   304
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   305
}// TestDialog  class