public class ScreenUtils extends Object implements ImageObserver, Comparator<com.tplan.robot.util.ScreenUtils.ScreenEntry>
T-Plan Robot Enterprise, (C) 2009-2022 T-Plan Limited. All rights reserved.
Modifier and Type | Field and Description |
---|---|
static boolean |
debug |
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Modifier and Type | Method and Description |
---|---|
static void |
addChangeListener(ChangeListener l)
Add a change listener to be notified of the screen layout changes.
|
int |
compare(com.tplan.robot.util.ScreenUtils.ScreenEntry o1,
com.tplan.robot.util.ScreenUtils.ScreenEntry o2) |
static BufferedImage |
createCompatibleCopy(Image image,
boolean copyPixels)
Create a copy of the image compatible with the Robot's image comparison
and display requirements.
|
static Robot |
getDefaultRobot()
Get the default
java.awt.Robot instance associated with the
primary display. |
static Rectangle |
getDisplayRectForPoint(int screenX,
int screenY)
Get rectangle of a display containing the specified coordinates.
|
static Rectangle |
getDisplayRectForRect(Rectangle rect)
Get rectangle of a display containing the specified rectangle or its
largest part if it spans across multiple displays.
|
static Color |
getEmptySpaceColor()
Get the transparent color used to pad empty areas of a virtual screen
image returned by
getScreenImage() . |
static Robot |
getRobot(Point source,
Point converted)
Get the
java.awt.Robot instance associated with the display
at the given coordinates. |
static int |
getScreenCount() |
static GraphicsDevice |
getScreenDevice(int screen) |
static BufferedImage |
getScreenImage()
Get the virtual screen image of the local OS.
|
static BufferedImage |
getScreenImage(int screenNo) |
static BufferedImage |
getScreenImage(Integer screenNo,
Rectangle bounds,
boolean boundsAreInRobotCoordSystem)
Get a screen shot of the specified area.
|
static Rectangle |
getScreenRect()
Get the screen rectangle in the local OS coordinates.
|
static Rectangle |
getScreenRect(int screenNo) |
static int |
getScreenRows() |
static List<Integer> |
getScreensForRect(Rectangle rect) |
static GraphicsDevice |
getTopLeftScreen(Rectangle r)
Get the top left graphics device.
|
boolean |
imageUpdate(Image img,
int infoflags,
int x,
int y,
int width,
int height)
Implementation of the
ImageObserver interface allowing the class
to act as a dummy image observer when performing buffered image
operations. |
static boolean |
isFullScreenCaptureSupported()
Find out if capture on the live screen is supported on the local
environment.
|
static boolean |
isScaled()
Find out if there's at least one scaled display.
|
static boolean |
isScaled(int screenNo)
Find out if the specified display is scaled.
|
static void |
removeChangeListener(ChangeListener l)
Remove a change listener.
|
static boolean |
setFullScreenWindow(Window w)
Set the full screen window.
|
static int |
toRobotX(int screenX)
Convert a local OS screen X-coordinate to the one compatible with the
Robot's coordinate system.
|
static int |
toRobotY(int screenY)
Convert a local OS screen Y-coordinate to the one compatible with the
Robot's coordinate system.
|
static int |
toScreenX(int robotX)
Convert a Robot screen X-coordinate to the one compatible with the local
OS screen coordinate system.
|
static int |
toScreenY(int robotY)
Convert a Robot screen Y-coordinate to the one compatible with the local
OS screen coordinate system.
|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
comparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
public static Color getEmptySpaceColor()
getScreenImage()
.public static Robot getDefaultRobot()
java.awt.Robot
instance associated with the
primary display.public static Robot getRobot(Point source, Point converted)
java.awt.Robot
instance associated with the display
at the given coordinates.source
- coordinates used to identify the target screen.converted
- when not null it will be populated with the coordinates
converted to the target java.awt.Robot
coordinates.java.awt.Robot
instance for the display at the
specified coordinates.public static int getScreenCount()
public static int getScreenRows()
public static GraphicsDevice getScreenDevice(int screen)
public static BufferedImage getScreenImage(int screenNo)
public static boolean isScaled()
public static boolean isScaled(int screenNo)
screenNo
- the display number.public static BufferedImage getScreenImage()
getEmptySpaceColor()
method.public static BufferedImage getScreenImage(Integer screenNo, Rectangle bounds, boolean boundsAreInRobotCoordSystem)
screenNo
- the screen number or null or a number lower than 1 to use
full screen consisting of multiple monitors.bounds
- rectangular part of the screen to capture . It must be in
the Robot coordinates which means that it may not contain negative X,Y
coordinates. See the toRobotX(int)
method for an explanation of the difference between the
local OS and Robot coordinate systems.boundsAreInRobotCoordSystem
- true/false mean that the bounds are
specified in the Robot/local OS coordinate system.public static int toRobotX(int screenX)
screenX
- a screen X-coordinate returned from the local OS.public static int toRobotY(int screenY)
screenY
- a screen Y-coordinate returned from the local OS.public static int toScreenX(int robotX)
robotX
- a Robot screen X-coordinate.public static int toScreenY(int robotY)
robotY
- a Robot screen Y-coordinate.public static Rectangle getDisplayRectForPoint(int screenX, int screenY)
screenX
- a local OS screen X-coordinate.screenY
- a local OS screen Y-coordinate.public static Rectangle getDisplayRectForRect(Rectangle rect)
rect
- a rectangle of the local OS screen coordinates. See the
toRobotX(int)
method for an explanation of the difference
between the local OS and Robot coordinate systems.public static Rectangle getScreenRect()
toRobotX(int)
method for an explanation of the difference
between the local OS and Robot coordinate systems.public static Rectangle getScreenRect(int screenNo)
public static BufferedImage createCompatibleCopy(Image image, boolean copyPixels)
BufferedImage.TYPE_INT_ARGB
or BufferedImage.TYPE_INT_RGB
depending on whether the argument image has an Alpha channel or not.image
- the image to create a copy of.copyPixels
- true will copy the source image pixels to the target
one. The value of false will make the method return an empty image of the
compatible type and equal dimensions.public static boolean isFullScreenCaptureSupported()
Find out if capture on the live screen is supported on the local environment. If the method returns true the calling screen capture components should take a screen shot and then display it in the image editor instead of showing the live screen editor implemented as a full screen window.
public static GraphicsDevice getTopLeftScreen(Rectangle r)
r
- an optional output rectangle to store the device bounds to.public static boolean setFullScreenWindow(Window w)
Set the full screen window. This method is equivalent to the
GraphicsDevice.setFullScreenWindow(java.awt.Window)
one save for
two features:
w
- a window.public static void addChangeListener(ChangeListener l)
l
- the change listener to add.public static void removeChangeListener(ChangeListener l)
l
- the listener to remove.public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height)
ImageObserver
interface allowing the class
to act as a dummy image observer when performing buffered image
operations.imageUpdate
in interface ImageObserver
img
- an image.infoflags
- flags.x
- the X-coordinate of the update.y
- the Y-coordinate of the update.width
- the update width.height
- the update height.public int compare(com.tplan.robot.util.ScreenUtils.ScreenEntry o1, com.tplan.robot.util.ScreenUtils.ScreenEntry o2)
compare
in interface Comparator<com.tplan.robot.util.ScreenUtils.ScreenEntry>