java.awt.Rectangle#getX ( )源码实例Demo

下面列出了java.awt.Rectangle#getX ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: rapidminer-studio   文件: ScrollBarUI.java
@Override
protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {
	int x = (int) thumbBounds.getX();
	int y = (int) thumbBounds.getY();
	int w = (int) thumbBounds.getWidth();
	int h = (int) thumbBounds.getHeight();

	if (c.isEnabled() && w > 0 && h > 0) {
		if (this.scrollbar.getOrientation() == Adjustable.HORIZONTAL) {
			h -= 1;
			y++;
			drawHorizThumb(g, x, y, w, h);
		} else {
			w -= 1;
			x++;
			drawVertThumb(g, x, y, w, h);
		}
	}
}
 
源代码2 项目: rapidminer-studio   文件: WindowChoreographer.java
/**
 * Recalculate the Window position
 *
 * @param window the window
 * @param position the position of the window
 */
private void recalculateWindowPosition(Window window, int position) {
	Rectangle parentBounds = parent.getBounds();
	parentBounds.setLocation(parent.getLocationOnScreen());
	int rightX = (int) (parentBounds.getX() + parent.getWidth() - DEFAULT_RIGHT_MARGIN);
	// this was going crazy sometimes
	int topY = (int) parentBounds.getY();
	int yOffset = windowYOffset.get(position);
	// Recalculate the window positions
	window.setLocation(rightX - window.getWidth(), topY + yOffset - window.getHeight());
	// Check if the Window fits into the parents bounds
	if (!parentBounds.contains(window.getBounds())) {
		// back into the bubbleStack
		window.setVisible(false);
		bubbleStack.addFirst(window);
		freeSpaces.add(windowPosition.remove(window));
		window.removeWindowListener(closeListener);
	}
}
 
源代码3 项目: plugins   文件: DevToolsOverlay.java
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);
	}
}
 
源代码4 项目: jclic   文件: PolygonDrawPanel.java
protected void paintDrawnBorders(java.awt.Graphics2D g) {
  for (Rectangle r : vDrawnBorders) {
    double x = r.getX();
    double y = r.getY();
    double w = r.getWidth();
    double h = r.getHeight();
    x = x + (w / 4);
    y = y + (h / 4);
    w = w / 2;
    h = h / 2;
    g.setColor(EditableShapeConstants.DRAWN_BORDER_COLOR);
    g.fillRect((int) x, (int) y, (int) w, (int) h);
  }
}
 
源代码5 项目: hifive-pitalium   文件: SimilarityUtils.java
private static CalcSimilarityPrep prepareCalcSimilarity(BufferedImage expectedImage, BufferedImage actualImage,
		Rectangle rectangle, Offset offset) {
	// set range to be checked
	int minWidth = Math.min(expectedImage.getWidth(), actualImage.getWidth());
	int minHeight = Math.min(expectedImage.getHeight(), actualImage.getHeight());
	int actualX = (int) rectangle.getX();
	int actualY = (int) rectangle.getY();
	int actualWidth = (int) rectangle.getWidth();
	int actualHeight = (int) rectangle.getHeight();
	int maxMove;
	if (offset == null) {
		maxMove = ComparisonParameterDefaults.getMaxMove();
		offset = new Offset(0, 0);
	} else {
		maxMove = 0;
	}
	int leftMove = Math.min(maxMove, actualX - 1);
	int rightMove = Math.min(maxMove, minWidth - (actualX + actualWidth));
	int topMove = Math.min(maxMove, actualY - 1);
	int downMove = Math.min(maxMove, minHeight - (actualY + actualHeight));
	int expectedX = actualX - (leftMove + 1) - offset.getX();
	int expectedY = actualY - (topMove + 1) - offset.getY();
	int expectedWidth = actualWidth + leftMove + rightMove + 1;
	int expectedHeight = actualHeight + topMove + downMove + 1;

	// initialize sub-image.
	Rectangle entireFrame = new Rectangle(expectedX, expectedY, expectedWidth, expectedHeight);

	CalcSimilarityPrep prep = new CalcSimilarityPrep(expectedWidth, expectedHeight, actualWidth, actualHeight,
			maxMove, rightMove, leftMove, downMove, topMove, null, null, null, null, null, null);

	return prepareCalcSimilarity(expectedImage, actualImage, entireFrame, rectangle, prep);
}
 
