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

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

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

Rectangle.getWidth介绍

暂无

代码示例

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

private void renderWidgetText(Graphics2D graphics, Rectangle bounds, int itemId, Color color)
{
  if (itemId == -1)
  {
    return;
  }
  String text = itemId + "";
  FontMetrics fm = graphics.getFontMetrics();
  Rectangle2D textBounds = fm.getStringBounds(text, graphics);
  int textX = (int) (bounds.getX() + (bounds.getWidth() / 2) - (textBounds.getWidth() / 2));
  int textY = (int) (bounds.getY() + (bounds.getHeight() / 2) + (textBounds.getHeight() / 2));
  graphics.setColor(Color.BLACK);
  graphics.drawString(text, textX + 1, textY + 1);
  graphics.setColor(color);
  graphics.drawString(text, textX, textY);
}

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

private boolean isFrameCloseToRightEdge()
  {
    Rectangle screenBounds = getGraphicsConfiguration().getBounds();
    return Math.abs((getX() + getWidth()) - (screenBounds.getX() + screenBounds.getWidth())) <= SCREEN_EDGE_CLOSE_DISTANCE;
  }
}

代码示例来源:origin: org.apache.poi/poi

int getGradientSteps(Shape gradientShape) {
  Rectangle rect = gradientShape.getBounds();
  int lower = 1;
  int upper = (int)(Math.max(rect.getWidth(),rect.getHeight())/2.0);
  while (lower < upper-1) {
    int mid = lower + (upper - lower) / 2;
    BasicStroke bs = new BasicStroke(mid, capStyle, joinStyle);
    Area area = new Area(bs.createStrokedShape(gradientShape));
    if (area.isSingular()) {
      upper = mid;
    } else {
      lower = mid;
    }
  }
  return upper;
}

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

@Override
public void setBounds(int x, int y, int width, int height)
{
  if (containedInScreen)
  {
    Rectangle bounds = this.getGraphicsConfiguration().getBounds();
    width = Math.min(width, width - (int)bounds.getX() + x);
    x = Math.max(x, (int)bounds.getX());
    height = Math.min(height, height - (int)bounds.getY() + y);
    y = Math.max(y, (int)bounds.getY());
    width = Math.min(width, (int)(bounds.getX() + bounds.getWidth()) - x);
    height = Math.min(height, (int)(bounds.getY() + bounds.getHeight()) - y);
  }
  super.setBounds(x, y, width, height);
}

代码示例来源:origin: igniterealtime/Smack

public ImageTransmitter(DatagramSocket socket, InetAddress remoteHost, int remotePort, Rectangle area) {
  try {
    robot = new Robot();
    maxI = (int) Math.ceil(area.getWidth() / tileWidth);
    maxJ = (int) Math.ceil(area.getHeight() / tileWidth);
    tiles = new int[maxI][maxJ][tileWidth * tileWidth];
    this.area = area;
    this.socket = socket;
    localHost = socket.getLocalAddress();
    localPort = socket.getLocalPort();
    this.remoteHost = remoteHost;
    this.remotePort = remotePort;
    this.encoder = new DefaultEncoder();
    transmit = true;
  }
  catch (AWTException e) {
    LOGGER.log(Level.WARNING, "exception", e);
  }
}

代码示例来源:origin: cmusphinx/sphinx4

