//MultiStubPanel.java

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class Trans_MultiStubPanel extends Panel implements ItemListener{
    //public static final Color bgcolor = new Color(180,147,112);
    //public static final Color bgcolor = new Color(200,200,200);
    private static final Color bgcolor = new Color(216,216,191); // kaki
    public StubPanel stp1, stp2, stp3;
    public Choice c1;
    GridBagLayout gb = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    private String titulo = "Unknown Title";
    private static final Font titlefont = TheFonts.bold16;
    private Label titlelabel;
    private Trans_State state;
    public Trans_MultiStubPanel(String titulo, Trans_State state){
	super();
	this.state = state;
	setBackground(bgcolor);
	this.titulo=titulo;
	stp1 = new StubPanel("Shunt 1",state.stub[0],state);
	stp2 = new StubPanel("Shunt 2",state.stub[1],state);
	stp3 = new StubPanel("Shunt 3",state.stub[2],state);
	setLayout(gb);
	titlelabel = new Label(titulo,Label.CENTER);
	titlelabel.setFont(titlefont);
	
	c1 = new Choice();
	c1.addItem("Shunt 1");
	c1.addItem("Shunt 2");
	c1.addItem("Shunt 3");
	c1.setBackground(bgcolor.brighter());
	//add(titlelabel);
	//titlelabel.setBounds(10,10,150,30);
	//add(c1);
	//c1.setBounds(160,10,60,30);
	
	try{
	    MaestroG.addComponent(this,titlelabel,0,0,1,1,
		GridBagConstraints.BOTH,GridBagConstraints.CENTER);
	} catch(Exception e){e.printStackTrace();}
	try{
	    MaestroG.addComponent(this,c1,0,1,1,1,
		GridBagConstraints.NONE,GridBagConstraints.CENTER);
	} catch(Exception e){e.printStackTrace();}
	{
	try{
	    MaestroG.addComponent(this,stp1,0,2,1,1,
		GridBagConstraints.BOTH,GridBagConstraints.CENTER);
	} catch(Exception e){e.printStackTrace();}
	try{
	    MaestroG.addComponent(this,stp2,0,2,1,1,
		GridBagConstraints.BOTH,GridBagConstraints.CENTER);
	} catch(Exception e){e.printStackTrace();}
	try{
	    MaestroG.addComponent(this,stp3,0,2,1,1,
		GridBagConstraints.BOTH,GridBagConstraints.CENTER);
	} catch(Exception e){e.printStackTrace();}
	//show and hide
	}
	/*
	stp1.setVisible(false);
	stp2.setVisible(false);
	stp3.setVisible(false);
	*/
	//Listeners
	c1.addItemListener(this);
    }
    
    public void paint(Graphics g){
		g.setColor(Color.black);
                g.drawLine(0,getSize().height-1,getSize().width-1,getSize().height-1);
                g.drawLine(getSize().width-1,0,getSize().width-1,getSize().height-1);
                g.setColor(Color.white);
                g.drawLine(0,0,getSize().width-1,0);
                g.drawLine(0,0,0,getSize().height-1);
    }
    
    public void itemStateChanged(ItemEvent evt){
	ItemSelectable ie = evt.getItemSelectable();
	    if(evt.getSource()==c1){
		if(ie.getSelectedObjects()[0]=="Shunt 1"){
		    stp1.setVisible(true);
		    
		    stp2.setVisible(false);
		    stp3.setVisible(false);
		}
		else if(ie.getSelectedObjects()[0]=="Shunt 2"){
		    stp1.setVisible(false);
		    stp2.setVisible(true);
		    stp3.setVisible(false);
		}
		else if(ie.getSelectedObjects()[0]=="Shunt 3"){
		    stp1.setVisible(false);
		    stp2.setVisible(false);
		    stp3.setVisible(true);
		    
		}
	    }
    }
    
}
