//Trans_MultiGraphPanelA.java

import java.awt.*;

public class Trans_MultiGraphPanelA extends Panel{
    private  static final Color bgcolor = new Color(255,255,255);
    private static final Color tinta2 = new Color(216,216,191); // kaki
    private static final Color tinta = new Color(236,236,236);
    private static final Font titlefont = TheFonts.bold14;
    private static final Font labfont = TheFonts.sanSerif11;
    private Label titlelabel, selectlabel;   
    private String titulo;
    public Choice c1;
    TransGraphCanvas tgc1, tgc2;
    TransGraphCanvas2 tgc3, tgc4;
    Trans_State state;

    public Trans_MultiGraphPanelA(String titulo, Trans_State state){
	super();
        this.state = state;
	this.titulo=titulo;
	setLayout(null);
	setBackground(bgcolor);
	 
	c1 = new Choice();
	
	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(tinta);
	c1.setForeground(Color.black);
	c1.setFont(TheFonts.sanSerif11);
	titlelabel = new Label(titulo,Label.LEFT);
	titlelabel.setFont(titlefont);
	
	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(state.s5,0,state.s200,state.s20);
	selectlabel.setBounds(state.s200,state.s30,state.s100,state.s25);
	c1.setBounds(state.s5,state.s30,state.s195,state.s25);
	
	tgc1.setBounds(state.s4,state.s4,state.s270,state.s123);
	tgc2.setBounds(state.s4,state.s131,state.s270,state.s123);
	tgc3.setBounds(state.s4,state.s4,state.s270,state.s123);
	tgc4.setBounds(state.s4,state.s131,state.s270,state.s123);
        
        tgc3.setScaling(state.sfactor);
        tgc4.setScaling(state.sfactor);
	
	Panel pgraph2 = new Panel();
	    pgraph2.setBackground(Color.black);
	    add(pgraph2);
	    pgraph2.setBounds(state.s4-1,state.s4-1,state.s270+2,state.s123+2);
	   
	Panel pgraph4 = new Panel();
	    pgraph4.setBackground(Color.black);
	    add(pgraph4);
	    pgraph4.setBounds(state.s4-1,state.s131-1,state.s270+2,state.s123+2);
	
        tgc3.setScaling(state.sfactor);
        tgc4.setScaling(state.sfactor);
    }			
	
     public synchronized void plotImpedance(Trans_State state){
	//state.ScanImpedance();
	//HERE
	tgc1.setTitle("Re{ Z(d) }   [    ]");
	tgc1.setFlag(1);
	tgc1.reset();
	tgc1.setDynamics(false);
	tgc1.setYRangeMin(0.0);
	//tgc1.reset();
	tgc1.plot(state.x,state.y1);
	
        tgc2.setTitle("Im{ Z(d) }   [    ]");
	tgc2.setFlag(2);
	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();
	/*
	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;
	/*
        labella =""+state.PlotTimeScale+" |V+|";
        if(state.PlotTimeScale==1){labella ="  |V+|";}
	
	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);
	
	
	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);
	*/
    }
    
    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";};
	/*
	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);
	
	
	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);
	*/
    }
    
    public synchronized void setIsVoltage(boolean IsVoltage){
	tgc3.setIsVoltage(IsVoltage);
	tgc4.setIsVoltage(IsVoltage);
    }
    
    public synchronized void plotVoltageCurrent(Trans_State state){
	tgc3.setScaling(state.sfactor);
        tgc4.setScaling(state.sfactor);
        
        state.ScanVoltageCurrent();
	String labella1, labella2;
	
	  labella1 = "2 |V+|";
	  labella2 = "2 |V+|/ Zo";
	 
	  tgc3.setTitle("| V (d) |   [ V ]");    
	
	tgc3.reset();
        tgc3.setFlag(1);
	tgc3.setDynamics(false);
	tgc3.setIsVoltage(true);
	tgc3.setYRangeMax(2.0);
	tgc3.setYRangeMin(0.0);
	tgc3.plot(state.x,state.y1);
	
	  tgc4.setTitle("| I (d) |   [ A ]");    
	
	tgc4.reset();
	tgc4.setDynamics(false);
        tgc4.setFlag(2);
	tgc4.setYRangeMax(2.0/Complex.Real(state.Z0));
	tgc4.setYRangeMin(0.0);
	tgc4.setIsVoltage(false);
	tgc4.plot(state.x,state.y2);
    
    }
}
