001package horstmann.ch06_scene3;
002import java.awt.Graphics2D;
003import java.awt.Shape;
004import java.awt.geom.AffineTransform;
005import java.awt.geom.GeneralPath;
006import java.awt.geom.Point2D;
007
008/**
009   A scene shape that is composed of multiple geometric shapes.
010 */
011public abstract class CompoundShape extends SelectableShape
012{
013        public CompoundShape()
014        {
015                path = new GeneralPath();
016        }
017
018        protected void add(Shape s)
019        {
020                path.append(s, false);
021        }
022
023        public boolean contains(Point2D aPoint)
024        {
025                return path.contains(aPoint);
026        }
027
028        public void translate(int dx, int dy)
029        {
030                path.transform(
031                                AffineTransform.getTranslateInstance(dx, dy));
032        }
033
034        public void draw(Graphics2D g2)
035        {
036                g2.draw(path);
037        }
038
039        private GeneralPath path;
040}
041
042
043
044
045
046
047