jdk/test/lib/testlibrary/ExtendedRobot.java
author iris
Wed, 20 Jan 2016 11:02:36 -0800
changeset 35302 e4d2275861c3
parent 27506 41ccac32e143
permissions -rw-r--r--
8136494: Update "@since 1.9" to "@since 9" to match java.version.specification Reviewed-by: alanb, chegar, lancea, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24171
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
     1
/*
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
     4
 *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    10
 *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    15
 * accompanied this code).
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    16
 *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    20
 *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    23
 * questions.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    24
 */
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    25
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    26
import java.awt.AWTException;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    27
import java.awt.Robot;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    28
import java.awt.GraphicsDevice;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    29
import java.awt.Toolkit;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    30
import java.awt.Point;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    31
import java.awt.MouseInfo;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    32
import java.awt.event.InputEvent;
27506
41ccac32e143 8056911: Remove internal API usage from ExtendedRobot class
dermashov
parents: 25108
diff changeset
    33
import java.awt.event.KeyEvent;
24171
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    34
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    35
/**
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    36
 * ExtendedRobot is a subclass of {@link java.awt.Robot}. It provides some convenience methods that are
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    37
 * ought to be moved to {@link java.awt.Robot} class.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    38
 * <p>
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    39
 * ExtendedRobot uses delay {@link #getSyncDelay()} to make syncing threads with {@link #waitForIdle()}
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    40
 * more stable. This delay can be set once on creating object and could not be changed throughout object
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    41
 * lifecycle. Constructor reads vm integer property {@code java.awt.robotdelay} and sets the delay value
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    42
 * equal to the property value. If the property was not set 500 milliseconds default value is used.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    43
 * <p>
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    44
 * When using jtreg you would include this class via something like:
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    45
 * <pre>
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    46
 * {@literal @}library ../../../../lib/testlibrary
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    47
 * {@literal @}build ExtendedRobot
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    48
 * </pre>
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    49
 *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    50
 * @author      Dmitriy Ermashov
35302
e4d2275861c3 8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents: 27506
diff changeset
    51
 * @since       9
24171
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    52
 */
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    53
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    54
public class ExtendedRobot extends Robot {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    55
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    56
    private static int DEFAULT_SPEED = 20;       // Speed for mouse glide and click
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    57
    private static int DEFAULT_SYNC_DELAY = 500; // Default Additional delay for waitForIdle()
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    58
    private static int DEFAULT_STEP_LENGTH = 2;  // Step length (in pixels) for mouse glide
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    59
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    60
    private final int syncDelay = DEFAULT_SYNC_DELAY;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    61
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    62
    //TODO: uncomment three lines below after moving functionality to java.awt.Robot
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    63
    //{
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    64
    //    syncDelay = AccessController.doPrivileged(new GetIntegerAction("java.awt.robotdelay", DEFAULT_SYNC_DELAY));
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    65
    //}
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    66
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    67
    /**
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    68
     * Constructs an ExtendedRobot object in the coordinate system of the primary screen.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    69
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    70
     * @throws  AWTException if the platform configuration does not allow low-level input
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    71
     *          control. This exception is always thrown when
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    72
     *          GraphicsEnvironment.isHeadless() returns true
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    73
     * @throws  SecurityException if {@code createRobot} permission is not granted
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    74
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    75
     * @see     java.awt.GraphicsEnvironment#isHeadless
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    76
     * @see     SecurityManager#checkPermission
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    77
     * @see     java.awt.AWTPermission
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    78
     */
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    79
    public ExtendedRobot() throws AWTException {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    80
        super();
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    81
    }
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    82
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    83
    /**
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    84
     * Creates an ExtendedRobot for the given screen device. Coordinates passed
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    85
     * to ExtendedRobot method calls like mouseMove and createScreenCapture will
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    86
     * be interpreted as being in the same coordinate system as the specified screen.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    87
     * Note that depending on the platform configuration, multiple screens may either:
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    88
     * <ul>
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    89
     * <li>share the same coordinate system to form a combined virtual screen</li>
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    90
     * <li>use different coordinate systems to act as independent screens</li>
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    91
     * </ul>
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    92
     * This constructor is meant for the latter case.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    93
     * <p>
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    94
     * If screen devices are reconfigured such that the coordinate system is
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    95
     * affected, the behavior of existing ExtendedRobot objects is undefined.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    96
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    97
     * @param   screen  A screen GraphicsDevice indicating the coordinate
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    98
     *                  system the Robot will operate in.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    99
     * @throws  AWTException if the platform configuration does not allow low-level input
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   100
     *          control. This exception is always thrown when
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   101
     *          GraphicsEnvironment.isHeadless() returns true.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   102
     * @throws  IllegalArgumentException if {@code screen} is not a screen
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   103
     *          GraphicsDevice.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   104
     * @throws  SecurityException if {@code createRobot} permission is not granted
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   105
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   106
     * @see     java.awt.GraphicsEnvironment#isHeadless
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   107
     * @see     GraphicsDevice
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   108
     * @see     SecurityManager#checkPermission
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   109
     * @see     java.awt.AWTPermission
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   110
     */
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   111
    public ExtendedRobot(GraphicsDevice screen) throws AWTException {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   112
        super(screen);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   113
    }
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   114
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   115
    /**
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   116
     * Returns delay length for {@link #waitForIdle()} method
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   117
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   118
     * @return  Current delay value
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   119
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   120
     * @see     #waitForIdle()
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   121
     */
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   122
    public int getSyncDelay(){ return this.syncDelay; }
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   123
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   124
    /**
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   125
     * Clicks mouse button(s) by calling {@link java.awt.Robot#mousePress(int)} and
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   126
     * {@link java.awt.Robot#mouseRelease(int)} methods
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   127
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   128
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   129
     * @param   buttons The button mask; a combination of one or more mouse button masks.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   130
     * @throws  IllegalArgumentException if the {@code buttons} mask contains the mask for
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   131
     *          extra mouse button and support for extended mouse buttons is
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   132
     *          {@link Toolkit#areExtraMouseButtonsEnabled() disabled} by Java
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   133
     * @throws  IllegalArgumentException if the {@code buttons} mask contains the mask for
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   134
     *          extra mouse button that does not exist on the mouse and support for extended
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   135
     *          mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled() enabled}
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   136
     *          by Java
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   137
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   138
     * @see     #mousePress(int)
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   139
     * @see     #mouseRelease(int)
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   140
     * @see     InputEvent#getMaskForButton(int)
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   141
     * @see     Toolkit#areExtraMouseButtonsEnabled()
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   142
     * @see     java.awt.event.MouseEvent
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   143
     */
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   144
    public void click(int buttons) {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   145
        mousePress(buttons);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   146
        waitForIdle(DEFAULT_SPEED);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   147
        mouseRelease(buttons);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   148
        waitForIdle();
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   149
    }
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   150
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   151
    /**
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   152
     * Clicks mouse button 1
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   153
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   154
     * @throws  IllegalArgumentException if the {@code buttons} mask contains the mask for
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   155
     *          extra mouse button and support for extended mouse buttons is
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   156
     *          {@link Toolkit#areExtraMouseButtonsEnabled() disabled} by Java
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   157
     * @throws  IllegalArgumentException if the {@code buttons} mask contains the mask for
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   158
     *          extra mouse button that does not exist on the mouse and support for extended
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   159
     *          mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled() enabled}
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   160
     *          by Java
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   161
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   162
     * @see     #click(int)
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   163
     */
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   164
    public void click() {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   165
        click(InputEvent.BUTTON1_DOWN_MASK);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   166
    }
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   167
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   168
    /**
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   169
     * Waits until all events currently on the event queue have been processed with given
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   170
     * delay after syncing threads. It uses more advanced method of synchronizing threads
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   171
     * unlike {@link java.awt.Robot#waitForIdle()}
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   172
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   173
     * @param   delayValue  Additional delay length in milliseconds to wait until thread
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   174
     *                      sync been completed
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   175
     * @throws  sun.awt.SunToolkit.IllegalThreadException if called on the AWT event
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   176
     *          dispatching thread
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   177
     */
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   178
    public synchronized void waitForIdle(int delayValue) {
27506
41ccac32e143 8056911: Remove internal API usage from ExtendedRobot class
dermashov
parents: 25108
diff changeset
   179
        super.waitForIdle();
24171
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   180
        delay(delayValue);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   181
    }
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   182
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   183
    /**
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   184
     * Waits until all events currently on the event queue have been processed with delay
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   185
     * {@link #getSyncDelay()} after syncing threads. It uses more advanced method of
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   186
     * synchronizing threads unlike {@link java.awt.Robot#waitForIdle()}
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   187
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   188
     * @throws  sun.awt.SunToolkit.IllegalThreadException if called on the AWT event
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   189
     *          dispatching thread
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   190
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   191
     * @see     #waitForIdle(int)
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   192
     */
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   193
    @Override
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   194
    public synchronized void waitForIdle() {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   195
        waitForIdle(syncDelay);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   196
    }
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   197
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   198
    /**
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   199
     * Move the mouse in multiple steps from where it is
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   200
     * now to the destination coordinates.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   201
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   202
     * @param   x   Destination point x coordinate
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   203
     * @param   y   Destination point y coordinate
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   204
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   205
     * @see     #glide(int, int, int, int)
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   206
     */
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   207
    public void glide(int x, int y) {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   208
        Point p = MouseInfo.getPointerInfo().getLocation();
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   209
        glide(p.x, p.y, x, y);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   210
    }
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   211
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   212
    /**
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   213
     * Move the mouse in multiple steps from where it is
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   214
     * now to the destination point.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   215
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   216
     * @param   dest    Destination point
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   217
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   218
     * @see     #glide(int, int)
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   219
     */
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   220
    public void glide(Point dest) {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   221
        glide(dest.x, dest.y);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   222
    }
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   223
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   224
    /**
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   225
     * Move the mouse in multiple steps from source coordinates
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   226
     * to the destination coordinates.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   227
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   228
     * @param   fromX   Source point x coordinate
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   229
     * @param   fromY   Source point y coordinate
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   230
     * @param   toX     Destination point x coordinate
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   231
     * @param   toY     Destination point y coordinate
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   232
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   233
     * @see     #glide(int, int, int, int, int, int)
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   234
     */
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   235
    public void glide(int fromX, int fromY, int toX, int toY) {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   236
        glide(fromX, fromY, toX, toY, DEFAULT_STEP_LENGTH, DEFAULT_SPEED);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   237
    }
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   238
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   239
    /**
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   240
     * Move the mouse in multiple steps from source point to the
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   241
     * destination point with default speed and step length.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   242
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   243
     * @param   src     Source point
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   244
     * @param   dest    Destination point
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   245
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   246
     * @see     #glide(int, int, int, int, int, int)
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   247
     */
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   248
    public void glide(Point src, Point dest) {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   249
        glide(src.x, src.y, dest.x, dest.y, DEFAULT_STEP_LENGTH, DEFAULT_SPEED);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   250
    }
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   251
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   252
    /**
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   253
     * Move the mouse in multiple steps from source point to the
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   254
     * destination point with given speed and step length.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   255
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   256
     * @param   srcX        Source point x cordinate
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   257
     * @param   srcY        Source point y cordinate
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   258
     * @param   destX       Destination point x cordinate
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   259
     * @param   destY       Destination point y cordinate
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   260
     * @param   stepLength  Approximate length of one step
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   261
     * @param   speed       Delay between steps.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   262
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   263
     * @see     #mouseMove(int, int)
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   264
     * @see     #delay(int)
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   265
     */
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   266
     public void glide(int srcX, int srcY, int destX, int destY, int stepLength, int speed) {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   267
        int stepNum;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   268
        double tDx, tDy;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   269
        double dx, dy, ds;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   270
        double x, y;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   271
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   272
        dx = (destX - srcX);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   273
        dy = (destY - srcY);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   274
        ds = Math.sqrt(dx*dx + dy*dy);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   275
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   276
        tDx = dx / ds * stepLength;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   277
        tDy = dy / ds * stepLength;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   278
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   279
        int stepsCount = (int) ds / stepLength;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   280
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   281
        // Walk the mouse to the destination one step at a time
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   282
        mouseMove(srcX, srcY);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   283
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   284
        for (x = srcX, y = srcY, stepNum = 0;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   285
             stepNum < stepsCount;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   286
             stepNum++) {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   287
            x += tDx;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   288
            y += tDy;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   289
            mouseMove((int)x, (int)y);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   290
            delay(speed);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   291
        }
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   292
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   293
        // Ensure the mouse moves to the right destination.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   294
        // The steps may have led the mouse to a slightly wrong place.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   295
        mouseMove(destX, destY);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   296
    }
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   297
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   298
    /**
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   299
     * Moves mouse pointer to given screen coordinates.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   300
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   301
     * @param   position    Target position
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   302
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   303
     * @see     java.awt.Robot#mouseMove(int, int)
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   304
     */
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   305
    public synchronized void mouseMove(Point position) {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   306
        mouseMove(position.x, position.y);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   307
    }
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   308
25108
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   309
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   310
    /**
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   311
     * Emulate native drag and drop process using {@code InputEvent.BUTTON1_DOWN_MASK}.
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   312
     * The method successively moves mouse cursor to point with coordinates
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   313
     * ({@code fromX}, {@code fromY}), presses mouse button 1, drag mouse to
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   314
     * point with coordinates ({@code toX}, {@code toY}) and releases mouse
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   315
     * button 1 at last.
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   316
     *
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   317
     * @param   fromX   Source point x coordinate
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   318
     * @param   fromY   Source point y coordinate
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   319
     * @param   toX     Destination point x coordinate
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   320
     * @param   toY     Destination point y coordinate
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   321
     *
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   322
     * @see     #mousePress(int)
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   323
     * @see     #glide(int, int, int, int)
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   324
     */
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   325
    public void dragAndDrop(int fromX, int fromY, int toX, int toY){
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   326
        mouseMove(fromX, fromY);
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   327
        mousePress(InputEvent.BUTTON1_DOWN_MASK);
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   328
        waitForIdle();
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   329
        glide(toX, toY);
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   330
        mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   331
        waitForIdle();
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   332
    }
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   333
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   334
    /**
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   335
     * Emulate native drag and drop process using {@code InputEvent.BUTTON1_DOWN_MASK}.
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   336
     * The method successively moves mouse cursor to point {@code from},
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   337
     * presses mouse button 1, drag mouse to point {@code to} and releases
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   338
     * mouse button 1 at last.
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   339
     *
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   340
     * @param   from    Source point
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   341
     * @param   to      Destination point
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   342
     *
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   343
     * @see     #mousePress(int)
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   344
     * @see     #glide(int, int, int, int)
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   345
     * @see     #dragAndDrop(int, int, int, int)
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   346
     */
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   347
    public void dragAndDrop(Point from, Point to){
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   348
        dragAndDrop(from.x, from.y, to.x, to.y);
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   349
    }
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   350
24171
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   351
    /**
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   352
     * Successively presses and releases a given key.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   353
     * <p>
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   354
     * Key codes that have more than one physical key associated with them
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   355
     * (e.g. {@code KeyEvent.VK_SHIFT} could mean either the
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   356
     * left or right shift key) will map to the left key.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   357
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   358
     * @param   keycode Key to press (e.g. {@code KeyEvent.VK_A})
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   359
     * @throws  IllegalArgumentException if {@code keycode} is not
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   360
     *          a valid key
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   361
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   362
     * @see     java.awt.Robot#keyPress(int)
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   363
     * @see     java.awt.Robot#keyRelease(int)
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   364
     * @see     java.awt.event.KeyEvent
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   365
     */
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   366
    public void type(int keycode) {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   367
        keyPress(keycode);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   368
        waitForIdle(DEFAULT_SPEED);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   369
        keyRelease(keycode);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   370
        waitForIdle(DEFAULT_SPEED);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   371
    }
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   372
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   373
    /**
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   374
     * Types given character
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   375
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   376
     * @param   c   Character to be typed (e.g. {@code 'a'})
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   377
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   378
     * @see     #type(int)
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   379
     * @see     java.awt.event.KeyEvent
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   380
     */
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   381
    public void type(char c) {
27506
41ccac32e143 8056911: Remove internal API usage from ExtendedRobot class
dermashov
parents: 25108
diff changeset
   382
        type(KeyEvent.getExtendedKeyCodeForChar(c));
24171
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   383
    }
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   384
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   385
    /**
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   386
     * Types given array of characters one by one
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   387
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   388
     * @param   symbols Array of characters to be typed
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   389
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   390
     * @see     #type(char)
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   391
     */
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   392
    public void type(char[] symbols) {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   393
        for (int i = 0; i < symbols.length; i++) {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   394
            type(symbols[i]);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   395
        }
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   396
    }
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   397
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   398
    /**
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   399
     * Types given string
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   400
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   401
     * @param   s   String to be typed
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   402
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   403
     * @see     #type(char[])
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   404
     */
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   405
    public void type(String s) {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   406
        type(s.toCharArray());
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   407
    }
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   408
}