//Trans_MultiGraphPanelA.java
//This is for frequency plots
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;


public class Trans_MultiGraphPanelA extends Panel{
    //private static final Color bgcolor = new Color(216,216,191);
    private  static final Color bgcolor = new Color(255,255,255);
    private static final Color tinta2 = new Color(236,236,221); // kaki
    //private  static final Color bgcolor = new Color(161,220,220);
    private static final Color tinta = new Color(236,236,221);
    private static final Font titlefont = new Font("SanSerif",Font.BOLD,16);
    private static final Font labfont = new Font("SanSerif",Font.PLAIN,11);
    private Label titlelabel, selectlabel;   
    private String titulo;
    public Choice c1;
    TransGraphCanvas tgc1, tgc2;
    TransGraphCanvas2 tgc3, tgc4;

    public Trans_MultiGraphPanelA(String titulo){
	super();
	this.titulo=titulo;
	setLayout(null);
	setBackground(bgcolor);
	 
	c1 = new Choice();
	c1.addItem(" Select a Plot");
	c1.addItem(" Standing Wave Pattern - | V | & | I |");
	c1.addItem(" Voltage Phasor");
	c1.addItem(" Current Phasor");
	c1.addItem(" Impedance");
	c1.addItem(" Admittance");
	c1.addItem(" Reflection Coefficient");
	c1.setBackground(bgcolor);
	c1.setForeground(Color.black);
	c1.setFont(new Font("SanSerif",Font.PLAIN,11));
	titlelabel = new Label(titulo,Label.LEFT);
	titlelabel.setFont(titlefont);
        titlelabel.setForeground(Color.black);
	
	selectlabel = new Label("click to select plot",Label.CENTER);
	selectlabel.setFont(labfont);
	selectlabel.setBackground(bgcolor);
	selectlabel.setForeground(Color.blue);
	
	
	tgc1 = new TransGraphCanvas();
	tgc2 = new TransGraphCanvas();
	tgc3 = new TransGraphCanvas2();
	tgc4 = new TransGraphCanvas2();
	add(titlelabel);
	//add(selectlabel);
	add(c1);
	add(tgc1);
	add(tgc2);
	add(tgc3);
	add(tgc4);
	titlelabel.setBounds(5,5,200,25);
	//selectlabel.setBounds(200,30,100,25);
        selectlabel.setBounds(200,30,100,25);
	// CHANGE #1 6/18/2017 =================================================
        // MODIFY LINE BELOW
        //c1.setBounds(5,30,195,25);
        c1.setBounds(5,30,250,25);
        //======================================================================
        
	//tgc1.setBounds(5,60,300,110);
	//tgc2.setBounds(5,175,300,110);
	
	tgc1.setBounds(5,61,795,156);
	tgc2.setBounds(5,225,795,156);
	tgc3.setBounds(5,61,795,156);
	tgc4.setBounds(5,225,795,156);
	Panel pgraph1 = new Panel();
	    pgraph1.setBackground(tinta2);
	    //pgraph1.setBackground(bgcolor);
	    add(pgraph1);
	    pgraph1.setBounds(5,61,795,156);
	    
	Panel pgraph2 = new Panel();
	    pgraph2.setBackground(Color.black);
	    add(pgraph2);
	    pgraph2.setBounds(4,60,797,158);
	    
	Panel pgraph3 = new Panel();
	    pgraph3.setBackground(tinta2);
	    //pgraph3.setBackground(bgcolor);
	    add(pgraph3);
	    pgraph3.setBounds(5,225,795,156);
	
	Panel pgraph4 = new Panel();
	    pgraph4.setBackground(Color.black);
	    add(pgraph4);
	    pgraph4.setBounds(4,224,797,158);
	    
    }			
	
