jdk/test/lib/testlibrary/ExtendedRobot.java
author yan
Mon, 26 May 2014 15:50:10 +0400
changeset 25108 cbf21a81a738
parent 24171 9a263c3c482b
child 27506 41ccac32e143
permissions -rw-r--r--
8041915: Move 8 awt tests to OpenJDK regression tests tree Reviewed-by: pchelko, alexsch Contributed-by: Dmitriy Ermashov <dmitriy.ermashov@oracle.com>
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 sun.awt.ExtendedKeyCodes;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    27
import sun.awt.SunToolkit;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    28
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    29
import java.awt.AWTException;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    30
import java.awt.Robot;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    31
import java.awt.GraphicsDevice;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    32
import java.awt.Toolkit;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    33
import java.awt.Point;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    34
import java.awt.MouseInfo;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    35
import java.awt.event.InputEvent;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    36
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    37
/**
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    38
 * 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
    39
 * ought to be moved to {@link java.awt.Robot} class.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    40
 * <p>
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    41
 * 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
    42
 * 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
    43
 * 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
    44
 * 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
    45
 * <p>
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    46
 * 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
    47
 * <pre>
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    48
 * {@literal @}library ../../../../lib/testlibrary
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    49
 * {@literal @}build ExtendedRobot
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    50
 * </pre>
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    51
 *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    52
 * @author      Dmitriy Ermashov
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    53
 * @since       1.9
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    54
 */
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
public class ExtendedRobot extends Robot {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    57
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    58
    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
    59
    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
    60
    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
    61
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    62
    private final int syncDelay = DEFAULT_SYNC_DELAY;
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
    //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
    65
    //{
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    66
    //    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
    67
    //}
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    68
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
     * 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
    71
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    72
     * @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
    73
     *          control. This exception is always thrown when
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    74
     *          GraphicsEnvironment.isHeadless() returns true
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    75
     * @throws  SecurityException if {@code createRobot} permission is not granted
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    76
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    77
     * @see     java.awt.GraphicsEnvironment#isHeadless
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    78
     * @see     SecurityManager#checkPermission
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    79
     * @see     java.awt.AWTPermission
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    80
     */
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    81
    public ExtendedRobot() throws AWTException {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    82
        super();
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
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    85
    /**
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    86
     * Creates an ExtendedRobot for the given screen device. Coordinates passed
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    87
     * to ExtendedRobot method calls like mouseMove and createScreenCapture will
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    88
     * 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
    89
     * 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
    90
     * <ul>
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    91
     * <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
    92
     * <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
    93
     * </ul>
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    94
     * This constructor is meant for the latter case.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    95
     * <p>
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    96
     * 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
    97
     * affected, the behavior of existing ExtendedRobot objects is undefined.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    98
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
    99
     * @param   screen  A screen GraphicsDevice indicating the coordinate
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   100
     *                  system the Robot will operate in.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   101
     * @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
   102
     *          control. This exception is always thrown when
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   103
     *          GraphicsEnvironment.isHeadless() returns true.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   104
     * @throws  IllegalArgumentException if {@code screen} is not a screen
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   105
     *          GraphicsDevice.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   106
     * @throws  SecurityException if {@code createRobot} permission is not granted
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   107
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   108
     * @see     java.awt.GraphicsEnvironment#isHeadless
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   109
     * @see     GraphicsDevice
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   110
     * @see     SecurityManager#checkPermission
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   111
     * @see     java.awt.AWTPermission
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   112
     */
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   113
    public ExtendedRobot(GraphicsDevice screen) throws AWTException {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   114
        super(screen);
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
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
     * Returns delay length for {@link #waitForIdle()} method
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
     * @return  Current delay value
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
     * @see     #waitForIdle()
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
    public int getSyncDelay(){ return this.syncDelay; }
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   125
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   126
    /**
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   127
     * 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
   128
     * {@link java.awt.Robot#mouseRelease(int)} methods
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   129
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   130
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   131
     * @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
   132
     * @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
   133
     *          extra mouse button and support for extended mouse buttons is
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   134
     *          {@link Toolkit#areExtraMouseButtonsEnabled() disabled} by Java
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   135
     * @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
   136
     *          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
   137
     *          mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled() enabled}
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   138
     *          by Java
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   139
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   140
     * @see     #mousePress(int)
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   141
     * @see     #mouseRelease(int)
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   142
     * @see     InputEvent#getMaskForButton(int)
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   143
     * @see     Toolkit#areExtraMouseButtonsEnabled()
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   144
     * @see     java.awt.event.MouseEvent
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   145
     */
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   146
    public void click(int buttons) {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   147
        mousePress(buttons);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   148
        waitForIdle(DEFAULT_SPEED);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   149
        mouseRelease(buttons);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   150
        waitForIdle();
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
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
     * Clicks mouse button 1
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   155
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   156
     * @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
   157
     *          extra mouse button and support for extended mouse buttons is
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   158
     *          {@link Toolkit#areExtraMouseButtonsEnabled() disabled} by Java
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   159
     * @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
   160
     *          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
   161
     *          mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled() enabled}
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   162
     *          by Java
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
     * @see     #click(int)
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   165
     */
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   166
    public void click() {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   167
        click(InputEvent.BUTTON1_DOWN_MASK);
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
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   170
    /**
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   171
     * 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
   172
     * 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
   173
     * unlike {@link java.awt.Robot#waitForIdle()}
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   174
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   175
     * @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
   176
     *                      sync been completed
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   177
     * @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
   178
     *          dispatching thread
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   179
     */
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   180
    public synchronized void waitForIdle(int delayValue) {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   181
        SunToolkit.flushPendingEvents();
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   182
        ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   183
        delay(delayValue);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   184
    }
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   185
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   186
    /**
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   187
     * 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
   188
     * {@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
   189
     * synchronizing threads unlike {@link java.awt.Robot#waitForIdle()}
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
     * @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
   192
     *          dispatching thread
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   193
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   194
     * @see     #waitForIdle(int)
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   195
     */
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   196
    @Override
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   197
    public synchronized void waitForIdle() {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   198
        waitForIdle(syncDelay);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   199
    }
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   200
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
     * Move the mouse in multiple steps from where it is
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   203
     * now to the destination coordinates.
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
     * @param   x   Destination point x coordinate
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   206
     * @param   y   Destination point y coordinate
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   207
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   208
     * @see     #glide(int, int, int, int)
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   209
     */
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   210
    public void glide(int x, int y) {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   211
        Point p = MouseInfo.getPointerInfo().getLocation();
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   212
        glide(p.x, p.y, x, y);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   213
    }
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   214
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
     * Move the mouse in multiple steps from where it is
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   217
     * now to the destination point.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   218
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   219
     * @param   dest    Destination point
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   220
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   221
     * @see     #glide(int, int)
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
    public void glide(Point dest) {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   224
        glide(dest.x, dest.y);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   225
    }
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   226
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
     * Move the mouse in multiple steps from source coordinates
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   229
     * to the destination coordinates.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   230
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   231
     * @param   fromX   Source point x coordinate
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   232
     * @param   fromY   Source point y coordinate
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   233
     * @param   toX     Destination point x coordinate
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   234
     * @param   toY     Destination point y coordinate
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   235
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   236
     * @see     #glide(int, int, int, int, int, int)
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
    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
   239
        glide(fromX, fromY, toX, toY, DEFAULT_STEP_LENGTH, DEFAULT_SPEED);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   240
    }
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   241
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
     * 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
   244
     * destination point with default speed and step length.
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
     * @param   src     Source point
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   247
     * @param   dest    Destination point
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   248
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   249
     * @see     #glide(int, int, int, int, int, int)
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
    public void glide(Point src, Point dest) {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   252
        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
   253
    }
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   254
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
     * 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
   257
     * destination point with given speed and step length.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   258
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   259
     * @param   srcX        Source point x cordinate
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   260
     * @param   srcY        Source point y cordinate
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   261
     * @param   destX       Destination point x cordinate
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   262
     * @param   destY       Destination point y cordinate
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   263
     * @param   stepLength  Approximate length of one step
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   264
     * @param   speed       Delay between steps.
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
     * @see     #mouseMove(int, int)
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   267
     * @see     #delay(int)
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   268
     */
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   269
     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
   270
        int stepNum;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   271
        double tDx, tDy;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   272
        double dx, dy, ds;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   273
        double x, y;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   274
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   275
        dx = (destX - srcX);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   276
        dy = (destY - srcY);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   277
        ds = Math.sqrt(dx*dx + dy*dy);
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
        tDx = dx / ds * stepLength;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   280
        tDy = dy / ds * stepLength;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   281
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   282
        int stepsCount = (int) ds / stepLength;
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
        // 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
   285
        mouseMove(srcX, srcY);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   286
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   287
        for (x = srcX, y = srcY, stepNum = 0;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   288
             stepNum < stepsCount;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   289
             stepNum++) {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   290
            x += tDx;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   291
            y += tDy;
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   292
            mouseMove((int)x, (int)y);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   293
            delay(speed);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   294
        }
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   295
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   296
        // Ensure the mouse moves to the right destination.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   297
        // 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
   298
        mouseMove(destX, destY);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   299
    }
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
    /**
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   302
     * Moves mouse pointer to given screen coordinates.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   303
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   304
     * @param   position    Target position
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   305
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   306
     * @see     java.awt.Robot#mouseMove(int, int)
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
    public synchronized void mouseMove(Point position) {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   309
        mouseMove(position.x, position.y);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   310
    }
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   311
25108
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   312
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   313
    /**
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   314
     * 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
   315
     * 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
   316
     * ({@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
   317
     * 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
   318
     * button 1 at last.
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   319
     *
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   320
     * @param   fromX   Source point x coordinate
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   321
     * @param   fromY   Source point y coordinate
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   322
     * @param   toX     Destination point x coordinate
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   323
     * @param   toY     Destination point y coordinate
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
     * @see     #mousePress(int)
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   326
     * @see     #glide(int, int, int, int)
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   327
     */
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   328
    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
   329
        mouseMove(fromX, fromY);
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   330
        mousePress(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
        glide(toX, toY);
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   333
        mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   334
        waitForIdle();
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   335
    }
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   336
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   337
    /**
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   338
     * 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
   339
     * 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
   340
     * 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
   341
     * mouse button 1 at last.
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
     * @param   from    Source point
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   344
     * @param   to      Destination point
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   345
     *
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   346
     * @see     #mousePress(int)
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   347
     * @see     #glide(int, int, int, int)
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   348
     * @see     #dragAndDrop(int, int, int, int)
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
    public void dragAndDrop(Point from, Point to){
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   351
        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
   352
    }
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents: 24171
diff changeset
   353
24171
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   354
    /**
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   355
     * Successively presses and releases a given key.
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   356
     * <p>
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   357
     * 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
   358
     * (e.g. {@code KeyEvent.VK_SHIFT} could mean either the
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   359
     * 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
   360
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   361
     * @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
   362
     * @throws  IllegalArgumentException if {@code keycode} is not
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   363
     *          a valid key
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   364
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   365
     * @see     java.awt.Robot#keyPress(int)
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   366
     * @see     java.awt.Robot#keyRelease(int)
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   367
     * @see     java.awt.event.KeyEvent
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   368
     */
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   369
    public void type(int keycode) {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   370
        keyPress(keycode);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   371
        waitForIdle(DEFAULT_SPEED);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   372
        keyRelease(keycode);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   373
        waitForIdle(DEFAULT_SPEED);
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   374
    }
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
    /**
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   377
     * Types given character
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   378
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   379
     * @param   c   Character to be typed (e.g. {@code 'a'})
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
     * @see     #type(int)
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   382
     * @see     java.awt.event.KeyEvent
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
    public void type(char c) {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   385
        type(ExtendedKeyCodes.getExtendedKeyCodeForChar(c));
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   386
    }
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
    /**
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   389
     * Types given array of characters one by one
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   390
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   391
     * @param   symbols Array of characters to be typed
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   392
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   393
     * @see     #type(char)
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   394
     */
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   395
    public void type(char[] symbols) {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   396
        for (int i = 0; i < symbols.length; i++) {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   397
            type(symbols[i]);
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
    }
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
    /**
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   402
     * Types given string
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   403
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   404
     * @param   s   String to be typed
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   405
     *
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   406
     * @see     #type(char[])
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
    public void type(String s) {
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   409
        type(s.toCharArray());
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   410
    }
9a263c3c482b 8038631: Create wrapper for awt.Robot with additional functionality
yan
parents:
diff changeset
   411
}