org.eclipse.jface.util.Geometry类的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(11.0k)|赞(0)|评价(0)|浏览(105)

本文整理了Java中org.eclipse.jface.util.Geometry类的一些代码示例,展示了Geometry类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Geometry类的具体详情如下:
包路径:org.eclipse.jface.util.Geometry
类名称:Geometry

Geometry介绍

[英]Contains static methods for performing simple geometric operations on the SWT geometry classes.
[中]包含用于对SWT几何体类执行简单几何体操作的静态方法。

代码示例

代码示例来源:origin: pentaho/pentaho-kettle

/**
 * @param constrainee
 * @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 );
}

代码示例来源:origin: pentaho/pentaho-kettle

Rectangle resizedRect = Geometry.copy( shellSize );
constrainRectangleToContainer( resizedRect, entireClientArea );

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jface.text

/**
 * 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;
}

代码示例来源:origin: org.eclipse.xtext/ui

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();
  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);
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.ui.workbench

public void addEndRect(Control ctrl) {
  Rectangle ctrlBounds = ctrl.getBounds();
  Rectangle endRect = Geometry.toDisplay(ctrl.getParent(), ctrlBounds);
  addEndRect(endRect);
}

代码示例来源:origin: org.eclipse.rap/org.eclipse.rap.jface

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]

代码示例来源:origin: org.eclipse.platform/org.eclipse.jface.text

location= Geometry.getLocation(bounds);
    size= Geometry.getSize(bounds);
  size= Geometry.max(size, sizeConstraints);
if (fEnforceAsMaximalSize)
  size= Geometry.min(size, sizeConstraints);
Rectangle controlBounds= Geometry.createRectangle(location, size);
cropToClosestMonitor(controlBounds);
location= Geometry.getLocation(controlBounds);
size= Geometry.getSize(controlBounds);
informationControl.setLocation(location);
informationControl.setSize(size.x, size.y);

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jface.text

/**
 * Determines the graphical area covered by the given text region.
 *
 * @param region the region whose graphical extend must be computed
 * @return the graphical extend of the given region
 */
