Class Screen

  • All Implemented Interfaces:
    IScreen
    Direct Known Subclasses:
    ScreenUnion

    public class Screen
    extends Region
    implements IScreen
    A screen represents a physical monitor with its coordinates and size according to the global point system: the screen areas are grouped around a point (0,0) like in a cartesian system (the top left corner and the points contained in the screen area might have negative x and/or y values)
    The screens are arranged in an array (index = id) and each screen is always the same object (not possible to create new objects).
    A screen inherits from class Region, so it can be used as such in all aspects. If you need the region of the screen more than once, you have to create new ones based on the screen.
    The so called primary screen is the one with top left (0,0) and has id 0.
    • Field Detail

      • screens

        protected static Screen[] screens
      • primaryScreen

        protected static int primaryScreen
      • curID

        protected int curID
      • oldID

        protected int oldID
      • monitor

        protected int monitor
      • waitPrompt

        protected boolean waitPrompt
      • ignorePrimaryAtCapture

        public static boolean ignorePrimaryAtCapture
    • Constructor Detail

      • Screen

        public Screen()
        Is the screen object having the top left corner as (0,0). If such a screen does not exist it is the screen with id 0.
      • Screen

        public Screen​(int id)
        The screen object with the given id
        Parameters:
        id - valid screen number
      • Screen

        public Screen​(boolean isScreenUnion)
        INTERNAL USE collect all physical screens to one big region
        TODO: under evaluation, wether it really makes sense
        Parameters:
        isScreenUnion - true/false
    • Method Detail

      • getDefaultInstance4py

        public static Screen getDefaultInstance4py()
      • isHeadless

        public static boolean isHeadless()
      • getMonitor

        public static Rectangle getMonitor​(int n)
      • initScreens

        protected static void initScreens​(boolean reset)
      • as

        public static Screen as​(int id)
      • getGlobalRobot

        protected static IRobot getGlobalRobot()
      • all

        public static ScreenUnion all()
        create a Screen (ScreenUnion) object as a united region of all available monitors
        Returns:
        ScreenUnion
      • setAsScreenUnion

        public void setAsScreenUnion()
        INTERNAL USE collect all physical screens to one big region
        This is under evaluation, wether it really makes sense
      • setAsScreen

        public void setAsScreen()
        INTERNAL USE reset from being a screen union to the screen used before
      • setScreen

        protected Region setScreen​(IScreen s)
        Should not be used - makes no sense for Screen object
        Overrides:
        setScreen in class Region
        Parameters:
        s - Screen
        Returns:
        returns a new Region with the screen's location/dimension
      • showMonitors

        public static void showMonitors()
        show the current monitor setup
      • resetMonitors

        public static void resetMonitors()
        re-initialize the monitor setup (e.g. when it was changed while running)
      • resetMonitorsQuiet

        public static void resetMonitorsQuiet()
      • getNumberScreens

        public static int getNumberScreens()
        Returns:
        number of available screens
      • getPrimaryId

        public static int getPrimaryId()
        Returns:
        the id of the screen at (0,0), if not exists 0
      • getPrimaryScreen

        public static Screen getPrimaryScreen()
        Returns:
        the screen at (0,0), if not exists the one with id 0
      • getScreen

        public static Screen getScreen​(int id)
        Parameters:
        id - of the screen
        Returns:
        the screen with given id, the primary screen if id is invalid
      • getBounds

        public static Rectangle getBounds​(int id)
        Parameters:
        id - of the screen
        Returns:
        the physical coordinate/size
        as AWT.Rectangle to avoid mix up with getROI
      • getRobot

        public static IRobot getRobot​(int id)
        each screen has exactly one robot (internally used for screen capturing)
        available as a convenience for those who know what they are doing. Should not be needed normally.
        Parameters:
        id - of the screen
        Returns:
        the AWT.Robot of the given screen, if id invalid the primary screen
      • getID

        public int getID()
        Specified by:
        getID in interface IScreen
        Returns:
        the id
      • getIdFromPoint

        public int getIdFromPoint​(int x,
                                  int y)
        INTERNAL USE: to be compatible with ScreenUnion
        Specified by:
        getIdFromPoint in interface IScreen
        Parameters:
        x - value
        y - value
        Returns:
        id of the screen
      • getRobot

        public IRobot getRobot()
        Gets the Robot of this Screen.
        Specified by:
        getRobot in interface IScreen
        Returns:
        The Robot for this Screen
      • getRobot

        protected static IRobot getRobot​(Region reg)
      • newRegion

        public Region newRegion​(Location loc,
                                int width,
                                int height)
        creates a region on the current screen with the given coordinate/size. The coordinate is translated to the current screen from its relative position on the screen it would have been created normally.
        Specified by:
        newRegion in interface IScreen
        Parameters:
        loc - Location
        width - value
        height - value
        Returns:
        the new region
      • newRegion

        public Region newRegion​(int x,
                                int y,
                                int w,
                                int h)
        Specified by:
        newRegion in interface IScreen
      • newLocation

        public Location newLocation​(Location loc)
        creates a location on the current screen with the given point. The coordinate is translated to the current screen from its relative position on the screen it would have been created normally.
        Specified by:
        newLocation in interface IScreen
        Parameters:
        loc - Location
        Returns:
        the new location
      • capture

        public ScreenImage capture()
        create a ScreenImage with the physical bounds of this screen
        Specified by:
        capture in interface IScreen
        Returns:
        the image
      • capture

        public ScreenImage capture​(int x,
                                   int y,
                                   int w,
                                   int h)
        create a ScreenImage with given coordinates on this screen.
        Specified by:
        capture in interface IScreen
        Parameters:
        x - x-coordinate of the region to be captured
        y - y-coordinate of the region to be captured
        w - width of the region to be captured
        h - height of the region to be captured
        Returns:
        the image of the region
      • capture

        public ScreenImage capture​(Rectangle rect)
        create a ScreenImage with given rectangle on this screen.
        Specified by:
        capture in interface IScreen
        Parameters:
        rect - The Rectangle to be captured
        Returns:
        the image of the region
      • capture

        public ScreenImage capture​(Region reg)
        create a ScreenImage with given region on this screen
        Specified by:
        capture in interface IScreen
        Parameters:
        reg - The Region to be captured
        Returns:
        the image of the region
      • closePrompt

        public static void closePrompt()
      • closePrompt

        public static void closePrompt​(Screen scr)
      • hasPrompt

        public boolean hasPrompt()
      • userCapture

        public ScreenImage userCapture()
        interactive capture with predefined message: lets the user capture a screen image using the mouse to draw the rectangle
        Returns:
        the image
      • userCapture

        public ScreenImage userCapture​(String message)
        interactive capture with given message: lets the user capture a screen image using the mouse to draw the rectangle
        Specified by:
        userCapture in interface IScreen
        Parameters:
        message - text
        Returns:
        the image
      • selectRegion

        public Region selectRegion()
        interactive region create with predefined message: lets the user draw the rectangle using the mouse
        Returns:
        the region
      • selectRegion

        public Region selectRegion​(String message)
        interactive region create with given message: lets the user draw the rectangle using the mouse
        Parameters:
        message - text
        Returns:
        the region