源代码6 项目: ExternalPlugins   文件: ExtUtils.java
public Point getClickPoint(@NotNull Rectangle rect)
{
	final int x = (int) (rect.getX() + getRandomIntBetweenRange((int) rect.getWidth() / 6 * -1, (int) rect.getWidth() / 6) + rect.getWidth() / 2);
	final int y = (int) (rect.getY() + getRandomIntBetweenRange((int) rect.getHeight() / 6 * -1, (int) rect.getHeight() / 6) + rect.getHeight() / 2);

	return new Point(x, y);
}
 
源代码7 项目: runelite   文件: DevToolsOverlay.java
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);
	}
}
 
源代码8 项目: runelite   文件: WidgetInspectorOverlay.java
private void renderWiw(Graphics2D g, Object wiw, Color color)
{
	g.setColor(color);

	if (wiw instanceof WidgetItem)
	{
		WidgetItem wi = (WidgetItem) wiw;
		Rectangle bounds = wi.getCanvasBounds();
		g.draw(bounds);

		String text = wi.getId() + "";
		FontMetrics fm = g.getFontMetrics();
		Rectangle2D textBounds = fm.getStringBounds(text, g);

		int textX = (int) (bounds.getX() + (bounds.getWidth() / 2) - (textBounds.getWidth() / 2));
		int textY = (int) (bounds.getY() + (bounds.getHeight() / 2) + (textBounds.getHeight() / 2));

		g.setColor(Color.BLACK);
		g.drawString(text, textX + 1, textY + 1);
		g.setColor(Color.ORANGE);
		g.drawString(text, textX, textY);
	}
	else
	{
		Widget w = (Widget) wiw;
		g.draw(w.getBounds());
	}
}
 
源代码9 项目: openjdk-jdk9   文件: JTreeOperator.java
/**
 * Retuns points which can be used to click on path.
 *
 * @param path a tree path to click on.
 * @return a Point in component's coordinate system.
 */
public Point getPointToClick(TreePath path) {
    if (path != null) {
        Rectangle rect = getPathBounds(path);
        if (rect != null) {
            return (new Point((int) (rect.getX() + rect.getWidth() / 2),
                    (int) (rect.getY() + rect.getHeight() / 2)));
        } else {
            throw (new NoSuchPathException(path));
        }
    } else {
        throw (new NoSuchPathException());
    }
}
 
源代码10 项目: swcv   文件: FontTests.java
private void drawTextInBox(Graphics2D g2, String text, Rectangle2D positionOnScreen)
{
    Font font = FontUtils.getFont();
    FontRenderContext frc = g2.getFontRenderContext();

    //bounding box of the word
    GlyphVector gv2 = font.layoutGlyphVector(frc, text.toCharArray(), 0, text.length(), Font.LAYOUT_LEFT_TO_RIGHT);
    Rectangle bb = gv2.getPixelBounds(frc, 0.0f, 0.0f);

    //find correct font size
    float scaleX = (float)(positionOnScreen.getWidth() / bb.getWidth());
    float scaleY = (float)(positionOnScreen.getHeight() / bb.getHeight());

    //get a new position for the text
    float x = (float)(positionOnScreen.getX() - bb.getX() * scaleX);
    float y = (float)(positionOnScreen.getY() - bb.getY() * scaleY);

    //preparing font
    AffineTransform at = new AffineTransform(scaleX, 0, 0, scaleY, 0, 0);
    Font deriveFont = font.deriveFont(at);
    g2.setFont(deriveFont);
    g2.setColor(Color.black);

    //draw the label
    GlyphVector gv = deriveFont.layoutGlyphVector(frc, text.toCharArray(), 0, text.length(), Font.LAYOUT_LEFT_TO_RIGHT);
    g2.drawGlyphVector(gv, x, y);
    g2.draw(positionOnScreen);
}
 
