//MultiStubPanel.java

import java.awt.*;
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(236,236,236);
    public StubPanel stp1, stp2, stp3, stp4, stp5, stp6, stp7, stp8, stp9, stp10;
    public StubPanelNew stpnew2;
    public Choice c1;
    private String titulo = "Unknown Title";
    private Font titlefont;
    protected Font buttonfont;
    private Label titlelabel;
    private Trans_State state;
    public Button SetLoad;
    public Trans_MultiStubPanel(String titulo, Trans_State state){
	super();
	this.state = state;
	setBackground(bgcolor);
	this.titulo=titulo;
        
        titlefont = new Font("SanSerif",Font.PLAIN,state.font14);
        buttonfont = new Font("SanSerif",Font.PLAIN,state.font12);
    
        
        Color color1 = Color.blue;
        Color color2 = Color.black;
        Color color3 = Color.red;

	stp1 = new StubPanel("Section 1",state.stub[0],state,color1);
	stp2 = new StubPanel("Section 2",state.stub[1],state,color2);
	stp3 = new StubPanel("Section 3",state.stub[2],state,color3);
	stp4 = new StubPanel("Section 4",state.stub[3],state,color1);
	stp5 = new StubPanel("Section 5",state.stub[4],state,color2);
	stp6 = new StubPanel("Section 6",state.stub[5],state,color3);
        stp7 = new StubPanel("Section 7",state.stub[6],state,color1);
	stp8 = new StubPanel("Section 8",state.stub[7],state,color2);
	stp9 = new StubPanel("Section 9",state.stub[8],state,color3);
        stp10 = new StubPanel("Section 10",state.stub[9],state,color1);
	
        stpnew2 = new StubPanelNew("Section 2",state.stub[1],state,color2);
        
        setLayout(null);
        
        titlelabel = new Label(titulo,Label.LEFT);
	titlelabel.setFont(titlefont);
	
        titlelabel.setBounds(state.s10,state.s5,state.s180,state.s20);
        
        titlelabel.setForeground(Color.red.darker());
        add(titlelabel);
        
	c1 = new Choice();
	//c1.addItem("Section 1");
	//c1.addItem("Section 2");
	//c1.addItem("Section 3");
        //c1.addItem("Section 4");
	//c1.addItem("Section 5");
	//c1.addItem("Section 6");
        //c1.addItem("Section 7");
	c1.addItem("Section 8");
	c1.addItem("Section 9");
        c1.addItem("Section 10");
	
        c1.setBackground(bgcolor.brighter());
        //c1.setBounds(150,10,100,25);
        //c1.setBounds(200,5,100,25);
        
        //add(c1);
        
        //======================================================================
        //======================================================================
        // This is the module used to describe "Set Line"
        stp1.setBounds(state.s5,state.s29,state.s300,state.s98);
        add(stp1);
        
        // This is the module to describe the transformer section
        stpnew2.setBounds(state.s5,state.s126,state.s300,state.s98);
        add(stpnew2);
        
        //======================================================================
        //======================================================================
        // Modules Below not used in this application
        
        stp2.setBounds(5,124,300,100);
        //add(stp2);
        
        stp3.setBounds(5,40,300,93);
        add(stp3);
        
        stp4.setBounds(5,40,300,93);
        add(stp4);
        
        stp5.setBounds(5,40,300,93);
        add(stp5);
        
        stp6.setBounds(5,40,300,93);
        add(stp6);
        
        stp7.setBounds(5,40,300,93);
        add(stp7);
        
        stp8.setBounds(5,40,300,93);
        add(stp8);
        
        stp9.setBounds(5,40,300,93);
        add(stp9);
        
        stp10.setBounds(5,40,300,93);
        add(stp10);
        
        //SetLoad = new Button("\u21aa Set  Load"); // this unicode character does not work in label environment, only in canvas.  Why?
        SetLoad = new Button(">>  Set  Load");
        SetLoad.setBounds(state.s200,state.s5,state.s105,state.s18);
        SetLoad.setBackground(Color.white);
        SetLoad.setFont(buttonfont);
        add(SetLoad);
        Panel load1 = new Panel();
		    load1.setBackground(Color.black);
		    add(load1);
		    load1.setBounds(state.s200-1,state.s5-1,state.s105+2,state.s18+2);
        
	//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);
                */
        
                g.setColor(bgcolor.darker());
                g.fillRect(0,getSize().height-2,getSize().width,2);
                g.fillRect(getSize().width-2,0,2,getSize().height);
                g.setColor(bgcolor.brighter());
                g.fillRect(0,0,2,getSize().height-1);
                g.fillRect(0,0,getSize().width-2,2);
    }
    
    public void itemStateChanged(ItemEvent evt){
	ItemSelectable ie = evt.getItemSelectable();
	    if(evt.getSource()==c1){
		/*
                if(ie.getSelectedObjects()[0]=="Section 10"){
		    stp1.setVisible(true);
		    stp2.setVisible(true);
		    stp3.setVisible(false);
                    stp4.setVisible(false);
		    stp5.setVisible(false);
                    stp6.setVisible(false);
		    stp7.setVisible(false);
                    stp8.setVisible(false);
		    stp9.setVisible(false);
                    stp10.setVisible(false);
                }
		else if(ie.getSelectedObjects()[0]=="Section 9"){
		    stp1.setVisible(false);
		    stp2.setVisible(true);
		    stp3.setVisible(false);
                    stp4.setVisible(false);
		    stp5.setVisible(false);
                    stp6.setVisible(false);
		    stp7.setVisible(false);
                    stp8.setVisible(false);
		    stp9.setVisible(false);
                    stp10.setVisible(false);
		}
		else if(ie.getSelectedObjects()[0]=="Section 8"){
		    stp1.setVisible(false);
		    stp2.setVisible(false);
		    stp3.setVisible(true);
		    stp4.setVisible(false);
		    stp5.setVisible(false);
                    stp6.setVisible(false);
		    stp7.setVisible(false);
                    stp8.setVisible(false);
		    stp9.setVisible(false);
                    stp10.setVisible(false);
		}
                else if(ie.getSelectedObjects()[0]=="Section 7"){
		    stp1.setVisible(false);
		    stp2.setVisible(false);
		    stp3.setVisible(false);
                    stp4.setVisible(true);
		    stp5.setVisible(false);
                    stp6.setVisible(false);
		    stp7.setVisible(false);
                    stp8.setVisible(false);
		    stp9.setVisible(false);
                    stp10.setVisible(false);
		}
		else if(ie.getSelectedObjects()[0]=="Section 6"){
		    stp1.setVisible(false);
		    stp2.setVisible(false);
		    stp3.setVisible(false);
                    stp4.setVisible(false);
		    stp5.setVisible(true);
                    stp6.setVisible(false);
		    stp7.setVisible(false);
                    stp8.setVisible(false);
		    stp9.setVisible(false);
                    stp10.setVisible(false);
		}
		else if(ie.getSelectedObjects()[0]=="Section 5"){
		    stp1.setVisible(false);
		    stp2.setVisible(false);
		    stp3.setVisible(false);
                    stp4.setVisible(false);
		    stp5.setVisible(false);
                    stp6.setVisible(true);
		    stp7.setVisible(false);
                    stp8.setVisible(false);
		    stp9.setVisible(false);
                    stp10.setVisible(false);
		}
                else if(ie.getSelectedObjects()[0]=="Section 4"){
		    stp1.setVisible(false);
		    stp2.setVisible(false);
		    stp3.setVisible(false);
                    stp4.setVisible(false);
		    stp5.setVisible(false);
                    stp6.setVisible(false);
		    stp7.setVisible(true);
                    stp8.setVisible(false);
		    stp9.setVisible(false);
                    stp10.setVisible(false);
		}
		else if(ie.getSelectedObjects()[0]=="Section 3"){
		    stp1.setVisible(false);
		    stp2.setVisible(false);
		    stp3.setVisible(false);
                    stp4.setVisible(false);
		    stp5.setVisible(false);
                    stp6.setVisible(false);
		    stp7.setVisible(false);
                    stp8.setVisible(true);
		    stp9.setVisible(false);
                    stp10.setVisible(false);
		}
		else if(ie.getSelectedObjects()[0]=="Section 2"){
		    stp1.setVisible(false);
		    stp2.setVisible(false);
		    stp3.setVisible(false);
                    stp4.setVisible(false);
		    stp5.setVisible(false);
                    stp6.setVisible(false);
		    stp7.setVisible(false);
                    stp8.setVisible(false);
		    stp9.setVisible(true);
                    stp10.setVisible(false);
		}
                else if(ie.getSelectedObjects()[0]=="Section 1"){
		    stp1.setVisible(false);
		    stp2.setVisible(false);
		    stp3.setVisible(false);
                    stp4.setVisible(false);
		    stp5.setVisible(false);
                    stp6.setVisible(false);
		    stp7.setVisible(false);
                    stp8.setVisible(false);
		    stp9.setVisible(false);
                    stp10.setVisible(true);   
		}
                */
	    }
    }
    
}
