@Override public void makeRelativeToFigureBounds(Figure f) { if (! isRelativeToFigureBounds) { isRelativeToFigureBounds = true; Rectangle2D.Double bounds = f.getBounds(); x1 = (x1 - bounds.x) / bounds.width; y1 = (y1 - bounds.y) / bounds.height; x2 = (x2 - bounds.x) / bounds.width; y2 = (y2 - bounds.y) / bounds.height; } }
@Override public void makeRelativeToFigureBounds(Figure f) { if (! isRelativeToFigureBounds) { isRelativeToFigureBounds = true; Rectangle2D.Double bounds = f.getBounds(); cx = (cx - bounds.x) / bounds.width; cy = (cy - bounds.y) / bounds.height; r = r / Math.sqrt(bounds.width * bounds.width / 2d + bounds.height * bounds.height / 2d); } }
@Override protected Point2D.Double chop(Figure target, Point2D.Double from) { return Geom.angleToPoint(target.getBounds(), angle); }
public StickyRectangleConnector(Figure owner, Point2D.Double p) { super(owner); this.angle = (float) Geom.pointToAngle(owner.getBounds(), p); }
@Override public void draw(Graphics2D g) { if (createdFigure != null && rubberbandColor != null) { g.setColor(rubberbandColor); g.draw(getView().drawingToView(createdFigure.getBounds())); } }
protected Rectangle2D.Double getTransformedBounds() { Figure owner = getOwner(); Rectangle2D.Double bounds = owner.getBounds(); if (owner.get(TRANSFORM) != null) { Rectangle2D r = owner.get(TRANSFORM). createTransformedShape(bounds).getBounds2D(); bounds.x = r.getX(); bounds.y = r.getY(); bounds.width = r.getWidth(); bounds.height = r.getHeight(); } return bounds; }
protected Rectangle2D.Double getTransformedBounds() { Figure owner = getOwner(); Rectangle2D.Double bounds = owner.getBounds(); if (owner.get(TRANSFORM) != null) { Rectangle2D r = owner.get(TRANSFORM). createTransformedShape(bounds).getBounds2D(); bounds.x = r.getX(); bounds.y = r.getY(); bounds.width = r.getWidth(); bounds.height = r.getHeight(); } return bounds; }
@Override public java.util.List<Figure> findFiguresWithin(Rectangle2D.Double bounds) { LinkedList<Figure> contained = new LinkedList<Figure>(); for (Figure f : children) { Rectangle2D.Double r = f.getBounds(); if (f.get(TRANSFORM) != null) { Rectangle2D rt = f.get(TRANSFORM).createTransformedShape(r).getBounds2D(); r = (rt instanceof Rectangle2D.Double) ? (Rectangle2D.Double) rt : new Rectangle2D.Double(rt.getX(), rt.getY(), rt.getWidth(), rt.getHeight()); } if (f.isVisible() && Geom.contains(bounds, r)) { contained.add(f); } } return contained; }
@Override public void updateAnchor(Point2D.Double p) { this.angle = (float) Geom.pointToAngle(getOwner().getBounds(), p); } @Override
@Override public java.util.List<Figure> findFigures(Rectangle2D.Double bounds) { LinkedList<Figure> intersection = new LinkedList<Figure>(); for (Figure f : getChildren()) { if (f.isVisible() && f.getBounds().intersects(bounds)) { intersection.add(f); } } return intersection; }
@Override public Point2D.Double getAnchor() { return Geom.angleToPoint(getOwner().getBounds(), angle); } @Override protected Point2D.Double chop(Figure target, Point2D.Double from) {
public java.util.List<Figure> findFiguresWithin(Rectangle2D.Double bounds) { LinkedList<Figure> contained = new LinkedList<Figure>(); for (Figure f : children) { Rectangle2D r = f.getBounds(); if (f.get(TRANSFORM) != null) { r = f.get(TRANSFORM).createTransformedShape(r).getBounds2D(); } if (f.isVisible() && bounds.contains(r)) { contained.add(f); } } return contained; }
@Override protected Rectangle basicGetBounds() { Figure o = getOwner(); Rectangle2D.Double b = o.getBounds(); Point2D.Double p = new Point2D.Double(b.x + b.width, b.y + b.height); if (o.get(TRANSFORM) != null) { o.get(TRANSFORM).transform(p, p); } Rectangle r = new Rectangle(view.drawingToView(p)); int h = getHandlesize(); r.x -= h*4; r.y -= h; r.width = h*2; r.height = h; return r; }
/** * 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(); }
@Override protected Rectangle basicGetBounds() { Shape bounds = getOwner().getBounds(); if (getOwner().get(TRANSFORM) != null) { bounds = getOwner().get(TRANSFORM).createTransformedShape(bounds); } bounds = view.getDrawingToViewTransform().createTransformedShape(bounds); Rectangle r = bounds.getBounds(); r.grow(2, 2); return r; }
@Override protected void alignFigures(Collection selectedFigures, Rectangle2D.Double selectionBounds) { double y = selectionBounds.y; for (Iterator i=getView().getSelectedFigures().iterator(); i.hasNext(); ) { Figure f = (Figure) i.next(); if (f.isTransformable()) { f.willChange(); Rectangle2D.Double b = f.getBounds(); AffineTransform tx = new AffineTransform(); tx.translate(0, y - b.y); f.transform(tx); f.changed(); fireUndoableEditHappened(new TransformEdit(f, tx)); } } } }
@Override protected void alignFigures(Collection selectedFigures, Rectangle2D.Double selectionBounds) { double x = selectionBounds.x; for (Iterator i=getView().getSelectedFigures().iterator(); i.hasNext(); ) { Figure f = (Figure) i.next(); if (f.isTransformable()) { f.willChange(); Rectangle2D.Double b = f.getBounds(); AffineTransform tx = new AffineTransform(); tx.translate(x - b.x, 0); f.transform(tx); f.changed(); fireUndoableEditHappened(new TransformEdit(f, tx)); } } } }
@Override public void trackStart(Point anchor, int modifiersEx) { oldValue = getOwner().get(ORIENTATION); centerBox = view.drawingToView(getOwner().getBounds()); centerBox.grow(centerBox.width / -3, centerBox.height / -3); }
@Override public void trackStart(Point anchor, int modifiersEx) { isTransformableCache = getOwner().isTransformable(); if (!isTransformableCache) { return; } geometry = getOwner().getTransformRestoreData(); Point location = getLocation(); sx = -anchor.x + location.x; sy = -anchor.y + location.y; sb = getOwner().getBounds(); aspectRatio = sb.height / sb.width; }