jview
Class RobotChoreography

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by jview.RobotChoreography
All Implemented Interfaces:
ComponentListener, Cloneable, EventListener, Initializable, LocalizedSupplying, PropertySupplying, Refreshing, ResourceSupplying

public class RobotChoreography
extends PropertyBundles
implements Refreshing, ComponentListener

This class mimicks a user on the mouse.


Nested Class Summary
private  class RobotChoreography.MouseRobot
          Starts the robot in its own thread.
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private  Map<Rectangle,Double> allowed
          This is the list of allowed regions.
private  boolean automatic
          If true, we are in automatic control.
private  boolean cancel
          I spotted mouse movements somewhere within a command and should stop.
static String CLICK
           
static String COLON
           
private static int DEFCLICKDELAY
           
private static long DEFIDLETIMEOUT
           
private static int DEFMOVEDELAY
           
static String DELAY
           
private  List<String> exe
          The list of commands to execute.
private  Map<Rectangle,Double> forbidden
          This is the list of forbidden regions.
static String KEY_ALLOWEDAREAS
          The mouse may move within these areas only.
static String KEY_CLICKDELAY
          The mouse-idle timeout until automatic action occurs.
static String KEY_FORBIDDENAREAS
          The mouse may move anywhere, except in these areas.
static String KEY_IDLETIMEOUT
          The mouse-idle timeout until automatic action occurs.
static String KEY_MOVEDELAY
          The mouse-idle timeout until automatic action occurs.
static String KEY_NIGHTTIME
          In these hours, if set, we do not perform mouse movements, we go idle.
static String KEY_WEEKEND
          On these days, if set, we do not perform mouse movements, we go idle.
private  Point last
          Last mouse position during checks if we should grab control.
private  RobotChoreography.MouseRobot mimic
          The thread the mimic user input.
static String MOVEIN
           
static String MOVERND
           
static String MOVETO
           
static String OFFSET
           
static String PIPE
           
static String PRESS
           
static String RELEASE
           
private  Robot robot
          Robot for mouse movements.
private  Dimension screen
          The dimension of the screen
static String WHEEL
           
 
Fields inherited from class util.PropertyBundles
KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_RESOURCEBUNDLES
 
Fields inherited from class util.PropertyResources
KEY_NOINITONCREATE, localurl, locate, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_URL, urlset
 
Fields inherited from class util.PropertyContainer
KEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Fields inherited from interface util.PropertySupplying
CONFIG, KEY_CLASS
 
Constructor Summary
RobotChoreography(Map<String,String> prop)
           
 
Method Summary
 boolean checkIdle()
          We check the current time against weekend and nighttime.
 boolean command(String tag)
          Executes a single robot command.
 void componentHidden(ComponentEvent e)
           
 void componentMoved(ComponentEvent e)
           
 void componentResized(ComponentEvent e)
           
 void componentShown(ComponentEvent e)
           
 boolean equals(Object o)
          We are equal to another robot if we serve the same sequence in the same region.
private  boolean executeSequence(List<String> sequence)
           
private  int getButtonMask(String par)
           
 Point getRandomOffset(int distance)
          Generates a random offset from the current mouse position.
 Point getRandomPosition()
          Generates a random position that is allowed.
 Point getRandomPositionInAllowed(Rectangle r)
          Generates a random position within the specified allowed region.
 long getRefreshInterval()
          Returns the period in milliseconds of the refresh intervall.
 int hashCode()
          Returns a hash code.
 void init()
          We initialize the areas that are allowed.
 boolean isAllowed(Point p)
          Tests, if the specified point is allowed.
 boolean isFixedRate()
          Returns true if fixed rate scheduling is desired, otherwise fixed delay is assumed.
 boolean isWithin(Map<Rectangle,Double> recs, Point p)
          Test, if the point is in any of the rectangle list.
static void main(String[] arg)
          We install a robot.
private  boolean mouseMove(Point xy)
          Moves the mouse from the current location to the specified one.
private  Map<Rectangle,Double> parseRectangle(String pipes)
          Parses rectangles, sparated by a pipe.
 void refresh()
          The method that should be invoked on refresh.
 void setSequence(List<String> sequence)
          Sets the sequence to be executed.
 void setSequence(String elements)
          Executes a robot sequence.
private  boolean shouldStop(Point was)
          We should stop if the current mouse pointer is not at the same position as before.
 
Methods inherited from class util.PropertyBundles
clone, getLocalized, getLocalized, getLocalizedString, getLocalizedString, loadResource
 
Methods inherited from class util.PropertyResources
createFrom, createFrom, createFrom, getApplet, getAsResources, getLocalClassLoader, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, keyCreate, keyCreate, reload, setApplet
 
Methods inherited from class util.PropertyContainer
augment, augment, augment, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, isNew, parseObject, reload, removeProperty, rescanned, setObject, setProperties, setProperty, stringProperties, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface util.ResourceSupplying
getResource, getResourceAsStream, getResources
 
Methods inherited from interface util.PropertySupplying
defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, parseObject, removeProperty, setObject, setProperty, stringProperties
 

Field Detail

COLON

public static final String COLON
See Also:
Constant Field Values

PIPE

public static final String PIPE
See Also:
Constant Field Values

MOVETO

public static final String MOVETO
See Also:
Constant Field Values

MOVEIN

public static final String MOVEIN
See Also:
Constant Field Values

OFFSET

public static final String OFFSET
See Also:
Constant Field Values

MOVERND

public static final String MOVERND
See Also:
Constant Field Values

