private Point getInitialDialogLocation( Point initialSize ) { Rectangle dispayBounds = getShell().getDisplay().getBounds(); Point centerPoint = Geometry.centerPoint( dispayBounds ); int x = centerPoint.x - ( initialSize.x / 2 ); int y = Math.min( centerPoint.y - ( initialSize.y * 2 / 3 ), dispayBounds.height - initialSize.y ); return new Point( x, Math.max( 0, y ) ); } //RAPEND [if]
/** * Gets the closest monitor given an anchor and the subject area. * * @param area the subject area * @param anchor the anchor * @return the monitor closest to the edge of <code>area</code> defined by * <code>anchor</code> * @since 3.3 */ private Monitor getClosestMonitor(Rectangle area, Anchor anchor) { Point center; if (ANCHOR_GLOBAL == anchor) center= Geometry.centerPoint(area); else center= Geometry.centerPoint(Geometry.getExtrudedEdge(area, 0, anchor.getSWTFlag())); return Util.getClosestMonitor(fSubjectControl.getDisplay(), center); }
/** * Gets the closest monitor given an anchor and the subject area. * * @param area the subject area * @param anchor the anchor * @return the monitor closest to the edge of <code>area</code> defined by * <code>anchor</code> * @since 3.3 */ private Monitor getClosestMonitor(Rectangle area, Anchor anchor) { Point center; if (ANCHOR_GLOBAL == anchor) center= Geometry.centerPoint(area); else center= Geometry.centerPoint(Geometry.getExtrudedEdge(area, 0, anchor.getSWTFlag())); return getClosestMonitor(fSubjectControl.getDisplay(), Geometry.createRectangle(center, new Point(0, 0))); }
/** * Returns the initial location to use for the shell. The default * implementation centers the shell horizontally (1/2 of the difference to * the left and 1/2 to the right) and vertically (1/3 above and 2/3 below) * relative to the parent shell, or display bounds if there is no parent * shell. * * @param initialSize * the initial size of the shell, as returned by * <code>getInitialSize</code>. * @return the initial location of the shell */ protected Point getInitialLocation(Point initialSize) { Composite parent = shell.getParent(); Monitor monitor = shell.getDisplay().getPrimaryMonitor(); if (parent != null) { monitor = parent.getMonitor(); } Rectangle monitorBounds = monitor.getClientArea(); Point centerPoint; if (parent != null) { centerPoint = Geometry.centerPoint(parent.getBounds()); } else { centerPoint = Geometry.centerPoint(monitorBounds); } return new Point(centerPoint.x - (initialSize.x / 2), Math.max( monitorBounds.y, Math.min(centerPoint.y - (initialSize.y * 2 / 3), monitorBounds.y + monitorBounds.height - initialSize.y))); }
/** * Returns the initial location to use for the shell. The default * implementation centers the shell horizontally (1/2 of the difference to * the left and 1/2 to the right) and vertically (1/3 above and 2/3 below) * relative to the parent shell, or display bounds if there is no parent * shell. * * @param initialSize * the initial size of the shell, as returned by * <code>getInitialSize</code>. * @return the initial location of the shell */ protected Point getInitialLocation(Point initialSize) { Composite parent = shell.getParent(); Monitor monitor = shell.getDisplay().getPrimaryMonitor(); if (parent != null) { monitor = parent.getMonitor(); } Rectangle monitorBounds = monitor.getClientArea(); Point centerPoint; if (parent != null) { centerPoint = Geometry.centerPoint(parent.getBounds()); } else { centerPoint = Geometry.centerPoint(monitorBounds); } return new Point(centerPoint.x - (initialSize.x / 2), Math.max( monitorBounds.y, Math.min(centerPoint.y - (initialSize.y * 2 / 3), monitorBounds.y + monitorBounds.height - initialSize.y))); }
@Override protected Point getInitialLocation(Point initialSize) { Composite parent = getShell().getParent(); if (!centerOnMonitor || parent == null) { return super.getInitialLocation(initialSize); } Monitor monitor = parent.getMonitor(); Rectangle monitorBounds = monitor.getClientArea(); Point centerPoint = Geometry.centerPoint(monitorBounds); return new Point(centerPoint.x - (initialSize.x / 2), Math.max( monitorBounds.y, Math.min(centerPoint.y - (initialSize.y * 2 / 3), monitorBounds.y + monitorBounds.height - initialSize.y))); }
/** * Returns the initial location to use for the shell. The default * implementation centers the shell horizontally (1/2 of the difference to * the left and 1/2 to the right) and vertically (1/3 above and 2/3 below) * relative to the parent shell, or display bounds if there is no parent * shell. * * @param initialSize * the initial size of the shell, as returned by * <code>getInitialSize</code>. * @return the initial location of the shell */ protected Point getInitialLocation(Point initialSize) { Composite parent = shell.getParent(); Monitor monitor = shell.getDisplay().getPrimaryMonitor(); if (parent != null) { monitor = parent.getMonitor(); } Rectangle monitorBounds = monitor.getClientArea(); Point centerPoint; if (parent != null) { centerPoint = Geometry.centerPoint(parent.getBounds()); } else { centerPoint = Geometry.centerPoint(monitorBounds); } return new Point(centerPoint.x - (initialSize.x / 2), Math.max( monitorBounds.y, Math.min(centerPoint.y - (initialSize.y * 2 / 3), monitorBounds.y + monitorBounds.height - initialSize.y))); }
/** * 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 closest = Integer.MAX_VALUE; Point toFind= Geometry.centerPoint(rectangle); Monitor[] monitors = toSearch.getMonitors(); Monitor result = monitors[0]; int distance = Geometry.distanceSquared(Geometry.centerPoint(clientArea), toFind); if (distance < closest) { closest = distance;
/** * Crops the given bounds such that they lie completely on the closest monitor. * * @param bounds shell bounds to crop * @since 3.4 */ void cropToClosestMonitor(Rectangle bounds) { Rectangle monitorBounds= Util.getClosestMonitor(fSubjectControl.getDisplay(), Geometry.centerPoint(bounds)).getClientArea(); bounds.intersect(monitorBounds); }
@Override protected void setDialogLocation(final Shell dialog, IWorkbenchPart activePart) { if (dialog == null) return; // Default to center on the display Point dlgAnchor = Geometry.centerPoint(dialog.getDisplay().getBounds()); // Center the dialog within the activePart's pane (if any) if (activePart != null) { WorkbenchPart wbPart = (WorkbenchPart) activePart; PartSite site = (PartSite) wbPart.getSite(); Control paneCtrl = (Control) site.getModel().getWidget(); // Get the center of the view pane's control Rectangle viewBounds = paneCtrl.getBounds(); Point vCenter = Geometry.centerPoint(viewBounds); // Map it to the display dlgAnchor = paneCtrl.getParent().toDisplay(vCenter); } // Offset the point by half the dialog size Rectangle dialogBounds = dialog.getBounds(); dlgAnchor.x -= (dialogBounds.width / 2); dlgAnchor.y -= (dialogBounds.height / 2); dialog.setLocation(dlgAnchor); }
.centerPoint(clientArea), toFind); if (distance < closest) { closest = distance;
/** * 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) { closest = distance;
.centerPoint(clientArea), toFind); if (distance < closest) { closest = distance;
Monitor closestMonitor = Util.getClosestMonitor(display, Geometry.centerPoint(modelBounds)); Rectangle displayBounds = closestMonitor.getClientArea(); if (!modelBounds.intersects(displayBounds)) {