@Override public java.util.List<Figure> sort(Collection<? extends Figure> c) { HashSet<Figure> unsorted = new HashSet<Figure>(); unsorted.addAll(c); ArrayList<Figure> sorted = new ArrayList<Figure>(c.size()); for (Figure f : getChildren()) { if (unsorted.contains(f)) { sorted.add(f); unsorted.remove(f); } } for (Figure f : c) { if (unsorted.contains(f)) { sorted.add(f); unsorted.remove(f); } } return sorted; }
@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; }
/** * Returns an iterator to iterate in * Z-order front to back over the children. */ @Override public java.util.List<Figure> getFiguresFrontToBack() { ensureSorted(); return new ReversedList<Figure>(getChildren()); }
@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; }
@Override public void draw(Graphics2D g) { synchronized (getLock()) { ensureSorted(); ArrayList<Figure> toDraw = new ArrayList<Figure>(getChildren().size()); Rectangle clipRect = g.getClipBounds(); for (Figure f : getChildren()) { if (f.getDrawingArea().intersects(clipRect)) { toDraw.add(f); } } draw(g, toDraw); } }