/** * Create a region with the provided coordinate / size and screen * * @param X X position * @param Y Y position * @param W width * @param H heigth * @param screenNumber The number of the screen containing the Region */ public Region(int X, int Y, int W, int H, int screenNumber) { this(X, Y, W, H, Screen.getScreen(screenNumber)); this.rows = 0; }
/** * new point with same offset to current screen's top left on given screen * * @param scrID number of screen * @return new location */ public Location copyTo(int scrID) { return copyTo(Screen.getScreen(scrID)); }
/** * Sets a new Screen for this region. * * @param id the containing screen object's id * @return the region itself */ protected Region setScreen(int id) { return setScreen(Screen.getScreen(id)); }
/** * each screen has exactly one robot (internally used for screen capturing) * <br>available as a convenience for those who know what they are doing. Should not be needed * normally. * * @param id of the screen * @return the AWT.Robot of the given screen, if id invalid the primary screen */ public static IRobot getRobot(int id) { return getScreen(id).getRobot(); }
/** * new region with same offset to current screen's top left on given screen * * @param scrID number of screen * @return new region */ public Region copyTo(int scrID) { return copyTo(Screen.getScreen(scrID)); }
@Override public void run() { String msg = message.isEmpty() ? promptMsg : message; for (int is = 0; is < Screen.getNumberScreens(); is++) { if (ignorePrimaryAtCapture && is == 0) { continue; } Screen.getScreen(is).prompt = new OverlayCapturePrompt(Screen.getScreen(is)); Screen.getScreen(is).prompt.addObserver(captureObserver); Screen.getScreen(is).prompt.prompt(msg); } } };
/** * Returns null, if outside of any screen and not contained in a non-Desktop Screen instance (e.g. remote screen)<br> * subsequent actions WILL crash if not tested for null return * * @return the screen, that contains the given point */ public IScreen getScreen() { Rectangle r; if (otherScreen != null) { return otherScreen; } for (int i = 0; i < Screen.getNumberScreens(); i++) { r = Screen.getScreen(i).getBounds(); if (r.contains(this.x, this.y)) { return Screen.getScreen(i); } } Debug.error("Location: outside any screen (%s, %s) - subsequent actions might not work as expected", x, y); return null; }
public static void resetPrompt(OverlayCapturePrompt ocp) { int scrID = ocp.getScrID(); if (scrID > -1) { Screen.getScreen(scrID).prompt = null; } resetActiveCapturePrompt(); }
void drawMessage(Graphics2D g2d) { if (promptMsg == null) { return; } g2d.setFont(fontMsg); g2d.setColor(new Color(1f, 1f, 1f, 1)); int sw = g2d.getFontMetrics().stringWidth(promptMsg); int sh = g2d.getFontMetrics().getMaxAscent(); Rectangle ubound = scrOCP.getBounds(); for (int i = 0; i < Screen.getNumberScreens(); i++) { if (!Screen.getScreen(i).hasPrompt()) { continue; } Rectangle bound = Screen.getBounds(i); int cx = bound.x + (bound.width - sw) / 2 - ubound.x; int cy = bound.y + (bound.height - sh) / 2 - ubound.y; g2d.drawString(promptMsg, cx, cy); } }
/** * Returns primary screen, if outside of any screen or not contained in a non-Desktop Screen instance (e.g. remote screen)<br> * * @return the real screen, that contains the given point */ public Screen getMonitor() { Rectangle r; Screen scr = null; if (otherScreen == null) { for (int i = 0; i < Screen.getNumberScreens(); i++) { r = Screen.getScreen(i).getBounds(); if (r.contains(this.x, this.y)) { scr = Screen.getScreen(i); break; } } } else { Debug.error("Location: getMonitor: (%s, %s) not on real screen - using primary", x, y); scr = Screen.getPrimaryScreen(); } if (scr == null) { Debug.error("Location: getMonitor: (%s, %s) outside any screen - using primary", x, y); scr = Screen.getPrimaryScreen(); } return scr; }
/** * show the current monitor setup */ public static void showMonitors() { // initScreens(); Debug.logp("*** monitor configuration [ %s Screen(s)] ***", Screen.getNumberScreens()); Debug.logp("*** Primary is Screen %d", primaryScreen); for (int i = 0; i < runTime.nMonitors; i++) { Debug.logp("Screen %d: %s", i, Screen.getScreen(i).toStringShort()); } Debug.logp("*** end monitor configuration ***"); }
@Override public int getIdFromPoint(int x, int y) { Rectangle sr = getBounds(); int _x = x + getBounds().x; int _y = y + getBounds().y; for (int i = 0; i < getNumberScreens(); i++) { if (Screen.getScreen(i).contains(new Location(_x, _y))) { Debug.log(3, "ScreenUnion: getIdFromPoint: " + "(%d, %d) as (%d, %d) in (%d, %d, %d, %d) on %d", x, y, _x, _y, sr.x, sr.y, sr.width, sr.height, i); return i; } } Debug.log(3, "ScreenUnion: getIdFromPoint: " + "(%d, %d) as (%d, %d) in (%d, %d, %d, %d) on ???", x, y, _x, _y, sr.x, sr.y, sr.width, sr.height); return 0; }
screen = Screen.getScreen(i); rect = regionOnScreen(screen); if (rect != null) {
/** * re-initialize the monitor setup (e.g. when it was changed while running) */ public static void resetMonitors() { Debug.error("*** BE AWARE: experimental - might not work ***"); Debug.error("Re-evaluation of the monitor setup has been requested"); Debug.error("... Current Region/Screen objects might not be valid any longer"); Debug.error("... Use existing Region/Screen objects only if you know what you are doing!"); initScreens(true); Debug.logp("*** new monitor configuration [ %s Screen(s)] ***", Screen.getNumberScreens()); Debug.logp("*** Primary is Screen %d", primaryScreen); for (int i = 0; i < runTime.nMonitors; i++) { Debug.logp("Screen %d: %s", i, Screen.getScreen(i).toStringShort()); } Debug.error("*** end new monitor configuration ***"); }