1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   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.*;
  27 
  28 /**
  29  * ExtendedRobot is a subclass of {@link Robot}. It provides some convenience methods that are
  30  * ought to be moved to {@link Robot} class.
  31  * <p>
  32  * ExtendedRobot uses delay {@link #getSyncDelay()} to make syncing threads with {@link #waitForIdle()}
  33  * more stable. This delay can be set once on creating object and could not be changed throughout object
  34  * lifecycle. Constructor reads vm integer property {@code java.awt.robotdelay} and sets the delay value
  35  * equal to the property value. If the property was not set 500 milliseconds default value is used.
  36  * <p>
  37  * When using jtreg you would include this class via something like:
  38  * <pre>
  39  * {@literal @}library ../../../../lib/testlibrary
  40  * {@literal @}build ExtendedRobot
  41  * </pre>
  42  *
  43  * @author      Dmitriy Ermashov
  44  * @since       1.9
  45  */
  46 
  47 public class ExtendedRobot extends Robot {
  48 
  49     /**
  50      * Constructs an ExtendedRobot object in the coordinate system of the primary screen.
  51      *
  52      * @throws  AWTException if the platform configuration does not allow low-level input
  53      *          control. This exception is always thrown when
  54      *          GraphicsEnvironment.isHeadless() returns true
  55      * @throws  SecurityException if {@code createRobot} permission is not granted
  56      *
  57      * @see     java.awt.GraphicsEnvironment#isHeadless
  58      * @see     SecurityManager#checkPermission
  59      * @see     java.awt.AWTPermission
  60      */
  61     public ExtendedRobot() throws AWTException {
  62         super();
  63     }
  64 
  65     /**
  66      * Creates an ExtendedRobot for the given screen device. Coordinates passed
  67      * to ExtendedRobot method calls like mouseMove and createScreenCapture will
  68      * be interpreted as being in the same coordinate system as the specified screen.
  69      * Note that depending on the platform configuration, multiple screens may either:
  70      * <ul>
  71      * <li>share the same coordinate system to form a combined virtual screen</li>
  72      * <li>use different coordinate systems to act as independent screens</li>
  73      * </ul>
  74      * This constructor is meant for the latter case.
  75      * <p>
  76      * If screen devices are reconfigured such that the coordinate system is
  77      * affected, the behavior of existing ExtendedRobot objects is undefined.
  78      *
  79      * @param   screen  A screen GraphicsDevice indicating the coordinate
  80      *                  system the Robot will operate in.
  81      * @throws  AWTException if the platform configuration does not allow low-level input
  82      *          control. This exception is always thrown when
  83      *          GraphicsEnvironment.isHeadless() returns true.
  84      * @throws  IllegalArgumentException if {@code screen} is not a screen
  85      *          GraphicsDevice.
  86      * @throws  SecurityException if {@code createRobot} permission is not granted
  87      *
  88      * @see     java.awt.GraphicsEnvironment#isHeadless
  89      * @see     GraphicsDevice
  90      * @see     SecurityManager#checkPermission
  91      * @see     java.awt.AWTPermission
  92      */
  93     public ExtendedRobot(GraphicsDevice screen) throws AWTException {
  94         super(screen);
  95     }
  96 }