import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.io.File;


/**
 * This class implements a tool that lets the user draw rectangles in the GUI and it shows a preview of the shape until you click to draw*
 * @author Bryan Warner
 *         Created Apr 10, 2008.
 */
public class RectangleFillTool extends Tool{
	/**
	 * this makes a rectangle that is filled with the selected color
	 *
	 */
	public RectangleFillTool(){
		super(20,new File("rectanglefill.bmp"),"filled rectangle");			
	}
		
		
	@Override
	public void finish(){
		this.x=-1;
		this.y=-1;
		Graphics2D g  = this.c.getImage().createGraphics();
		g.setColor(this.c.getPaint().cc.getColor());
		g.fill(this.c.getShape());
		this.c.setShape(null);
		this.c.repaint();
	}
	@Override
	public void Paint(Canvas c, int x, int y){
		if(this.x != -1 && this.y != -1){
			Rectangle2D.Double r = new Rectangle2D.Double(this.x,this.y,x-this.x,y-this.y);
			this.c.setShape(r);
		}
		else{
		this.c = c;
		this.x = x;
		this.y = y;
		}
	}

}