List of usage examples for org.eclipse.jface.util Geometry set
public static void set(Rectangle result, Rectangle toCopy)
From source file:au.gov.ga.earthsci.jface.extras.information.AbstractInformationControlManager.java
License:Open Source License
/** * Computes the location of the information control depending on the * subject area and the size of the information control. This method attempts * to find a location at which the information control lies completely in the display's * client area while honoring the manager's default anchor. If this isn't possible using the * default anchor, the fallback anchors are tried out. * * @param subjectArea the information area * @param controlSize the size of the information control * @return the computed location of the information control */// w w w . j a va 2s .com protected Point computeInformationControlLocation(Rectangle subjectArea, Point controlSize) { Rectangle subjectAreaDisplayRelative = Geometry.toDisplay(fSubjectControl, subjectArea); Point upperLeft; Anchor testAnchor = fAnchor; Rectangle bestBounds = null; int bestArea = Integer.MIN_VALUE; Anchor bestAnchor = null; do { upperLeft = computeLocation(subjectArea, controlSize, testAnchor); Monitor monitor = getClosestMonitor(subjectAreaDisplayRelative, testAnchor); if (updateLocation(upperLeft, controlSize, monitor.getClientArea(), testAnchor)) return upperLeft; // compute available area for this anchor and update if better than best Rectangle available = computeAvailableArea(subjectAreaDisplayRelative, monitor.getClientArea(), testAnchor); Rectangle proposed = new Rectangle(upperLeft.x, upperLeft.y, controlSize.x, controlSize.y); available.intersect(proposed); int area = available.width * available.height; if (area > bestArea) { bestArea = area; bestBounds = available; bestAnchor = testAnchor; } testAnchor = getNextFallbackAnchor(testAnchor); } while (testAnchor != fAnchor && testAnchor != null); // no anchor is perfect - select the one with larges area and set the size to not overlap with the subjectArea if (bestAnchor != ANCHOR_GLOBAL) Geometry.set(controlSize, Geometry.getSize(bestBounds)); return Geometry.getLocation(bestBounds); }