public Rectangle2D getBounds(Iterable<?> objects) { Rectangle2D.Double bounds = new Rectangle2D.Double(); for (Object o : objects) { if (o instanceof Point) { Point pt = (Point) o; bounds.add(pt.toPoint2D()); } else if (o instanceof Iterable) { bounds.add(getBounds((Iterable<?>) o)); } } bounds.x -= 5; bounds.y -= 5; bounds.width += 10; bounds.height += 10; return bounds; }
public Rectangle2D getBounds(Iterable<?> objects) { Rectangle2D.Double bounds = new Rectangle2D.Double(); for (Object o : objects) { if (o instanceof Grob) { Grob grob = (Grob) o; bounds.add(grob.getBounds().getRectangle2D()); } else if (o instanceof Iterable) { bounds.add(getBounds((Iterable<?>) o)); } } // Make sure the width and height or greater than zero. // This happen when drawing a single vertical line, for example. bounds.width = bounds.width > 0 ? bounds.width : 1; bounds.height = bounds.height > 0 ? bounds.height : 1; return bounds; }
private Rectangle2D.Double convertRectangleUnits(Rectangle2D rect, Units ux, Units uy, double magnification) { Rectangle2D.Double ret = new Rectangle2D.Double( Units.PIXEL.convertTo(ux, rect.getMinX() / magnification), Units.PIXEL.convertTo(uy, rect.getMinY() / magnification), 0, 0); ret.add(Units.PIXEL.convertTo(ux, rect.getMaxX() / magnification), Units.PIXEL.convertTo(uy, rect.getMaxY() / magnification)); return ret; }
@Override public Rectangle2D.Double getBounds() { if (cachedBounds == null) { if (getChildCount() == 0) { cachedBounds = new Rectangle2D.Double(); } else { for (Figure f : children) { Rectangle2D.Double bounds = f.getBounds(); if (f.get(TRANSFORM) != null) { bounds.setRect(f.get(TRANSFORM).createTransformedShape(bounds).getBounds2D()); } if (cachedBounds == null || cachedBounds.isEmpty()) { cachedBounds = bounds; } else { cachedBounds.add(bounds); } } } } return (Rectangle2D.Double) cachedBounds.clone(); }
@Override public Rectangle2D.Double getBounds() { if (cachedBounds == null) { if (getChildCount() == 0) { cachedBounds = new Rectangle2D.Double(); } else { for (Figure f : children) { if (cachedBounds == null) { cachedBounds = f.getBounds(); } else { cachedBounds.add(f.getBounds()); } } } } return (Rectangle2D.Double) cachedBounds.clone(); }
@Override public Rectangle2D.Double getDrawingArea() { Rectangle2D.Double r = super.getDrawingArea(); if (getNodeCount() > 1) { if (get(START_DECORATION) != null) { Point2D.Double p1 = getPoint(0, 0); Point2D.Double p2 = getPoint(1, 0); r.add(get(START_DECORATION).getDrawingArea(this, p1, p2)); } if (get(END_DECORATION) != null) { Point2D.Double p1 = getPoint(getNodeCount() - 1, 0); Point2D.Double p2 = getPoint(getNodeCount() - 2, 0); r.add(get(END_DECORATION).getDrawingArea(this, p1, p2)); } } return r; }
@Override public Rectangle2D.Double getDrawingArea() { if (cachedDrawingArea == null) { if (getChildCount() == 0) { cachedDrawingArea = new Rectangle2D.Double(); } else { for (Figure f : children) { if (cachedDrawingArea == null) { cachedDrawingArea = f.getDrawingArea(); } else { cachedDrawingArea.add(f.getDrawingArea()); } } } } return (Rectangle2D.Double) cachedDrawingArea.clone(); }
@Override public Rectangle2D.Double getDrawingArea() { if (cachedDrawingArea == null) { cachedDrawingArea = super.getDrawingArea(); for (Figure child : getChildrenFrontToBack()) { if (child.isVisible()) { Rectangle2D.Double childBounds = child.getDrawingArea(); if (! childBounds.isEmpty()) { cachedDrawingArea.add(childBounds); } } } } return (Rectangle2D.Double) cachedDrawingArea.clone(); } @Override
/** * Returns the bounds of the selected figures. */ protected Rectangle2D.Double getSelectionBounds() { Rectangle2D.Double bounds = null; for (Iterator i=getView().getSelectedFigures().iterator(); i.hasNext(); ) { Figure f = (Figure) i.next(); if (bounds == null) { bounds = f.getBounds(); } else { bounds.add(f.getBounds()); } } return bounds; }
public Rectangle2D.Double getBounds() { if (bounds == null) { bounds = body.getBounds(); Point2D.Double[] pts = head.calcArrowPoints(body.start, body.end); for (Point2D.Double pt : pts) { if (bounds == null) { bounds = new Rectangle2D.Double(pt.x, pt.y, 0, 0); } else { bounds.add(pt); } } } return bounds; }
/** * Grows the bounds to contain the coordinate provided. * * @param newx x component of point * @param newy y component of point */ public void add(final double newx, final double newy) { if (isEmpty) { setRect(newx, newy, 0, 0); isEmpty = false; } else { super.add(newx, newy); } }
/** * Returns the drawing area of the decorator. */ @Override public Rectangle2D.Double getDrawingArea(Figure f, Point2D.Double p1, Point2D.Double p2) { Rectangle2D.Double r = null; for (LineDecoration decoration : decorations) { Rectangle2D.Double aR = decoration.getDrawingArea(f, p1, p2); if (r == null) r = aR; else r.add(aR); } return r; }
@Override public void figureChanged(FigureEvent e) { if (!isChanging()) { Rectangle2D.Double invalidatedArea = getDrawingArea(); invalidatedArea.add(e.getInvalidatedArea()); // We call invalidate/validate here, because we must layout // the figure again. invalidate(); validate(); // Forward the figureChanged event to listeners on AbstractCompositeFigure. invalidatedArea.add(getDrawingArea()); fireFigureChanged(invalidatedArea); } }
public Rectangle2D.Double getBounds() { if (bounds == null) { bounds = body.getBounds(); Point2D.Double[] pts = head.calcArrowPoints(body.start, body.end); for (Point2D.Double pt : pts) { if (bounds == null) { bounds = new Rectangle2D.Double(pt.x, pt.y, 0, 0); } else { bounds.add(pt); } } } return bounds; }
/** * Grows bounds to contain the rectangle if needed. * * @param r rectangle being added */ public void add(final Rectangle2D r) { if (isEmpty) { setRect(r); } else { super.add(r); } }
/** * Return the draw area. This method is delegated to the * encapsulated presentation figure. */ @Override public Rectangle2D.Double getDrawingArea() { Rectangle2D.Double r = super.getDrawingArea(); if (getPresentationFigure() != null) { r.add(getPresentationFigure().getDrawingArea()); } return r; }
@Override public Rectangle2D deserialize(JsonParser jp, DeserializationContext arg1) throws IOException { IntermediateBoundingBox bbox = jp.readValueAs(IntermediateBoundingBox.class); if (bbox.north == null || bbox.south == null || bbox.east == null || bbox.west == null) throw new JsonParseException("Unable to deserialize bounding box; need north, south, east, and west.", jp.getCurrentLocation()); Rectangle2D.Double ret = new Rectangle2D.Double(bbox.west, bbox.north, 0, 0); ret.add(bbox.east, bbox.south); return ret; }
private void fireAreaInvalidated(BezierPath.Node v) { Rectangle2D.Double dr = new Rectangle2D.Double(v.x[0], v.y[0], 0, 0); for (int i = 1; i < 3; i++) { dr.add(v.x[i], v.y[i]); } Rectangle vr = view.drawingToView(dr); vr.grow(getHandlesize(), getHandlesize()); fireAreaInvalidated(vr); }
private void fireAreaInvalidated(BezierPath.Node v) { Rectangle2D.Double dr = new Rectangle2D.Double(v.x[0], v.y[0], 0, 0); for (int i = 1; i < 3; i++) { dr.add(v.x[i], v.y[i]); } Rectangle vr = view.drawingToView(dr); vr.grow(getHandlesize(), getHandlesize()); fireAreaInvalidated(vr); }
@Override public final Rectangle2D.Double getDrawingArea() { Rectangle2D.Double r = getFigureDrawingArea(); if (decorator != null) { updateDecoratorBounds(); r.add(decorator.getDrawingArea()); } return r; } protected Rectangle2D.Double getFigureDrawingArea() {