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

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

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

Rectangle.contains介绍

[英]Checks whether or not this Rectangle contains the point at the specified location (x, y).
[中]检查此Rectangle是否包含指定位置(x,y)的点。

代码示例

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

public boolean inCheckBoxHitRegion(MouseEvent e) {
 TreePath path = tree.getPathForLocation(e.getX(),
   e.getY());
 if (path == null) {
  return false;
 }
 CategoryNode node = (CategoryNode) path.getLastPathComponent();
 boolean rv = false;
 if (true) {
  // offset and lastRow DefaultTreeCellEditor
  // protected members
  Rectangle bounds = tree.getRowBounds(lastRow);
  Dimension checkBoxOffset =
    renderer.getCheckBoxOffset();
  bounds.translate(offset + checkBoxOffset.width,
    checkBoxOffset.height);
  rv = bounds.contains(e.getPoint());
 }
 return true;
}

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

@Inject
@Override
public boolean contains(Point point)
{
  Rectangle bounds = getBounds();
  return bounds != null && bounds.contains(new java.awt.Point(point.getX(), point.getY()));
}

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

Point p1 = new Point(currentWp.getX() - maxSquaresAway, currentWp.getY() - maxSquaresAway);
Rectangle r1 = new Rectangle((int) p1.getX(), (int) p1.getY(), 2 * maxSquaresAway + 1, 2 * maxSquaresAway + 1);
Point p2 = new Point(currentWp.getX() - minSquaresAway, currentWp.getY() - minSquaresAway);
Rectangle r2 = new Rectangle((int) p2.getX(), (int) p2.getY(), 2 * minSquaresAway + 1, 2 * minSquaresAway + 1);
digLocations.removeIf(entry -> r2.contains(entry.getRect()) || !r1.intersects(entry.getRect()));

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

/**
 * Paint UI related overlays to target graphics
 * @param graphics target graphics
 */
public void paintOverlays(final Graphics2D graphics)
{
  if (!(client instanceof Client) || withTitleBar)
  {
    return;
  }
  final Client client = (Client) this.client;
  final int x = client.getRealDimensions().width - sidebarOpenIcon.getWidth() - 5;
  // Offset sidebar button if resizable mode logout is visible
  final Widget logoutButton = client.getWidget(WidgetInfo.RESIZABLE_VIEWPORT_BOTTOM_LINE_LOGOUT_BUTTON);
  final int y = logoutButton != null && !logoutButton.isHidden() && logoutButton.getParent() != null
    ? logoutButton.getHeight() + logoutButton.getRelativeY()
    : 5;
  final BufferedImage image = sidebarOpen ? sidebarClosedIcon : sidebarOpenIcon;
  final Rectangle sidebarButtonRange = new Rectangle(x - 15, 0, image.getWidth() + 25, client.getRealDimensions().height);
  final Point mousePosition = new Point(
    client.getMouseCanvasPosition().getX() + client.getViewportXOffset(),
    client.getMouseCanvasPosition().getY() + client.getViewportYOffset());
  if (sidebarButtonRange.contains(mousePosition.getX(), mousePosition.getY()))
  {
    graphics.drawImage(image, x, y, null);
  }
  // Update button dimensions
  sidebarButtonPosition.setBounds(x, y, image.getWidth(), image.getHeight());
}

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

@Override
public MouseEvent mouseDragged(MouseEvent mouseEvent)
{
  if (!inOverlayDraggingMode)
  {
    return mouseEvent;
  }
  final Point mousePoint = mouseEvent.getPoint();
  mousePosition.setLocation(mousePoint);
  final Rectangle canvasRect = new Rectangle(client.getRealDimensions());
  if (!canvasRect.contains(mousePoint))
  {
    return mouseEvent;
  }
  if (movedOverlay != null)
  {
    final Dimension realDimension = client.getRealDimensions();
    mousePoint.translate(-overlayOffset.x, -overlayOffset.y);
    mousePoint.x = Ints.constrainToRange(mousePoint.x, 0, realDimension.width - movedOverlay.getBounds().width);
    mousePoint.y = Ints.constrainToRange(mousePoint.y, 0, realDimension.height - movedOverlay.getBounds().height);
    movedOverlay.setPreferredPosition(null);
    movedOverlay.setPreferredLocation(mousePoint);
    mouseEvent.consume();
  }
  return mouseEvent;
}

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

