import javax.swing.JPanel;
import javax.swing.JComboBox;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;

public class TeamChooser extends JPanel {
    // OVERVIEW: SimObjectChooser manipulates the interface for selecting objects
    //    and maintains state for the current object type.  
    //
    // When clicking on a spot on the grid, it will be set to this class.
    // Rep:

    private Color selectedClass; 
    private JComboBox combolist;
    private String[] classes;
    public String[] teams;
    
    
    public Color team;

   TeamChooser ()
	// EFFECT: Initializes this to a SimObjectChooser with no classes.
    {
	selectedClass = null;
        team=null;
	classes = null;
	combolist = new JComboBox ();

	combolist.addActionListener 
	    (new ActionListener () {
		    public void actionPerformed (ActionEvent e) {
			JComboBox cb = (JComboBox) e.getSource ();
			String classname = (String) cb.getSelectedItem ();
			setSelectedClass (classname);
		    }
		}
	     );

	add (combolist);
    }

    public void addClass (String className) throws ClassNotFoundException
        // MODIFIES: this, the display panel
	// EFFECTS: If className is the name of a loadable Java class, sets the current object
        //    to the type loaded by className. If className is not available, throws ClassNotFoundException. 
    {
	//Class newClass = Class.forName (className); // throws ClassNotFoundException if not found
	Color newClass = stringToColor(className);
        
	String [] oldclasses = classes;

	if (oldclasses == null) {
	    classes = new String [1];
	    selectedClass = newClass;
	} else {
	    classes = new String [oldclasses.length + 1];
	}

	if (oldclasses != null) {
	    for (int i = 0; i < oldclasses.length; i++) {
		classes[i] = oldclasses[i];
	    }
	}

	classes[classes.length - 1] = className;
	combolist.addItem (className);
    }

    public Color getSelectedClass()
	// EFFECTS: Returns the currently selected class (possibly null).
    {
	return selectedClass;
    }

    public void setSelectedClass (String classname)
	// MODIFIES: this
	// EFFECTS: Sets the currently selected class to the class associated
	//    with the button press (described by the ActionEvent).
    {
	
	    Color newClass = stringToColor (classname);
	    selectedClass = newClass;
	
    }
    
    public Color stringToColor(String c1)
    {
        if(c1=="Blue")
            return Color.blue;
        if(c1=="Red")
            return Color.red;
            
        if(c1=="Green")
            return Color.green;
        
        if(c1=="Purple")
            return Color.magenta;
        
        if(c1=="Orange")
            return Color.orange;
        
         if(c1=="Black")
            return Color.black;
        
         if(c1=="White")
            return Color.white;
        
        return(new Color(120,57,89));
        
        
        
    }

     public void setSelectedTeam (String c1)
	// MODIFIES: this
	// EFFECTS: Sets the currently selected class to the class associated
	//    with the button press (described by the ActionEvent).
    {
	
	    team = stringToColor(c1);
            //selectedClass = newClass;
	
    }
}