java.awt.Rectangle.grow()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(120)

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

Rectangle.grow介绍

[英]Resizes the Rectangle both horizontally and vertically.

This method modifies the Rectangle so that it is h units larger on both the left and right side, and v units larger at both the top and bottom.

The new Rectangle has (x - h, y - v) as its top-left corner, a width of width + 2h, and a height of height + 2v.

If negative values are supplied for h and v, the size of the Rectangle decreases accordingly. The grow method does not check whether the resulting values of width and height are non-negative.
[中]水平和垂直调整Rectangle的大小。
此方法修改Rectangle,使其在左侧和右侧都大h个单位,在顶部和底部都大v个单位。
Rectangle的左上角有(x - hy - v),宽[$7$][$8$]2h,高[$10$][$11$]2v
如果为hv提供负值,Rectangle的大小相应减小。grow方法不会检查widthheight的结果值是否为非负值。

代码示例

代码示例来源:origin: nodebox/nodebox

private static void growHitRectangle(Rectangle r) {
  r.grow(2, 2);
}

代码示例来源:origin: nodebox/nodebox

private static void paintTooltip(Graphics2D g, Point2D point, String text) {
  FontMetrics fontMetrics = g.getFontMetrics();
  int textWidth = fontMetrics.stringWidth(text);
  int verticalOffset = 10;
  Rectangle r = new Rectangle((int) point.getX(), (int) point.getY() + verticalOffset, textWidth, fontMetrics.getHeight());
  r.grow(4, 3);
  g.setColor(TOOLTIP_STROKE_COLOR);
  g.drawRoundRect(r.x, r.y, r.width, r.height, 8, 8);
  g.setColor(TOOLTIP_BACKGROUND_COLOR);
  g.fillRoundRect(r.x, r.y, r.width, r.height, 8, 8);
  g.setColor(TOOLTIP_TEXT_COLOR);
  g.drawString(text, (float) point.getX(), (float) point.getY() + fontMetrics.getAscent() + verticalOffset);
}

代码示例来源:origin: RaiMan/SikuliX2

@Override
 public void paintComponent(Graphics g) {
  super.paintComponent(g);
  Graphics2D g2d = (Graphics2D) g;
  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
      RenderingHints.VALUE_ANTIALIAS_ON);
  Stroke pen = new BasicStroke((float) stroke);
  g2d.setStroke(pen);
  Rectangle r = new Rectangle(getActualBounds());
  r.grow(-(stroke-1), -(stroke-1));
  g2d.translate(stroke-1, stroke-1);
  Ellipse2D.Double ellipse = new Ellipse2D.Double(0, 0, r.width - 1, r.height - 1);
  g2d.draw(ellipse);
 }
}

代码示例来源:origin: nodebox/nodebox

@Override
  protected void paintComponent(Graphics g) {
    Rectangle r = g.getClipBounds();
    if (ColorControl.this.isEnabled()) {
      g.setColor(Color.darkGray);
    } else {
      g.setColor(Theme.PORT_LABEL_BACKGROUND);
    }
    g.fillRect(r.x, r.y, r.width - 1, r.height - 1);
    if (ColorControl.this.isEnabled()) {
      r.grow(1, 1);
    } else {
      r.grow(-5, -5);
    }
    g.setColor(color);
    g.fillRect(r.x, r.y, r.width - 1, r.height - 1);
  }
}

代码示例来源:origin: ron190/jsql-injection

@Override
  public void repaint(Rectangle r) {
    JScrollIndicator scrollIndicator = JScrollIndicator.this;
    // Fix #15956: NullPointerException on convertRectangle()
    try {
      Rectangle rect = SwingUtilities.convertRectangle(this, r, scrollIndicator);
      rect.grow(1, 1);
      // ensure for a translucent thumb, that the view is first painted
      scrollIndicator.repaint(rect);
    } catch (NullPointerException e) {
      LOGGER.error(e.getMessage(), e);
    }
  }
}

代码示例来源:origin: RaiMan/SikuliX2

public Element grow(int hori, int verti) {
 Rectangle r = getRectangle();
 r.grow(hori, verti);
 return new Element(r);
}

代码示例来源:origin: RaiMan/SikuliX2

@Override
public void updateComponent() {
 fm = getFontMetrics(font);
 textBox.setSize(fm.stringWidth(text),fm.getHeight());
 textBox.grow(PADDING_X, PADDING_Y);
 setLocationRelativeToRegion(getTarget(), layout);
}

代码示例来源:origin: nodebox/nodebox

int vMargin = 3;
Rectangle r = new Rectangle(0, 0, getWidth() - 1, getHeight() - 1);
r.grow(-hMargin, -vMargin);

代码示例来源:origin: geotools/geotools

/**
 * This method is responsible for computing the raster bounds of the final mosaic.
 *
 * @throws TransformException In case transformation fails during the process.
 */
private void initRasterBounds() throws TransformException {
  final GeneralEnvelope tempRasterBounds = CRS.transform(finalWorldToGridCorner, targetBBox);
  rasterBounds = tempRasterBounds.toRectangle2D().getBounds();
  // SG using the above may lead to problems since the reason is that may be a little (1 px)
  // bigger
  // than what we need. The code below is a bit better since it uses a proper logic (see
  // GridEnvelope
  // Javadoc)
  // rasterBounds = new GridEnvelope2D(new Envelope2D(tempRasterBounds),
  // PixelInCell.CELL_CORNER);
  if (rasterBounds.width == 0) {
    rasterBounds.width++;
  }
  if (rasterBounds.height == 0) {
    rasterBounds.height++;
  }
  if (oversampledRequest) {
    rasterBounds.grow(2, 2);
  }
}

