List of usage examples for org.eclipse.jface.util Geometry moveInside
public static void moveInside(Rectangle inner, Rectangle outer)
From source file:com.cisco.yangide.ext.refactoring.ui.RenameInformationPopup.java
License:Open Source License
/** * @param snapPosition one of the SNAP_POSITION_* constants * @return the location in display coordinates or <code>null</code> iff not visible *//*from www . j a va 2 s .com*/ private Point computePopupLocation(int snapPosition) { if (fPopup == null || fPopup.isDisposed()) { return null; } switch (snapPosition) { case SNAP_POSITION_LOWER_RIGHT: { StyledText eWidget = editor.getViewer().getTextWidget(); Rectangle eBounds = eWidget.getClientArea(); Point eLowerRight = eWidget.toDisplay(eBounds.x + eBounds.width, eBounds.y + eBounds.height); Point pSize = getExtent(); return new Point(eLowerRight.x - pSize.x - 5, eLowerRight.y - pSize.y - 5); } case SNAP_POSITION_UNDER_RIGHT_FIELD: case SNAP_POSITION_OVER_RIGHT_FIELD: { LinkedPosition position = renameLinkedMode.getCurrentLinkedPosition(); if (position == null) { return null; } ISourceViewer viewer = editor.getViewer(); ITextViewerExtension5 viewer5 = (ITextViewerExtension5) viewer; int widgetOffset = viewer5.modelOffset2WidgetOffset(position.offset + position.length); StyledText textWidget = viewer.getTextWidget(); Point pos = textWidget.getLocationAtOffset(widgetOffset); Point pSize = getExtent(); if (snapPosition == SNAP_POSITION_OVER_RIGHT_FIELD) { pos.y -= pSize.y + GAP; } else { pos.y += textWidget.getLineHeight(widgetOffset) + GAP; } pos.x += GAP; Point dPos = textWidget.toDisplay(pos); Rectangle displayBounds = textWidget.getDisplay().getClientArea(); Rectangle dPopupRect = Geometry.createRectangle(dPos, pSize); Geometry.moveInside(dPopupRect, displayBounds); return new Point(dPopupRect.x, dPopupRect.y); } case SNAP_POSITION_UNDER_LEFT_FIELD: case SNAP_POSITION_OVER_LEFT_FIELD: default: // same as SNAP_POSITION_UNDER_LEFT_FIELD { LinkedPosition position = renameLinkedMode.getCurrentLinkedPosition(); if (position == null) { return null; } ISourceViewer viewer = editor.getViewer(); ITextViewerExtension5 viewer5 = (ITextViewerExtension5) viewer; int widgetOffset = viewer5.modelOffset2WidgetOffset(position.offset/* + position.length */); StyledText textWidget = viewer.getTextWidget(); Point pos = textWidget.getLocationAtOffset(widgetOffset); Point pSize = getExtent(); pSize.y += HAH + 1; pos.x -= HAO; if (snapPosition == SNAP_POSITION_OVER_LEFT_FIELD) { pos.y -= pSize.y; } else { pos.y += textWidget.getLineHeight(widgetOffset); } Point dPos = textWidget.toDisplay(pos); Rectangle displayBounds = textWidget.getDisplay().getClientArea(); Rectangle dPopupRect = Geometry.createRectangle(dPos, pSize); Geometry.moveInside(dPopupRect, displayBounds); return new Point(dPopupRect.x, dPopupRect.y); } } }
From source file:com.google.dart.tools.ui.internal.refactoring.reorg.RenameInformationPopup.java
License:Open Source License
/** * @param snapPosition one of the SNAP_POSITION_* constants * @return the location in display coordinates or <code>null</code> iff not visible *///from w w w.j a v a 2 s. c om private Point computePopupLocation(int snapPosition) { if (fPopup == null || fPopup.isDisposed()) { return null; } switch (snapPosition) { case SNAP_POSITION_LOWER_RIGHT: { StyledText eWidget = fEditor.getViewer().getTextWidget(); Rectangle eBounds = eWidget.getClientArea(); Point eLowerRight = eWidget.toDisplay(eBounds.x + eBounds.width, eBounds.y + eBounds.height); Point pSize = getExtent(); return new Point(eLowerRight.x - pSize.x - 5, eLowerRight.y - pSize.y - 5); } case SNAP_POSITION_UNDER_RIGHT_FIELD: case SNAP_POSITION_OVER_RIGHT_FIELD: { LinkedPosition position = fRenameLinkedMode.getCurrentLinkedPosition(); if (position == null) { return null; } ISourceViewer viewer = fEditor.getViewer(); ITextViewerExtension5 viewer5 = (ITextViewerExtension5) viewer; int widgetOffset = viewer5.modelOffset2WidgetOffset(position.offset + position.length); StyledText textWidget = viewer.getTextWidget(); Point pos = textWidget.getLocationAtOffset(widgetOffset); Point pSize = getExtent(); if (snapPosition == SNAP_POSITION_OVER_RIGHT_FIELD) { pos.y -= pSize.y + GAP; } else { pos.y += textWidget.getLineHeight(widgetOffset) + GAP; } pos.x += GAP; Point dPos = textWidget.toDisplay(pos); Rectangle displayBounds = textWidget.getDisplay().getClientArea(); Rectangle dPopupRect = Geometry.createRectangle(dPos, pSize); Geometry.moveInside(dPopupRect, displayBounds); return new Point(dPopupRect.x, dPopupRect.y); } case SNAP_POSITION_UNDER_LEFT_FIELD: case SNAP_POSITION_OVER_LEFT_FIELD: default: // same as SNAP_POSITION_UNDER_LEFT_FIELD { LinkedPosition position = fRenameLinkedMode.getCurrentLinkedPosition(); if (position == null) { return null; } ISourceViewer viewer = fEditor.getViewer(); ITextViewerExtension5 viewer5 = (ITextViewerExtension5) viewer; int widgetOffset = viewer5.modelOffset2WidgetOffset(position.offset/* + position.length */); StyledText textWidget = viewer.getTextWidget(); Point pos = textWidget.getLocationAtOffset(widgetOffset); Point pSize = getExtent(); pSize.y += HAH + 1; pos.x -= HAO; if (snapPosition == SNAP_POSITION_OVER_LEFT_FIELD) { pos.y -= pSize.y; } else { pos.y += textWidget.getLineHeight(widgetOffset); } Point dPos = textWidget.toDisplay(pos); Rectangle displayBounds = textWidget.getDisplay().getClientArea(); Rectangle dPopupRect = Geometry.createRectangle(dPos, pSize); Geometry.moveInside(dPopupRect, displayBounds); return new Point(dPopupRect.x, dPopupRect.y); } } }
From source file:com.redhat.ceylon.eclipse.code.refactor.RefactorInformationPopup.java
License:Open Source License
/** * @param snapPosition one of the SNAP_POSITION_* constants * @return the location in display coordinates or <code>null</code> iff not visible *///from w ww. j av a2s. co m private Point computePopupLocation(int snapPosition) { if (fPopup == null || fPopup.isDisposed()) return null; switch (snapPosition) { case SNAP_POSITION_LOWER_RIGHT: { StyledText eWidget = fEditor.getCeylonSourceViewer().getTextWidget(); Rectangle eBounds = eWidget.getClientArea(); Point eLowerRight = eWidget.toDisplay(eBounds.x + eBounds.width, eBounds.y + eBounds.height); Point pSize = getExtent(); return new Point(eLowerRight.x - pSize.x - 5, eLowerRight.y - pSize.y - 5); } case SNAP_POSITION_UNDER_RIGHT_FIELD: case SNAP_POSITION_OVER_RIGHT_FIELD: { LinkedPosition position = fLinkedMode.getCurrentLinkedPosition(); if (position == null) return null; ISourceViewer viewer = fEditor.getCeylonSourceViewer(); ITextViewerExtension5 viewer5 = (ITextViewerExtension5) viewer; int widgetOffset = viewer5.modelOffset2WidgetOffset(position.offset + position.length); StyledText textWidget = viewer.getTextWidget(); Point pos = textWidget.getLocationAtOffset(widgetOffset); Point pSize = getExtent(); if (snapPosition == SNAP_POSITION_OVER_RIGHT_FIELD) { pos.y -= pSize.y + GAP; } else { pos.y += textWidget.getLineHeight(widgetOffset) + GAP; } pos.x += GAP; Point dPos = textWidget.toDisplay(pos); Rectangle displayBounds = textWidget.getDisplay().getClientArea(); Rectangle dPopupRect = Geometry.createRectangle(dPos, pSize); Geometry.moveInside(dPopupRect, displayBounds); return new Point(dPopupRect.x, dPopupRect.y); } case SNAP_POSITION_UNDER_LEFT_FIELD: case SNAP_POSITION_OVER_LEFT_FIELD: default: // same as SNAP_POSITION_UNDER_LEFT_FIELD { LinkedPosition position = fLinkedMode.getCurrentLinkedPosition(); if (position == null) return null; ISourceViewer viewer = fEditor.getCeylonSourceViewer(); ITextViewerExtension5 viewer5 = (ITextViewerExtension5) viewer; int widgetOffset = viewer5.modelOffset2WidgetOffset(position.offset/* + position.length*/); StyledText textWidget = viewer.getTextWidget(); Point pos = textWidget.getLocationAtOffset(widgetOffset); Point pSize = getExtent(); pSize.y += HAH + 1; pos.x -= HAO; if (snapPosition == SNAP_POSITION_OVER_LEFT_FIELD) { pos.y -= pSize.y; } else { pos.y += textWidget.getLineHeight(widgetOffset); } Point dPos = textWidget.toDisplay(pos); Rectangle displayBounds = textWidget.getDisplay().getClientArea(); Rectangle dPopupRect = Geometry.createRectangle(dPos, pSize); Geometry.moveInside(dPopupRect, displayBounds); return new Point(dPopupRect.x, dPopupRect.y); } } }
From source file:de.walware.ecommons.ui.dialogs.ToolPopup.java
License:Open Source License
protected void open(final Shell parent, final Rectangle position) { create(parent);/*from w w w . j a v a 2 s . co m*/ final Point size = fShell.getSize(); final Display display = fShell.getDisplay(); final Monitor monitor = DialogUtil.getClosestMonitor(display, position); final Rectangle clientArea = monitor.getClientArea(); final Rectangle bounds = new Rectangle(position.x, position.y - size.y, size.x, size.y); if (bounds.y < 0) { bounds.y = position.y + position.height; } Geometry.moveInside(bounds, clientArea); fShell.setBounds(bounds); selectTab(getBestTab()); fShell.open(); }
From source file:ext.org.eclipse.jdt.internal.ui.refactoring.reorg.RenameInformationPopup.java
License:Open Source License
/** * @param snapPosition one of the SNAP_POSITION_* constants * @return the location in display coordinates or <code>null</code> iff not visible *//*from w w w. j ava2s . c o m*/ private Point computePopupLocation(int snapPosition) { if (fPopup == null || fPopup.isDisposed()) return null; switch (snapPosition) { case SNAP_POSITION_LOWER_RIGHT: { StyledText eWidget = fEditor.getViewer().getTextWidget(); Rectangle eBounds = eWidget.getClientArea(); Point eLowerRight = eWidget.toDisplay(eBounds.x + eBounds.width, eBounds.y + eBounds.height); Point pSize = getExtent(); return new Point(eLowerRight.x - pSize.x - 5, eLowerRight.y - pSize.y - 5); } case SNAP_POSITION_UNDER_RIGHT_FIELD: case SNAP_POSITION_OVER_RIGHT_FIELD: { LinkedPosition position = fRenameLinkedMode.getCurrentLinkedPosition(); if (position == null) return null; ISourceViewer viewer = fEditor.getViewer(); ITextViewerExtension5 viewer5 = (ITextViewerExtension5) viewer; int widgetOffset = viewer5.modelOffset2WidgetOffset(position.offset + position.length); StyledText textWidget = viewer.getTextWidget(); Point pos = textWidget.getLocationAtOffset(widgetOffset); Point pSize = getExtent(); if (snapPosition == SNAP_POSITION_OVER_RIGHT_FIELD) { pos.y -= pSize.y + GAP; } else { pos.y += textWidget.getLineHeight(widgetOffset) + GAP; } pos.x += GAP; Point dPos = textWidget.toDisplay(pos); Rectangle displayBounds = textWidget.getDisplay().getClientArea(); Rectangle dPopupRect = Geometry.createRectangle(dPos, pSize); Geometry.moveInside(dPopupRect, displayBounds); return new Point(dPopupRect.x, dPopupRect.y); } case SNAP_POSITION_UNDER_LEFT_FIELD: case SNAP_POSITION_OVER_LEFT_FIELD: default: // same as SNAP_POSITION_UNDER_LEFT_FIELD { LinkedPosition position = fRenameLinkedMode.getCurrentLinkedPosition(); if (position == null) return null; ISourceViewer viewer = fEditor.getViewer(); ITextViewerExtension5 viewer5 = (ITextViewerExtension5) viewer; int widgetOffset = viewer5.modelOffset2WidgetOffset(position.offset/* + position.length*/); StyledText textWidget = viewer.getTextWidget(); Point pos = textWidget.getLocationAtOffset(widgetOffset); Point pSize = getExtent(); pSize.y += HAH + 1; pos.x -= HAO; if (snapPosition == SNAP_POSITION_OVER_LEFT_FIELD) { pos.y -= pSize.y; } else { pos.y += textWidget.getLineHeight(widgetOffset); } Point dPos = textWidget.toDisplay(pos); Rectangle displayBounds = textWidget.getDisplay().getClientArea(); Rectangle dPopupRect = Geometry.createRectangle(dPos, pSize); Geometry.moveInside(dPopupRect, displayBounds); return new Point(dPopupRect.x, dPopupRect.y); } } }
From source file:org.eclipse.cdt.internal.ui.refactoring.rename.RenameInformationPopup.java
License:Open Source License
/** * @param snapPosition one of the SNAP_POSITION_* constants * @return the location in display coordinates or <code>null</code> iff not visible *//* w w w.j a va 2s . c om*/ private Point computePopupLocation(int snapPosition) { if (fPopup == null || fPopup.isDisposed()) return null; switch (snapPosition) { case SNAP_POSITION_LOWER_RIGHT: { StyledText eWidget = fEditor.getViewer().getTextWidget(); Rectangle eBounds = eWidget.getClientArea(); Point eLowerRight = eWidget.toDisplay(eBounds.x + eBounds.width, eBounds.y + eBounds.height); Point pSize = getExtent(); return new Point(eLowerRight.x - pSize.x - 5, eLowerRight.y - pSize.y - 5); } case SNAP_POSITION_UNDER_RIGHT_FIELD: case SNAP_POSITION_OVER_RIGHT_FIELD: { LinkedPosition position = fRenameLinkedMode.getCurrentLinkedPosition(); if (position == null) return null; ISourceViewer viewer = fEditor.getViewer(); ITextViewerExtension5 viewer5 = (ITextViewerExtension5) viewer; int widgetOffset = viewer5.modelOffset2WidgetOffset(position.offset + position.length); StyledText textWidget = viewer.getTextWidget(); Point pos = textWidget.getLocationAtOffset(widgetOffset); Point pSize = getExtent(); if (snapPosition == SNAP_POSITION_OVER_RIGHT_FIELD) { pos.y -= pSize.y + GAP; } else { pos.y += textWidget.getLineHeight(widgetOffset) + GAP; } pos.x += GAP; Point dPos = textWidget.toDisplay(pos); Rectangle displayBounds = textWidget.getDisplay().getClientArea(); Rectangle dPopupRect = Geometry.createRectangle(dPos, pSize); Geometry.moveInside(dPopupRect, displayBounds); return new Point(dPopupRect.x, dPopupRect.y); } case SNAP_POSITION_UNDER_LEFT_FIELD: case SNAP_POSITION_OVER_LEFT_FIELD: default: // same as SNAP_POSITION_UNDER_LEFT_FIELD { LinkedPosition position = fRenameLinkedMode.getCurrentLinkedPosition(); if (position == null) return null; ISourceViewer viewer = fEditor.getViewer(); ITextViewerExtension5 viewer5 = (ITextViewerExtension5) viewer; int widgetOffset = viewer5.modelOffset2WidgetOffset(position.offset/* + position.length*/); StyledText textWidget = viewer.getTextWidget(); Point pos = textWidget.getLocationAtOffset(widgetOffset); Point pSize = getExtent(); pSize.y += HAH + 1; pos.x -= HAO; if (snapPosition == SNAP_POSITION_OVER_LEFT_FIELD) { pos.y -= pSize.y; } else { pos.y += textWidget.getLineHeight(widgetOffset); } Point dPos = textWidget.toDisplay(pos); Rectangle displayBounds = textWidget.getDisplay().getClientArea(); Rectangle dPopupRect = Geometry.createRectangle(dPos, pSize); Geometry.moveInside(dPopupRect, displayBounds); return new Point(dPopupRect.x, dPopupRect.y); } } }
From source file:org.eclipse.php.refactoring.ui.rename.RenameInformationPopup.java
License:Open Source License
/** * @param snapPosition//from w ww . ja v a2 s . com * one of the SNAP_POSITION_* constants * @return the location in display coordinates or <code>null</code> iff not * visible */ private Point computePopupLocation(int snapPosition) { if (fPopup == null || fPopup.isDisposed()) return null; switch (snapPosition) { case SNAP_POSITION_LOWER_RIGHT: { StyledText eWidget = fEditor.getTextViewer().getTextWidget(); Rectangle eBounds = eWidget.getClientArea(); Point eLowerRight = eWidget.toDisplay(eBounds.x + eBounds.width, eBounds.y + eBounds.height); Point pSize = getExtent(); return new Point(eLowerRight.x - pSize.x - 5, eLowerRight.y - pSize.y - 5); } case SNAP_POSITION_UNDER_RIGHT_FIELD: case SNAP_POSITION_OVER_RIGHT_FIELD: { LinkedPosition position = fRenameLinkedMode.getCurrentLinkedPosition(); if (position == null) return null; ISourceViewer viewer = fEditor.getTextViewer(); ITextViewerExtension5 viewer5 = (ITextViewerExtension5) viewer; int widgetOffset = viewer5.modelOffset2WidgetOffset(position.offset + position.length); StyledText textWidget = viewer.getTextWidget(); Point pos = textWidget.getLocationAtOffset(widgetOffset); Point pSize = getExtent(); if (snapPosition == SNAP_POSITION_OVER_RIGHT_FIELD) { pos.y -= pSize.y + GAP; } else { pos.y += textWidget.getLineHeight(widgetOffset) + GAP; } pos.x += GAP; Point dPos = textWidget.toDisplay(pos); Rectangle displayBounds = textWidget.getDisplay().getClientArea(); Rectangle dPopupRect = Geometry.createRectangle(dPos, pSize); Geometry.moveInside(dPopupRect, displayBounds); return new Point(dPopupRect.x, dPopupRect.y); } case SNAP_POSITION_UNDER_LEFT_FIELD: case SNAP_POSITION_OVER_LEFT_FIELD: default: // same as SNAP_POSITION_UNDER_LEFT_FIELD { LinkedPosition position = fRenameLinkedMode.getCurrentLinkedPosition(); if (position == null) return null; ISourceViewer viewer = fEditor.getTextViewer(); ITextViewerExtension5 viewer5 = (ITextViewerExtension5) viewer; int widgetOffset = viewer5.modelOffset2WidgetOffset(position.offset/* + position.length */); StyledText textWidget = viewer.getTextWidget(); Point pos = textWidget.getLocationAtOffset(widgetOffset); Point pSize = getExtent(); pSize.y += HAH + 1; pos.x -= HAO; if (snapPosition == SNAP_POSITION_OVER_LEFT_FIELD) { pos.y -= pSize.y; } else { pos.y += textWidget.getLineHeight(widgetOffset); } Point dPos = textWidget.toDisplay(pos); Rectangle displayBounds = textWidget.getDisplay().getClientArea(); Rectangle dPopupRect = Geometry.createRectangle(dPos, pSize); Geometry.moveInside(dPopupRect, displayBounds); return new Point(dPopupRect.x, dPopupRect.y); } } }
From source file:org.eclipse.ui.internal.dnd.DragBorder.java
License:Open Source License
/** * Move the border (and its 'contained' control to a new position. The new * position will be adjusted to lie entirely within the client area of the * <code>clientControl</code>. * // ww w. j a va2s. co m * @param newPos The new position for the border * @param alignment The location of the cursor relative to the border being dragged. * Current implementation only recognizes SWT.TOP & SWT.BOTTOM (which implies SWT.LEFT) * and SWT.CENTER (which centers teh dragged border on the cursor. */ public void setLocation(Point newPos, int alignment) { // Move the border but ensure that it is still inside the Client area if (alignment == SWT.CENTER) { Point size = border.getSize(); border.setLocation(newPos.x - (size.x / 2), newPos.y - (size.y / 2)); } else if (alignment == SWT.TOP) { border.setLocation(newPos.x, newPos.y); } else { border.setLocation(newPos.x, newPos.y - border.getSize().y); } // Force the control to remain inside the shell Rectangle bb = border.getBounds(); Rectangle cr = clientControl.getClientArea(); Geometry.moveInside(bb, cr); // Ensure that the controls are the 'topmost' controls border.moveAbove(null); dragControl.moveAbove(null); // OK, now move the drag control and the border to their new locations dragControl.setLocation(bb.x + 1, bb.y + 1); border.setBounds(bb); }
From source file:org.eclipse.xtext.ui.refactoring.ui.RenameRefactoringPopup.java
License:Open Source License
protected Point computePopupLocation() { if (popup == null || popup.isDisposed()) return null; LinkedPosition position = renameLinkedMode.getCurrentLinkedPosition(); if (position == null) return null; ISourceViewer viewer = editor.getInternalSourceViewer(); ITextViewerExtension5 viewer5 = (ITextViewerExtension5) viewer; int widgetOffset = viewer5.modelOffset2WidgetOffset(position.offset); StyledText textWidget = viewer.getTextWidget(); Point pos = textWidget.getLocationAtOffset(widgetOffset); Point pSize = getExtent();/*from w ww . j a va2 s . c o m*/ pSize.y += HAH + 1; pos.x -= HAO; pos.y += textWidget.getLineHeight(widgetOffset); Point dPos = textWidget.toDisplay(pos); Rectangle displayBounds = textWidget.getDisplay().getClientArea(); Rectangle dPopupRect = Geometry.createRectangle(dPos, pSize); Geometry.moveInside(dPopupRect, displayBounds); return new Point(dPopupRect.x, dPopupRect.y); }
From source file:org.pentaho.di.ui.core.gui.WindowProperty.java
License:Apache License
/** * @param constrainee/*from ww w .j ava 2 s . c om*/ * @param container */ private void constrainRectangleToContainer(Rectangle constrainee, Rectangle container) { Point originalSize = Geometry.getSize(constrainee); Point containerSize = Geometry.getSize(container); Point oversize = Geometry.subtract(originalSize, containerSize); if (oversize.x > 0) { constrainee.width = originalSize.x - oversize.x; } if (oversize.y > 0) { constrainee.height = originalSize.y - oversize.y; } // Detect if the dialog was positioned outside the container Geometry.moveInside(constrainee, container); }