6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 import sun.awt.ExtendedKeyCodes;
27 import sun.awt.SunToolkit;
28
29 import java.awt.AWTException;
30 import java.awt.Robot;
31 import java.awt.GraphicsDevice;
32 import java.awt.Toolkit;
33 import java.awt.Point;
34 import java.awt.MouseInfo;
35 import java.awt.event.InputEvent;
36
37 /**
38 * ExtendedRobot is a subclass of {@link java.awt.Robot}. It provides some convenience methods that are
39 * ought to be moved to {@link java.awt.Robot} class.
40 * <p>
41 * ExtendedRobot uses delay {@link #getSyncDelay()} to make syncing threads with {@link #waitForIdle()}
42 * more stable. This delay can be set once on creating object and could not be changed throughout object
43 * lifecycle. Constructor reads vm integer property {@code java.awt.robotdelay} and sets the delay value
44 * equal to the property value. If the property was not set 500 milliseconds default value is used.
45 * <p>
46 * When using jtreg you would include this class via something like:
47 * <pre>
48 * {@literal @}library ../../../../lib/testlibrary
49 * {@literal @}build ExtendedRobot
50 * </pre>
51 *
52 * @author Dmitriy Ermashov
53 * @since 1.9
54 */
55
161 * mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled() enabled}
162 * by Java
163 *
164 * @see #click(int)
165 */
166 public void click() {
167 click(InputEvent.BUTTON1_DOWN_MASK);
168 }
169
170 /**
171 * Waits until all events currently on the event queue have been processed with given
172 * delay after syncing threads. It uses more advanced method of synchronizing threads
173 * unlike {@link java.awt.Robot#waitForIdle()}
174 *
175 * @param delayValue Additional delay length in milliseconds to wait until thread
176 * sync been completed
177 * @throws sun.awt.SunToolkit.IllegalThreadException if called on the AWT event
178 * dispatching thread
179 */
180 public synchronized void waitForIdle(int delayValue) {
181 SunToolkit.flushPendingEvents();
182 ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();
183 delay(delayValue);
184 }
185
186 /**
187 * Waits until all events currently on the event queue have been processed with delay
188 * {@link #getSyncDelay()} after syncing threads. It uses more advanced method of
189 * synchronizing threads unlike {@link java.awt.Robot#waitForIdle()}
190 *
191 * @throws sun.awt.SunToolkit.IllegalThreadException if called on the AWT event
192 * dispatching thread
193 *
194 * @see #waitForIdle(int)
195 */
196 @Override
197 public synchronized void waitForIdle() {
198 waitForIdle(syncDelay);
199 }
200
201 /**
202 * Move the mouse in multiple steps from where it is
365 * @see java.awt.Robot#keyPress(int)
366 * @see java.awt.Robot#keyRelease(int)
367 * @see java.awt.event.KeyEvent
368 */
369 public void type(int keycode) {
370 keyPress(keycode);
371 waitForIdle(DEFAULT_SPEED);
372 keyRelease(keycode);
373 waitForIdle(DEFAULT_SPEED);
374 }
375
376 /**
377 * Types given character
378 *
379 * @param c Character to be typed (e.g. {@code 'a'})
380 *
381 * @see #type(int)
382 * @see java.awt.event.KeyEvent
383 */
384 public void type(char c) {
385 type(ExtendedKeyCodes.getExtendedKeyCodeForChar(c));
386 }
387
388 /**
389 * Types given array of characters one by one
390 *
391 * @param symbols Array of characters to be typed
392 *
393 * @see #type(char)
394 */
395 public void type(char[] symbols) {
396 for (int i = 0; i < symbols.length; i++) {
397 type(symbols[i]);
398 }
399 }
400
401 /**
402 * Types given string
403 *
404 * @param s String to be typed
405 *
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 import java.awt.AWTException;
27 import java.awt.Robot;
28 import java.awt.GraphicsDevice;
29 import java.awt.Toolkit;
30 import java.awt.Point;
31 import java.awt.MouseInfo;
32 import java.awt.event.InputEvent;
33 import java.awt.event.KeyEvent;
34
35 /**
36 * ExtendedRobot is a subclass of {@link java.awt.Robot}. It provides some convenience methods that are
37 * ought to be moved to {@link java.awt.Robot} class.
38 * <p>
39 * ExtendedRobot uses delay {@link #getSyncDelay()} to make syncing threads with {@link #waitForIdle()}
40 * more stable. This delay can be set once on creating object and could not be changed throughout object
41 * lifecycle. Constructor reads vm integer property {@code java.awt.robotdelay} and sets the delay value
42 * equal to the property value. If the property was not set 500 milliseconds default value is used.
43 * <p>
44 * When using jtreg you would include this class via something like:
45 * <pre>
46 * {@literal @}library ../../../../lib/testlibrary
47 * {@literal @}build ExtendedRobot
48 * </pre>
49 *
50 * @author Dmitriy Ermashov
51 * @since 1.9
52 */
53
159 * mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled() enabled}
160 * by Java
161 *
162 * @see #click(int)
163 */
164 public void click() {
165 click(InputEvent.BUTTON1_DOWN_MASK);
166 }
167
168 /**
169 * Waits until all events currently on the event queue have been processed with given
170 * delay after syncing threads. It uses more advanced method of synchronizing threads
171 * unlike {@link java.awt.Robot#waitForIdle()}
172 *
173 * @param delayValue Additional delay length in milliseconds to wait until thread
174 * sync been completed
175 * @throws sun.awt.SunToolkit.IllegalThreadException if called on the AWT event
176 * dispatching thread
177 */
178 public synchronized void waitForIdle(int delayValue) {
179 super.waitForIdle();
180 delay(delayValue);
181 }
182
183 /**
184 * Waits until all events currently on the event queue have been processed with delay
185 * {@link #getSyncDelay()} after syncing threads. It uses more advanced method of
186 * synchronizing threads unlike {@link java.awt.Robot#waitForIdle()}
187 *
188 * @throws sun.awt.SunToolkit.IllegalThreadException if called on the AWT event
189 * dispatching thread
190 *
191 * @see #waitForIdle(int)
192 */
193 @Override
194 public synchronized void waitForIdle() {
195 waitForIdle(syncDelay);
196 }
197
198 /**
199 * Move the mouse in multiple steps from where it is
362 * @see java.awt.Robot#keyPress(int)
363 * @see java.awt.Robot#keyRelease(int)
364 * @see java.awt.event.KeyEvent
365 */
366 public void type(int keycode) {
367 keyPress(keycode);
368 waitForIdle(DEFAULT_SPEED);
369 keyRelease(keycode);
370 waitForIdle(DEFAULT_SPEED);
371 }
372
373 /**
374 * Types given character
375 *
376 * @param c Character to be typed (e.g. {@code 'a'})
377 *
378 * @see #type(int)
379 * @see java.awt.event.KeyEvent
380 */
381 public void type(char c) {
382 type(KeyEvent.getExtendedKeyCodeForChar(c));
383 }
384
385 /**
386 * Types given array of characters one by one
387 *
388 * @param symbols Array of characters to be typed
389 *
390 * @see #type(char)
391 */
392 public void type(char[] symbols) {
393 for (int i = 0; i < symbols.length; i++) {
394 type(symbols[i]);
395 }
396 }
397
398 /**
399 * Types given string
400 *
401 * @param s String to be typed
402 *
|