import java.awt.Font;
import java.awt.Panel;
import java.awt.ScrollPane;
import java.awt.Color;
import java.awt.Event;
import java.awt.Button;
import java.util.Vector;
import java.awt.Dimension;

public class ButtonPanel extends Panel implements buttonpanelAble{
    Vector listvec, typevec;
    private Vector ButtonGraphSet, ButtonRemoveGraphSet;
    private String temp;
    private String btype;
    public Panel panel;
    private newButton tmpb;
    private Model model_parent;

    ButtonPanel (Vector list, Model model) {

	setLayout(new VListLayout(40, 30));
	setBackground(new Color(255,153,255));
        String temp=new String();
        listvec = list;
	btype = listvec.elementAt(0).toString();
	typevec = new Vector();
	model_parent = model;
	ButtonGraphSet = new Vector();
	ButtonRemoveGraphSet = new Vector();
    }

	
    public void update_panel() {
	for (int i=1; i<listvec.size(); i++) {
	    typevec.addElement(this);
	    typevec.addElement(listvec.elementAt(i).toString());
	    System.err.println("i="+i+" "+listvec.elementAt(i).toString());
	    typevec.addElement(btype);
	    tmpb = new newButton(typevec);
	    tmpb.setBackground(new Color(204,102,204));
	    add(tmpb);
	    ButtonGraphSet.addElement(tmpb);
	    typevec.removeAllElements();
	}

	Font f = new Font("Monospaced", Font.BOLD, 12);
	//model_data.setFont(f);
	//model_results.setFont(f);
    }

    public void newButtonAction(String who, String command) {
	System.err.println("ButtonPanel: who="+who+" command="+command);
    }

    public boolean action (Event e, Object o) {

	for (int i=0; i<ButtonGraphSet.size(); i++) {
	    if (e.target==ButtonGraphSet.elementAt(i)) {
		//tmpb = (Button)ButtonGraphSet.elementAt(i);
		tmpb = (newButton)ButtonGraphSet.elementAt(i);
		temp = tmpb.getLabel();
	    	//System.out.println("Drawing graph for: "+temp);
		// Remove the element to disable future events
		ButtonRemoveGraphSet.addElement(tmpb);
		model_parent.update_graph("Add", temp);
		ButtonGraphSet.removeElementAt(i);
		// Extract info such as url
		return(true);
	    }
	}

        for (int i=0; i<ButtonRemoveGraphSet.size(); i++) {
            if (e.target==ButtonRemoveGraphSet.elementAt(i)) {
		//tmpb = (Button)ButtonRemoveGraphSet.elementAt(i);
		tmpb = (newButton)ButtonRemoveGraphSet.elementAt(i);
		temp = tmpb.getLabel();
                //System.out.println("Removing graph for: "+temp);
                // Remove the element to disable future events
		ButtonGraphSet.addElement(tmpb);
		model_parent.update_graph("Remove", temp);
                ButtonRemoveGraphSet.removeElementAt(i);
                // Extract info such as url
		return(true);
            }
        }
	return(false);
    }
}
	