if (viewport != null) {
  Rectangle r = viewport.getViewRect();
  pos = (int) r.getX();
  length = (int) r.getWidth();
} else {
  pos = 0;

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

@Override
public void setLocation(int x, int y)
{
  if (containedInScreen)
  {
    Rectangle bounds = this.getGraphicsConfiguration().getBounds();
    x = Math.max(x, (int)bounds.getX());
    x = Math.min(x, (int)(bounds.getX() + bounds.getWidth() - this.getWidth()));
    y = Math.max(y, (int)bounds.getY());
    y = Math.min(y, (int)(bounds.getY() + bounds.getHeight() - this.getHeight()));
  }
  super.setLocation(x, y);
}

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

double magnificationX = rectangle2d.getWidth() / rect.getWidth();
double magnificationY = rectangle2d.getHeight() / rect.getHeight();
float magnification = (float) Math.min( 1, Math.min( magnificationX, magnificationY ) );

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

final boolean wouldExpandThroughEdge = getX() + newWindowWidth > screenBounds.getX() + screenBounds.getWidth();
int newWindowX = getX();
    newWindowX = (int)(screenBounds.getX() + screenBounds.getWidth()) - getWidth();

代码示例来源:origin: JetBrains/ideavim

@NotNull
private static List<EditorWindow> findWindowsInRow(@NotNull EditorWindow anchor,
                          @NotNull List<EditorWindow> windows, final boolean vertical) {
 final Rectangle anchorRect = getEditorWindowRectangle(anchor);
 if (anchorRect != null) {
  final List<EditorWindow> result = new ArrayList<>();
  final double coord = vertical ? anchorRect.getX() : anchorRect.getY();
  for (EditorWindow window : windows) {
   final Rectangle rect = getEditorWindowRectangle(window);
   if (rect != null) {
    final double min = vertical ? rect.getX() : rect.getY();
    final double max = min + (vertical ? rect.getWidth() : rect.getHeight());
    if (coord >= min && coord <= max) {
     result.add(window);
    }
   }
  }
  result.sort((window1, window2) -> {
   final Rectangle rect1 = getEditorWindowRectangle(window1);
   final Rectangle rect2 = getEditorWindowRectangle(window2);
   if (rect1 != null && rect2 != null) {
    final double diff = vertical ? (rect1.getY() - rect2.getY()) : (rect1.getX() - rect2.getX());
    return diff < 0 ? -1 : diff > 0 ? 1 : 0;
   }
   return 0;
  });
  return result;
 }
 return Collections.singletonList(anchor);
}

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

double magnificationX = rectangle2d.getWidth() / rect.getWidth();
double magnificationY = rectangle2d.getHeight() / rect.getHeight();
float magnification = (float) Math.min( 1, Math.min( magnificationX, magnificationY ) );

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

private void renderInventory(Graphics2D graphics)
{
  Widget inventoryWidget = client.getWidget(WidgetInfo.INVENTORY);
  if (inventoryWidget == null || inventoryWidget.isHidden())
  {
    return;
  }
  for (WidgetItem item : inventoryWidget.getWidgetItems())
  {
    Rectangle slotBounds = item.getCanvasBounds();
    String idText = "" + item.getId();
    FontMetrics fm = graphics.getFontMetrics();
    Rectangle2D textBounds = fm.getStringBounds(idText, graphics);
    int textX = (int) (slotBounds.getX() + (slotBounds.getWidth() / 2) - (textBounds.getWidth() / 2));
    int textY = (int) (slotBounds.getY() + (slotBounds.getHeight() / 2) + (textBounds.getHeight() / 2));
    graphics.setColor(new Color(255, 255, 255, 65));
    graphics.fill(slotBounds);
    graphics.setColor(Color.BLACK);
    graphics.drawString(idText, textX + 1, textY + 1);
    graphics.setColor(YELLOW);
    graphics.drawString(idText, textX, textY);
  }
}

代码示例来源:origin: stackoverflow.com

"Config " +
i,
(int) gc[i].getBounds().getWidth() +
"x" +
(int) gc[i].getBounds().getHeight() +
" " +
gc[i].getColorModel() +

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

private Point clipToRectangle(Point drawPoint, Rectangle mapDisplayRectangle)
  {
    int clippedX = drawPoint.getX();

    if (drawPoint.getX() < mapDisplayRectangle.getX())
    {
      clippedX = (int) mapDisplayRectangle.getX();
    }

    if (drawPoint.getX() > mapDisplayRectangle.getX() + mapDisplayRectangle.getWidth())
    {
      clippedX = (int) (mapDisplayRectangle.getX() + mapDisplayRectangle.getWidth());
    }

    int clippedY = drawPoint.getY();

    if (drawPoint.getY() < mapDisplayRectangle.getY())
    {
      clippedY = (int) mapDisplayRectangle.getY();
    }

    if (drawPoint.getY() > mapDisplayRectangle.getY() + mapDisplayRectangle.getHeight())
    {
      clippedY = (int) (mapDisplayRectangle.getY() + mapDisplayRectangle.getHeight());
    }

    return new Point(clippedX, clippedY);
  }
}

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

private GeneralPath makeEllipsePath(Diagram diagram) {
  if(points.size() != 4) return null;
  Rectangle bounds = makeIntoPath().getBounds();
  float xOff = (float) bounds.getWidth() * 0.5f * KAPPA;
  float yOff = (float) bounds.getHeight() * 0.5f * KAPPA;
  ShapePoint pointMid = new ShapePoint((float)bounds.getCenterX(), (float)bounds.getCenterY());
  ShapePoint left = new ShapePoint((float)bounds.getMinX(), (float)pointMid.getY());
  ShapePoint right = new ShapePoint((float)bounds.getMaxX(), (float)pointMid.getY());
  ShapePoint top = new ShapePoint((float)pointMid.getX(), (float)bounds.getMinY());
  ShapePoint bottom = new ShapePoint((float)pointMid.getX(), (float)bounds.getMaxY());
  GeneralPath path = new GeneralPath();
  path.moveTo(top.x, top.y);
  path.curveTo(top.x + xOff, top.y, right.x, right.y - yOff, right.x, right.y);
  path.curveTo(right.x, right.y + yOff, bottom.x + xOff, bottom.y, bottom.x, bottom.y);
  path.curveTo(bottom.x - xOff, bottom.y, left.x, left.y + yOff, left.x, left.y);
  path.curveTo(left.x, left.y - yOff, top.x - xOff, top.y, top.x, top.y);
  path.closePath();
  return path;
}

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

