import java.util.*; /** I use this class to associate a Frame and a HashMap of shapes with a frame id. @author Charlie McDowell */ class FrameMap { private Frame frame; private int id; private HashMap shapes = new HashMap(); /** Construct a FrameMap to wrap an underlying Frame. @param id to be associated with this Frame. @param frame the Frame */ FrameMap(int id, Frame frame) { this.id = id; this.frame = frame; } /** Check if this frame contains a shape with the specified id. */ boolean contains(int id) { return shapes.get(id) != null; } /** Get the frame id of this frame. */ int getId() { return id; } /** Remove a shape from this frame given the shape's id. @param sid - the shapes integer id */ void remove(int sid) { Shape shape = shapes.get(sid); if (shape == null) { System.out.println("Warning: No such shape"); } else { frame.remove(shape); shapes.remove(sid); } } /** Show the underlying frame. */ void show() { frame.show(); } /** Remove all shapes from the underlying Frame. */ void clear() { for (Shape s : shapes.values()) { frame.remove(s); } shapes.clear(); } /** Add a shape with a specified id to this frame. @param shape - the shape to be added @param sid - the integer id used to delet the shape if needed later */ void add(Shape shape, int sid) { frame.add(shape); shapes.put(sid, shape); } }