@Override public Collection<Figure> getDecomposition() { LinkedList<Figure> list = new LinkedList<Figure>(); list.add(this); list.addAll(getChildren()); return list; }
/** * Returns an iterator to iterate in * Z-order front to back over the children. */ public java.util.List<Figure> getChildrenFrontToBack() { return children.size() == 0 ? new LinkedList<Figure>() : new ReversedList<Figure>(getChildren()); }
/** * Removes all children. * * @see #add */ @Override public void basicRemoveAllChildren() { for (Figure f : new LinkedList<Figure>(getChildren())) { basicRemove(f); } }
@Override public Object getTransformRestoreData() { LinkedList<Object> list = new LinkedList<Object>(); for (Figure child : getChildren()) { list.add(child.getTransformRestoreData()); } return list; }
/** * Removes all children. * * @see #add */ @Override public void removeAllChildren() { removeAll(getChildren()); }
@Override public Object getAttributesRestoreData() { LinkedList<Object> data = new LinkedList<Object>(); for (Figure child : getChildren()) { data.add(child.getAttributesRestoreData()); } return data; }
@Override public void restoreAttributesTo(Object newData) { @SuppressWarnings("unchecked") Iterator<Object> data = ((LinkedList<Object>) newData).iterator(); for (Figure child : getChildren()) { child.restoreAttributesTo(data.next()); } }
@Override public void restoreTransformTo(Object geometry) { LinkedList list = (LinkedList) geometry; Iterator i = list.iterator(); for (Figure child : getChildren()) { child.restoreTransformTo(i.next()); } invalidate(); }
@Override public void removeNotify(Drawing drawing) { super.removeNotify(drawing); // Copy children collection to avoid concurrent modification exception for (Figure child : new LinkedList<Figure>(getChildren())) { child.removeNotify(drawing); } }
@Override public void addNotify(Drawing drawing) { super.addNotify(drawing); for (Figure child : getChildren()) { child.addNotify(drawing); } }
/** * Transforms the figure. */ @Override public void transform(AffineTransform tx) { for (Figure f : getChildren()) { f.transform(tx); } invalidate(); //invalidate(); }
@Override public <T> void set(AttributeKey<T> key, T value) { for (Figure child : getChildren()) { child.set(key, value); } invalidate(); }
@Override public void write(DOMOutput out) throws IOException { out.openElement("children"); for (Figure child : getChildren()) { out.writeObject(child); } out.closeElement(); }
@Override public void draw(Graphics2D g) { Rectangle2D clipBounds = g.getClipBounds(); if (clipBounds != null) { for (Figure child : getChildren()) { if (child.isVisible() && child.getDrawingArea().intersects(clipBounds)) { child.draw(g); } } } else { for (Figure child : getChildren()) { if (child.isVisible()) { child.draw(g); } } } }
/** * 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(); } }
@Override public boolean contains(Point2D.Double p) { if (getDrawingArea().contains(p)) { if (get(TRANSFORM) != null) { try { p = (Point2D.Double) get(TRANSFORM).inverseTransform(p, new Point2D.Double()); } catch (NoninvertibleTransformException ex) { InternalError error = new InternalError(ex.getMessage()); error.initCause(ex); throw error; } } for (Figure child : getChildren()) { if (child.isVisible() && child.contains(p)) { return true; } } } return false; }