jdk/src/share/classes/java/awt/Robot.java
author henryjen
Tue, 10 Jun 2014 16:18:54 -0700
changeset 24865 09b1d992ca72
parent 23717 6457189cd574
child 25162 c388078278d4
permissions -rw-r--r--
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo Reviewed-by: mduigou, lancea, alanb, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23274
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 5506
diff changeset
     2
 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3956
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3956
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3956
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3956
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3956
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    28
import java.awt.event.InputEvent;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    29
import java.awt.event.KeyEvent;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    30
import java.awt.image.BufferedImage;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    31
import java.awt.image.DataBufferInt;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    32
import java.awt.image.DirectColorModel;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    33
import java.awt.image.Raster;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    34
import java.awt.image.WritableRaster;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    35
import java.awt.peer.RobotPeer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.lang.reflect.InvocationTargetException;
22060
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 5506
diff changeset
    37
import sun.awt.AWTPermissions;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.awt.ComponentFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.awt.SunToolkit;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    40
import sun.awt.image.SunWritableRaster;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * This class is used to generate native system input events
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * for the purposes of test automation, self-running demos, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * other applications where control of the mouse and keyboard
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * is needed. The primary purpose of Robot is to facilitate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * automated testing of Java platform implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Using the class to generate input events differs from posting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * events to the AWT event queue or AWT components in that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * events are generated in the platform's native input
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * queue. For example, <code>Robot.mouseMove</code> will actually move
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * the mouse cursor instead of just generating mouse move events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * Note that some platforms require special privileges or extensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * to access low-level input control. If the current platform configuration
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * does not allow input control, an <code>AWTException</code> will be thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * when trying to construct Robot objects. For example, X-Window systems
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * will throw the exception if the XTEST 2.2 standard extension is not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * (or not enabled) by the X server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * Applications that use Robot for purposes other than self-testing should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * handle these error conditions gracefully.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * @author      Robi Khan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * @since       1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
public class Robot {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private static final int MAX_DELAY = 60000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private RobotPeer peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private boolean isAutoWaitForIdle = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private int autoDelay = 0;
3232
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
    73
    private static int LEGAL_BUTTON_MASK = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private DirectColorModel screenCapCM = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * Constructs a Robot object in the coordinate system of the primary screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @throws  AWTException if the platform configuration does not allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * low-level input control.  This exception is always thrown when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * GraphicsEnvironment.isHeadless() returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @throws  SecurityException if <code>createRobot</code> permission is not granted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @see     java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @see     SecurityManager#checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @see     AWTPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public Robot() throws AWTException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        if (GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            throw new AWTException("headless environment");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        init(GraphicsEnvironment.getLocalGraphicsEnvironment()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            .getDefaultScreenDevice());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * Creates a Robot for the given screen device. Coordinates passed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * to Robot method calls like mouseMove and createScreenCapture will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * be interpreted as being in the same coordinate system as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * specified screen. Note that depending on the platform configuration,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * multiple screens may either:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * <li>share the same coordinate system to form a combined virtual screen</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * <li>use different coordinate systems to act as independent screens</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * This constructor is meant for the latter case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * If screen devices are reconfigured such that the coordinate system is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * affected, the behavior of existing Robot objects is undefined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @param screen    A screen GraphicsDevice indicating the coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *                  system the Robot will operate in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @throws  AWTException if the platform configuration does not allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * low-level input control.  This exception is always thrown when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * GraphicsEnvironment.isHeadless() returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @throws  IllegalArgumentException if <code>screen</code> is not a screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *          GraphicsDevice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @throws  SecurityException if <code>createRobot</code> permission is not granted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @see     java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @see     GraphicsDevice
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @see     SecurityManager#checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @see     AWTPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public Robot(GraphicsDevice screen) throws AWTException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        checkIsScreenDevice(screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        init(screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private void init(GraphicsDevice screen) throws AWTException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        checkRobotAllowed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        Toolkit toolkit = Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        if (toolkit instanceof ComponentFactory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            peer = ((ComponentFactory)toolkit).createRobot(this, screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            disposer = new RobotDisposer(peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            sun.java2d.Disposer.addRecord(anchor, disposer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
3232
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   137
        initLegalButtonMask();
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   138
    }
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   139
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   140
    private static synchronized void initLegalButtonMask() {
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   141
        if (LEGAL_BUTTON_MASK != 0) return;
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   142
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   143
        int tmpMask = 0;
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   144
        if (Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   145
            if (Toolkit.getDefaultToolkit() instanceof SunToolkit) {
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   146
                final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   147
                for (int i = 0; i < buttonsNumber; i++){
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   148
                    tmpMask |= InputEvent.getMaskForButton(i+1);
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   149
                }
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   150
            }
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   151
        }
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   152
        tmpMask |= InputEvent.BUTTON1_MASK|
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   153
            InputEvent.BUTTON2_MASK|
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   154
            InputEvent.BUTTON3_MASK|
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   155
            InputEvent.BUTTON1_DOWN_MASK|
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   156
            InputEvent.BUTTON2_DOWN_MASK|
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   157
            InputEvent.BUTTON3_DOWN_MASK;
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   158
        LEGAL_BUTTON_MASK = tmpMask;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    /* determine if the security policy allows Robot's to be created */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    private void checkRobotAllowed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        if (security != null) {
22060
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 5506
diff changeset
   165
            security.checkPermission(AWTPermissions.CREATE_ROBOT_PERMISSION);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /* check if the given device is a screen device */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    private void checkIsScreenDevice(GraphicsDevice device) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        if (device == null || device.getType() != GraphicsDevice.TYPE_RASTER_SCREEN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            throw new IllegalArgumentException("not a valid screen device");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    private transient Object anchor = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    static class RobotDisposer implements sun.java2d.DisposerRecord {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        private final RobotPeer peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        public RobotDisposer(RobotPeer peer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            this.peer = peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                peer.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    private transient RobotDisposer disposer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Moves mouse pointer to given screen coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @param x         X position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @param y         Y position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public synchronized void mouseMove(int x, int y) {
23274
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 5506
diff changeset
   198
        peer.mouseMove(x, y);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        afterEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * Presses one or more mouse buttons.  The mouse buttons should
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   204
     * be released using the {@link #mouseRelease(int)} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   206
     * @param buttons the Button mask; a combination of one or more
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   207
     * mouse button masks.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   208
     * <p>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   209
     * It is allowed to use only a combination of valid values as a {@code buttons} parameter.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   210
     * A valid combination consists of {@code InputEvent.BUTTON1_DOWN_MASK},
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   211
     * {@code InputEvent.BUTTON2_DOWN_MASK}, {@code InputEvent.BUTTON3_DOWN_MASK}
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   212
     * and values returned by the
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   213
     * {@link InputEvent#getMaskForButton(int) InputEvent.getMaskForButton(button)} method.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   214
     *
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   215
     * The valid combination also depends on a
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   216
     * {@link Toolkit#areExtraMouseButtonsEnabled() Toolkit.areExtraMouseButtonsEnabled()} value as follows:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * <ul>
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   218
     * <li> If support for extended mouse buttons is
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   219
     * {@link Toolkit#areExtraMouseButtonsEnabled() disabled} by Java
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   220
     * then it is allowed to use only the following standard button masks:
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   221
     * {@code InputEvent.BUTTON1_DOWN_MASK}, {@code InputEvent.BUTTON2_DOWN_MASK},
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   222
     * {@code InputEvent.BUTTON3_DOWN_MASK}.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   223
     * <li> If support for extended mouse buttons is
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   224
     * {@link Toolkit#areExtraMouseButtonsEnabled() enabled} by Java
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   225
     * then it is allowed to use the standard button masks
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   226
     * and masks for existing extended mouse buttons, if the mouse has more then three buttons.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   227
     * In that way, it is allowed to use the button masks corresponding to the buttons
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   228
     * in the range from 1 to {@link java.awt.MouseInfo#getNumberOfButtons() MouseInfo.getNumberOfButtons()}.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   229
     * <br>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   230
     * It is recommended to use the {@link InputEvent#getMaskForButton(int) InputEvent.getMaskForButton(button)}
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   231
     * method to obtain the mask for any mouse button by its number.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * </ul>
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   233
     * <p>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   234
     * The following standard button masks are also accepted:
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   235
     * <ul>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   236
     * <li>{@code InputEvent.BUTTON1_MASK}
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   237
     * <li>{@code InputEvent.BUTTON2_MASK}
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   238
     * <li>{@code InputEvent.BUTTON3_MASK}
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   239
     * </ul>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   240
     * However, it is recommended to use {@code InputEvent.BUTTON1_DOWN_MASK},
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   241
     * {@code InputEvent.BUTTON2_DOWN_MASK},  {@code InputEvent.BUTTON3_DOWN_MASK} instead.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   242
     * Either extended {@code _DOWN_MASK} or old {@code _MASK} values
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   243
     * should be used, but both those models should not be mixed.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   244
     * @throws IllegalArgumentException if the {@code buttons} mask contains the mask for extra mouse button
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   245
     *         and support for extended mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled() disabled} by Java
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   246
     * @throws IllegalArgumentException if the {@code buttons} mask contains the mask for extra mouse button
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   247
     *         that does not exist on the mouse and support for extended mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled() enabled} by Java
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @see #mouseRelease(int)
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   249
     * @see InputEvent#getMaskForButton(int)
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   250
     * @see Toolkit#areExtraMouseButtonsEnabled()
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   251
     * @see java.awt.MouseInfo#getNumberOfButtons()
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   252
     * @see java.awt.event.MouseEvent
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    public synchronized void mousePress(int buttons) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        checkButtonsArgument(buttons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        peer.mousePress(buttons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        afterEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * Releases one or more mouse buttons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   263
     * @param buttons the Button mask; a combination of one or more
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   264
     * mouse button masks.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   265
     * <p>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   266
     * It is allowed to use only a combination of valid values as a {@code buttons} parameter.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   267
     * A valid combination consists of {@code InputEvent.BUTTON1_DOWN_MASK},
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   268
     * {@code InputEvent.BUTTON2_DOWN_MASK}, {@code InputEvent.BUTTON3_DOWN_MASK}
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   269
     * and values returned by the
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   270
     * {@link InputEvent#getMaskForButton(int) InputEvent.getMaskForButton(button)} method.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   271
     *
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   272
     * The valid combination also depends on a
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   273
     * {@link Toolkit#areExtraMouseButtonsEnabled() Toolkit.areExtraMouseButtonsEnabled()} value as follows:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * <ul>
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   275
     * <li> If the support for extended mouse buttons is
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   276
     * {@link Toolkit#areExtraMouseButtonsEnabled() disabled} by Java
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   277
     * then it is allowed to use only the following standard button masks:
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   278
     * {@code InputEvent.BUTTON1_DOWN_MASK}, {@code InputEvent.BUTTON2_DOWN_MASK},
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   279
     * {@code InputEvent.BUTTON3_DOWN_MASK}.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   280
     * <li> If the support for extended mouse buttons is
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   281
     * {@link Toolkit#areExtraMouseButtonsEnabled() enabled} by Java
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   282
     * then it is allowed to use the standard button masks
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   283
     * and masks for existing extended mouse buttons, if the mouse has more then three buttons.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   284
     * In that way, it is allowed to use the button masks corresponding to the buttons
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   285
     * in the range from 1 to {@link java.awt.MouseInfo#getNumberOfButtons() MouseInfo.getNumberOfButtons()}.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   286
     * <br>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   287
     * It is recommended to use the {@link InputEvent#getMaskForButton(int) InputEvent.getMaskForButton(button)}
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   288
     * method to obtain the mask for any mouse button by its number.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * </ul>
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   290
     * <p>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   291
     * The following standard button masks are also accepted:
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   292
     * <ul>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   293
     * <li>{@code InputEvent.BUTTON1_MASK}
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   294
     * <li>{@code InputEvent.BUTTON2_MASK}
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   295
     * <li>{@code InputEvent.BUTTON3_MASK}
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   296
     * </ul>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   297
     * However, it is recommended to use {@code InputEvent.BUTTON1_DOWN_MASK},
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   298
     * {@code InputEvent.BUTTON2_DOWN_MASK},  {@code InputEvent.BUTTON3_DOWN_MASK} instead.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   299
     * Either extended {@code _DOWN_MASK} or old {@code _MASK} values
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   300
     * should be used, but both those models should not be mixed.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   301
     * @throws IllegalArgumentException if the {@code buttons} mask contains the mask for extra mouse button
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   302
     *         and support for extended mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled() disabled} by Java
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   303
     * @throws IllegalArgumentException if the {@code buttons} mask contains the mask for extra mouse button
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   304
     *         that does not exist on the mouse and support for extended mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled() enabled} by Java
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @see #mousePress(int)
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   306
     * @see InputEvent#getMaskForButton(int)
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   307
     * @see Toolkit#areExtraMouseButtonsEnabled()
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   308
     * @see java.awt.MouseInfo#getNumberOfButtons()
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   309
     * @see java.awt.event.MouseEvent
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public synchronized void mouseRelease(int buttons) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        checkButtonsArgument(buttons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        peer.mouseRelease(buttons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        afterEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    private void checkButtonsArgument(int buttons) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        if ( (buttons|LEGAL_BUTTON_MASK) != LEGAL_BUTTON_MASK ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            throw new IllegalArgumentException("Invalid combination of button flags");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * Rotates the scroll wheel on wheel-equipped mice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * @param wheelAmt  number of "notches" to move the mouse wheel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *                  Negative values indicate movement up/away from the user,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *                  positive values indicate movement down/towards the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    public synchronized void mouseWheel(int wheelAmt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        peer.mouseWheel(wheelAmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        afterEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * Presses a given key.  The key should be released using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * <code>keyRelease</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * Key codes that have more than one physical key associated with them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * (e.g. <code>KeyEvent.VK_SHIFT</code> could mean either the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * left or right shift key) will map to the left key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * @param   keycode Key to press (e.g. <code>KeyEvent.VK_A</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * @throws  IllegalArgumentException if <code>keycode</code> is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     *          a valid key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * @see     #keyRelease(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * @see     java.awt.event.KeyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    public synchronized void keyPress(int keycode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        checkKeycodeArgument(keycode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        peer.keyPress(keycode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        afterEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * Releases a given key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * Key codes that have more than one physical key associated with them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * (e.g. <code>KeyEvent.VK_SHIFT</code> could mean either the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * left or right shift key) will map to the left key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * @param   keycode Key to release (e.g. <code>KeyEvent.VK_A</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * @throws  IllegalArgumentException if <code>keycode</code> is not a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *          valid key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @see  #keyPress(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @see     java.awt.event.KeyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    public synchronized void keyRelease(int keycode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        checkKeycodeArgument(keycode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        peer.keyRelease(keycode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        afterEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    private void checkKeycodeArgument(int keycode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        // rather than build a big table or switch statement here, we'll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        // just check that the key isn't VK_UNDEFINED and assume that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        // peer implementations will throw an exception for other bogus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        // values e.g. -1, 999999
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        if (keycode == KeyEvent.VK_UNDEFINED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            throw new IllegalArgumentException("Invalid key code");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * Returns the color of a pixel at the given screen coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * @param   x       X position of pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * @param   y       Y position of pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * @return  Color of the pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    public synchronized Color getPixelColor(int x, int y) {
23274
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 5506
diff changeset
   393
        Color color = new Color(peer.getRGBPixel(x, y));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        return color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * Creates an image containing pixels read from the screen.  This image does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * not include the mouse cursor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @param   screenRect      Rect to capture in screen coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * @return  The captured image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * @throws  IllegalArgumentException if <code>screenRect</code> width and height are not greater than zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * @throws  SecurityException if <code>readDisplayPixels</code> permission is not granted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * @see     SecurityManager#checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * @see     AWTPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    public synchronized BufferedImage createScreenCapture(Rectangle screenRect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        checkScreenCaptureAllowed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
23274
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 5506
diff changeset
   410
        checkValidRect(screenRect);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        BufferedImage image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        DataBufferInt buffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        WritableRaster raster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        if (screenCapCM == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
             * Fix for 4285201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
             * Create a DirectColorModel equivalent to the default RGB ColorModel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
             * except with no Alpha component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            screenCapCM = new DirectColorModel(24,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                                               /* red mask */    0x00FF0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                                               /* green mask */  0x0000FF00,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                                               /* blue mask */   0x000000FF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   429
        // need to sync the toolkit prior to grabbing the pixels since in some
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   430
        // cases rendering to the screen may be delayed
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   431
        Toolkit.getDefaultToolkit().sync();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   432
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        int pixels[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        int[] bandmasks = new int[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
23274
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 5506
diff changeset
   436
        pixels = peer.getRGBPixels(screenRect);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        buffer = new DataBufferInt(pixels, pixels.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        bandmasks[0] = screenCapCM.getRedMask();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        bandmasks[1] = screenCapCM.getGreenMask();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        bandmasks[2] = screenCapCM.getBlueMask();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
23274
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 5506
diff changeset
   443
        raster = Raster.createPackedRaster(buffer, screenRect.width, screenRect.height, screenRect.width, bandmasks, null);
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   444
        SunWritableRaster.makeTrackable(buffer);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        image = new BufferedImage(screenCapCM, raster, false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        return image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    private static void checkValidRect(Rectangle rect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        if (rect.width <= 0 || rect.height <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            throw new IllegalArgumentException("Rectangle width and height must be > 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    private static void checkScreenCaptureAllowed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        if (security != null) {
22060
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 5506
diff changeset
   460
            security.checkPermission(AWTPermissions.READ_DISPLAY_PIXELS_PERMISSION);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * Called after an event is generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    private void afterEvent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        autoWaitForIdle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        autoDelay();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * Returns whether this Robot automatically invokes <code>waitForIdle</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * after generating an event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * @return Whether <code>waitForIdle</code> is automatically called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    public synchronized boolean isAutoWaitForIdle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        return isAutoWaitForIdle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * Sets whether this Robot automatically invokes <code>waitForIdle</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * after generating an event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * @param   isOn    Whether <code>waitForIdle</code> is automatically invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    public synchronized void setAutoWaitForIdle(boolean isOn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        isAutoWaitForIdle = isOn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * Calls waitForIdle after every event if so desired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    private void autoWaitForIdle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        if (isAutoWaitForIdle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            waitForIdle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * Returns the number of milliseconds this Robot sleeps after generating an event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    public synchronized int getAutoDelay() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        return autoDelay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * Sets the number of milliseconds this Robot sleeps after generating an event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * @throws  IllegalArgumentException If <code>ms</code> is not between 0 and 60,000 milliseconds inclusive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    public synchronized void setAutoDelay(int ms) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        checkDelayArgument(ms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        autoDelay = ms;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * Automatically sleeps for the specified interval after event generated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    private void autoDelay() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        delay(autoDelay);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * Sleeps for the specified time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * To catch any <code>InterruptedException</code>s that occur,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * <code>Thread.sleep()</code> may be used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * @param   ms      time to sleep in milliseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * @throws  IllegalArgumentException if <code>ms</code> is not between 0 and 60,000 milliseconds inclusive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * @see     java.lang.Thread#sleep
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    public synchronized void delay(int ms) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        checkDelayArgument(ms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            Thread.sleep(ms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        } catch(InterruptedException ite) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            ite.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    private void checkDelayArgument(int ms) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        if (ms < 0 || ms > MAX_DELAY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            throw new IllegalArgumentException("Delay must be to 0 to 60,000ms");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * Waits until all events currently on the event queue have been processed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * @throws  IllegalThreadStateException if called on the AWT event dispatching thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    public synchronized void waitForIdle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        checkNotDispatchThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        // post a dummy event to the queue so we know when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        // all the events before it have been processed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            SunToolkit.flushPendingEvents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            EventQueue.invokeAndWait( new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                                            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                                                // dummy implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                                        } );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        } catch(InterruptedException ite) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            System.err.println("Robot.waitForIdle, non-fatal exception caught:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            ite.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        } catch(InvocationTargetException ine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            System.err.println("Robot.waitForIdle, non-fatal exception caught:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            ine.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    private void checkNotDispatchThread() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        if (EventQueue.isDispatchThread()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            throw new IllegalThreadStateException("Cannot call method from the event dispatcher thread");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * Returns a string representation of this Robot.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * @return  the string representation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    public synchronized String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        String params = "autoDelay = "+getAutoDelay()+", "+"autoWaitForIdle = "+isAutoWaitForIdle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        return getClass().getName() + "[ " + params + " ]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
}