import java.awt.*;
import javax.swing.*;
import java.util.*;

//[0
/**
 * A simple GUI component that contains a collection of Shape objects
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class ShapeCanvas extends JComponent
{
    private HashSet       shapes;
    
    /**
     * Default Constructor
     */
    public ShapeCanvas()
    {
       shapes = new HashSet();       
    }

    /**
     * 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.add(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)
    {
       Iterator       i;       
       Graphics2D     g2;
       Shape          s;
       
       

       g2 = (Graphics2D)g;
       i = shapes.iterator();
       while (i.hasNext())
       {
          s = (Shape)i.next();
          g2.draw(s);          
       }
    }
    //]1
    //[0
}
//]0
