List of usage examples for org.eclipse.jface.util Geometry expand
public static void expand(Rectangle rect, int left, int right, int top, int bottom)
From source file:au.gov.ga.earthsci.jface.extras.information.AbstractHoverInformationControlManager.java
License:Open Source License
/** * Tests whether a given mouse location is within the keep-up zone. * The hover should not be hidden as long as the mouse stays inside this zone. * * @param x the x coordinate, relative to the <em>subject control</em> * @param y the y coordinate, relative to the <em>subject control</em> * @param subjectControl the subject control * @param subjectArea the area for which the presented information is valid * @param blowUp If <code>true</code>, then calculate for the closer, i.e. blow up the keepUp area. * If <code>false</code>, then use tight bounds for hover detection. * * @return <code>true</code> iff the mouse event occurred in the keep-up zone * @since 3.4/*from w ww . ja v a 2s . c o m*/ */ private boolean inKeepUpZone(int x, int y, Control subjectControl, Rectangle subjectArea, boolean blowUp) { if (subjectArea.contains(x, y)) return true; IInformationControl iControl = getCurrentInformationControl(); if ((iControl instanceof IInformationControlExtension5 && !((IInformationControlExtension5) iControl).isVisible())) { iControl = null; if (getInformationControlReplacer() != null) { iControl = getInformationControlReplacer().getCurrentInformationControl2(); if ((iControl instanceof IInformationControlExtension5 && !((IInformationControlExtension5) iControl).isVisible())) { return false; } } } if (iControl instanceof IInformationControlExtension3) { IInformationControlExtension3 iControl3 = (IInformationControlExtension3) iControl; Rectangle iControlBounds = subjectControl.getDisplay().map(null, subjectControl, iControl3.getBounds()); Rectangle totalBounds = Geometry.copy(iControlBounds); if (blowUp && isReplaceInProgress()) { //Problem: blown up iControl overlaps rest of subjectArea's line // solution for now: only blow up for keep up (closer), but not for further hover detection int margin = getInformationControlReplacer().getKeepUpMargin(); Geometry.expand(totalBounds, margin, margin, margin, margin); } if (!blowUp) { if (iControlBounds.contains(x, y)) return true; if (subjectArea.y + subjectArea.height < iControlBounds.y) { // special case for hover events: subjectArea totally above iControl: // +-----------+ // |subjectArea| // +-----------+ // |also keepUp| // ++-----------+-------+ // | InformationControl | // +--------------------+ if (subjectArea.y + subjectArea.height <= y && y <= totalBounds.y) { // is vertically between subject area and iControl if (subjectArea.x <= x && x <= subjectArea.x + subjectArea.width) { // is below subject area (in a vertical projection) return true; } // FIXME: cases when subjectArea extends to left or right of iControl? } return false; } else if (iControlBounds.x + iControlBounds.width < subjectArea.x) { // special case for hover events (e.g. in overview ruler): iControl totally left of subjectArea // +--------------------+-----------+ // | | +-----------+ // | InformationControl |also keepUp|subjectArea| // | | +-----------+ // +--------------------+-----------+ if (iControlBounds.x + iControlBounds.width <= x && x <= subjectArea.x) { // is horizontally between iControl and subject area if (iControlBounds.y <= y && y <= iControlBounds.y + iControlBounds.height) { // is to the right of iControl (in a horizontal projection) return true; } } return false; } else if (subjectArea.x + subjectArea.width < iControlBounds.x) { // special case for hover events (e.g. in annotation ruler): subjectArea totally left of iControl // +-----------+--------------------+ // +-----------+ | | // |subjectArea|also keepUp| InformationControl | // +-----------+ | | // +-----------+--------------------+ if (subjectArea.x + subjectArea.width <= x && x <= iControlBounds.x) { // is horizontally between subject area and iControl if (iControlBounds.y <= y && y <= iControlBounds.y + iControlBounds.height) { // is to the left of iControl (in a horizontal projection) return true; } } return false; } } // FIXME: should maybe use convex hull, not bounding box totalBounds.add(subjectArea); if (totalBounds.contains(x, y)) return true; } return false; }
From source file:org.eclipse.m2e.editor.xml.internal.FormHoverProvider.java
License:Open Source License
public static Execute createHoverRunnable(final Shell parentShell, final IMarker[] markers, final ISourceViewer sourceViewer) { if (markers.length > 0) { return new Execute() { public void run(Point position) { List<IMarker> markersSet = Arrays.asList(markers); PomTextHover.CompoundRegion compound = new PomTextHover.CompoundRegion(sourceViewer, 0); Iterator<Annotation> it = sourceViewer.getAnnotationModel().getAnnotationIterator(); while (it.hasNext()) { Annotation ann = it.next(); if (ann instanceof MarkerAnnotation) { MarkerAnnotation mann = (MarkerAnnotation) ann; if (markersSet.contains(mann.getMarker())) ;//from w w w . ja va 2s .c o m compound.addRegion(new PomHyperlinkDetector.MarkerRegion(0, 0, mann)); } } final MarkerHoverControl mhc = new MarkerHoverControl(parentShell); final Display fDisplay = mhc.getMyShell().getDisplay(); final Listener displayListener = new Listener() { public void handleEvent(Event event) { if (event.type == SWT.MouseMove) { if (!(event.widget instanceof Control) || event.widget.isDisposed()) return; IInformationControl infoControl = mhc; if (infoControl != null && !infoControl.isFocusControl() && infoControl instanceof IInformationControlExtension3) { IInformationControlExtension3 iControl3 = (IInformationControlExtension3) infoControl; Rectangle controlBounds = iControl3.getBounds(); if (controlBounds != null) { Point mouseLoc = event.display.map((Control) event.widget, null, event.x, event.y); int margin = 20; Geometry.expand(controlBounds, margin, margin, margin, margin); if (!controlBounds.contains(mouseLoc)) { mhc.setVisible(false); } } // } else { // System.out.println("removing mouse move.."); // /* // * TODO: need better understanding of why/if this is needed. // * Looks like the same panic code we have in org.eclipse.jface.text.AbstractHoverInformationControlManager.Closer.handleMouseMove(Event) // */ // if (fDisplay != null && !fDisplay.isDisposed()) // fDisplay.removeFilter(SWT.MouseMove, this); } } else if (event.type == SWT.FocusOut) { IInformationControl iControl = mhc; if (iControl != null && !iControl.isFocusControl()) mhc.setVisible(false); } } }; mhc.setLocation(new Point(position.x, position.y)); mhc.setSizeConstraints(400, 400); mhc.setInput(compound); Point hint = mhc.computeSizeHint(); mhc.setSize(hint.x, Math.min(hint.y, 400)); if (!fDisplay.getBounds().contains(position.x + hint.x, position.y)) { mhc.setLocation(new Point(position.x - (position.x + hint.x - fDisplay.getBounds().width), position.y)); } // mhc.getMyShell().addShellListener(new ShellAdapter() { // public void shellActivated(ShellEvent e) { // mhc.setFocus(); // } // }); if (!fDisplay.isDisposed()) { fDisplay.addFilter(SWT.MouseMove, displayListener); fDisplay.addFilter(SWT.FocusOut, displayListener); } mhc.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { fDisplay.removeFilter(SWT.MouseMove, displayListener); fDisplay.removeFilter(SWT.FocusOut, displayListener); } }); mhc.setVisible(true); } }; } else { return null; } }
From source file:org.eclipse.ui.internal.presentations.defaultpresentation.NativeTabFolder.java
License:Open Source License
public Rectangle getTabArea() { Rectangle bounds = control.getBounds(); Rectangle clientArea = control.getClientArea(); bounds.x = 0;//from www . j a v a 2 s. c om bounds.y = 0; Geometry.expand(bounds, 0, 0, -(clientArea.height + clientArea.y), 0); return Geometry.toDisplay(control.getParent(), bounds); }
From source file:org.eclipse.ui.internal.presentations.util.EnhancedFillLayout.java
License:Open Source License
protected void layout(Composite composite, boolean flushCache) { Control[] children = composite.getChildren(); for (int i = 0; i < children.length; i++) { Control control = children[i]; Rectangle area = composite.getClientArea(); Geometry.expand(area, -xmargin, -xmargin, -ymargin, -ymargin); control.setBounds(area);/*w w w . ja v a 2 s . c om*/ } }