/** * Returns the monitor whose client area contains the given point. If no monitor contains the * point, returns the monitor that is closest to the point. * <p> * Copied from <code>org.eclipse.jface.window.Window.getClosestMonitor(Display, Point)</code> * </p> * * @param display the display showing the monitors * @param point point to find (display coordinates) * @return the monitor closest to the given point */ private static Monitor getClosestMonitor(Display display, Point point) { int closest= Integer.MAX_VALUE; Monitor[] monitors= display.getMonitors(); Monitor result= monitors[0]; for (int i= 0; i < monitors.length; i++) { Monitor current= monitors[i]; Rectangle clientArea= current.getClientArea(); if (clientArea.contains(point)) return current; int distance= Geometry.distanceSquared(Geometry.centerPoint(clientArea), point); if (distance < closest) { closest= distance; result= current; } } return result; }
int distance = Geometry.distanceSquared(Geometry .centerPoint(clientArea), toFind); if (distance < closest) {
int distance = Geometry.distanceSquared(Geometry.centerPoint(clientArea), toFind); if (distance < closest) { closest = distance;
int distance = Geometry.distanceSquared(Geometry .centerPoint(clientArea), toFind); if (distance < closest) {
/** * Copied from org.eclipse.jface.window.Window. Returns the monitor whose client area contains * the given point. If no monitor contains the point, returns the monitor that is closest to the * point. If this is ever made public, it should be moved into a separate utility class. * * @param display the display to search for monitors * @param rectangle the rectangle to find the closest monitor for (display coordinates) * @return the monitor closest to the given point * @since 3.3 */ private Monitor getClosestMonitor(Display display, Rectangle rectangle) { int closest = Integer.MAX_VALUE; Point toFind= Geometry.centerPoint(rectangle); Monitor[] monitors = display.getMonitors(); Monitor result = monitors[0]; for (int idx = 0; idx < monitors.length; idx++) { Monitor current = monitors[idx]; Rectangle clientArea = current.getClientArea(); if (clientArea.contains(toFind)) { return current; } int distance = Geometry.distanceSquared(Geometry.centerPoint(clientArea), toFind); if (distance < closest) { closest = distance; result = current; } } return result; }
/** * Copied from org.eclipse.jface.window.Window. Returns the monitor whose client area * contains the given point. If no monitor contains the point, returns the monitor that is * closest to the point. If this is ever made public, it should be moved into a separate * utility class. * * @param toSearch point to find (display coordinates) * @param rectangle rectangle to find (display coordinates) * @return the monitor closest to the given point * @since 3.3 */ private Monitor getClosestMonitor(Display toSearch, Rectangle rectangle) { int closest = Integer.MAX_VALUE; Point toFind= Geometry.centerPoint(rectangle); Monitor[] monitors = toSearch.getMonitors(); Monitor result = monitors[0]; for (Monitor current : monitors) { Rectangle clientArea = current.getClientArea(); if (clientArea.contains(toFind)) { return current; } int distance = Geometry.distanceSquared(Geometry.centerPoint(clientArea), toFind); if (distance < closest) { closest = distance; result = current; } } return result; } }
int distance = Geometry.distanceSquared(Geometry.centerPoint(clientArea), toFind); if (distance < closest) { closest = distance;