PRESS

public static final String PRESS
See Also:
Constant Field Values

RELEASE

public static final String RELEASE
See Also:
Constant Field Values

DELAY

public static final String DELAY
See Also:
Constant Field Values

CLICK

public static final String CLICK
See Also:
Constant Field Values

WHEEL

public static final String WHEEL
See Also:
Constant Field Values

KEY_ALLOWEDAREAS

public static final String KEY_ALLOWEDAREAS
The mouse may move within these areas only.

See Also:
Constant Field Values

KEY_FORBIDDENAREAS

public static final String KEY_FORBIDDENAREAS
The mouse may move anywhere, except in these areas.

See Also:
Constant Field Values

KEY_CLICKDELAY

public static final String KEY_CLICKDELAY
The mouse-idle timeout until automatic action occurs.

See Also:
Constant Field Values

KEY_IDLETIMEOUT

public static final String KEY_IDLETIMEOUT
The mouse-idle timeout until automatic action occurs.

See Also:
Constant Field Values

KEY_MOVEDELAY

public static final String KEY_MOVEDELAY
The mouse-idle timeout until automatic action occurs.

See Also:
Constant Field Values

KEY_WEEKEND

public static final String KEY_WEEKEND
On these days, if set, we do not perform mouse movements, we go idle.

See Also:
Constant Field Values

KEY_NIGHTTIME

public static final String KEY_NIGHTTIME
In these hours, if set, we do not perform mouse movements, we go idle.

See Also:
Constant Field Values

DEFCLICKDELAY

private static final int DEFCLICKDELAY
See Also:
Constant Field Values

DEFMOVEDELAY

private static final int DEFMOVEDELAY
See Also:
Constant Field Values

DEFIDLETIMEOUT

private static final long DEFIDLETIMEOUT
See Also:
Constant Field Values

exe

private List<String> exe
The list of commands to execute.


allowed

private Map<Rectangle,Double> allowed
This is the list of allowed regions.


forbidden

private Map<Rectangle,Double> forbidden
This is the list of forbidden regions.


screen

private Dimension screen
The dimension of the screen


automatic

private boolean automatic
If true, we are in automatic control.


mimic

private RobotChoreography.MouseRobot mimic
The thread the mimic user input.


robot

private Robot robot
Robot for mouse movements.


last

private Point last
Last mouse position during checks if we should grab control.


cancel

private boolean cancel
I spotted mouse movements somewhere within a command and should stop.

Constructor Detail

RobotChoreography

public RobotChoreography(Map<String,String> prop)
Method Detail

init

public void init()
We initialize the areas that are allowed.

Specified by:
init in interface Initializable
Overrides:
init in class PropertyResources

componentHidden

public void componentHidden(ComponentEvent e)
Specified by:
componentHidden in interface ComponentListener

componentMoved

public void componentMoved(ComponentEvent e)
Specified by:
componentMoved in interface ComponentListener

componentResized

public void componentResized(ComponentEvent e)
Specified by:
componentResized in interface ComponentListener

componentShown

public void componentShown(ComponentEvent e)
Specified by:
componentShown in interface ComponentListener

isFixedRate

public boolean isFixedRate()
Description copied from interface: Refreshing
Returns true if fixed rate scheduling is desired, otherwise fixed delay is assumed. Returning false is appropriate for blinking cursors, execution is scheduled relative to the last execution. Returning true here is appropriate for cron job, execution is always relative to the first execution.

Specified by:
isFixedRate in interface Refreshing
See Also:
Timer

getRefreshInterval

public long getRefreshInterval()
Description copied from interface: Refreshing
Returns the period in milliseconds of the refresh intervall.

Specified by:
getRefreshInterval in interface Refreshing

refresh

public void refresh()
Description copied from interface: Refreshing
The method that should be invoked on refresh. The method must not take any argument.

Specified by:
refresh in interface Refreshing

isAllowed

public boolean isAllowed(Point p)
Tests, if the specified point is allowed.


isWithin

public boolean isWithin(Map<Rectangle,Double> recs,
                        Point p)
Test, if the point is in any of the rectangle list.


getRandomPosition

public Point getRandomPosition()
Generates a random position that is allowed.


getRandomOffset

public Point getRandomOffset(int distance)
Generates a random offset from the current mouse position. For small offsets only.


getRandomPositionInAllowed

public Point getRandomPositionInAllowed(Rectangle r)
Generates a random position within the specified allowed region.


setSequence

public void setSequence(String elements)
Executes a robot sequence.


setSequence

public void setSequence(List<String> sequence)
Sets the sequence to be executed.


hashCode

public int hashCode()
Returns a hash code.

Overrides:
hashCode in class Object

equals

public boolean equals(Object o)
We are equal to another robot if we serve the same sequence in the same region.

Overrides:
equals in class Object

executeSequence

private boolean executeSequence(List<String> sequence)

command

public boolean command(String tag)
Executes a single robot command. If the command needs special parameter they are added after the command with a colon.


mouseMove

private boolean mouseMove(Point xy)
Moves the mouse from the current location to the specified one.


parseRectangle

private Map<Rectangle,Double> parseRectangle(String pipes)
Parses rectangles, sparated by a pipe.


getButtonMask

private int getButtonMask(String par)

shouldStop

private boolean shouldStop(Point was)
We should stop if the current mouse pointer is not at the same position as before.


checkIdle

public boolean checkIdle()
We check the current time against weekend and nighttime. If we should get idel, we return true here.


main

public static void main(String[] arg)
We install a robot.