package express.awt;

import java.awt.*;
import java.awt.event.*;
import java.lang.reflect.*;

public class ColumnOfBoxes extends Panel {
	
	public ChoiceBox[] choiceBoxes;
	public Color theColor;
	int columnLength;
	int boxHeight;
	int boxWidth;
	
	public Insets getInsets() {
		return new Insets(0, 0, 0, 0);
	}
	
	public ColumnOfBoxes(Color c, int n)  {
		setLayout(new GridLayout(0, 1, 0, 0));
		for(int i = 0; i < n; i++) {
			add(new ChoiceBox(c));
		}
		boxHeight = choiceBoxes[0].getSize().height;
		boxWidth = choiceBoxes[0].getSize().width;
	}
	
	public ColumnOfBoxes(Color[] colors) {
		columnLength = Array.getLength(colors);
		choiceBoxes = new ChoiceBox[columnLength];
		setLayout(new GridLayout(0, 1, 0, 0));			
		for(int i = 0; i < columnLength; i++) {
			choiceBoxes[i] = new ChoiceBox(colors[i]);
			add(choiceBoxes[i]);
		}
	}
	
	public void getColor(int y) {

		boxHeight = choiceBoxes[0].getSize().height;
		int selected = y/(boxHeight);
		selectColorBox(selected);		
	}
	

	public void selectColorBox(int selected) {

		theColor = choiceBoxes[selected].getForeground();

		choiceBoxes[selected].paintCorners();

		for(int i = 0; i < selected; i++) {
			choiceBoxes[i].eraseCorners();		
		}	
	
		for(int i = selected+1; i < columnLength; i++) {
			choiceBoxes[i].eraseCorners();		
		}		
		
	}

	public Dimension getPreferredSize() {
		return new Dimension(20, 400);
	}
	
	public void update(Graphics g) {
		paint(g);
	}	
	
}

