import java.awt.*;
import javax.swing.*;
import java.util.*;

//[0
/**
 * A simple GUI component that contains a
 * bunch of Shape objects
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class ShapeCanvas extends JComponent
{
    private Hashtable       shapes;
    
    /**
     * Default Constructor
     */
    public ShapeCanvas()
    {
       shapes = new Hashtable();       
    }
    

    /**
     * Add a Shape to this canvas
     *
     * @param s   The Shape to add
     */
    public void addShape(Shape s)
    {
       // The Shape is used as the key and the value
       shapes.put(s, s);
    }
    


    /**
     * Remove a Shape from this canvas
     *
     * @param s   The Shape to remove
     */
    public void removeShape(Shape s)
    {
       shapes.remove(s);       
    }
    

    //]0
    //[1
    /**
     * Render this canvas
     *
     * @param g   The rendering engine
     */
    public void paint(Graphics g)
    {
       Enumeration    e;       
       Graphics2D     g2;
       Shape          s;
       
       

       g2 = (Graphics2D)g;
       e = shapes.elements();
       while (e.hasMoreElements())
       {
          s = (Shape)e.nextElement();
          g2.draw(s);          
       }
    }
    //]1
    //[0
}
//]0
