ToolBox.java 1.55 KB
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.JPanel;

/**
 * ToolBox this is another main component of paint. This holds all the tools and 
 * all the different things can be done.
 **/
public class ToolBox extends JPanel
{
	public static int RANDOMDRAW = 0, ERASER = 1, EYEDROPPER = 2, PENCIL = 3, 
	SPRAY = 4, LINE = 5, RECTANGLE = 6, OVAL = 7, ROUNDRECTANGLE = 8, 
	POLYGON = 9, CURVELINE = 10, TEXT = 11, BRUSH = 12, DRAG = 13, FILL = 14,
	SELECT = 15;
	public static ToolIcon[] tools;
	public static int toolSelected;
	
	/** Creates a default ToolBox. **/
	public ToolBox()
	{
		// sets the normal settings and calls the run method
		setLayout(null);
		setSize(200,300);
		run();
	}
	
	/** 
	 * Instantiates the tools and creates them in an array of ToolIcons. Sets
	 * bounds to them and a graphic and adds them to the screen.
	 **/
	public void run()
	{
		// instantiates and sets the background to white and then runs through
		// a loop to go through 16 tools and sets a image to each one and sets 
		// a location and size for it
		tools = new ToolIcon[16];
		setBackground(Color.white);
		for(int i=0;i<tools.length;i++)
		{
			String iconPath = "Images/"+i+".gif";
			tools[i] = new ToolIcon(iconPath,i);
			if(i<8)
				tools[i].setBounds(25,i*25+25,25,25);
			else
				tools[i].setBounds(50,(tools.length-i)*25,25,25);
			add(tools[i]);
			repaint();
		}
		// sets the initial default tool the pencil tool
		toolSelected = PENCIL;
		tools[toolSelected].setEnabled(false);
	}
}