     public synchronized void plotImpedance(Trans_State state){
	state.ScanImpedance();
	//HERE
	tgc1.setTitle("Re{ Z(d) }   [    ]");
	tgc1.reset();
	tgc1.setDynamics(false);
	tgc1.setYRangeMin(0.0);
	//tgc1.reset();
	tgc1.plot(state.x,state.y1);
	//HERE
	tgc2.setTitle("Im{ Z(d) }   [    ]");
	tgc2.setDynamics(false);
	tgc2.reset();
	tgc2.plot(state.x,state.y2);
    }
    
    public synchronized void plotAdmittance(Trans_State state){
	state.ScanAdmittance();
	
	tgc1.setTitle("Re{ Y(d) }   [ S ]");
	tgc1.reset();
	tgc1.setDynamics(false);
	tgc1.setYRangeMin(0.0);
	
	//tgc1.reset();
	tgc1.plot(state.x,state.y1);
	
	tgc2.setTitle("Im{ Y(d) }   [ S ]");
	tgc2.setDynamics(false);
	tgc2.reset();
	tgc2.plot(state.x,state.y2);
    }
    
    public synchronized void plotReflectionCoefficient(Trans_State state){
	state.ScanReflectionCoefficient();
	//HERE
	tgc1.setTitle("Re{    (d)}");
	tgc1.setDynamics(false);
	tgc1.setYRangeMax(1.0);
	tgc1.setYRangeMin(-1.0);
	tgc1.plot(state.x,state.y1);
	//HERE
	tgc2.setTitle(" Im{    (d)}");
	tgc2.setDynamics(false);
	tgc2.setYRangeMax(1.0);
	tgc2.setYRangeMin(-1.0);
	tgc2.plot(state.x,state.y2);
    }
    
