import java.awt.Graphics2D;
import java.awt.Polygon;
import java.io.File;
import java.util.ArrayList;


/**
 * TODO Put here a description of what this class does.
 *
 * @author Bryan Warner
 *         Created Apr 10, 2008.
 */
public class PolygonTool extends Tool{
	/**
	 * this is an array for the x components of a list of points
	 */
	ArrayList<Integer> xarray = new ArrayList<Integer>();
	/**
	 * this is an array for the y components of a list of points
	 */
	ArrayList<Integer> yarray = new ArrayList<Integer>();
	/**
	 * this constructor makes a custom polygon with the selected color as its outline.
	 *
	 */
	public PolygonTool(){
		super(20,new File("Poly.bmp"),"polygon");			
	}
		
		
	/**
	 * adds the polygon to the canvas 
	 *
	 */
	public void polyFinish(){
		this.x=-1;
		this.y=-1;
		try{
		Graphics2D g  = this.c.getImage().createGraphics();
		g.setColor(this.c.getPaint().cc.getColor());
		g.draw(this.c.getShape());
		this.c.setShape(null);
		this.c.repaint();
		}
		catch(NullPointerException e){
			//
		}
		
	}
	@Override
	public void finish(){
		//
	}
	@Override
	public void Paint(Canvas c, int x, int y){
		this.c = c;
		this.xarray.add(x);
		this.yarray.add(y);
		int[] xs=new int[this.xarray.size()];
		int[] ys=new int[this.yarray.size()];
		for (int i =0; i<xs.length;i++){
			xs[i]=this.xarray.get(i);
		}
		for (int i =0; i<ys.length;i++){
			ys[i]=this.yarray.get(i);
		}
		if(this.xarray.size()!=1){
			Polygon e = new Polygon(xs,ys,this.xarray.size());
			this.c.setShape(e);
		}
	}

}