private void drawTooltip(Graphics2D graphics, WorldMapPoint worldPoint)
{
  String tooltip = worldPoint.getTooltip();
  Point drawPoint = mapWorldPointToGraphicsPoint(worldPoint.getWorldPoint());
  if (tooltip == null || tooltip.length() <= 0 || drawPoint == null)
  {
    return;
  }
  drawPoint = new Point(drawPoint.getX() + TOOLTIP_OFFSET_WIDTH, drawPoint.getY() + TOOLTIP_OFFSET_HEIGHT);
  graphics.setClip(client.getCanvas().getBounds());
  graphics.setColor(JagexColors.TOOLTIP_BACKGROUND);
  graphics.setFont(FontManager.getRunescapeFont());
  FontMetrics fm = graphics.getFontMetrics();
  int width = fm.stringWidth(tooltip);
  int height = fm.getHeight();
  Rectangle tooltipRect = new Rectangle(drawPoint.getX() - TOOLTIP_PADDING_WIDTH, drawPoint.getY() - TOOLTIP_PADDING_HEIGHT, width + TOOLTIP_PADDING_WIDTH * 2, height + TOOLTIP_PADDING_HEIGHT * 2);
  graphics.fillRect((int) tooltipRect.getX(), (int) tooltipRect.getY(), (int) tooltipRect.getWidth(), (int) tooltipRect.getHeight());
  graphics.setColor(JagexColors.TOOLTIP_BORDER);
  graphics.drawRect((int) tooltipRect.getX(), (int) tooltipRect.getY(), (int) tooltipRect.getWidth(), (int) tooltipRect.getHeight());
  graphics.setColor(JagexColors.TOOLTIP_TEXT);
  graphics.drawString(tooltip, drawPoint.getX(), drawPoint.getY() + height);
}

代码示例来源:origin: stackoverflow.com

graphics = (Graphics2D) offlineBuffer.getGraphics();
     graphics.setBackground(new Color(255, 255, 255, 0));
     Rectangle screen = transformationContext.getScreen();
     graphics.clearRect(0,0, (int)screen.getWidth(), (int)screen.getHeight());

代码示例来源:origin: org.apache.poi/poi

void createRaster() {
    ColorModel cm = getColorModel();
    raster = cm.createCompatibleWritableRaster((int)deviceBounds.getWidth(), (int)deviceBounds.getHeight());
    BufferedImage img = new BufferedImage(cm, raster, false, null);
    Graphics2D graphics = img.createGraphics();
    graphics.setRenderingHints(hints);
    graphics.translate(-deviceBounds.getX(), -deviceBounds.getY());
    graphics.transform(xform);
    Raster img2 = pCtx.getRaster(0, 0, gradientSteps, 1);
    int[] rgb = new int[cm.getNumComponents()];
    for (int i = gradientSteps-1; i>=0; i--) {
      img2.getPixel(i, 0, rgb);
      Color c = new Color(rgb[0],rgb[1],rgb[2]);
      if (rgb.length == 4) {
        // it doesn't work to use just a color with transparency ...
        graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, rgb[3]/255.0f));                           
      }
      graphics.setStroke(new BasicStroke(i+1, capStyle, joinStyle));
      graphics.setColor(c);
      graphics.draw(shape);
    }
    
    graphics.dispose();
  }
}

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

private Dimension getStartDimension() {
  double width;
  double height;
  width = pixelDimension.getWidth() / rescaleX;
  height = pixelDimension.getHeight() / rescaleY;
  return new Dimension((int) Math.round(width), (int) Math.round(height));
}

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

graphics.setClip(worldMapRect);
int widthInTiles = (int) Math.ceil(worldMapRect.getWidth() / pixelsPerTile);
int heightInTiles = (int) Math.ceil(worldMapRect.getHeight() / pixelsPerTile);
    int xTileOffset = x + widthInTiles / 2 - worldMapPosition.getX();
    int xPos = ((int) (xTileOffset * pixelsPerTile)) + (int) worldMapRect.getX();
    int yPos = (worldMapRect.height - (int) (yTileOffset * pixelsPerTile)) + (int) worldMapRect.getY();

相关文章