import java.awt.*; import java.awt.geom.*; /** A scene shape that is composed of multiple geometric shapes. */ public abstract class CompoundShape extends SelectableShape { public CompoundShape() { path = new GeneralPath(); area = new Area(); } /** * Adds the shape to the compound shape (unfilled by default). * @param s a Shape */ protected void add(Shape s) { add(s, false); } /** * Adds the shape to the compound shape, with the caller * designating whether or not this shape should be filled. * @param s a shape * @param filled true to make this shape filled; false otherwise */ protected void add(Shape s, boolean filled) { path.append(s, false); if (filled) area.add(new Area(s)); } public boolean contains(Point2D aPoint) { return path.contains(aPoint); } public void translate(int dx, int dy) { AffineTransform t = AffineTransform.getTranslateInstance(dx,dy); path.transform(t); area.transform(t); } public void draw(Graphics2D g2) { g2.fill(area); g2.draw(path); } private GeneralPath path; private Area area; }