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

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

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

Rectangle.getX介绍

暂无

代码示例

代码示例来源: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: runelite/runelite

/**
 * Gets the upper-left coordinate of where the widget is being drawn
 * on the canvas.
 *
 * @return the upper-left coordinate of where this widget is drawn
 */
public Point getCanvasLocation()
{
  return new Point((int) canvasBounds.getX(), (int) canvasBounds.getY());
}

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

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

代码示例来源:origin: zgqq/mah

@Override
public void moveToRight() {
  Rectangle currentScreen = getCurrentScreen();
  int y = getY(currentScreen.getHeight());
  frame.setLocation((int) (currentScreen.getX() + currentScreen.getWidth() - getWindowWidth()), y);
}

代码示例来源:origin: org.scijava/scijava-ui-swing

public static void locateUpperRight(final Container component) {
  final int w = component.getWidth();
  final Rectangle bounds = getWorkSpaceBounds();
  final int x = (int) (bounds.getX() + bounds.getWidth() - w);
  final int y = (int) (bounds.getY());
  component.setLocation(x, y);
}

代码示例来源:origin: org.scijava/scijava-ui-swing

public static void locateLowerLeft(final Container component) {
  final int h = component.getHeight();
  final Rectangle bounds = getWorkSpaceBounds();
  final int x = (int) (bounds.getX());
  final int y = (int) (bounds.getY() + bounds.getHeight() - h);
  component.setLocation(x, y);
}

代码示例来源:origin: zgqq/mah

@Override
public void moveToLeft() {
  Rectangle currentScreen = getCurrentScreen();
  int y = getY(currentScreen.getHeight());
  frame.setLocation((int) currentScreen.getX(), y);
}

代码示例来源: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: cmusphinx/sphinx4

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

代码示例来源:origin: zgqq/mah

@Override
public void centerOnScreen() {
  Rectangle currentScreen = getCurrentScreen();
  double width = currentScreen.getWidth();
  int x = (int) (currentScreen.getX() + ((width - getWindowWidth()) / 2));
  int y = getY(currentScreen.getHeight());
  frame.setLocation(x, y);
}

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

private boolean isWithinCloseButton(final Point point)
  {
    Point overlayPoint = new Point(point.x - (int) overlay.getBounds().getX(),
      point.y - (int) overlay.getBounds().getY());

    return overlay.getCloseButtonBounds() != null
      && overlay.getCloseButtonBounds().contains(overlayPoint);
  }
}

代码示例来源:origin: net.imagej/ij-ui-swing

public static void locateUpperRight(java.awt.Container component) {
 int w = component.getWidth();
 Rectangle bounds = getWorkSpaceBounds();
 int x = (int) (bounds.getX() + bounds.getWidth() - w);
 int y = (int) (bounds.getY());
 component.setLocation(x, y);
}

代码示例来源:origin: net.imagej/ij-ui-swing

public static void locateLowerLeft(java.awt.Container component) {
 int h = component.getHeight();
 Rectangle bounds = getWorkSpaceBounds();
 int x = (int) (bounds.getX());
 int y = (int) (bounds.getY() + bounds.getHeight() - h);
 component.setLocation(x, y);
}

代码示例来源: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: runelite/runelite

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

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

public Raster getRaster(int xOffset, int yOffset, int w, int h) {
  ColorModel cm = getColorModel();
  if (raster == null) createRaster();
  // TODO: eventually use caching here
  WritableRaster childRaster = cm.createCompatibleWritableRaster(w, h);
  Rectangle2D childRect = new Rectangle2D.Double(xOffset, yOffset, w, h);
  if (!childRect.intersects(deviceBounds)) {
    // usually doesn't happen ...
    return childRaster;
  }
  
  Rectangle2D destRect = new Rectangle2D.Double();
  Rectangle2D.intersect(childRect, deviceBounds, destRect);
  int dx = (int)(destRect.getX()-deviceBounds.getX());
  int dy = (int)(destRect.getY()-deviceBounds.getY());
  int dw = (int)destRect.getWidth();
  int dh = (int)destRect.getHeight();
  Object data = raster.getDataElements(dx, dy, dw, dh, null);
  dx = (int)(destRect.getX()-childRect.getX());
  dy = (int)(destRect.getY()-childRect.getY());
  childRaster.setDataElements(dx, dy, dw, dh, data);
  
  return childRaster;
}

代码示例来源: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: org.swinglabs.swingx/swingx-all

private Rectangle boundsWithYandHeight(Rectangle bounds, double y, double height) {
 Rectangle r = new Rectangle();
 r.setBounds((int)(bounds.getX()), (int)y, (int)(bounds.getWidth()), (int)height);
 return r;
}

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

(int) closeButtonBounds.getX(), (int) closeButtonBounds.getY(), null);

代码示例来源: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);
  }
}

相关文章