//MultiStubPanel.java
/* A Java class for
 * LineImpedance.java
 * Electromagnetic Transmission Line Applet
 * Applet without Smith Chart - Prepared by Umberto Ravaioli 
 * for 6th edition of Fundamentals of Applied Electromagnetics Book
 * May 2009 - All Rights Reserved
 */ 

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);
    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("Stub 1",state.stub[0],state);
	stp2 = new StubPanel("Stub 2",state.stub[1],state);
	stp3 = new StubPanel("Stub 3",state.stub[2],state);
	setLayout(gb);
	titlelabel = new Label(titulo,Label.CENTER);
	titlelabel.setFont(titlefont);
	c1 = new Choice();
	c1.addItem("Stub 1");
	c1.addItem("Stub 2");
	c1.addItem("Stub 3");
	c1.setBackground(bgcolor.brighter());
	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]=="Stub 1"){
		    stp1.setVisible(true);
		    stp2.setVisible(false);
		    stp3.setVisible(false);
		}
		else if(ie.getSelectedObjects()[0]=="Stub 2"){
		    stp1.setVisible(false);
		    stp2.setVisible(true);
		    stp3.setVisible(false);
		}
		else if(ie.getSelectedObjects()[0]=="Stub 3"){
		    stp1.setVisible(false);
		    stp2.setVisible(false);
		    stp3.setVisible(true);
		}
	    }
    }	
}
