org.sikuli.api
Class DefaultScreenRegion

java.lang.Object
  extended by org.sikuli.api.AbstractScreenRegion
      extended by org.sikuli.api.DefaultScreenRegion
All Implemented Interfaces:
Region, ScreenRegion
Direct Known Subclasses:
DesktopScreenRegion, StaticImageScreenRegion

public class DefaultScreenRegion
extends AbstractScreenRegion
implements ScreenRegion

This class provides manipulation methods that can be used by the default screen region.


Constructor Summary
DefaultScreenRegion(Screen screen)
          Constructs a new DefaultScreenRegion on the specified Screen object whose upper-left corner is at (0, 0) in the coordinate space.
DefaultScreenRegion(Screen screen, int x, int y, int width, int height)
          Constructs a new DefaultScreenRegion object on the specified Screen and region values.
DefaultScreenRegion(ScreenRegion parent, int x, int y, int width, int height)
          Constructs a new DefaultScreenRegion object whose Screen is the same as the parent ScreenRegion with the specified region values.
 
Method Summary
 void addROI(int x, int y, int width, int height)
          Add a rectangular region of interest into this ScreenRegion.
 void addState(Target target, Object state)
          Defines a new state of this screen region as represented by the presence of the given target.
 void addStateChangeEventListener(StateChangeListener listener)
          Adds a listener to handle the state changes within this screen region.
 void addTargetEventListener(Target target, TargetEventListener listener)
          Adds a listener for a given target.
 BufferedImage capture()
          Captures and returns a screenshot of this screen region.
 ScreenRegion find(Target target)
          Finds a target on the screen immediately.
 List<ScreenRegion> findAll(Target target)
          Finds all the instances of the target on the screen immediately.
 ScreenLocation getCenter()
          Returns the center of this screen region.
 BufferedImage getLastCapturedImage()
          Returns the last captured screenshot in this screen region.
 ScreenLocation getLowerLeftCorner()
          Returns the lower-left corner of this screen region.
 ScreenLocation getLowerRightCorner()
          Returns the lower-right corner of this screen region.
 List<Rectangle> getROIs()
          Returns a list of Rectangle that represent the rectangular regions of interest for this ScreenRegion.
 Object getState()
          Returns the state of this ScreenRegion.
 Map<Target,Object> getStates()
          Returns a map of Target objects and states, which can be any object, of this DefaultScreenRegion.
 ScreenLocation getUpperLeftCorner()
          Returns the upper-left corner of this screen region.
 ScreenLocation getUpperRightCorner()
          Returns the upper-right corner of this screen region.
 void removeState(Target target)
          Removes a particular state represented by the given target from this screen region.
 void removeTargetEventListener(Target target, TargetEventListener listener)
          Removes a particular listener for a particular target.
 ScreenRegion snapshot()
          Returns a ScreenRegion object that corresponds to the screen and region of this ScreenRegion.
 ScreenRegion wait(Target target, int mills)
          Blocks and waits until a target is found in this screen region within a given time period.
 
Methods inherited from class org.sikuli.api.AbstractScreenRegion
getBounds, getHeight, getRelativeScreenLocation, getRelativeScreenRegion, getScore, getScreen, getWidth, getX, getY, setBounds, setHeight, setScore, setScreen, setWidth, setX, setY, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.sikuli.api.ScreenRegion
getRelativeScreenLocation, getRelativeScreenRegion, getScore, getScreen, setScore, setScreen
 
Methods inherited from interface org.sikuli.api.Region
getBounds, getHeight, getWidth, getX, getY, setBounds
 

Constructor Detail

DefaultScreenRegion

public DefaultScreenRegion(Screen screen)
Constructs a new DefaultScreenRegion on the specified Screen object whose upper-left corner is at (0, 0) in the coordinate space.

Parameters:
screen - The Screen to create a region from.

DefaultScreenRegion

public DefaultScreenRegion(ScreenRegion parent,
                           int x,
                           int y,
                           int width,
                           int height)
Constructs a new DefaultScreenRegion object whose Screen is the same as the parent ScreenRegion with the specified region values.

Parameters:
parent - the parent of this ScreenRegion
x - The X coordinate of the upper-left corner of the rectangular screen region.
y - The Y coordinate of the upper-left corner of the rectangular screen region.
width - The width of the rectangular screen region.
height - The height of the rectangular screen region.

DefaultScreenRegion

public DefaultScreenRegion(Screen screen,
                           int x,
                           int y,
                           int width,
                           int height)
Constructs a new DefaultScreenRegion object on the specified Screen and region values.

Parameters:
screen - The Screen to create a region from.
x - The X coordinate of the upper-left corner of the rectangular screen region.
y - The Y coordinate of the upper-left corner of the rectangular screen region.
width - The width of the rectangular screen region.
height - The height of the rectangular screen region.
Method Detail

findAll

public List<ScreenRegion> findAll(Target target)
Description copied from interface: ScreenRegion
Finds all the instances of the target on the screen immediately.

Specified by:
findAll in interface ScreenRegion
Parameters:
target - the target to find.
Returns:
a list of ScreenRegions, each of which corresponds to a found target, or an empty list. if no such target can be found.

find

public ScreenRegion find(Target target)
Description copied from interface: ScreenRegion
Finds a target on the screen immediately.

Specified by:
find in interface ScreenRegion
Parameters:
target - the target to find on the current screen.
Returns:
the screen region occupied by the found target or null if the can not be found now.

