//TransLoadPanel

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


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);
    protected static final Font titfont = new Font("SanSerif",Font.PLAIN,14);
    protected static final Font buttonfont = new Font("SanSerif",Font.PLAIN,11);
    public Button SetTr;
    private boolean ShowZ = true;
    //private static final Color bgcolor = new Color(200,200,200);
    
    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);
        //titlelabel.setForeground(Color.black);
        
        titlelabel.setBounds(15,5,80,20);
        titlelabel.setForeground(Color.red.darker());
        titlelabel.setFont(titfont);
        
        // CHANGE #1 6/13/2017 =================================================
        // DO NOT lab1[0]
        //lab1[0].setText("Z");
	//lab1[0].setBounds(22,63,10,12);
	//======================================================================
        text1[0].setBounds(55,60,80,20);
	
	lab2[0].setBounds(145,60,20,20);
	text2[0].setBounds(170,60,80,20);
	
	lab3[0].setBounds(255,60,45,20);
	c1.setBounds(55,90,100,20);
	c1.setBackground(bgcolor);
	//CHANGE #2 6/13/2017 ==================================================
        // MODIFY LINE BELOW
        //c2.setBounds(170,90,100,20);
        c2.setBounds(170,90,120,20);
	//======================================================================
        c2.setBackground(bgcolor);
	b1.setBounds(120,120,70,20);
        b1.setBackground(bgcolor);
	
	text1[0].setText(""+state.ZL.Real());
	text2[0].setText(""+state.ZL.Imaginary());
	
	//Listeners
	c1.addItemListener(this);
	c2.addItemListener(this);
        
        SetTr = new Button(">>  Set  Line / Transformer");
        SetTr.setBounds(150,5,155,18);
        SetTr.setBackground(Color.white);
        SetTr.setFont(buttonfont);
        add(SetTr);
        Panel but1 = new Panel();
		    but1.setBackground(Color.black);
		    add(but1);
		    but1.setBounds(149,4,157,20);
    }
    
    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);	
	      
            // CHANGE #3 6/13/2017 =============================================
	    // MODIFY LINE BELOW
            //MaestroG.subscripter("   ","L","=",g,12,25,75);
            if(ShowZ){
                  MaestroG.subscripter("Z","L","=",g,14,20,75);
            }
            else{
                  MaestroG.subscripter("Y","L","=",g,14,20,75);
            }
            //==================================================================
            g.setColor(Color.red.darker());
            g.drawRect(52,57,84,24);
            g.drawRect(167,57,84,24);
            g.drawRect(117,117,74,24);
    }
    
    public void itemStateChanged(ItemEvent evt){
	if(evt.getSource()==c1){
	    lab1[0].setText("Z");
	    lab3[0].setText("[ \u03a9 ]");
	    
            //CHANGE #4 6/13/2017 ==============================================
            // MODIFY LINEs BELOW
            //text1[0].setText(""+state.ZL.Real());
	    //text2[0].setText(""+state.ZL.Imaginary());
	    text1[0].setText(""+MaestroA.rounder(state.ZL.Real(),6));
	    text2[0].setText(""+MaestroA.rounder(state.ZL.Imaginary(),6));
            ShowZ = true;
            repaint();
            //==================================================================
	    state.is_Load_Ztype = true;
	}
	
	else if(evt.getSource()==c2){
	    lab1[0].setText("Y");
	    lab3[0].setText("[ S ]");
            //CHANGE #5 6/13/2017 ==============================================
            // MODIFY LINES BELOW
            //text1[0].setText(""+state.YL.Real());
	    //text2[0].setText(""+state.YL.Imaginary());
	    text1[0].setText(""+MaestroA.rounder(state.YL.Real(),6));
	    text2[0].setText(""+MaestroA.rounder(state.YL.Imaginary(),6));
            ShowZ = false;
            repaint();
            //====================================================================
	    state.is_Load_Ztype = false;
	}
    }

}