    public synchronized void plotVoltagePhasor(Trans_State state){
	state.ScanVoltage();
	String labella;
	//if(!state.stub[0].isEnable() && !state.stub[1].isEnable() && !state.stub[2].isEnable()){
	  //  labella = "2 |V+|";
	//}
	//else{
	  //  labella = "3 |V+|";
	//}
        
        //labella =""+state.PlotTimeScale+" |V+|";
        //if(state.PlotTimeScale==1){labella ="  |V+|";}
	labella ="";
        
        
	if (state.getYRangeMax(1)>=1.0 && state.getYRangeMax(1)<1.0E3|| state.getYRangeMax(1)==0.0){
	    tgc3.setTitle("   Re{ V(d) }   [ V ]                                  "+labella);    
	}
	else if(state.getYRangeMax(1)<1.0E6 && state.getYRangeMax(1)>=1.0E3  ){
	    tgc3.setTitle("   Re{ V(d) } [ k V ]                                "+labella); 
	   
	}
	else if(state.getYRangeMax(1)>=1.0E6  ){
	    tgc3.setTitle("   Re{ V(d) } [ M V ]                                "+labella); 
	   
	}
	else if(state.getYRangeMax(1)<1.0 && state.getYRangeMax(1)>=1.0E-3  ){
	    tgc3.setTitle("   Re{ V(d) } [ m V ]                                "+labella); 
	   
	}
	else if(state.getYRangeMax(1)<1.0E-3 && state.getYRangeMax(1)>=1.0E-6  ){
	    tgc3.setTitle("   Re{ V(d) } \u00b5 V ]                                "+labella); 
	    
	}
	else if(state.getYRangeMax(1)<1.0E-6 && state.getYRangeMax(1)>=1.0E-9  ){
	    tgc3.setTitle("   Re{ V(d) } [ n V ]                                "+labella); 
	    
	}
	else if(state.getYRangeMax(1)<1.0E-9 && state.getYRangeMax(1)>=1.0E-12  ){
	    tgc3.setTitle("   Re{ V(d) } [ p V ]                                "+labella); 
	    
	}
	else if(state.getYRangeMax(1)<1.0E-12 &&  state.getYRangeMax(1)>=1.0E-15){
	    tgc3.setTitle("   Re{ V(d) } [ f V ]                                "+labella); 
	   
	}
	else if(state.getYRangeMax(1)<1.0E-15){
	    tgc3.setTitle("   Re{ V(d) } [ a V ]                                "+labella); 
	   
	}
	
	tgc3.reset();
	tgc3.setDynamics(false);
	tgc3.setYRangeMax(state.getYRangeMax(1));
	tgc3.setYRangeMin(-state.getYRangeMax(1));
	tgc3.plot(state.x,state.y1, state.yV1, state.yV2);
	
	
	if (state.getYRangeMax(1)>=1.0 && state.getYRangeMax(1)<1.0E3|| state.getYRangeMax(1)==0.0){
	    tgc4.setTitle("   Im{ V(d) }   [ V ]                                   "+labella);    
	}
	else if(state.getYRangeMax(1)<1.0E6 && state.getYRangeMax(1)>=1.0E3  ){
	    tgc4.setTitle("   Im{ V(d) } [ k V ]                               "+labella);  
	}
	else if(state.getYRangeMax(1)>=1.0E6  ){
	    tgc4.setTitle("   Im{ V(d) } [ M V ]                               "+labella);  
	}
	else if(state.getYRangeMax(1)<1.0 && state.getYRangeMax(1)>=1.0E-3  ){
	    tgc4.setTitle("   Im{ V(d) } [ m V ]                               "+labella);  
	}
	else if(state.getYRangeMax(1)<1.0E-3 && state.getYRangeMax(1)>=1.0E-6  ){
	    tgc4.setTitle("   Im{ V(d) } [ \u00b5 V ]                               "+labella);  
	}
	else if(state.getYRangeMax(1)<1.0E-6 && state.getYRangeMax(1)>=1.0E-9  ){
	    tgc4.setTitle("   Im{ V(d) } [ n V ]                               "+labella);  
	}
	else if(state.getYRangeMax(1)<1.0E-9 && state.getYRangeMax(1)>=1.0E-12  ){
	    tgc4.setTitle("   Im{ V(d) } [ p V ]                               "+labella);  
	}
	else if(state.getYRangeMax(1)<1.0E-12 && state.getYRangeMax(1)>=1.0E-15){
	    tgc4.setTitle("   Im{ V(d) } [ f V ]                               "+labella);  
	}
	else if(state.getYRangeMax(1)<1.0E-15){
	    tgc4.setTitle("   Im{ V(d) } [ a V ]                               "+labella);  
	}
	
	
	tgc4.reset();
	tgc4.setDynamics(false);
	tgc4.setYRangeMax(state.getYRangeMax(1));
	tgc4.setYRangeMin(-state.getYRangeMax(1));
	tgc4.plot(state.x,state.y2, state.yV1, state.yV2);
	
	/*
	tgc3.setTitle("   Re{ V(d) }   [ V ]                                     2 |V+|");
	tgc3.reset();
	tgc3.setDynamics(false);
	tgc3.setYRangeMax(state.getYRangeMax(1));
	tgc3.setYRangeMin(-state.getYRangeMax(1));
	tgc3.plot(state.x,state.y1);
	
	tgc4.setTitle("   Im{ V(d) }   [ V ]                                      2 |V+|");
	tgc4.reset();
	tgc4.setDynamics(false);
	tgc4.setYRangeMax(state.getYRangeMax(1));
	tgc4.setYRangeMin(-state.getYRangeMax(1));
	tgc4.plot(state.x,state.y2);
	*/
    }
    
