/** * Fills the given {@link RectF} with the path bounds. * * @param bounds the RectF to be filled. */ public void fillBounds(RectF bounds) { Rectangle2D rect = mPath.getBounds2D(); bounds.left = (float) rect.getMinX(); bounds.right = (float) rect.getMaxX(); bounds.top = (float) rect.getMinY(); bounds.bottom = (float) rect.getMaxY(); }
@Override public void paint(Graphics g) { super.paint(g); g.setColor(Color.WHITE); g.fillRect(0, 0, width, height); g.setColor(Color.BLACK); g.drawRect(0, 0, width - 1, height - 1); g.drawRect(1, 1, width - 3, height - 3); // g.setColor(Color.RED); // final String status = done + "/" + total; // g.drawString(status, width / 2, height / 2); g.drawImage(logo, width - logo.getWidth() - 4, height - logo.getHeight() - 4, null); drawProgessBar(g, done.intValue(), total.intValue()); final int nbErrors = errors.get(); if (nbErrors > 0) { g.setColor(Color.RED); final String message = "" + nbErrors + (nbErrors > 1 ? " diagrams" : " diagram") + " contains errors"; g.drawString(message, 10, 20); } g.setColor(link); final String urllink = "http://plantuml.com"; final Rectangle2D rect = getUsed(g, urllink); g.drawString(urllink, 10, (int) (height - rect.getMaxY())); limY = (int) (height - rect.getMaxY() + rect.getMinY()); limX = (int) (10 + rect.getMaxX()); }
/** * Utility method for drawing a crosshair on the chart (if required). * * @param g2 The graphics device. * @param dataArea The data area. * @param value The coordinate, where to draw the line. * @param stroke The stroke to use. * @param paint The paint to use. */ protected void drawHorizontalLine(Graphics2D g2, Rectangle2D dataArea, double value, Stroke stroke, Paint paint) { double yy = getRangeAxis().valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(dataArea.getMinX(), yy, dataArea.getMaxX(), yy); g2.setStroke(stroke); g2.setPaint(paint); g2.draw(line); }
private void drawStraightLabelLine( java.awt.Shape outline, boolean drawingHalo, float thickness, float offset) { Rectangle2D bounds = outline.getBounds2D().getBounds(); double minX = bounds.getMinX(); double maxX = bounds.getMaxX(); if ((Math.abs(maxX - minX) < 0.0000001)) { // nothing to draw return; } // let's se if we are drawing the halo around the underline line if (drawingHalo) { // when drawing the halo we assume that the correct halo configuration has been set graphics.draw(new Line2D.Double(minX, offset, maxX, offset)); } else { // storing the current stroke and setting the stroke according to the specified // thickness Stroke currentStroke = graphics.getStroke(); graphics.setStroke(new BasicStroke(thickness)); // we draw a line with the same color of the text and a stroke of 2 graphics.draw(new Line2D.Double(minX, offset, maxX, offset)); // we need to restore the previous stroke graphics.setStroke(currentStroke); } }
@Override public void draw(Graphics2D graphics) { super.draw(graphics); Color oldColor = graphics.getColor(); GeneralPath fold = new GeneralPath(); Rectangle2D bounds = getBounds(); fold.moveTo((float) (bounds.getMaxX() - FOLD_X), (float) bounds.getY()); fold.lineTo((float) bounds.getMaxX() - FOLD_X, (float) bounds.getY() + FOLD_X); fold.lineTo((float) bounds.getMaxX(), (float) (bounds.getY() + FOLD_Y)); fold.closePath(); graphics.setColor(ThemeManager.getInstance().getTheme().getWhiteColor()); graphics.fill(fold); graphics.setColor(getBorderColor()); graphics.draw(fold); graphics.setColor(oldColor); }
Rectangle2D getBounds() { Rectangle2D vb = null; for (LineComponent lineComponent : components) { Rectangle2D componentVisualBounds = lineComponent.getGlyphVector().getVisualBounds(); Rectangle2D componentLogicalBounds = lineComponent.getGlyphVector().getLogicalBounds(); // the logical bounds include the spaces, we want them in the horizontal direction // in order to compose the element in the row, but we need the visual bounds for // vertical alignment Rectangle2D componentBounds = new Rectangle2D.Double( componentLogicalBounds.getX(), componentVisualBounds.getY(), componentLogicalBounds.getWidth(), componentVisualBounds.getHeight()); if (vb == null) { vb = componentBounds; } else { Rectangle2D other = new Rectangle2D.Double( vb.getMaxX(), vb.getMinY(), componentBounds.getWidth(), componentBounds.getHeight()); vb = vb.createUnion(other); } } return vb; }
private static Rectangle2D union(Rectangle2D src1, Rectangle2D src2) { double x1 = Math.min(src1.getMinX(), src2.getMinX()); double y1 = Math.min(src1.getMinY(), src2.getMinY()); double x2 = Math.max(src1.getMaxX(), src2.getMaxX()); double y2 = Math.max(src1.getMaxY(), src2.getMaxY()); Rectangle2D result = new Rectangle2D.Double(); result.setFrameFromDiagonal(x1, y1, x2, y2); return result; }
static Point2D intersection(Rectangle2D rect, Point2D pt1, Point2D pt2) { Point2D p; p = intersection(new Point2D.Double(rect.getMinX(), rect.getMinY()), new Point2D.Double(rect.getMaxX(), rect.getMinY()), pt1, pt2); if (p != null) { return p; } p = intersection(new Point2D.Double(rect.getMinX(), rect.getMaxY()), new Point2D.Double(rect.getMaxX(), rect.getMaxY()), pt1, pt2); if (p != null) { return p; } p = intersection(new Point2D.Double(rect.getMinX(), rect.getMinY()), new Point2D.Double(rect.getMinX(), rect.getMaxY()), pt1, pt2); if (p != null) { return p; } p = intersection(new Point2D.Double(rect.getMaxX(), rect.getMinY()), new Point2D.Double(rect.getMaxX(), rect.getMaxY()), pt1, pt2); if (p != null) { return p; } return null; }
public LineRectIntersection(Line2D line, Rectangle2D rect) { final Point2D p1 = new Point2D.Double(rect.getMinX(), rect.getMinY()); final Point2D p2 = new Point2D.Double(rect.getMaxX(), rect.getMinY()); final Point2D p3 = new Point2D.Double(rect.getMaxX(), rect.getMaxY()); final Point2D p4 = new Point2D.Double(rect.getMinX(), rect.getMaxY()); final Point2D inter1 = new LineSegmentIntersection(new Line2D.Double(p1, p2), line).getIntersection(); final Point2D inter2 = new LineSegmentIntersection(new Line2D.Double(p2, p3), line).getIntersection(); final Point2D inter3 = new LineSegmentIntersection(new Line2D.Double(p3, p4), line).getIntersection(); final Point2D inter4 = new LineSegmentIntersection(new Line2D.Double(p4, p1), line).getIntersection(); final Point2D o = line.getP1(); inter = getCloser(o, inter1, inter2, inter3, inter4); }
Point2D inter = null; if (in.getX() > rect.getMinX() && in.getX() < rect.getMaxX()) { if (in.getY() < rect.getMinY()) { inter = new Point2D.Double(in.getX(), rect.getMinY()); } else if (in.getY() > rect.getMaxY()) { inter = new Point2D.Double(in.getX(), rect.getMaxY()); } else { throw new IllegalArgumentException(); } else if (in.getY() > rect.getMinY() && in.getY() < rect.getMaxY()) { if (in.getX() < rect.getMinX()) { inter = new Point2D.Double(rect.getMinX(), in.getY()); } else if (in.getX() > rect.getMaxX()) { inter = new Point2D.Double(rect.getMaxX(), in.getY()); } else { throw new IllegalArgumentException(); final Point2D p1 = new Point2D.Double(rect.getMinX(), rect.getMinY()); final Point2D p2 = new Point2D.Double(rect.getMaxX(), rect.getMinY()); final Point2D p3 = new Point2D.Double(rect.getMaxX(), rect.getMaxY()); final Point2D p4 = new Point2D.Double(rect.getMinX(), rect.getMaxY());
final double ww = bounds.getMaxX() - bounds.getMinX(); final double hh = bounds.getMaxY() - bounds.getMinY(); final Graphics2D gg = destination.createGraphics(); gg.scale(dpiFactor, dpiFactor); gg.translate(deltaShadow - bounds.getMinX(), deltaShadow - bounds.getMinY()); final boolean isLine = shape instanceof Line2D.Double; if (isLine) { gg.setColor(colorLine); gg.draw(shape); } else { gg.setColor(color); final AffineTransform at = g2d.getTransform(); g2d.scale(1 / dpiFactor, 1 / dpiFactor); g2d.drawImage(destination, (int) (bounds.getMinX() * dpiFactor), (int) (bounds.getMinY() * dpiFactor), null); g2d.setTransform(at);
public DotPath getRacordIn(Rectangle2D rect, Line2D tangeante) { // Log.println("rect x=" + rect.getX() + " y=" + rect.getY() + " w=" + rect.getWidth() + " h=" // + rect.getHeight()); // Log.println("tangeante (" + tangeante.getX1() + "," + tangeante.getY1() + ") (" + tangeante.getX2() // + "," + tangeante.getY2() + ")"); final DotPath result = new DotPath(); // final Point2D inter = BezierUtils.intersect((Line2D.Double) // tangeante, rect); Point2D inter = new LineRectIntersection(tangeante, rect).getIntersection(); // Log.println("inter=" + inter); if (inter == null) { final Point2D p1 = new Point2D.Double(rect.getMinX(), rect.getMinY()); final Point2D p2 = new Point2D.Double(rect.getMaxX(), rect.getMinY()); final Point2D p3 = new Point2D.Double(rect.getMaxX(), rect.getMaxY()); final Point2D p4 = new Point2D.Double(rect.getMinX(), rect.getMaxY()); inter = LineRectIntersection.getCloser(tangeante.getP1(), p1, p2, p3, p4); } final CubicCurve2D.Double curv = new CubicCurve2D.Double(tangeante.getX1(), tangeante.getY1(), tangeante.getX1(), tangeante.getY1(), inter.getX(), inter.getY(), inter.getX(), inter.getY()); return result.addAfter(curv); }
private boolean isFirstPointCloserRect(WorldPoint firstWp, WorldPoint secondWp, Rectangle2D r) { WorldPoint p1 = new WorldPoint((int) r.getMaxX(), (int) r.getMaxY(), 0); if (!isFirstPointCloser(firstWp, secondWp, p1)) { return false; } WorldPoint p2 = new WorldPoint((int) r.getMaxX(), (int) r.getMinY(), 0); if (!isFirstPointCloser(firstWp, secondWp, p2)) { return false; } WorldPoint p3 = new WorldPoint((int) r.getMinX(), (int)r.getMaxY(), 0); if (!isFirstPointCloser(firstWp, secondWp, p3)) { return false; } WorldPoint p4 = new WorldPoint((int) r.getMinX(), (int) r.getMinY(), 0); return (isFirstPointCloser(firstWp, secondWp, p4)); }
/** * Constructs a geographic bounding box from the specified rectangle. The rectangle is assumed * in {@linkplain DefaultGeographicCRS#WGS84 WGS 84} CRS. * * @param bounds The rectangle to use for initializing this geographic bounding box. */ public GeographicBoundingBoxImpl(final Rectangle2D bounds) { this( bounds.getMinX(), bounds.getMaxX(), bounds.getMinY(), bounds.getMaxY()); }
/** * Adds a {@code Rectangle2D} object to this {@code Rectangle2D}. The resulting {@code * Rectangle2D} is the union of the two {@code Rectangle2D} objects. * * @param rect the {@code Rectangle2D} to add to this {@code Rectangle2D}. */ @Override public void add(final Rectangle2D rect) { double t; if ((t = rect.getMinX()) < xmin) xmin = t; if ((t = rect.getMaxX()) > xmax) xmax = t; if ((t = rect.getMinY()) < ymin) ymin = t; if ((t = rect.getMaxY()) > ymax) ymax = t; }