public void draw(Graphics2D g, Collection<Figure> c) { for (Figure f : c) { if (f.isVisible()) { f.draw(g); } } }
@Override public Figure findFigureExcept(Point2D.Double p, Collection<? extends Figure> ignore) { for (Figure f : getFiguresFrontToBack()) { if (!ignore.contains(f) && f.isVisible() && f.contains(p)) { return f; } } return null; }
@Override public Figure findFigureBehind(Point2D.Double p, Collection<? extends Figure> children) { int inFrontOf = children.size(); for (Figure f : getFiguresFrontToBack()) { if (inFrontOf == 0) { if (f.isVisible() && f.contains(p)) { return f; } } else { if (children.contains(f)) { inFrontOf--; } } } return null; }
@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 java.util.List<Figure> findFiguresWithin(Rectangle2D.Double bounds) { LinkedList<Figure> contained = new LinkedList<Figure>(); for (Figure f : getChildren()) { 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; }
/** * Draw the figure. This method is delegated to the encapsulated presentation figure. */ @Override public void draw(Graphics2D g) { super.draw(g); for (Figure child : children) { if (child.isVisible()) { child.draw(g); } } }
@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 Figure findFigureExcept(Point2D.Double p, Figure ignore) { for (Figure f : getFiguresFrontToBack()) { if (f != ignore && f.isVisible() && f.contains(p)) { return f; } } return null; }
@Override public Figure findFigure(Point2D.Double p) { for (Figure f : getFiguresFrontToBack()) { if (f.isVisible() && f.contains(p)) { return f; } } return null; }
@Override public Figure findFigureBehind(Point2D.Double p, Figure figure) { boolean isBehind = false; for (Figure f : getFiguresFrontToBack()) { if (isBehind) { if (f.isVisible() && f.contains(p)) { return f; } } else { isBehind = figure == f; } } return null; }
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 public Figure findFigureBehind(Point2D.Double p, Figure figure) { boolean isBehind = false; for (Figure f : getFiguresFrontToBack()) { if (isBehind) { if (f.isVisible() && f.contains(p)) { return f; } } else { isBehind = figure == f; } } return null; }
@Nullable public Figure findFigureBehind(Point2D.Double p, Collection<Figure> figures) { int inFrontOf = figures.size(); for (Figure f : getFiguresFrontToBack()) { if (inFrontOf == 0) { if (f.isVisible() && f.contains(p)) { return f; } } else { if (figures.contains(f)) { inFrontOf--; } } } return null; }
public void draw(Graphics2D g, Collection<Figure> children) { Rectangle2D clipBounds = g.getClipBounds(); if (clipBounds != null) { for (Figure f : children) { if (f.isVisible() && f.getDrawingArea().intersects(clipBounds)) { f.draw(g); } } } else { for (Figure f : children) { if (f.isVisible()) { f.draw(g); } } } }
@Nullable public Figure findFigureBehind(Point2D.Double p, Figure figure) { boolean isBehind = false; for (Figure f : getFiguresFrontToBack()) { if (isBehind) { if (f.isVisible() && f.contains(p)) { return f; } } else { isBehind = figure == f; } } return null; } @Nullable public Figure findFigureBehind(Point2D.Double p, Collection<Figure> figures) {
@Override public Figure findFigureInside(Point2D.Double p) { if (getDrawingArea().contains(p)) { Figure found = null; for (Figure child : getChildrenFrontToBack()) { if (child.isVisible()) { found = child.findFigureInside(p); if (found != null) { return found; } } } } return null; } // CONNECTING
@Override public boolean contains(Point2D.Double p) { if (getDrawingArea().contains(p)) { for (Figure child : getChildrenFrontToBack()) { if (child.isVisible() && child.contains(p)) return true; } return super.contains(p); } return false; } // ATTRIBUTES
@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; }
@Override @Nullable public Figure findFigureInside(Point2D.Double p) { if (getDrawingArea().contains(p)) { Figure found = null; for (Figure child : getChildrenFrontToBack()) { if (child.isVisible()) { found = child.findFigureInside(p); if (found != null) { return found; } } } } return null; }
@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