源代码11 项目: runelite   文件: PoisonOverlay.java
@Override
public Dimension render(Graphics2D graphics)
{
	if (plugin.getLastDamage() <= 0)
	{
		return null;
	}

	final Widget healthOrb = client.getWidget(WidgetInfo.MINIMAP_HEALTH_ORB);

	if (healthOrb == null || healthOrb.isHidden())
	{
		return null;
	}

	final Rectangle bounds = healthOrb.getBounds();

	if (bounds.getX() <= 0)
	{
		return null;
	}

	final Point mousePosition = client.getMouseCanvasPosition();

	if (bounds.contains(mousePosition.getX(), mousePosition.getY()))
	{
		tooltipManager.add(new Tooltip(plugin.createTooltip()));
	}

	return null;
}
 
源代码12 项目: render   文件: TileSpec.java
/**
 * The bounding box is only valid for a given meshCellSize, i.e. setting it
 * independently of the meshCellSize is potentially harmful.
 *
 * @param  box  coordinates that define the bounding box for this tile.
 */
public void setBoundingBox(final Rectangle box, final double meshCellSize) {
    this.minX = box.getX();
    this.minY = box.getY();
    this.maxX = box.getMaxX();
    this.maxY = box.getMaxY();
    this.meshCellSize = meshCellSize;
}
 
源代码13 项目: runelite   文件: WorldMapRegionOverlay.java
private void drawRegionOverlay(Graphics2D graphics)
{
	RenderOverview ro = client.getRenderOverview();
	Widget map = client.getWidget(WidgetInfo.WORLD_MAP_VIEW);
	Float pixelsPerTile = ro.getWorldMapZoom();

	if (map == null)
	{
		return;
	}

	Rectangle worldMapRect = map.getBounds();
	graphics.setClip(worldMapRect);

	int widthInTiles = (int) Math.ceil(worldMapRect.getWidth() / pixelsPerTile);
	int heightInTiles = (int) Math.ceil(worldMapRect.getHeight() / pixelsPerTile);

	Point worldMapPosition = ro.getWorldMapPosition();

	// Offset in tiles from anchor sides
	int yTileMin = worldMapPosition.getY() - heightInTiles / 2;
	int xRegionMin = (worldMapPosition.getX() - widthInTiles / 2) & REGION_TRUNCATE;
	int xRegionMax = ((worldMapPosition.getX() + widthInTiles / 2) & REGION_TRUNCATE) + REGION_SIZE;
	int yRegionMin = (yTileMin & REGION_TRUNCATE);
	int yRegionMax = ((worldMapPosition.getY() + heightInTiles / 2) & REGION_TRUNCATE) + REGION_SIZE;
	int regionPixelSize = (int) Math.ceil(REGION_SIZE * pixelsPerTile);

	for (int x = xRegionMin; x < xRegionMax; x += REGION_SIZE)
	{
		for (int y = yRegionMin; y < yRegionMax; y += REGION_SIZE)
		{
			graphics.setColor(WHITE_TRANSLUCENT);

			int yTileOffset = -(yTileMin - y);
			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();
			// Offset y-position by a single region to correct for drawRect starting from the top
			yPos -= regionPixelSize;

			graphics.drawRect(xPos, yPos, regionPixelSize, regionPixelSize);

			int regionId = ((x >> 6) << 8) | (y >> 6);
			String regionText = String.valueOf(regionId);
			FontMetrics fm = graphics.getFontMetrics();
			Rectangle2D textBounds = fm.getStringBounds(regionText, graphics);
			int labelWidth = (int) textBounds.getWidth() + 2 * LABEL_PADDING;
			int labelHeight = (int) textBounds.getHeight() + 2 * LABEL_PADDING;
			graphics.fillRect(xPos, yPos, labelWidth, labelHeight);
			graphics.setColor(Color.BLACK);
			graphics.drawString(regionText, xPos + LABEL_PADDING, yPos + (int) textBounds.getHeight() + LABEL_PADDING);
		}
	}
}
 