wait

public ScreenRegion wait(Target target,
                         int mills)
Description copied from interface: ScreenRegion
Blocks and waits until a target is found in this screen region within a given time period.

Specified by:
wait in interface ScreenRegion
Parameters:
target - the target to wait.
mills - the maximum time to wait in milliseconds.
Returns:
a ScreenRegion object representing the region occupied by the found target, or null if the specified target can not be found within the given time.

capture

public BufferedImage capture()
Description copied from interface: ScreenRegion
Captures and returns a screenshot of this screen region.

Specified by:
capture in interface ScreenRegion
Returns:
a BufferedImage containing the screenshot. The type of the image is TYPE_3BYTE_BGR.

getLastCapturedImage

public BufferedImage getLastCapturedImage()
Returns the last captured screenshot in this screen region.

Specified by:
getLastCapturedImage in interface ScreenRegion
Returns:
a BufferedImage that holds the last captured screenshot in this screen region.

getUpperLeftCorner

public ScreenLocation getUpperLeftCorner()
Description copied from interface: ScreenRegion
Returns the upper-left corner of this screen region.

Specified by:
getUpperLeftCorner in interface ScreenRegion
Returns:
a Location object corresponding to the upper-left corner of the screen region.

getLowerLeftCorner

public ScreenLocation getLowerLeftCorner()
Description copied from interface: ScreenRegion
Returns the lower-left corner of this screen region.

Specified by:
getLowerLeftCorner in interface ScreenRegion
Returns:
a Location object corresponding to the lower-left corner of the screen region.

getUpperRightCorner

public ScreenLocation getUpperRightCorner()
Description copied from interface: ScreenRegion
Returns the upper-right corner of this screen region.

Specified by:
getUpperRightCorner in interface ScreenRegion
Returns:
a Location object corresponding to the upper-right corner of the screen region.

getLowerRightCorner

public ScreenLocation getLowerRightCorner()
Description copied from interface: ScreenRegion
Returns the lower-right corner of this screen region.

Specified by:
getLowerRightCorner in interface ScreenRegion
Returns:
a Location object corresponding to the lower-right corner of the screen region.

getCenter

public ScreenLocation getCenter()
Description copied from interface: ScreenRegion
Returns the center of this screen region.

Specified by:
getCenter in interface ScreenRegion
Overrides:
getCenter in class AbstractScreenRegion
Returns:
a Location object corresponding to the center of the screen region.

addTargetEventListener

public void addTargetEventListener(Target target,
                                   TargetEventListener listener)
Description copied from interface: ScreenRegion
Adds a listener for a given target.

Specified by:
addTargetEventListener in interface ScreenRegion
Parameters:
target - the target to listener its events for.
listener - the listener to handle the events associated with the target.

removeTargetEventListener

public void removeTargetEventListener(Target target,
                                      TargetEventListener listener)
Description copied from interface: ScreenRegion
Removes a particular listener for a particular target.

Specified by:
removeTargetEventListener in interface ScreenRegion
Parameters:
target - the target from which the given listener should be removed.
listener - the listener to remove from the given target.

snapshot

public ScreenRegion snapshot()
Description copied from interface: ScreenRegion
Returns a ScreenRegion object that corresponds to the screen and region of this ScreenRegion.

Specified by:
snapshot in interface ScreenRegion
Returns:
a ScreenRegion that corresponds to the region of this ScreenRegion.

addStateChangeEventListener

public void addStateChangeEventListener(StateChangeListener listener)
Description copied from interface: ScreenRegion
Adds a listener to handle the state changes within this screen region.

Specified by:
addStateChangeEventListener in interface ScreenRegion
Parameters:
listener - the listener to handle state changes in this screen region.

addROI

public void addROI(int x,
                   int y,
                   int width,
                   int height)
Description copied from interface: ScreenRegion
Add a rectangular region of interest into this ScreenRegion.

Specified by:
addROI in interface ScreenRegion
Parameters:
x - The X coordinate of the upper-left corner of the rectangle to be added.
y - The Y coordinate of the upper-left corner of the rectangle to be added.
width - The width of the rectangle.
height - width The width of the rectangle.

getROIs

public List<Rectangle> getROIs()
Description copied from interface: ScreenRegion
Returns a list of Rectangle that represent the rectangular regions of interest for this ScreenRegion.

Specified by:
getROIs in interface ScreenRegion
Returns:
a list of rectangles.

getStates

public Map<Target,Object> getStates()
Returns a map of Target objects and states, which can be any object, of this DefaultScreenRegion.

Specified by:
getStates in interface ScreenRegion
Returns:
a map of Target objects and their states.

addState

public void addState(Target target,
                     Object state)
Description copied from interface: ScreenRegion
Defines a new state of this screen region as represented by the presence of the given target.

Specified by:
addState in interface ScreenRegion
Parameters:
target - the target whose presence indicates this state.
state - the state, which can be any object.

removeState

public void removeState(Target target)
Description copied from interface: ScreenRegion
Removes a particular state represented by the given target from this screen region.

Specified by:
removeState in interface ScreenRegion
Parameters:
target - the representative target of the state to remove.

getState

public Object getState()
Description copied from interface: ScreenRegion
Returns the state of this ScreenRegion.

Specified by:
getState in interface ScreenRegion
Returns:
the state of this ScreenRegion.


Copyright © 2014. All rights reserved.