    public synchronized void plotCurrentPhasor(Trans_State state){
	state.ScanCurrent();
	String labella;
	//if(!state.stub[0].isEnable() && !state.stub[1].isEnable() && !state.stub[2].isEnable()){
	 //   labella = "2 |V+|/ Zo";
	//}
	//else{
	  //  labella = "3 |V+|/ Zo";
	//}
        
        //labella =""+state.PlotTimeScale+" |V+|/ Zo";
        //if(state.PlotTimeScale==1){labella ="  |V+|/ Zo";};
	labella ="";
        
	if (state.getYRangeMax(2)>=1.0 && state.getYRangeMax(2)<1.0E3|| state.getYRangeMax(2)==0.0){
	    tgc3.setTitle("   Re{ I(d) }   [ A ]                                "+labella);    
	}
	else if(state.getYRangeMax(2)<1.0E6 && state.getYRangeMax(2)>=1.0E3  ){
	    tgc3.setTitle("   Re{ I(d) } [ k A ]                              "+labella); 
	   
	}
	else if(state.getYRangeMax(2)>=1.0E6  ){
	    tgc3.setTitle("   Re{ I(d) } [ M A ]                              "+labella); 
	   
	}
	else if(state.getYRangeMax(2)<1.0 && state.getYRangeMax(2)>=1.0E-3  ){
	    tgc3.setTitle("   Re{ I(d) } [ m A ]                              "+labella); 
	   
	}
	else if(state.getYRangeMax(2)<1.0E-3 && state.getYRangeMax(2)>=1.0E-6  ){
	    tgc3.setTitle("   Re{ I(d) } [ \u00b5 A ]                              "+labella); 
	    
	}
	else if(state.getYRangeMax(2)<1.0E-6 && state.getYRangeMax(2)>=1.0E-9  ){
	    tgc3.setTitle("   Re{ I(d) } [ n A ]                              "+labella); 
	    
	}
	else if(state.getYRangeMax(2)<1.0E-9 && state.getYRangeMax(2)>=1.0E-12  ){
	    tgc3.setTitle("   Re{ I(d) } [ p A ]                              "+labella); 
	    
	}
	else if(state.getYRangeMax(2)<1.0E-12 && state.getYRangeMax(2)>=1.0E-15  ){
	    tgc3.setTitle("   Re{ I(d) } [ f A ]                              "+labella); 
	   
	}
	else if(state.getYRangeMax(2)<1.0E-15  ){
	    tgc3.setTitle("   Re{ I(d) } [ a A ]                              "+labella); 
	   
	}
	
	tgc3.reset();
	tgc3.setDynamics(false);
	tgc3.setYRangeMax(state.getYRangeMax(2));
	tgc3.setYRangeMin(-state.getYRangeMax(2));
	tgc3.plot(state.x,state.y1, state.yV1, state.yV2);
	
	
	if (state.getYRangeMax(2)>=1.0 && state.getYRangeMax(2)<1.0E3|| state.getYRangeMax(2)==0.0){
	    tgc4.setTitle("   Im{ I(d) }   [ A ]                                 "+labella);    
	}
	else if(state.getYRangeMax(2)<1.0E6 && state.getYRangeMax(2)>=1.0E3  ){
	    tgc4.setTitle("   Im{ I(d) } [ k A ]                               "+labella);  
	}
	else if(state.getYRangeMax(2)>=1.0E6  ){
	    tgc4.setTitle("   Im{ I(d) } [ M A ]                               "+labella);  
	}
	else if(state.getYRangeMax(2)<1.0 && state.getYRangeMax(2)>=1.0E-3  ){
	    tgc4.setTitle("   Im{ I(d) } [ m A ]                               "+labella);  
	}
	else if(state.getYRangeMax(2)<1.0E-3 && state.getYRangeMax(2)>=1.0E-6  ){
	    tgc4.setTitle("   Im{ I(d) } [ \u00b5 A ]                               "+labella);  
	}
	else if(state.getYRangeMax(2)<1.0E-6 && state.getYRangeMax(2)>=1.0E-9  ){
	    tgc4.setTitle("   Im{ I(d) } [ n A ]                               "+labella);  
	}
	else if(state.getYRangeMax(2)<1.0E-9 && state.getYRangeMax(2)>=1.0E-12  ){
	    tgc4.setTitle("   Im{ I(d) } [ p A ]                               "+labella);  
	}
	else if(state.getYRangeMax(2)<1.0E-12 && state.getYRangeMax(2)>=1.0E-15){
	    tgc4.setTitle("   Im{ I(d) } [ f A ]                               "+labella);  
	}
	else if(state.getYRangeMax(2)<1.0E-15){
	    tgc4.setTitle("   Im{ I(d) } [ a A ]                               "+labella);  
	}
	
	tgc4.reset();
	tgc4.setDynamics(false);
	tgc4.setYRangeMax(state.getYRangeMax(2));
	tgc4.setYRangeMin(-state.getYRangeMax(2));
	tgc4.plot(state.x,state.y2, state.yV1, state.yV2);
	
	/*
	tgc3.setTitle("   Re{ I(d) }   [ A ]                                  2 |V+|/ Zo");
	tgc3.reset();
	tgc3.setDynamics(false);
	tgc3.setYRangeMax(state.getYRangeMax(2));
	tgc3.setYRangeMin(-state.getYRangeMax(2));
	tgc3.plot(state.x,state.y1);
	
	tgc4.setTitle("   Im{ I(d) }   [ A ]                                   2 |V+|/ Zo");
	tgc4.reset();
	tgc4.setDynamics(false);
	tgc4.setYRangeMax(state.getYRangeMax(2));
	tgc4.setYRangeMin(-state.getYRangeMax(2));
	tgc4.plot(state.x,state.y2);
	*/
    }
    