源代码14 项目: filthy-rich-clients   文件: CopyAreaPerformance.java
protected void paintComponent(Graphics g) {
    long startTime = System.nanoTime();
    // prevVX is set to -10000 when first enabled
    if (useCopyArea && prevVX > -9999) {
        // Most of this code determines the proper areas to copy and clip
        int scrollX = viewX - prevVX;
        int scrollY = viewY - prevVY;
        int copyFromY, copyFromX;
        int clipFromY, clipFromX;
        if (scrollX == 0) {
            // vertical scroll
            if (scrollY < 0) {
                copyFromY = 0;
                clipFromY = 0;
            } else {
                copyFromY = scrollY;
                clipFromY = getHeight() - scrollY;
            }
            // copy the old content, set the clip to the new area
            g.copyArea(0, copyFromY, getWidth(), getHeight() - Math.abs(scrollY),
                    0, -scrollY);
            g.setClip(0, clipFromY, getWidth(), Math.abs(scrollY));
        } else {
            // horizontal scroll
            if (scrollX < 0) {
                copyFromX = 0;
                clipFromX = 0;
            } else {
                copyFromX = scrollX;
                clipFromX = getWidth() - scrollX;
            }
            // copy the old content, set the clip to the new area
            g.copyArea(copyFromX, 0, getWidth() - Math.abs(scrollX), 
                    getHeight(), -scrollX, 0);
            g.setClip(clipFromX, 0, Math.abs(scrollX), getHeight());
        }
    }
    // Track previous view position for next scrolling operation
    prevVX = viewX;
    prevVY = viewY;
    // Get the clip in case we need it later
    Rectangle clipRect = g.getClip().getBounds();
    int clipL = (int)(clipRect.getX());
    int clipT = (int)(clipRect.getY());
    int clipR = (int)(clipRect.getMaxX());
    int clipB = (int)(clipRect.getMaxY());
    g.setColor(Color.WHITE);
    g.fillRect(clipL, clipT, (int)clipRect.getWidth(), (int)clipRect.getHeight());
    for (int column = 0; column < 256; ++column) {
        int x = column * (SMILEY_SIZE + PADDING) - viewX;
        if (useClip) {
            if (x > clipR || (x + (SMILEY_SIZE + PADDING)) < clipL) {
                // trivial reject; outside to the left or right
                continue;
            }
        }
        for (int row = 0; row < 256; ++row) {
            int y = row * (SMILEY_SIZE + PADDING) - viewY;
            if (useClip) {
                if (y > clipB || (y + (SMILEY_SIZE + PADDING)) < clipT) {
                    // trivial reject; outside to the top or bottom
                    continue;
                }
            }
            Color faceColor = new Color(column, row, 0);
            drawSmiley(g, faceColor, x, y);
        }
    }
    long stopTime = System.nanoTime();
    System.out.println("Painted in " + 
            ((stopTime - startTime) / 1000000) + " ms");
}
 
源代码15 项目: Pixelitor   文件: RotatedRectangle.java
public RotatedRectangle(Rectangle r, double theta) {
    this(r.getX(), r.getY(), r.getWidth(), r.getHeight(), theta);
}
 
源代码16 项目: openjdk-jdk9   文件: JComponentOperator.java
@Override
public int getCenterXForClick() {
    Rectangle rect = getVisibleRect();
    return ((int) rect.getX()
            + (int) rect.getWidth() / 2);
}
 
源代码17 项目: pgptool   文件: UiUtils.java
private static String format(Rectangle bounds) {
	return "x=" + (int) bounds.getX() + ",y=" + (int) bounds.getY() + ",w=" + (int) bounds.getWidth() + ",h="
			+ (int) bounds.getHeight();
}
 
