@Override public void setBounds(Point2D.Double anchor, Point2D.Double lead) { Rectangle2D.Double oldBounds = getBounds(); Rectangle2D.Double newBounds = new Rectangle2D.Double( Math.min(anchor.x, lead.x), Math.min(anchor.y, lead.y), Math.abs(anchor.x - lead.x), Math.abs(anchor.y - lead.y)); double sx = newBounds.width / oldBounds.width; double sy = newBounds.height / oldBounds.height; AffineTransform tx = new AffineTransform(); tx.translate(-oldBounds.x, -oldBounds.y); if (!Double.isNaN(sx) && !Double.isNaN(sy) && !Double.isInfinite(sx) && !Double.isInfinite(sy) && (sx != 1d || sy != 1d) && !(sx < 0.0001) && !(sy < 0.0001)) { transform(tx); tx.setToIdentity(); tx.scale(sx, sy); transform(tx); tx.setToIdentity(); } tx.translate(newBounds.x, newBounds.y); transform(tx); }
/** * Return the logcal display area. This method is delegated to the encapsulated * presentation figure. */ @Override public Rectangle2D.Double getBounds() { if (getPresentationFigure() == null) { return super.getBounds(); } return getPresentationFigure().getBounds(); }
@Nullable public Figure findChild(Point2D.Double p) { if (getBounds().contains(p)) { Figure found = null; for (Figure child : getChildrenFrontToBack()) { if (child.isVisible() && child.contains(p)) { return child; } } } return null; }
/** * A layout algorithm is used to define how the child components * should be laid out in relation to each other. The task for * layouting the child components for presentation is delegated * to a Layouter which can be plugged in at runtime. */ @Override public void layout() { // Note: We increase and below decrease the changing depth here, // because we want to ignore change events from our children // why we lay them out. changingDepth++; for (Figure child : getChildren()) { if (child instanceof CompositeFigure) { CompositeFigure cf = (CompositeFigure) child; cf.layout(); } } changingDepth--; if (getLayouter() != null) { Rectangle2D.Double bounds = getBounds(); Point2D.Double p = new Point2D.Double(bounds.x, bounds.y); Rectangle2D.Double r = getLayouter().layout( this, p, p); setBounds(new Point2D.Double(r.x, r.y), new Point2D.Double(r.x + r.width, r.y + r.height)); invalidate(); } }