jdk/src/share/classes/java/awt/Robot.java
author ewendeli
Sun, 03 Feb 2013 23:25:38 +0100
changeset 16100 379f48d34516
parent 5506 202f599c92aa
child 22060 cd4f9d7dbeda
child 23274 3b6993da89df
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3956
diff changeset
     2
 * Copyright (c) 1999, 2009, 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;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.awt.ComponentFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.awt.SunToolkit;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    39
import sun.awt.image.SunWritableRaster;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.security.util.SecurityConstants;
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
    // location of robot's GC, used in mouseMove(), getPixelColor() and captureScreenImage()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private Point gdLoc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private DirectColorModel screenCapCM = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * Constructs a Robot object in the coordinate system of the primary screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @throws  AWTException if the platform configuration does not allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * low-level input control.  This exception is always thrown when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * GraphicsEnvironment.isHeadless() returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @throws  SecurityException if <code>createRobot</code> permission is not granted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @see     java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @see     SecurityManager#checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @see     AWTPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public Robot() throws AWTException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        if (GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            throw new AWTException("headless environment");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        init(GraphicsEnvironment.getLocalGraphicsEnvironment()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            .getDefaultScreenDevice());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * Creates a Robot for the given screen device. Coordinates passed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * to Robot method calls like mouseMove and createScreenCapture will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * be interpreted as being in the same coordinate system as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * specified screen. Note that depending on the platform configuration,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * multiple screens may either:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * <li>share the same coordinate system to form a combined virtual screen</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * <li>use different coordinate systems to act as independent screens</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * This constructor is meant for the latter case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * If screen devices are reconfigured such that the coordinate system is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * affected, the behavior of existing Robot objects is undefined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @param screen    A screen GraphicsDevice indicating the coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *                  system the Robot will operate in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @throws  AWTException if the platform configuration does not allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * low-level input control.  This exception is always thrown when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * GraphicsEnvironment.isHeadless() returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @throws  IllegalArgumentException if <code>screen</code> is not a screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *          GraphicsDevice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @throws  SecurityException if <code>createRobot</code> permission is not granted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @see     java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @see     GraphicsDevice
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @see     SecurityManager#checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @see     AWTPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public Robot(GraphicsDevice screen) throws AWTException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        checkIsScreenDevice(screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        init(screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    private void init(GraphicsDevice screen) throws AWTException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        checkRobotAllowed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        gdLoc = screen.getDefaultConfiguration().getBounds().getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        Toolkit toolkit = Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if (toolkit instanceof ComponentFactory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            peer = ((ComponentFactory)toolkit).createRobot(this, screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            disposer = new RobotDisposer(peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            sun.java2d.Disposer.addRecord(anchor, disposer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
3232
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   142
        initLegalButtonMask();
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   143
    }
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   144
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   145
    private static synchronized void initLegalButtonMask() {
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   146
        if (LEGAL_BUTTON_MASK != 0) return;
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   147
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   148
        int tmpMask = 0;
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   149
        if (Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   150
            if (Toolkit.getDefaultToolkit() instanceof SunToolkit) {
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   151
                final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   152
                for (int i = 0; i < buttonsNumber; i++){
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   153
                    tmpMask |= InputEvent.getMaskForButton(i+1);
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   154
                }
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   155
            }
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   156
        }
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   157
        tmpMask |= InputEvent.BUTTON1_MASK|
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   158
            InputEvent.BUTTON2_MASK|
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   159
            InputEvent.BUTTON3_MASK|
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   160
            InputEvent.BUTTON1_DOWN_MASK|
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   161
            InputEvent.BUTTON2_DOWN_MASK|
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   162
            InputEvent.BUTTON3_DOWN_MASK;
aacdc74b37d2 6855323: Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
dcherepanov
parents: 2810
diff changeset
   163
        LEGAL_BUTTON_MASK = tmpMask;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /* determine if the security policy allows Robot's to be created */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    private void checkRobotAllowed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        if (security != null) {
3956
2586d23078e4 6854954: Eliminate static dependency on java.awt.AWTPermission
alanb
parents: 3288
diff changeset
   170
            security.checkPermission(SecurityConstants.AWT.CREATE_ROBOT_PERMISSION);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /* check if the given device is a screen device */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    private void checkIsScreenDevice(GraphicsDevice device) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        if (device == null || device.getType() != GraphicsDevice.TYPE_RASTER_SCREEN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            throw new IllegalArgumentException("not a valid screen device");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    private transient Object anchor = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    static class RobotDisposer implements sun.java2d.DisposerRecord {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        private final RobotPeer peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        public RobotDisposer(RobotPeer peer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            this.peer = peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                peer.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    private transient RobotDisposer disposer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * Moves mouse pointer to given screen coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @param x         X position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @param y         Y position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public synchronized void mouseMove(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        peer.mouseMove(gdLoc.x + x, gdLoc.y + y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        afterEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * 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
   209
     * be released using the {@link #mouseRelease(int)} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   211
     * @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
   212
     * mouse button masks.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   213
     * <p>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   214
     * 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
   215
     * 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
   216
     * {@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
   217
     * and values returned by the
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   218
     * {@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
   219
     *
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   220
     * 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
   221
     * {@link Toolkit#areExtraMouseButtonsEnabled() Toolkit.areExtraMouseButtonsEnabled()} value as follows:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * <ul>
1962
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() disabled} 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 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
   226
     * {@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
   227
     * {@code InputEvent.BUTTON3_DOWN_MASK}.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   228
     * <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
   229
     * {@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
   230
     * 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
   231
     * 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
   232
     * 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
   233
     * 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
   234
     * <br>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   235
     * 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
   236
     * method to obtain the mask for any mouse button by its number.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * </ul>
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   238
     * <p>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   239
     * 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
   240
     * <ul>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   241
     * <li>{@code InputEvent.BUTTON1_MASK}
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   242
     * <li>{@code InputEvent.BUTTON2_MASK}
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   243
     * <li>{@code InputEvent.BUTTON3_MASK}
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   244
     * </ul>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   245
     * 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
   246
     * {@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
   247
     * 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
   248
     * 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
   249
     * @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
   250
     *         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
   251
     * @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
   252
     *         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
   253
     * @see #mouseRelease(int)
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   254
     * @see InputEvent#getMaskForButton(int)
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   255
     * @see Toolkit#areExtraMouseButtonsEnabled()
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   256
     * @see java.awt.MouseInfo#getNumberOfButtons()
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   257
     * @see java.awt.event.MouseEvent
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    public synchronized void mousePress(int buttons) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        checkButtonsArgument(buttons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        peer.mousePress(buttons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        afterEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * Releases one or more mouse buttons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   268
     * @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
   269
     * mouse button masks.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   270
     * <p>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   271
     * 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
   272
     * 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
   273
     * {@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
   274
     * and values returned by the
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   275
     * {@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
   276
     *
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   277
     * 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
   278
     * {@link Toolkit#areExtraMouseButtonsEnabled() Toolkit.areExtraMouseButtonsEnabled()} value as follows:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * <ul>
1962
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() disabled} 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 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
   283
     * {@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
   284
     * {@code InputEvent.BUTTON3_DOWN_MASK}.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   285
     * <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
   286
     * {@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
   287
     * 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
   288
     * 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
   289
     * 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
   290
     * 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
   291
     * <br>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   292
     * 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
   293
     * method to obtain the mask for any mouse button by its number.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * </ul>
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   295
     * <p>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   296
     * 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
   297
     * <ul>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   298
     * <li>{@code InputEvent.BUTTON1_MASK}
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   299
     * <li>{@code InputEvent.BUTTON2_MASK}
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   300
     * <li>{@code InputEvent.BUTTON3_MASK}
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   301
     * </ul>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   302
     * 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
   303
     * {@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
   304
     * 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
   305
     * 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
   306
     * @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
   307
     *         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
   308
     * @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
   309
     *         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
   310
     * @see #mousePress(int)
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   311
     * @see InputEvent#getMaskForButton(int)
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   312
     * @see Toolkit#areExtraMouseButtonsEnabled()
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   313
     * @see java.awt.MouseInfo#getNumberOfButtons()
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   314
     * @see java.awt.event.MouseEvent
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    public synchronized void mouseRelease(int buttons) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        checkButtonsArgument(buttons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        peer.mouseRelease(buttons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        afterEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    private void checkButtonsArgument(int buttons) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        if ( (buttons|LEGAL_BUTTON_MASK) != LEGAL_BUTTON_MASK ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            throw new IllegalArgumentException("Invalid combination of button flags");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * Rotates the scroll wheel on wheel-equipped mice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * @param wheelAmt  number of "notches" to move the mouse wheel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     *                  Negative values indicate movement up/away from the user,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     *                  positive values indicate movement down/towards the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    public synchronized void mouseWheel(int wheelAmt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        peer.mouseWheel(wheelAmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        afterEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * Presses a given key.  The key should be released using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * <code>keyRelease</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * Key codes that have more than one physical key associated with them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * (e.g. <code>KeyEvent.VK_SHIFT</code> could mean either the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * left or right shift key) will map to the left key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * @param   keycode Key to press (e.g. <code>KeyEvent.VK_A</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @throws  IllegalArgumentException if <code>keycode</code> is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     *          a valid key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @see     #keyRelease(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @see     java.awt.event.KeyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    public synchronized void keyPress(int keycode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        checkKeycodeArgument(keycode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        peer.keyPress(keycode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        afterEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * Releases a given key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * Key codes that have more than one physical key associated with them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * (e.g. <code>KeyEvent.VK_SHIFT</code> could mean either the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * left or right shift key) will map to the left key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * @param   keycode Key to release (e.g. <code>KeyEvent.VK_A</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @throws  IllegalArgumentException if <code>keycode</code> is not a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *          valid key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @see  #keyPress(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @see     java.awt.event.KeyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    public synchronized void keyRelease(int keycode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        checkKeycodeArgument(keycode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        peer.keyRelease(keycode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        afterEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    private void checkKeycodeArgument(int keycode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        // rather than build a big table or switch statement here, we'll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        // just check that the key isn't VK_UNDEFINED and assume that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        // peer implementations will throw an exception for other bogus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        // values e.g. -1, 999999
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        if (keycode == KeyEvent.VK_UNDEFINED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            throw new IllegalArgumentException("Invalid key code");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * Returns the color of a pixel at the given screen coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @param   x       X position of pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @param   y       Y position of pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @return  Color of the pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    public synchronized Color getPixelColor(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        Color color = new Color(peer.getRGBPixel(gdLoc.x + x, gdLoc.y + y));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        return color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * Creates an image containing pixels read from the screen.  This image does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * not include the mouse cursor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * @param   screenRect      Rect to capture in screen coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * @return  The captured image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * @throws  IllegalArgumentException if <code>screenRect</code> width and height are not greater than zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * @throws  SecurityException if <code>readDisplayPixels</code> permission is not granted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * @see     SecurityManager#checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * @see     AWTPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    public synchronized BufferedImage createScreenCapture(Rectangle screenRect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        checkScreenCaptureAllowed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        // according to the spec, screenRect is relative to robot's GD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        Rectangle translatedRect = new Rectangle(screenRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        translatedRect.translate(gdLoc.x, gdLoc.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        checkValidRect(translatedRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        BufferedImage image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        DataBufferInt buffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        WritableRaster raster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        if (screenCapCM == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
             * Fix for 4285201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
             * Create a DirectColorModel equivalent to the default RGB ColorModel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
             * except with no Alpha component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            screenCapCM = new DirectColorModel(24,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                                               /* red mask */    0x00FF0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                                               /* green mask */  0x0000FF00,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                                               /* blue mask */   0x000000FF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   437
        // 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
   438
        // cases rendering to the screen may be delayed
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   439
        Toolkit.getDefaultToolkit().sync();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   440
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        int pixels[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        int[] bandmasks = new int[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        pixels = peer.getRGBPixels(translatedRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        buffer = new DataBufferInt(pixels, pixels.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        bandmasks[0] = screenCapCM.getRedMask();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        bandmasks[1] = screenCapCM.getGreenMask();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        bandmasks[2] = screenCapCM.getBlueMask();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        raster = Raster.createPackedRaster(buffer, translatedRect.width, translatedRect.height, translatedRect.width, bandmasks, null);
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   452
        SunWritableRaster.makeTrackable(buffer);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        image = new BufferedImage(screenCapCM, raster, false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        return image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    private static void checkValidRect(Rectangle rect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        if (rect.width <= 0 || rect.height <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            throw new IllegalArgumentException("Rectangle width and height must be > 0");
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
    private static void checkScreenCaptureAllowed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            security.checkPermission(
3956
2586d23078e4 6854954: Eliminate static dependency on java.awt.AWTPermission
alanb
parents: 3288
diff changeset
   469
                SecurityConstants.AWT.READ_DISPLAY_PIXELS_PERMISSION);
2
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
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * Called after an event is generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    private void afterEvent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        autoWaitForIdle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        autoDelay();
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
     * Returns 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
     * @return Whether <code>waitForIdle</code> is automatically called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    public synchronized boolean isAutoWaitForIdle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        return isAutoWaitForIdle;
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
     * Sets whether this Robot automatically invokes <code>waitForIdle</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * after generating an event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * @param   isOn    Whether <code>waitForIdle</code> is automatically invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    public synchronized void setAutoWaitForIdle(boolean isOn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        isAutoWaitForIdle = isOn;
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
     * Calls waitForIdle after every event if so desired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    private void autoWaitForIdle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        if (isAutoWaitForIdle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            waitForIdle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * Returns the number of milliseconds this Robot sleeps after generating an event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    public synchronized int getAutoDelay() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        return autoDelay;
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
     * Sets the number of milliseconds this Robot sleeps after generating an event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * @throws  IllegalArgumentException If <code>ms</code> is not between 0 and 60,000 milliseconds inclusive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    public synchronized void setAutoDelay(int ms) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        checkDelayArgument(ms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        autoDelay = ms;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * Automatically sleeps for the specified interval after event generated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    private void autoDelay() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        delay(autoDelay);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * Sleeps for the specified time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * To catch any <code>InterruptedException</code>s that occur,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * <code>Thread.sleep()</code> may be used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * @param   ms      time to sleep in milliseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * @throws  IllegalArgumentException if <code>ms</code> is not between 0 and 60,000 milliseconds inclusive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * @see     java.lang.Thread#sleep
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    public synchronized void delay(int ms) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        checkDelayArgument(ms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            Thread.sleep(ms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        } catch(InterruptedException ite) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            ite.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    private void checkDelayArgument(int ms) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        if (ms < 0 || ms > MAX_DELAY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            throw new IllegalArgumentException("Delay must be to 0 to 60,000ms");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * Waits until all events currently on the event queue have been processed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * @throws  IllegalThreadStateException if called on the AWT event dispatching thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    public synchronized void waitForIdle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        checkNotDispatchThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        // post a dummy event to the queue so we know when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        // all the events before it have been processed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            SunToolkit.flushPendingEvents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            EventQueue.invokeAndWait( new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                                            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                                                // dummy implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                                        } );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        } catch(InterruptedException ite) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            System.err.println("Robot.waitForIdle, non-fatal exception caught:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            ite.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        } catch(InvocationTargetException ine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            System.err.println("Robot.waitForIdle, non-fatal exception caught:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            ine.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    private void checkNotDispatchThread() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        if (EventQueue.isDispatchThread()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            throw new IllegalThreadStateException("Cannot call method from the event dispatcher thread");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * Returns a string representation of this Robot.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * @return  the string representation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    public synchronized String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        String params = "autoDelay = "+getAutoDelay()+", "+"autoWaitForIdle = "+isAutoWaitForIdle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        return getClass().getName() + "[ " + params + " ]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
}