Java Code Examples for java.awt.Rectangle#getX()

The following examples show how to use java.awt.Rectangle#getX() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WindowChoreographer.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example 2
Source File: ScrollBarUI.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
@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);
		}
	}
}
 
Example 3
Source File: DevToolsOverlay.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
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);
	}
}
 
Example 4
Source File: PolygonDrawPanel.java    From jclic with GNU General Public License v2.0 5 votes vote down vote up
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);
  }
}
 
Example 5
Source File: TileSpec.java    From render with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 6
Source File: SimilarityUtils.java    From hifive-pitalium with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 7
Source File: ExtUtils.java    From ExternalPlugins with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example 8
Source File: DevToolsOverlay.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
	}
}
 
Example 9
Source File: WidgetInspectorOverlay.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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());
	}
}
 
Example 10
Source File: JTreeOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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());
    }
}
 
Example 11
Source File: FontTests.java    From swcv with MIT License 5 votes vote down vote up
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);
}
 
Example 12
Source File: PoisonOverlay.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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;
}
 
Example 13
Source File: PrayerDoseOverlay.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@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());
}
 
Example 14
Source File: UiUtils.java    From pgptool with GNU General Public License v3.0 4 votes vote down vote up
private static String format(Rectangle bounds) {
	return "x=" + (int) bounds.getX() + ",y=" + (int) bounds.getY() + ",w=" + (int) bounds.getWidth() + ",h="
			+ (int) bounds.getHeight();
}
 
Example 15
Source File: JComponentOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getCenterXForClick() {
    Rectangle rect = getVisibleRect();
    return ((int) rect.getX()
            + (int) rect.getWidth() / 2);
}
 
Example 16
Source File: RotatedRectangle.java    From Pixelitor with GNU General Public License v3.0 4 votes vote down vote up
public RotatedRectangle(Rectangle r, double theta) {
    this(r.getX(), r.getY(), r.getWidth(), r.getHeight(), theta);
}
 
Example 17
Source File: CopyAreaPerformance.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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");
}
 
Example 18
Source File: WorldMapRegionOverlay.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
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);
		}
	}
}
 
Example 19
Source File: JTableOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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)));
}
 
Example 20
Source File: WidgetItem.java    From runelite with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * 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());
}