源代码18 项目: runelite   文件: PrayerDoseOverlay.java
@Override
public Dimension render(Graphics2D graphics)
{
	final Widget xpOrb = client.getWidget(WidgetInfo.MINIMAP_QUICK_PRAYER_ORB);
	if (xpOrb == null || xpOrb.isHidden())
	{
		return null;
	}

	final Rectangle bounds = xpOrb.getBounds();
	if (bounds.getX() <= 0)
	{
		return null;
	}

	final Point mousePosition = client.getMouseCanvasPosition();

	if (config.showPrayerStatistics() && bounds.contains(mousePosition.getX(), mousePosition.getY()))
	{
		final StringBuilder sb = new StringBuilder();

		if (config.replaceOrbText())
		{
			sb.append("Prayer points remaining: ").append(client.getBoostedSkillLevel(Skill.PRAYER));
		}
		else
		{
			sb.append("Time Remaining: ").append(plugin.getEstimatedTimeRemaining(false));
		}

		sb.append("</br>").append("Prayer Bonus: ").append(plugin.getPrayerBonus());
		tooltipManager.add(new Tooltip(sb.toString()));
	}

	if (!config.showPrayerDoseIndicator() || !hasPrayerRestore)
	{
		return null;
	}

	final int currentPrayer = client.getBoostedSkillLevel(Skill.PRAYER);
	final int maxPrayer = client.getRealSkillLevel(Skill.PRAYER);

	final int prayerPointsMissing = maxPrayer - currentPrayer;
	if (prayerPointsMissing <= 0)
	{
		return null;
	}

	final double dosePercentage = hasHolyWrench ? .27 : .25;
	final int basePointsRestored = (int) Math.floor(maxPrayer * dosePercentage);

	final int pointsRestored = basePointsRestored + 7 + bonusPrayer;

	if (prayerPointsMissing < pointsRestored)
	{
		return null;
	}

	// Purposefully using height twice here as the bounds of the prayer orb includes the number sticking out the side
	final int orbInnerSize = (int) bounds.getHeight();

	final int orbInnerX = (int) (bounds.getX() + 24); // x pos of the inside of the prayer orb
	final int orbInnerY = (int) (bounds.getY() - 1); // y pos of the inside of the prayer orb

	final long timeSinceLastTick = Duration.between(startOfLastTick, Instant.now()).toMillis();

	final float tickProgress = Math.min(timeSinceLastTick / PULSE_TIME, 1); // Cap between 0 and 1
	final double t = tickProgress * Math.PI; // Convert to 0 - pi

	graphics.setColor(ColorUtil.colorLerp(START_COLOR, END_COLOR, Math.sin(t)));
	graphics.setStroke(new BasicStroke(2));
	graphics.drawOval(orbInnerX, orbInnerY, orbInnerSize, orbInnerSize);

	return new Dimension((int) bounds.getWidth(), (int) bounds.getHeight());
}
 
源代码19 项目: runelite   文件: WidgetItem.java
/**
 * Gets the upper-left coordinate of where the widget is being drawn
 * on the canvas, accounting for drag.
 *
 * @return the upper-left coordinate of where this widget is drawn
 */
public Point getCanvasLocation()
{
	Rectangle bounds = getCanvasBounds();
	return new Point((int) bounds.getX(), (int) bounds.getY());
}
 
源代码20 项目: openjdk-jdk9   文件: JTableOperator.java
/**
 * Returns a point at the center of the cell rectangle.
 *
 * @param row a row index
 * @param column a column index
 * @return a Point in component's coordinate system.
 */
public Point getPointToClick(int row, int column) {
    Rectangle rect = getCellRect(row, column, false);
    return (new Point((int) (rect.getX() + rect.getWidth() / 2),
            (int) (rect.getY() + rect.getHeight() / 2)));
}