Refine search
@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); }
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); }
@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); }
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; }
@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); }
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); } }