final Point mousePoint = mouseEvent.getPoint();
mousePosition.setLocation(mousePoint);
    if (overlay.getBounds().contains(mousePoint))
        final Point offset = new Point(mousePoint.x, mousePoint.y);
        offset.translate(-overlay.getBounds().x, -overlay.getBounds().y);
        overlayOffset.setLocation(offset);

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

if (worldMapRectangle.contains(drawPoint.getX(), drawPoint.getY()))
Rectangle clickbox = new Rectangle(drawX, drawY, image.getWidth(), image.getHeight());
worldPoint.setClickbox(clickbox);

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

final Rectangle clientCanvasBounds = new Rectangle(client.getRealDimensions());
final net.runelite.api.Point mouseCanvasPosition = client.getMouseCanvasPosition();
final Point mousePosition = new Point(mouseCanvasPosition.getX(), mouseCanvasPosition.getY() + OFFSET);
final Rectangle bounds = new Rectangle(getBounds());
bounds.setLocation(mousePosition);
if (!clientCanvasBounds.contains(bounds))
final Rectangle newBounds = new Rectangle(-1, -1, 0, 0);
  tooltipComponent.setText(tooltip.getText());
  if (newBounds.contains(mousePosition))

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

@Override
public MouseEvent mousePressed(MouseEvent e)
  final Point mousePos = e.getPoint();
      if (plugin.getHiddenBoxBounds() != null && plugin.getHiddenBoxBounds().getKey().contains(mousePos))
      if (plugin.getHighlightBoxBounds() != null && plugin.getHighlightBoxBounds().getKey().contains(mousePos))
      if (plugin.getTextBoxBounds() != null && plugin.getTextBoxBounds().getKey().contains(mousePos))
      if (plugin.getTextBoxBounds() != null && plugin.getTextBoxBounds().getKey().contains(mousePos))

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

Rectangle bounds = new Rectangle(ccl.getX() + ox, ccl.getY() + y, w > 0 ? w : fullWidth, h);
isInBounds = ev -> bounds.contains(ev.getPoint());
getCharOffset = ev ->

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

@Override
  public String getToolTipText(MouseEvent e) {
    int item = list.locationToIndex(e.getPoint());
    if (item >= 0) {
      Rectangle r = list.getCellBounds(item, item);
      if (r.contains(e.getPoint())) {
        Point p = new Point(e.getPoint().x, e.getPoint().y - r.y);
        if (MapLayerTableCellRenderer.hitSelectionLabel(p)) {
          return SELECT_LAYER;
        } else if (MapLayerTableCellRenderer.hitVisibilityLabel(p)) {
          return SHOW_HIDE_LAYER;
        } else if (MapLayerTableCellRenderer.hitStyleLabel(p)) {
          return STYLE_LAYER;
        } else if (MapLayerTableCellRenderer.hitRemoveLabel(p)) {
          return REMOVE_LAYER;
        } else if (MapLayerTableCellRenderer.hitNameLabel(p)) {
          return RENAME_LAYER;
        }
      }
    }
    return null;
  }
};

代码示例来源:origin: apache/cloudstack

public boolean add(Rectangle rect) {
  if (bound.isEmpty()) {
    assert (rectList.size() == 0);
    bound.x = rect.x;
    bound.y = rect.y;
    bound.width = rect.width;
    bound.height = rect.height;
    rectList.add(rect);
    return true;
  }
  Rectangle rcInflated = new Rectangle(rect.x - 1, rect.y - 1, rect.width + 2, rect.height + 2);
  if (!bound.intersects(rcInflated))
    return false;
  for (Rectangle r : rectList) {
    if (r.intersects(rcInflated)) {
      if (!r.contains(rect)) {
        enlargeBound(rect);
        rectList.add(rect);
        return true;
      }
    }
  }
  return false;
}

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