private Rectangle computeArea(IRegion region) {
  int start= 0;
  int end= 0;
  IRegion widgetRegion= modelRange2WidgetRange(region);
  if (widgetRegion != null) {
    start= widgetRegion.getOffset();
    end= widgetRegion.getOffset() + widgetRegion.getLength();
  }
  StyledText styledText= fTextViewer.getTextWidget();
  Rectangle bounds;
  if (end > 0 && start < end)
    bounds= styledText.getTextBounds(start, end - 1);
  else {
    Point loc= styledText.getLocationAtOffset(start);
    bounds= new Rectangle(loc.x, loc.y, 0, styledText.getLineHeight(start));
  }
  
  Rectangle clientArea= styledText.getClientArea();
  Geometry.moveInside(bounds, clientArea);
  return bounds;
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.jface.text

Rectangle subjectAreaDisplayRelative= Geometry.toDisplay(fSubjectControl, subjectArea);
  Geometry.set(controlSize, Geometry.getSize(bestBounds));
return Geometry.getLocation(bestBounds);

代码示例来源:origin: org.eclipse.platform/org.eclipse.e4.ui.workbench.renderers.swt

Monitor closestMonitor = Util.getClosestMonitor(display, Geometry.centerPoint(modelBounds));
Rectangle displayBounds = closestMonitor.getClientArea();
if (!modelBounds.intersects(displayBounds)) {
  Geometry.moveInside(modelBounds, displayBounds);

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jface.text

/**
 * 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)));
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.jface.text

int endOffset= modelRange2ClosestWidgetRange(endRegion).getOffset();
Point clientAreaOrigin= new Point(fTextWidget.getHorizontalPixel(), fTextWidget.getTopPixel());
Point startLocation= Geometry.add(clientAreaOrigin, fTextWidget.getLocationAtOffset(startOffset));
int averageCharWidth= getAverageCharWidth();
startLocation.x += startVirtuals * averageCharWidth;
Point endLocation= Geometry.add(clientAreaOrigin, fTextWidget.getLocationAtOffset(endOffset));
endLocation.x += endVirtuals * averageCharWidth;
endLocation.y += fTextWidget.getLineHeight(endOffset);
validateSelectionRange(widgetSelection);
if (widgetSelection[0] >= 0) {
  fTextWidget.setBlockSelectionBounds(Geometry.createRectangle(startLocation, Geometry.subtract(endLocation, startLocation)));
  selectionChanged(startOffset, widgetLength);

代码示例来源:origin: org.eclipse.platform/org.eclipse.jface.text

Rectangle totalBounds= Geometry.copy(iControlBounds);
if (blowUp && isReplaceInProgress()) {
  Geometry.expand(totalBounds, margin, margin, margin, margin);

代码示例来源:origin: org.eclipse.platform/org.eclipse.jface

/**
 * Returns the distance from the point to the nearest edge of the given
 * rectangle. Returns negative values if the point lies outside the rectangle.
 *
 * @param boundary rectangle to test
 * @param toTest point to test
 * @return the distance between the given point and the nearest edge of the rectangle.
 * Returns positive values for points inside the rectangle and negative values for points
 * outside the rectangle.
 * @since 3.1
 */
public static int getDistanceFrom(Rectangle boundary, Point toTest) {
  int side = getClosestSide(boundary, toTest);
  return getDistanceFromEdge(boundary, toTest, side);
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.jface.text

/**
 * 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);
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jface

return nonWrappingLabelData.copy();
return GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).hint(Geometry.max(button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true), LayoutConstants.getMinButtonSize()));

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui

Geometry.createRectangle(LOCATIONS[0], pSize),
  Geometry.createRectangle(LOCATIONS[1], pSize),
  new Rectangle(LOCATIONS[2].x, LOCATIONS[2].y + HAH, pSize.x, pSize.y),
  Geometry.createRectangle(LOCATIONS[3], pSize),
  Geometry.createRectangle(LOCATIONS[4], pSize)
};
final Rectangle MOUSE_MOVE_SOURCE= new Rectangle(1000000, 0, 0, 0);

代码示例来源:origin: org.eclipse.platform/org.eclipse.jface

/**
 * Returns the edge of the given rectangle is closest to the given
 * point.
 *
 * @param boundary rectangle to test
 * @param toTest point to compare
 * @return one of SWT.LEFT, SWT.RIGHT, SWT.TOP, or SWT.BOTTOM
 *
 * @since 3.0
 */
public static int getClosestSide(Rectangle boundary, Point toTest) {
  int[] sides = new int[] { SWT.LEFT, SWT.RIGHT, SWT.TOP, SWT.BOTTOM };
  int closestSide = SWT.LEFT;
  int closestDistance = Integer.MAX_VALUE;
  for (int side : sides) {
    int distance = getDistanceFromEdge(boundary, toTest, side);
    if (distance < closestDistance) {
      closestDistance = distance;
      closestSide = side;
    }
  }
  return closestSide;
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.ui.workbench

/**
 * Returns the relative position of the given point (in display coordinates)
 * with respect to the given control. Returns one of SWT.LEFT, SWT.RIGHT, SWT.CENTER, SWT.TOP,
 * or SWT.BOTTOM if the point is on the control or SWT.DEFAULT if the point is not on the control.
 *
 * @param control control to perform hit detection on
 * @param toTest point to test, in display coordinates
 * @return
 */
public static int getRelativePosition(Control c, Point toTest) {
  Point p = c.toControl(toTest);
  Point e = c.getSize();
  if (p.x > e.x || p.y > e.y || p.x < 0 || p.y < 0) {
    return SWT.DEFAULT;
  }
  // first determine whether mouse position is in center of part
  int hmargin = Math.min(e.x / 3, MARGIN);
  int vmargin = Math.min(e.y / 3, MARGIN);
  Rectangle inner = new Rectangle(hmargin, vmargin, e.x - (hmargin * 2),
      e.y - (vmargin * 2));
  if (inner.contains(p)) {
    return SWT.CENTER;
  }
  return Geometry.getClosestSide(inner, p);
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.jface.text

/**
   * 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;
  }
}

相关文章