    public synchronized void plotVoltageCurrent(Trans_State state){
	state.ScanVoltageCurrent();
	String labella1, labella2;
	//if(!state.stub[0].isEnable() && !state.stub[1].isEnable() && !state.stub[2].isEnable()){
	  //  labella1 = "2 |V+|";
	  //  labella2 = "2 |V+|/ Zo";
	//}
	//else{
	  //  labella1 = "3 |V+|";
	  //  labella2 = "3 |V+|/ Zo";
	//} 
        
        //labella1 =""+state.PlotTimeScale+" |V+|";
        //if(state.PlotTimeScale==1){labella1 ="  |V+|";};
        //labella2 =""+state.PlotTimeScale+" |V+|/ Zo";
        //if(state.PlotTimeScale==1){labella2 ="  |V+|/ Zo";};
        
        labella1 ="";
        labella2 ="";
        
	//tgc1.setTitle("\u2223 V(d) \u2223   [ V ]");
	if (state.getYRangeMax(1)>=1.0 && state.getYRangeMax(1)<1.0E3 || state.getYRangeMax(1)==0.0){
	    tgc3.setTitle("   | V (d) |   [ V ]                                        "+labella1);    
	}
	else if(state.getYRangeMax(1)<1.0E6 && state.getYRangeMax(1)>=1.0E3  ){
	    tgc3.setTitle("   | V (d) |[ k V ]                                      "+labella1);  
	}
	else if(state.getYRangeMax(1)>=1.0E6  ){
	    tgc3.setTitle("   | V (d) | [ M V ]                                      "+labella1);  
	}
	
	else if(state.getYRangeMax(1)<1.0 && state.getYRangeMax(1)>=1.0E-3  ){
	    tgc3.setTitle("   | V (d) | [ m V ]                                      "+labella1);  
	}
	else if(state.getYRangeMax(1)<1.0E-3 && state.getYRangeMax(1)>=1.0E-6  ){
	    tgc3.setTitle("   | V (d) | [ \u00b5 V ]                                      "+labella1);  
	}
	else if(state.getYRangeMax(1)<1.0E-6 && state.getYRangeMax(1)>=1.0E-9  ){
	    tgc3.setTitle("   | V (d) | [ n V ]                                      "+labella1);  
	}
	else if(state.getYRangeMax(1)<1.0E-9 && state.getYRangeMax(1)>=1.0E-12  ){
	    tgc3.setTitle("   | V (d) | [ p V ]                                      "+labella1);  
	}
	else if(state.getYRangeMax(1)<1.0E-12 && state.getYRangeMax(1)>=1.0E-15){
	    tgc3.setTitle("   | V (d) | [ f V ]                                      "+labella1);  
	}
	else if(state.getYRangeMax(1)<1.0E-15){
	    tgc3.setTitle("   | V (d) | [ a V ]                                      "+labella1);  
	}
	
	tgc3.reset();
	tgc3.setDynamics(false);
	//tgc1.setIsVoltage(true);
	tgc3.setYRangeMax(state.getYRangeMax(1));
	tgc3.setYRangeMin(0.0);
	tgc3.plot(state.x,state.y1, state.yV1, state.yV2);
	
	//tgc2.setTitle("\u2223 I(d) \u2223   [ A ]");
	    //tgc2.setTitle("   | I (d) |  [ A ]                                       2 |V+|/ Zo");
	if (state.getYRangeMax(2)>=1.0 && state.getYRangeMax(2)<1.0E3 || state.getYRangeMax(2)==0.0){
	    tgc4.setTitle("   | I (d) |   [ A ]                                     "+labella2);    
	}
	else if(state.getYRangeMax(2)<1.0E6 && state.getYRangeMax(2)>=1.0E3  ){
	    tgc4.setTitle("   | I (d) |  [ k A ]                                   "+labella2);  
	}
	else if(state.getYRangeMax(2)>=1.0E6  ){
	    tgc4.setTitle("   | I (d) | [ M A ]                                   "+labella2);  
	}
	else if(state.getYRangeMax(2)<1.0 && state.getYRangeMax(2)>=1.0E-3  ){
	    tgc4.setTitle("   | I (d) | [ m A ]                                   "+labella2);  
	}
	else if(state.getYRangeMax(2)<1.0E-3 && state.getYRangeMax(2)>=1.0E-6  ){
	    tgc4.setTitle("   | I (d) | [ \u00b5 A ]                                   "+labella2);  
	}
	else if(state.getYRangeMax(2)<1.0E-6 && state.getYRangeMax(2)>=1.0E-9  ){
	    tgc4.setTitle("   | I (d) | [ n A ]                                   "+labella2);  
	}
	else if(state.getYRangeMax(2)<1.0E-9 && state.getYRangeMax(2)>=1.0E-12  ){
	    tgc4.setTitle("   | I (d) | [ p A ]                                   "+labella2);  
	}
	else if(state.getYRangeMax(2)<1.0E-12 && state.getYRangeMax(2)>=1.0E-15 ){
	    tgc4.setTitle("   | I (d) | [ f A ]                                   "+labella2);  
	}
	else if(state.getYRangeMax(2)<1.0E-15 ){
	    tgc4.setTitle("   | I (d) | [ a A ]                                   "+labella2);  
	}
	
	tgc4.reset();
	tgc4.setDynamics(false);
	tgc4.setYRangeMax(state.getYRangeMax(2));
	tgc4.setYRangeMin(0.0);
	//tgc2.setIsVoltage(false);
	tgc4.plot(state.x,state.y2, state.yV1, state.yV2);
    
	//tgc1.setTitle("\u2223 V(d) \u2223   [ V ]");
	/*
	tgc3.setTitle("   | V (d) |  [ V ]                                           2 |V+|");    
	tgc3.reset();
	tgc3.setDynamics(false);
	tgc3.setYRangeMax(state.getYRangeMax(1));
	tgc3.setYRangeMin(0.0);
	tgc3.plot(state.x,state.y1);
	*/
	//tgc2.setTitle("\u2223 I(d) \u2223   [ A ]");
	/*
	tgc4.setTitle("   | I (d) |  [ A ]                                        2 |V+|/ Zo");
	tgc4.reset();
	tgc4.setDynamics(false);
	tgc4.setYRangeMax(state.getYRangeMax(2));
	tgc4.setYRangeMin(0.0);
	tgc4.plot(state.x,state.y2);
	*/
    }
}
