import java.awt.event.*;
import java.awt.*;
import gjt.rubberband.*;

/**
  * a tool for creating rectangles, and in general any figure
  * by extending and overriding getFigure
  *
  * @author Owen Astrachan
  *
  * @see ToolAdapter
  *
  */
public class RectangleTool extends ToolAdapter
{
    public RectangleTool(Controller c)
    {
	super(c);
	myOutline = new RubberbandRectangle();
    }

    public void setActive(boolean status)
    {
	if (status == true)
	{
	    myOutline.setComponent(myController.getDrawingArea());
	    myOutline.setActive(true);
	    myController.getDrawingArea().addMouseListener(this);	    
	}
	else
	{
	    myOutline.setActive(false);
	    myController.getDrawingArea().removeMouseListener(this);
	}
    }

    /**
      * when mouse is released draw a figure, this should check
      * to see if the figure is big enough to be viewable
      */
    
    public void mouseReleased(MouseEvent e)
    {
	myController.addFigure(getFigure());
    }

    /**
     * @return the figure that will be drawn when mouse is released
     */
    
    protected Figure getFigure()
    {
	return new RectangleFigure(myOutline.getBounds(),
				   myController.getColor());
    }

    boolean             myIsFinished;
    RubberbandRectangle myOutline;
}