final java.awt.Point awtMousePos = new java.awt.Point(mousePos.getX(), mousePos.getY());
GroundItem groundItem = null;
    && plugin.getTextBoxBounds().getKey().contains(awtMousePos))
    && plugin.getHiddenBoxBounds().getKey().contains(awtMousePos))
    && plugin.getHighlightBoxBounds().getKey().contains(awtMousePos))
  int width = stringWidth + 4;
  int height = stringHeight + 4;
  final Rectangle itemBounds = new Rectangle(x, y, width, height);
  y = textY - (RECTANGLE_SIZE + stringHeight) / 2;
  width = height = RECTANGLE_SIZE;
  final Rectangle itemHiddenBox = new Rectangle(x, y, width, height);
  final Rectangle itemHighlightBox = new Rectangle(x, y, width, height);
  boolean mouseInBox = itemBounds.contains(mousePos.getX(), mousePos.getY());
  boolean mouseInHiddenBox = itemHiddenBox.contains(mousePos.getX(), mousePos.getY());
  boolean mouseInHighlightBox = itemHighlightBox.contains(mousePos.getX(), mousePos.getY());
textComponent.setPosition(new java.awt.Point(textX, textY));
textComponent.render(graphics);

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

if (snapCorner.contains(mouseEvent.getPoint()))

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

/**
*  Setup the variables used to control the moving of the component:
*
*  source - the source component of the mouse event
*  destination - the component that will ultimately be moved
*  pressed - the Point where the mouse was pressed in the destination
*      component coordinates.
*/
@Override
public void mousePressed(MouseEvent e)
{
 source = e.getComponent();
 int width  = source.getSize().width  - dragInsets.left - dragInsets.right;
 int height = source.getSize().height - dragInsets.top - dragInsets.bottom;
 Rectangle r = new Rectangle(dragInsets.left, dragInsets.top, width, height);
 if (r.contains(e.getPoint()))
   setupForDragging(e);
}

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

graphics.setColor(corner.contains(mousePosition) ? SNAP_CORNER_ACTIVE_COLOR : SNAP_CORNER_COLOR);
    graphics.fill(corner);
final Point mouse = new Point(mouseCanvasPosition.getX(), mouseCanvasPosition.getY());
    safeRender(client, overlay, layer, graphics, new Point());
    if (menuEntries == null && !client.isMenuOpen() && bounds.contains(mouse))

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

/**
 * Handle a mouse click on a cell in the JList that displays layer names and states.
 *
 * @param ev the mouse event
 * @param doubleClick true if this is the second click of a double-click; false otherwise
 */
private void onLayerItemClicked(MouseEvent ev, boolean doubleClick) {
  int item = list.locationToIndex(ev.getPoint());
  if (item >= 0) {
    Rectangle r = list.getCellBounds(item, item);
    if (r.contains(ev.getPoint())) {
      Layer layer = listModel.getElementAt(item);
      Point p = new Point(ev.getPoint().x, ev.getPoint().y - r.y);
      if (MapLayerTableCellRenderer.hitSelectionLabel(p)) {
        layer.setSelected(!layer.isSelected());
      } else if (MapLayerTableCellRenderer.hitVisibilityLabel(p)) {
        layer.setVisible(!layer.isVisible());
      } else if (MapLayerTableCellRenderer.hitStyleLabel(p)) {
        doSetStyle(layer);
      } else if (MapLayerTableCellRenderer.hitRemoveLabel(p)) {
        doRemoveLayer(layer);
      } else if (MapLayerTableCellRenderer.hitNameLabel(p)) {
        if (doubleClick) {
          doSetLayerName(layer);
        }
      }
    }
  }
}

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

public boolean contains(Element elem) {
 if (!isRectangle() || (!elem.isRectangle() && !elem.isPoint())) {
  return false;
 }
 Rectangle r1 = new Rectangle(x, y, w, h);
 Rectangle r2 = elem.getRectangle();
 if (elem.isRectangle()) {
  return r1.contains(r2);
 } else {
  return r1.contains(elem.x, elem.y);
 }
}
//</editor-fold>

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

final Point mouse = new Point(client.getMouseCanvasPosition().getX(), client.getMouseCanvasPosition().getY());
      final Rectangle intersectionRectangle = new Rectangle(component.getPreferredLocation(), component.getPreferredSize());
      intersectionRectangle.translate(transformed.x, transformed.y);
      if (intersectionRectangle.contains(mouse))

相关文章