代码示例来源:origin: RaiMan/SikuliX2

bounds.grow(10, 10);
spotlight.setBounds(bounds);
cc.grow(7, 0);
circle = new SxCircle(new Element(cc));
circle.setForeground(Color.white);

代码示例来源:origin: RaiMan/SikuliX2

@Override
public void updateComponent() {
 textArea.setText(text);
 textArea.setLocation(PADDING_X, PADDING_Y);
 Rectangle rect = textArea.getBounds();
 rect.grow(PADDING_X, PADDING_Y);
 rbox.setBounds(rect);
 makeComponent();
 triangle.setForeground(colorBack);
 rbox.setForeground(colorBack);
 if (targetRegion != null) {
  super.setLocationRelativeToRegion(targetRegion, layout);
 }
}

代码示例来源:origin: RaiMan/SikuliX2

@Override
public void updateComponent() {
 setForeground(colorFront);
 Rectangle dirtyBounds = getBounds();
 if (from != null && to != null) {
  source = from.getCenter();
  destination = to.getCenter();
 }
 Rectangle r = new Rectangle(getSource());
 r.add(getDestination());
 r.grow(10, 10);
 setActualBounds(r);
 dirtyBounds.add(getBounds());
 if (getTopLevelAncestor() != null) {
  getTopLevelAncestor().repaint(dirtyBounds.x, dirtyBounds.y, dirtyBounds.width, dirtyBounds.height);
 }
 if (hasComponents) {
  updateVisibility();
 }
}

代码示例来源:origin: RaiMan/SikuliX2

@Override
 void update() {
  if (side == Layout.FOLLOWERS) {
   // set to the total bounds of the other followers
   // first set its bounds to be equal to the targets, so that
   // its current bounds won't have effect on the calculation
   // of the total bounds
   setBounds(getTargetComponent().getBounds());
   // then this call will gives us the total bounds of the
   // rest of the followers
   Rectangle totalBounds = getTargetComponent().getFollowerBounds();
   totalBounds.grow(5, 5);
   setBounds(totalBounds);
  } else {
   setLocationRelativeToRegion(getTargetComponent().getRegion(), side);
  }
  super.update();
 }
}

代码示例来源:origin: geotools/geotools

sourceArea.grow(2, 2);

代码示例来源:origin: geotools/geotools

/**
 * This method is responsible for computing the raster bounds of the final mosaic.
 *
 * @throws TransformException In case transformation fails during the process.
 */
private void initRasterBounds() throws TransformException {
  final GeneralEnvelope tempRasterBounds = CRS.transform(finalWorldToGridCorner, mosaicBBox);
  rasterBounds = tempRasterBounds.toRectangle2D().getBounds();
  // SG using the above may lead to problems since the reason is that may be a little (1 px)
  // bigger
  // than what we need. The code below is a bit better since it uses a proper logic (see
  // GridEnvelope
  // Javadoc)
  rasterBounds =
      new GridEnvelope2D(new Envelope2D(tempRasterBounds), PixelInCell.CELL_CORNER);
  if (rasterBounds.width == 0) rasterBounds.width++;
  if (rasterBounds.height == 0) rasterBounds.height++;
  if (oversampledRequest) rasterBounds.grow(2, 2);
  // make sure the expanded bounds are still within the reach of the granule bounds, not
  // larger
  // (the above expansion might have made them so)
  final GeneralEnvelope levelRasterArea_ =
      CRS.transform(
          finalWorldToGridCorner, request.spatialRequestHelper.getCoverageBBox());
  final GridEnvelope2D levelRasterArea =
      new GridEnvelope2D(new Envelope2D(levelRasterArea_), PixelInCell.CELL_CORNER);
  XRectangle2D.intersect(levelRasterArea, rasterBounds, rasterBounds);
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-xml-xam-ui

public void focusGained(FocusEvent e) {
  Rectangle rect = getBounds();
  rect.grow(0, FONT_SIZE);
  scrollRectToVisible(rect);
}

代码示例来源:origin: com.sikulix/sikulixapi

@Override
public void updateComponent() {
 fm = getFontMetrics(font);
 textBox.setSize(fm.stringWidth(text),fm.getHeight());
 textBox.grow(PADDING_X, PADDING_Y);
 setLocationRelativeToRegion(getTarget(), layout);
}

代码示例来源:origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

@Override
protected Rectangle basicGetBounds() {
  Shape bounds = getOwner().getBounds();
  if (getOwner().get(TRANSFORM) != null) {
    bounds = getOwner().get(TRANSFORM).createTransformedShape(bounds);
  }
  bounds = view.getDrawingToViewTransform().createTransformedShape(bounds);
  Rectangle r = bounds.getBounds();
  r.grow(2, 2);
  return r;
}

代码示例来源:origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

private void fireAreaInvalidated(BezierPath.Node v) {
  Rectangle2D.Double dr = new Rectangle2D.Double(v.x[0], v.y[0], 0, 0);
  for (int i = 1; i < 3; i++) {
    dr.add(v.x[i], v.y[i]);
  }
  Rectangle vr = view.drawingToView(dr);
  vr.grow(getHandlesize(), getHandlesize());
  fireAreaInvalidated(vr);
}

代码示例来源:origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

@Override
public void trackStart(Point anchor, int modifiersEx) {
  oldValue = getOwner().get(ORIENTATION);
  
  centerBox = view.drawingToView(getOwner().getBounds());
  centerBox.grow(centerBox.width / -3, centerBox.height / -3);
}

相关文章