//LossyLoadPanel
/* A Java class for
 * LossyWide.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.awt.event.*;
import java.applet.*;
import java.lang.*;


public class TransLoadPanel extends PC implements ItemListener{
    public Checkbox c1, c2;
    protected CheckboxGroup cgrp;
    private Trans_State state;
    //private static final Color bgcolor = new Color(216,216,191);
    private static final Color tinta = new Color(236,236,236);
    private static final Color bgcolor = new Color(236,236,236);
    //private static final Color bgcolor = new Color(200,200,200);
    public Button bupdate;
    
    public TransLoadPanel(String titulo, String[] nome, String[] unidade, Trans_State state){
	super(titulo,nome,unidade);
	setLayout(null);
	setBackground(bgcolor);
	this.state = state;
	cgrp = new CheckboxGroup();
	c1 = new Checkbox("Impedance",cgrp,true);
	c2 = new Checkbox("Admittance",cgrp,false);
	add(c1);
	add(c2);
	//titlelabel.setBounds(5,15,280,30);
	lab1[0].setBounds(20,53,10,12);  // don't think this is even used
        lab1[0].setBounds(80,53,10,12);  // gets rid of junky "Z"
	text1[0].setBounds(55,50,80,20);
	
	lab2[0].setBounds(140,50,20,20);
	text2[0].setBounds(170,50,80,20);
	
	lab3[0].setBounds(255,50,25,20);
	c1.setBounds(55,80,100,20);
	c1.setBackground(bgcolor);
	c2.setBounds(170,80,100,20);
	c2.setBackground(bgcolor);
	b1.setBounds(120,110,70,20);
        b1.setBackground(new Color(220,220,210));
        b1.setBackground(Color.white);
        
	text1[0].setText(""+state.ZL.Real());
	text2[0].setText(""+state.ZL.Imaginary());
        
        // update button
	bupdate = new Button("Instructions");
        //bupdate.setBackground(new Color(240,240,255));
        bupdate.setBackground(new Color(255,255,250));
	add(bupdate);
        int buttonx = 90;
        int buttony = 9;
        int buttonwide = 120;
        int buttonheight = 22;
        
        bupdate.setBounds(buttonx,buttony,buttonwide,buttonheight);	
        Panel ps7 = new Panel();
	    ps7.setBackground(Color.lightGray);
	    add(ps7);
	    ps7.setBounds(buttonx-1,buttony-1,buttonwide+2,buttonheight+2);
	    
	Panel ps8 = new Panel();
	    ps8.setBackground(Color.black);
	    add(ps8);
	    ps8.setBounds(buttonx-2,buttony-2,buttonwide+4,buttonheight+4);
	
	//Listeners
	c1.addItemListener(this);
	c2.addItemListener(this);
    }
    
    public void paint(Graphics g){
	    g.clearRect(0,0,getSize().width,getSize().height);
	    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);
	    
	    g.setColor(Color.black);	
            g.drawLine(0, 39, getSize().width, 39);
	    if(state.is_Load_Ztype){  
                MaestroG.subscripter(" Z","L","=",g,12,20,65);
            }
            else if(!state.is_Load_Ztype){ 
                MaestroG.subscripter(" Y","L","=",g,12,20,65);
            }
            g.setColor(Color.red.darker());
            g.drawRect(52,47,84,25);
            g.drawRect(167,47,84,25);
            g.drawRect(117,107,75,25);

    }
    
    public void itemStateChanged(ItemEvent evt){
	if(evt.getSource()==c1){
	    lab1[0].setText("Z");
	    lab3[0].setText("\u03a9");
	    text1[0].setText(""+state.ZL.Real());
	    text2[0].setText(""+state.ZL.Imaginary());
	    state.is_Load_Ztype = true;
            repaint();
	}
	
	else if(evt.getSource()==c2){
	    lab1[0].setText("Y");
	    lab3[0].setText("S");
	    text1[0].setText(""+state.YL.Real());
	    text2[0].setText(""+state.YL.Imaginary());
	    state.is_Load_Ztype = false;
            repaint();
	}
    }

}
