//Trans_MultiGraphPanelA.java
//This is for frequency plots
/* 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.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(216,216,191); // kaki
    //private  static final Color bgcolor = new Color(161,220,220);
    //private static final Color tinta = new Color(236,236,221);
    
    private static final Color tinta = new Color(246,246,231); 
    private static final Color maroon = new Color(185,50,50);
    private static final Color tinta2 = new Color(236,236,236);
    
    private Label titlelabel, selectlabel;   
    //private  static final Color bgcolor = new Color(180,147,112);
    //private static final Font labfont = new Font("SanSerif",Font.PLAIN,11);
    //private static final Font titlefont = new Font("SanSerif",Font.BOLD,16);
    //private static final Font symbolfont = new Font("Symbol",Font.PLAIN,12);
    public static  Font labfont;
    public static  Font titlefont;
    public static  Font symbolfont;
    public static  Font normalfont;
    private String titulo;
    public Choice c1;
    
    TransGraphCanvas tgc1, tgc2;
    TransGraphCanvas3 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.addItem("  Time-average Power");
	c1.setBackground(Color.white);
	//c1.setFont(new Font("SanSerif",Font.PLAIN,14));
	c1.setFont(normalfont);
	titlelabel = new Label(titulo,Label.CENTER);
	titlelabel.setFont(titlefont);
	
	     
	selectlabel = new Label("Click to select a plot",Label.RIGHT);
	selectlabel.setFont(labfont);
	selectlabel.setBackground(bgcolor);
	selectlabel.setForeground(Color.blue);
	//add(selectlabel);

	selectlabel.setBounds(280,407,100,25);
	
	tgc1 = new TransGraphCanvas();
	tgc2 = new TransGraphCanvas();
	tgc3 = new TransGraphCanvas3();
	tgc4 = new TransGraphCanvas3();
	add(titlelabel);
	add(c1);
	add(tgc1);
	add(tgc2);
	add(tgc3);
	add(tgc4);
	//titlelabel.setBounds(5,5,300,25);
	// CHANGE ==============================================================
        //c1.setBounds(5,407,290,25);
        c1.setBounds(5,407,310,25);
        //======================================================================
	
	tgc1.setBounds(6,6,888,195);
	tgc2.setBounds(6,207,888,195);
	tgc3.setBounds(6,6,888,195);
	tgc4.setBounds(6,207,888,195);
	
	Panel pgraph1 = new Panel();
	    pgraph1.setBackground(tinta2);
	    add(pgraph1);
	    pgraph1.setBounds(6,6,888,195);
	    
	Panel pgraph2 = new Panel();
	    pgraph2.setBackground(Color.black);
	    add(pgraph2);
	    pgraph2.setBounds(5,5,890,197);
	    
	Panel pgraph3 = new Panel();
	    pgraph3.setBackground(tinta2);
	    add(pgraph3);
	    pgraph3.setBounds(6,207,888,195);
	
	Panel pgraph4 = new Panel();
	    pgraph4.setBackground(Color.black);
	    add(pgraph4);
	    pgraph4.setBounds(5,206,890,197);
    }		
    
    public void paint(Graphics g){
	    
	    g.setColor(Color.black);
	    g.drawRect(0,0,getSize().width-1,getSize().height-1);
    }	
	
     public synchronized void plotImpedance(Trans_State state){
	String alpha, Ohm, lambda, infinity, Gamma;
	    setFont(symbolfont);
	    alpha="\u03b1";
	    lambda="\u03bb";
	    Ohm="\u03a9";
	    infinity="\u221e";
	    Gamma="\uu0393";
	    setFont(labfont);
		
	state.ScanImpedance();
	state.IsPhasorPlot = 4;
	
	tgc1.setTitle("Re{Z(d)}");
	
	tgc1.setLabelY("");
	tgc1.setUnits("[ "+Ohm+" ]");
	tgc1.reset();
	tgc1.setDynamics(false);
	tgc1.setYRangeMin(0.0);
	tgc1.plot(state.x,state.y1);
	
        tgc1.setLabFlag(1); // Label is Re{ Z(d) }
        
	double tempvalue;
	tempvalue = Math.abs(state.Zin.Real());
	
	if (tempvalue>=1.0 && tempvalue<1.0E3|| tempvalue==0.0){
	    tgc1.setValue("Re{Z} = "+MaestroA.rounder(state.Zin.Real(),3)+"  [ "+Ohm+" ]");   
	}
	else if(tempvalue<1.0E6 && tempvalue>=1.0E3  ){
	    tgc1.setValue("Re{Z} = "+MaestroA.rounder(state.Zin.Real()/1.0E3,3)+"  [ k "+Ohm+" ]");   
	}
	else if(tempvalue>=1.0E6  ){
	    tgc1.setValue("Re{Z} = "+MaestroA.rounder(state.Zin.Real()/1.0E6,3)+"  [ M "+Ohm+" ]");   
	}
	else if(tempvalue<1.0 && tempvalue>=1.0E-3  ){
	    tgc1.setValue("Re{Z} = "+MaestroA.rounder(state.Zin.Real()*1.0E3,3)+"  [ m "+Ohm+" ]");   
	}
	else if(tempvalue<1.0E-3 && tempvalue>=1.0E-6  ){
	    tgc1.setValue("Re{Z} = "+MaestroA.rounder(state.Zin.Real()*1.0E6,3)+"  [ \u00b5 "+Ohm+" ]");   
	}
	else if(tempvalue<1.0E-6 && tempvalue>=1.0E-9  ){
	    tgc1.setValue("Re{Z} = "+MaestroA.rounder(state.Zin.Real()*1.0E9,3)+"  [ n "+Ohm+" ]");   
	}
	else if(tempvalue<1.0E-9 && tempvalue>=1.0E-12  ){
	    tgc1.setValue("Re{Z} = "+MaestroA.rounder(state.Zin.Real()*1.0E12,3)+"  [ p "+Ohm+" ]");   
	}
	else if(tempvalue<1.0E-12 &&  tempvalue>=1.0E-15){
	    tgc1.setValue("Re{Z} = "+MaestroA.rounder(state.Zin.Real()*1.0E15,3)+"  [ f "+Ohm+" ]");   
	}
	else if(tempvalue<1.0E-15){
	    tgc1.setValue("Re{Z} = 0.0  [ "+Ohm+" ]");   
	}
	
	
	tgc2.setTitle("Im{Z(d)}");
	tgc2.setLabelY("");
	tgc2.setUnits("[ "+Ohm+" ]");
	tgc2.setDynamics(false);
	tgc2.reset();
	tgc2.plot(state.x,state.y2);
	tgc2.setLabFlag(2); // Label is Im{Z(d)}
	tempvalue = Math.abs(state.Zin.Imaginary());
	
	if (tempvalue>=1.0 && tempvalue<1.0E3|| tempvalue==0.0){
	    tgc2.setValue("Im{Z} = "+MaestroA.rounder(state.Zin.Imaginary(),3)+"  [ "+Ohm+" ]");   
	}
	else if(tempvalue<1.0E6 && tempvalue>=1.0E3  ){
	    tgc2.setValue("Im{Z} = "+MaestroA.rounder(state.Zin.Imaginary()/1.0E3,3)+"  [ k "+Ohm+" ]");   
	}
	else if(tempvalue>=1.0E6  ){
	    tgc2.setValue("Im{Z} = "+MaestroA.rounder(state.Zin.Imaginary()/1.0E6,3)+"  [ M "+Ohm+" ]");   
	}
	else if(tempvalue<1.0 && tempvalue>=1.0E-3  ){
	    tgc2.setValue("Im{Z} = "+MaestroA.rounder(state.Zin.Imaginary()*1.0E3,3)+"  [ m "+Ohm+" ]");   
	}
	else if(tempvalue<1.0E-3 && tempvalue>=1.0E-6  ){
	    tgc2.setValue("Im{Z} = "+MaestroA.rounder(state.Zin.Imaginary()*1.0E6,3)+"  [ \u00b5 "+Ohm+" ]");   
	}
	else if(tempvalue<1.0E-6 && tempvalue>=1.0E-9  ){
	    tgc2.setValue("Im{Z} = "+MaestroA.rounder(state.Zin.Imaginary()*1.0E9,3)+"  [ n "+Ohm+" ]");   
	}
	else if(tempvalue<1.0E-9 && tempvalue>=1.0E-12  ){
	    tgc2.setValue("Im{Z} = "+MaestroA.rounder(state.Zin.Imaginary()*1.0E12,3)+"  [ p "+Ohm+" ]");   
	}
	else if(tempvalue<1.0E-12 &&  tempvalue>=1.0E-15){
	    tgc2.setValue("Im{Z} = "+MaestroA.rounder(state.Zin.Imaginary()*1.0E15,3)+"  [ f "+Ohm+" ]");   
	}
	else if(tempvalue<1.0E-15){
	    tgc2.setValue("Im{Z} = 0.0  [ "+Ohm+" ]");   
	}
	
    }
    
    public synchronized void plotAdmittance(Trans_State state){
	state.ScanAdmittance();
	state.IsPhasorPlot = 5;
	tgc1.setTitle("Re{Y(d)}");
	tgc1.setLabelY("");
	tgc1.setUnits("[ S ]");
	tgc1.reset();
	tgc1.setDynamics(false);
	tgc1.setYRangeMin(0.0);
	tgc1.plot(state.x,state.y1);
	tgc1.setLabFlag(3); // Label is Re{Y(d)}
	double tempvalue;
	tempvalue = Math.abs(state.Yin.Real());
	
	if (tempvalue>=1.0 && tempvalue<1.0E3|| tempvalue==0.0){
	    tgc1.setValue("Re{Y} = "+MaestroA.rounder(state.Yin.Real(),3)+"  [ S ]");   
	}
	else if(tempvalue<1.0E6 && tempvalue>=1.0E3  ){
	    tgc1.setValue("Re{Y} = "+MaestroA.rounder(state.Yin.Real()/1.0E3,3)+"  [ k S ]");   
	}
	else if(tempvalue>=1.0E6  ){
	    tgc1.setValue("Re{Y} = "+MaestroA.rounder(state.Yin.Real()/1.0E6,3)+"  [ M S ]");   
	}
	else if(tempvalue<1.0 && tempvalue>=1.0E-3  ){
	    tgc1.setValue("Re{Y} = "+MaestroA.rounder(state.Yin.Real()*1.0E3,3)+"  [ m S ]");   
	}
	else if(tempvalue<1.0E-3 && tempvalue>=1.0E-6  ){
	    tgc1.setValue("Re{Y} = "+MaestroA.rounder(state.Yin.Real()*1.0E6,3)+"  [ \u00b5 S ]");   
	}
	else if(tempvalue<1.0E-6 && tempvalue>=1.0E-9  ){
	    tgc1.setValue("Re{Y} = "+MaestroA.rounder(state.Yin.Real()*1.0E9,3)+"  [ n S ]");   
	}
	else if(tempvalue<1.0E-9 && tempvalue>=1.0E-12  ){
	    tgc1.setValue("Re{Y} = "+MaestroA.rounder(state.Yin.Real()*1.0E12,3)+"  [ p S ]");   
	}
	else if(tempvalue<1.0E-12 &&  tempvalue>=1.0E-15){
	    tgc1.setValue("Re{Y} = "+MaestroA.rounder(state.Yin.Real()*1.0E15,3)+"  [ f S ]");   
	}
	else if(tempvalue<1.0E-15){
	    tgc1.setValue("Re{Y} = 0.0  [ S ]");   
	}
	
	tgc2.setTitle("Im{Y(d)}");
	tgc2.setLabelY("");
	tgc2.setUnits("[ S ]");
	tgc2.setDynamics(false);
	tgc2.reset();
	tgc2.plot(state.x,state.y2);
	tgc2.setLabFlag(4); // Label is Im{Y(d)} 
	tempvalue = Math.abs(state.Yin.Imaginary());
	
	if (tempvalue>=1.0 && tempvalue<1.0E3|| tempvalue==0.0){
	    tgc2.setValue("Im{Y} = "+MaestroA.rounder(state.Yin.Imaginary(),3)+"  [ S ]");   
	}
	else if(tempvalue<1.0E6 && tempvalue>=1.0E3  ){
	    tgc2.setValue("Im{Y} = "+MaestroA.rounder(state.Yin.Imaginary()/1.0E3,3)+"  [ k S ]");   
	}
	else if(tempvalue>=1.0E6  ){
	    tgc2.setValue("Im{Y} = "+MaestroA.rounder(state.Yin.Imaginary()/1.0E6,3)+"  [ M S ]");   
	}
	else if(tempvalue<1.0 && tempvalue>=1.0E-3  ){
	    tgc2.setValue("Im{Y} = "+MaestroA.rounder(state.Yin.Imaginary()*1.0E3,3)+"  [ m S ]");   
	}
	else if(tempvalue<1.0E-3 && tempvalue>=1.0E-6  ){
	    tgc2.setValue("Im{Y} = "+MaestroA.rounder(state.Yin.Imaginary()*1.0E6,3)+"  [ \u00b5 S ]");   
	}
	else if(tempvalue<1.0E-6 && tempvalue>=1.0E-9  ){
	    tgc2.setValue("Im{Y} = "+MaestroA.rounder(state.Yin.Imaginary()*1.0E9,3)+"  [ n S ]");   
	}
	else if(tempvalue<1.0E-9 && tempvalue>=1.0E-12  ){
	    tgc2.setValue("Im{Y} = "+MaestroA.rounder(state.Yin.Imaginary()*1.0E12,3)+"  [ p S ]");   
	}
	else if(tempvalue<1.0E-12 &&  tempvalue>=1.0E-15){
	    tgc2.setValue("Im{Y} = "+MaestroA.rounder(state.Yin.Imaginary()*1.0E15,3)+"  [ f S ]");   
	}
	else if(tempvalue<1.0E-15){
	    tgc2.setValue("Im{Y} = 0.0  [ S ]");   
	}
    }
    
    public synchronized void plotReflectionCoefficient(Trans_State state){
	String alpha, Ohm, lambda, infinity, Gamma;
	    setFont(symbolfont);
	    alpha="\u03b1";
	    lambda="\u03bb";
	    Ohm="\u03a9";
	    infinity="\u221e";
	    Gamma="\uu0393";
	    setFont(labfont);
	
	state.ScanReflectionCoefficient();
	state.IsPhasorPlot = 6;
	
	tgc1.setTitle("Re{"+Gamma+"(d)}");
	tgc1.setDynamics(false);
	tgc1.setLabelY("");
	tgc1.setUnits("");
	if(state.IsLargerThanOne){
	    tgc1.setYRangeMax(2.414);
	    tgc1.setYRangeMin(-2.414);
	    tgc1.setLabelY("| "+Gamma+" | > 1.0 !!!");
	}
	else{
	    tgc1.setYRangeMax(1.0);
	    tgc1.setYRangeMin(-1.0);
	}
	tgc1.plot(state.x,state.y1);
	tgc1.setLabFlag(5); // Label is Re{Gamma_d} 
        
	tgc1.setValue("Re{"+Gamma+"} = "+MaestroA.rounder(state.Gammain.Real(),8));
	
	tgc2.setTitle(" Im{"+Gamma+"(d)}");
	tgc2.setLabelY("");
	tgc2.setUnits("");
	tgc2.setDynamics(false);
	if(state.IsLargerThanOne){
	    tgc2.setYRangeMax(2.414);
	    tgc2.setYRangeMin(-2.414);
	    tgc2.setLabelY("| "+Gamma+" | > 1.0 !!!");
	}
	else{
	    tgc2.setYRangeMax(1.0);
	    tgc2.setYRangeMin(-1.0);
	}
	tgc2.plot(state.x,state.y2);
	tgc2.setLabFlag(6); // Label is Im{Gamma_d}
	tgc2.setValue("Im{"+Gamma+"} = "+MaestroA.rounder(state.Gammain.Imaginary(),8));
    }
    
    public synchronized void plotVoltagePhasor(Trans_State state){
	String alpha, Ohm, lambda, infinity, Gamma;
	    setFont(symbolfont);
	    alpha="\u03b1";
	    lambda="\u03bb";
	    Ohm="\u03a9";
	    infinity="\u221e";
	    Gamma="\uu0393";
	    setFont(labfont);
	
	state.ScanVoltage();
	state.IsPhasorPlot = 2;
	
	//tgc3.setLabelY("2 |V+| exp ("+alpha+" l)");
	tgc3.setLabelY("2 |V+|");
	tgc3.setTitle("Re{V(d)}");
	tgc3.setLabFlag(1); // Label is Re{V(d)} 
        
	if (state.getYRangeMax(1)>=1.0 && state.getYRangeMax(1)<1.0E3|| state.getYRangeMax(1)==0.0){
	    tgc3.setUnits("[ V ]"); 
	}
	else if(state.getYRangeMax(1)<1.0E6 && state.getYRangeMax(1)>=1.0E3  ){
	    tgc3.setUnits("[ k V ]");   
	}
	else if(state.getYRangeMax(1)>=1.0E6  ){
	    tgc3.setUnits("[ M V ]"); 
	}
	else if(state.getYRangeMax(1)<1.0 && state.getYRangeMax(1)>=1.0E-3  ){
	    tgc3.setUnits("[ m V ]");
	}
	else if(state.getYRangeMax(1)<1.0E-3 && state.getYRangeMax(1)>=1.0E-6  ){
	    tgc3.setUnits("[ \u00b5 V ]");   
	}
	else if(state.getYRangeMax(1)<1.0E-6 && state.getYRangeMax(1)>=1.0E-9  ){
	    tgc3.setUnits("[ n V ]");  
	}
	else if(state.getYRangeMax(1)<1.0E-9 && state.getYRangeMax(1)>=1.0E-12  ){
	    tgc3.setUnits("[ p V ]");
	}
	else if(state.getYRangeMax(1)<1.0E-12 &&  state.getYRangeMax(1)>=1.0E-15){
	    tgc3.setUnits("[ f V ]"); 
	}
	else if(state.getYRangeMax(1)<1.0E-15){
	    tgc3.setUnits("[ a V ]");  
	}
	
	double tempvalue;
	tempvalue = Math.abs(state.Vin.Real());
	
	if (tempvalue>=1.0 && tempvalue<1.0E3|| tempvalue==0.0){
	    tgc3.setValue("Re{V} = "+MaestroA.rounder(state.Vin.Real(),3)+"  [ V ]");   
	}
	else if(tempvalue<1.0E6 && tempvalue>=1.0E3  ){
	    tgc3.setValue("Re{V} = "+MaestroA.rounder(state.Vin.Real()/1.0E3,3)+"  [ k V ]");   
	}
	else if(tempvalue>=1.0E6  ){
	    tgc3.setValue("Re{V} = "+MaestroA.rounder(state.Vin.Real()/1.0E6,3)+"  [ M V ]");   
	}
	else if(tempvalue<1.0 && tempvalue>=1.0E-3  ){
	    tgc3.setValue("Re{V} = "+MaestroA.rounder(state.Vin.Real()*1.0E3,3)+"  [ m V ]");   
	}
	else if(tempvalue<1.0E-3 && tempvalue>=1.0E-6  ){
	    tgc3.setValue("Re{V} = "+MaestroA.rounder(state.Vin.Real()*1.0E6,3)+"  [ \u00b5 V ]");   
	}
	else if(tempvalue<1.0E-6 && tempvalue>=1.0E-9  ){
	    tgc3.setValue("Re{V} = "+MaestroA.rounder(state.Vin.Real()*1.0E9,3)+"  [ n V ]");   
	}
	else if(tempvalue<1.0E-9 && tempvalue>=1.0E-12  ){
	    tgc3.setValue("Re{V} = "+MaestroA.rounder(state.Vin.Real()*1.0E12,3)+"  [ p V ]");   
	}
	else if(tempvalue<1.0E-12 &&  tempvalue>=1.0E-15){
	    tgc3.setValue("Re{V} = "+MaestroA.rounder(state.Vin.Real()*1.0E15,3)+"  [ f V ]");   
	}
	else if(tempvalue<1.0E-15){
	    tgc3.setValue("Re{V} = 0.0  [ V ]");   
	}
	
	
	
	tgc3.reset();
	tgc3.setDynamics(false);
	tgc3.setYRangeMax(state.getYRangeMax(1));
	tgc3.setYRangeMin(-state.getYRangeMax(1));
	tgc3.plot(state.x,state.y1);
	
	//tgc4.setLabelY("2 |V+| exp ("+alpha+" l)");
	tgc4.setLabelY("2 |V+|");
	tgc4.setTitle("Im{V(d)}");
        tgc4.setLabFlag(2); // Label is Im{V(d)}
        
	if (state.getYRangeMax(1)>=1.0 && state.getYRangeMax(1)<1.0E3|| state.getYRangeMax(1)==0.0){
	    tgc4.setUnits("[ V ]");    
	}
	else if(state.getYRangeMax(1)<1.0E6 && state.getYRangeMax(1)>=1.0E3  ){
	    tgc4.setUnits("[ k V ]"); 
	   
	}
	else if(state.getYRangeMax(1)>=1.0E6  ){
	    tgc4.setUnits("[ M V ]");
	   
	}
	else if(state.getYRangeMax(1)<1.0 && state.getYRangeMax(1)>=1.0E-3  ){
	    tgc4.setUnits("[ m V ]");
	   
	}
	else if(state.getYRangeMax(1)<1.0E-3 && state.getYRangeMax(1)>=1.0E-6  ){
	    tgc4.setUnits("[ \u00b5 V ])");
	    
	}
	else if(state.getYRangeMax(1)<1.0E-6 && state.getYRangeMax(1)>=1.0E-9  ){
	    tgc4.setUnits("[ n V ]");
	    
	}
	else if(state.getYRangeMax(1)<1.0E-9 && state.getYRangeMax(1)>=1.0E-12  ){
	    tgc4.setUnits("[ p V ]");
	    
	}
	else if(state.getYRangeMax(1)<1.0E-12 &&  state.getYRangeMax(1)>=1.0E-15){
	    tgc4.setUnits("[ f V ]");
	   
	}
	else if(state.getYRangeMax(1)<1.0E-15){
	    tgc4.setUnits("[ a V ]");
	   
	}
	
	tempvalue = Math.abs(state.Vin.Imaginary());
	
	if (tempvalue>=1.0 && tempvalue<1.0E3|| tempvalue==0.0){
	    tgc4.setValue("Im{V} = "+MaestroA.rounder(state.Vin.Imaginary(),3)+"  [ V ]");   
	}
	else if(tempvalue<1.0E6 && tempvalue>=1.0E3  ){
	    tgc4.setValue("Im{V} = "+MaestroA.rounder(state.Vin.Imaginary()/1.0E3,3)+"  [ k V ]");   
	}
	else if(tempvalue>=1.0E6  ){
	    tgc4.setValue("Im{V} = "+MaestroA.rounder(state.Vin.Imaginary()/1.0E6,3)+"  [ M V ]");   
	}
	else if(tempvalue<1.0 && tempvalue>=1.0E-3  ){
	    tgc4.setValue("Im{V} = "+MaestroA.rounder(state.Vin.Imaginary()*1.0E3,3)+"  [ m V ]");   
	}
	else if(tempvalue<1.0E-3 && tempvalue>=1.0E-6  ){
	    tgc4.setValue("Im{V} = "+MaestroA.rounder(state.Vin.Imaginary()*1.0E6,3)+"  [ \u00b5 V ]");   
	}
	else if(tempvalue<1.0E-6 && tempvalue>=1.0E-9  ){
	    tgc4.setValue("Im{V} = "+MaestroA.rounder(state.Vin.Imaginary()*1.0E9,3)+"  [ n V ]");   
	}
	else if(tempvalue<1.0E-9 && tempvalue>=1.0E-12  ){
	    tgc4.setValue("Im{V} = "+MaestroA.rounder(state.Vin.Imaginary()*1.0E12,3)+"  [ p V ]");   
	}
	else if(tempvalue<1.0E-12 &&  tempvalue>=1.0E-15){
	    tgc4.setValue("Im{V} = "+MaestroA.rounder(state.Vin.Imaginary()*1.0E15,3)+"  [ f V ]");   
	}
	else if(tempvalue<1.0E-15){
	    tgc4.setValue("Im{V} = 0.0  [ 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){
	String alpha, Ohm, lambda, infinity, Gamma;
	    setFont(symbolfont);
	    alpha="\u03b1";
	    lambda="\u03bb";
	    Ohm="\u03a9";
	    infinity="\u221e";
	    Gamma="\uu0393";
	    setFont(labfont);
	
	state.ScanCurrent();
	state.IsPhasorPlot = 3;
	
	//tgc3.setLabelY("2 |V+| exp ("+alpha+" l)/ Zo");
	tgc3.setLabelY("2 |V+| / Zo");
	tgc3.setTitle("Re{I (d)}");
	tgc3.setLabFlag(3); // Label is Re{I(d)}
        
	if (state.getYRangeMax(2)>=1.0 && state.getYRangeMax(2)<1.0E3|| state.getYRangeMax(2)==0.0){
	    tgc3.setUnits("[ A ]");
	}
	else if(state.getYRangeMax(2)<1.0E6 && state.getYRangeMax(2)>=1.0E3  ){
	    tgc3.setUnits("[ k A ]"); 
	   
	}
	else if(state.getYRangeMax(2)>=1.0E6  ){
	    tgc3.setUnits("[ M A ]");
	   
	}
	else if(state.getYRangeMax(2)<1.0 && state.getYRangeMax(2)>=1.0E-3  ){
	    tgc3.setUnits("[ m A ]");
	   
	}
	else if(state.getYRangeMax(2)<1.0E-3 && state.getYRangeMax(2)>=1.0E-6  ){
	    tgc3.setUnits("[ \u00b5 A ]"); 
	     
	}
	else if(state.getYRangeMax(2)<1.0E-6 && state.getYRangeMax(2)>=1.0E-9  ){
	    tgc3.setUnits("[ n A ]");
	    
	}
	else if(state.getYRangeMax(2)<1.0E-9 && state.getYRangeMax(2)>=1.0E-12  ){
	    tgc3.setUnits("[ p A ]"); 
	    
	}
	else if(state.getYRangeMax(2)<1.0E-12 && state.getYRangeMax(2)>=1.0E-15  ){
	    tgc3.setUnits("[ f A ]"); 
	   
	}
	else if(state.getYRangeMax(2)<1.0E-15  ){
	    tgc3.setUnits("[ a A ]"); 
	    
	}
	
	double tempvalue;
	tempvalue = Math.abs(state.Iin.Real());
	
	if (tempvalue>=1.0 && tempvalue<1.0E3|| tempvalue==0.0){
	    tgc3.setValue("Re{I} = "+MaestroA.rounder(state.Iin.Real(),3)+"  [ A ]");   
	}
	else if(tempvalue<1.0E6 && tempvalue>=1.0E3  ){
	    tgc3.setValue("Re{I} = "+MaestroA.rounder(state.Iin.Real()/1.0E3,3)+"  [ k A ]");   
	}
	else if(tempvalue>=1.0E6  ){
	    tgc3.setValue("Re{I} = "+MaestroA.rounder(state.Iin.Real()/1.0E6,3)+"  [ M A ]");   
	}
	else if(tempvalue<1.0 && tempvalue>=1.0E-3  ){
	    tgc3.setValue("Re{I} = "+MaestroA.rounder(state.Iin.Real()*1.0E3,3)+"  [ m A ]");   
	}
	else if(tempvalue<1.0E-3 && tempvalue>=1.0E-6  ){
	    tgc3.setValue("Re{I} = "+MaestroA.rounder(state.Iin.Real()*1.0E6,3)+"  [ \u00b5 A ]");   
	}
	else if(tempvalue<1.0E-6 && tempvalue>=1.0E-9  ){
	    tgc3.setValue("Re{I} = "+MaestroA.rounder(state.Iin.Real()*1.0E9,3)+"  [ n A ]");   
	}
	else if(tempvalue<1.0E-9 && tempvalue>=1.0E-12  ){
	    tgc3.setValue("Re{I} = "+MaestroA.rounder(state.Iin.Real()*1.0E12,3)+"  [ p A ]");   
	}
	else if(tempvalue<1.0E-12 &&  tempvalue>=1.0E-15){
	    tgc3.setValue("Re{I} = "+MaestroA.rounder(state.Iin.Real()*1.0E15,3)+"  [ f A ]");   
	}
	else if(tempvalue<1.0E-15){
	    tgc3.setValue("Re{I} = 0.0  [ A ]");   
	}
	
	
	tgc3.reset();
	tgc3.setDynamics(false);
	tgc3.setYRangeMax(state.getYRangeMax(2));
	tgc3.setYRangeMin(-state.getYRangeMax(2));
	tgc3.plot(state.x,state.y1);
	
	
        //tgc4.setLabelY("2 |V+| exp ("+alpha+" l)/ Zo");
        tgc4.setLabelY("2 |V+| / Zo");
	tgc4.setTitle("Im{I (d)}");
	tgc4.setLabFlag(4); // Label is Im{I(d)} 
	if (state.getYRangeMax(2)>=1.0 && state.getYRangeMax(2)<1.0E3|| state.getYRangeMax(2)==0.0){
	    tgc4.setUnits("[ A ]");   
	}
	else if(state.getYRangeMax(2)<1.0E6 && state.getYRangeMax(2)>=1.0E3  ){
	    tgc4.setUnits("[ k A ]");  
	}
	else if(state.getYRangeMax(2)>=1.0E6  ){
	    tgc4.setUnits("[ M A ]");  
	}
	else if(state.getYRangeMax(2)<1.0 && state.getYRangeMax(2)>=1.0E-3  ){
	    tgc4.setUnits("[ m A ]");
	}
	else if(state.getYRangeMax(2)<1.0E-3 && state.getYRangeMax(2)>=1.0E-6  ){
	    tgc4.setUnits("[ \u00b5 A ]"); 
	}
	else if(state.getYRangeMax(2)<1.0E-6 && state.getYRangeMax(2)>=1.0E-9  ){
	    tgc4.setUnits("[ n A ]");  
	}
	else if(state.getYRangeMax(2)<1.0E-9 && state.getYRangeMax(2)>=1.0E-12  ){
	    tgc4.setUnits("[ p A ]"); 
	}
	else if(state.getYRangeMax(2)<1.0E-12 && state.getYRangeMax(2)>=1.0E-15){
	    tgc4.setUnits("[ f A ]");
	}
	else if(state.getYRangeMax(2)<1.0E-15){
	    tgc4.setUnits("[ a A ]");  
	}
	
	tempvalue = Math.abs(state.Iin.Imaginary());
	
	if (tempvalue>=1.0 && tempvalue<1.0E3|| tempvalue==0.0){
	    tgc4.setValue("Im{I} = "+MaestroA.rounder(state.Iin.Imaginary(),3)+"  [ A ]");   
	}
	else if(tempvalue<1.0E6 && tempvalue>=1.0E3  ){
	    tgc4.setValue("Im{I} = "+MaestroA.rounder(state.Iin.Imaginary()/1.0E3,3)+"  [ k A ]");   
	}
	else if(tempvalue>=1.0E6  ){
	    tgc4.setValue("Im{I} = "+MaestroA.rounder(state.Iin.Imaginary()/1.0E6,3)+"  [ M A ]");   
	}
	else if(tempvalue<1.0 && tempvalue>=1.0E-3  ){
	    tgc4.setValue("Im{I} = "+MaestroA.rounder(state.Iin.Imaginary()*1.0E3,3)+"  [ m A ]");   
	}
	else if(tempvalue<1.0E-3 && tempvalue>=1.0E-6  ){
	    tgc4.setValue("Im{I} = "+MaestroA.rounder(state.Iin.Imaginary()*1.0E6,3)+"  [ \u00b5 A ]");   
	}
	else if(tempvalue<1.0E-6 && tempvalue>=1.0E-9  ){
	    tgc4.setValue("Im{I} = "+MaestroA.rounder(state.Iin.Imaginary()*1.0E9,3)+"  [ n A ]");   
	}
	else if(tempvalue<1.0E-9 && tempvalue>=1.0E-12  ){
	    tgc4.setValue("Im{I} = "+MaestroA.rounder(state.Iin.Imaginary()*1.0E12,3)+"  [ p A ]");   
	}
	else if(tempvalue<1.0E-12 &&  tempvalue>=1.0E-15){
	    tgc4.setValue("Im{I} = "+MaestroA.rounder(state.Iin.Imaginary()*1.0E15,3)+"  [ f A ]");   
	}
	else if(tempvalue<1.0E-15){
	    tgc4.setValue("Im{I} = 0.0  [ A ]");   
	}
	
	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){
	String alpha, Ohm, lambda, infinity, Gamma;
	    setFont(symbolfont);
	    alpha="\u03b1";
	    lambda="\u03bb";
	    Ohm="\u03a9";
	    infinity="\u221e";
	    Gamma="\uu0393";
	    setFont(labfont);
		
	state.ScanVoltageCurrent();
	state.IsPhasorPlot = 1;
	
	//tgc3.setLabelY("2 |V+| exp ("+alpha+" l)");
	tgc3.setLabelY("2 |V+|");
	tgc3.setTitle("| V(d) |");
	tgc3.setLabFlag(5); // Label is |V(d)|
        
	if (state.getYRangeMax(1)>=1.0 && state.getYRangeMax(1)<1.0E3 || state.getYRangeMax(1)==0.0){
	    tgc3.setUnits("[ V ]");      
	}
	else if(state.getYRangeMax(1)<1.0E6 && state.getYRangeMax(1)>=1.0E3  ){
	    tgc3.setUnits("[ k V ]");    
	}
	else if(state.getYRangeMax(1)>=1.0E6  ){
	    tgc3.setUnits("[ M V ]");  
	}
	
	else if(state.getYRangeMax(1)<1.0 && state.getYRangeMax(1)>=1.0E-3  ){
	    tgc3.setUnits("[ m V ]");    
	}
	else if(state.getYRangeMax(1)<1.0E-3 && state.getYRangeMax(1)>=1.0E-6  ){
	    tgc3.setUnits("[ \u00b5 V ]");    
	}
	else if(state.getYRangeMax(1)<1.0E-6 && state.getYRangeMax(1)>=1.0E-9  ){
	    tgc3.setUnits("[ n V ]");    
	}
	else if(state.getYRangeMax(1)<1.0E-9 && state.getYRangeMax(1)>=1.0E-12  ){
	    tgc3.setUnits("[ p V ]");    
	}
	else if(state.getYRangeMax(1)<1.0E-12 && state.getYRangeMax(1)>=1.0E-15){
	    tgc3.setUnits("[ f V ]");    
	}
	else if(state.getYRangeMax(1)<1.0E-15){
	    tgc3.setUnits("[ a V ]");   
	}
	
	tgc3.reset();
	tgc3.setDynamics(false);
	tgc3.setYRangeMax(state.getYRangeMax(1));
	tgc3.setYRangeMin(0.0);
	tgc3.plot(state.x,state.y1);
	
	double tempvalue;
	tempvalue = Complex.Magnitude(state.Vin);
	
	if (tempvalue>=1.0 && tempvalue<1.0E3|| tempvalue==0.0){
	    tgc3.setValue("| V | = "+MaestroA.rounder(tempvalue,3)+"  [ V ]");   
	}
	else if(tempvalue<1.0E6 && tempvalue>=1.0E3  ){
	    tgc3.setValue("| V | = "+MaestroA.rounder(tempvalue/1.0E3,3)+"  [ k V ]");   
	}
	else if(tempvalue>=1.0E6  ){
	    tgc3.setValue("| V | = "+MaestroA.rounder(tempvalue/1.0E6,3)+"  [ M V ]");   
	}
	else if(tempvalue<1.0 && tempvalue>=1.0E-3  ){
	    tgc3.setValue("| V | = "+MaestroA.rounder(tempvalue*1.0E3,3)+"  [ m V ]");   
	}
	else if(tempvalue<1.0E-3 && tempvalue>=1.0E-6  ){
	    tgc3.setValue("| V | = "+MaestroA.rounder(tempvalue*1.0E6,3)+"  [ \u00b5 V ]");   
	}
	else if(tempvalue<1.0E-6 && tempvalue>=1.0E-9  ){
	    tgc3.setValue("| V | = "+MaestroA.rounder(tempvalue*1.0E9,3)+"  [ n V ]");   
	}
	else if(tempvalue<1.0E-9 && tempvalue>=1.0E-12  ){
	    tgc3.setValue("| V | = "+MaestroA.rounder(tempvalue*1.0E12,3)+"  [ p V ]");   
	}
	else if(tempvalue<1.0E-12 &&  tempvalue>=1.0E-15){
	    tgc3.setValue("| V | = "+MaestroA.rounder(tempvalue*1.0E15,3)+"  [ f V ]");   
	}
	else if(tempvalue<1.0E-15){
	    tgc3.setValue("| V | = 0.0  [ V ]");   
	}
	
        //tgc4.setLabelY("2 |V+| exp ("+alpha+" l)/ Zo");
        tgc4.setLabelY("2 |V+| / Zo");
	tgc4.setTitle("| I (d) |");
	tgc4.setLabFlag(6); // Label is |I(d)|
        
	if (state.getYRangeMax(2)>=1.0 && state.getYRangeMax(2)<1.0E3 || state.getYRangeMax(2)==0.0){
	    tgc4.setUnits("[ A ]");   
	}
	else if(state.getYRangeMax(2)<1.0E6 && state.getYRangeMax(2)>=1.0E3  ){
	    tgc4.setUnits("[ k A ]");  
	}
	else if(state.getYRangeMax(2)>=1.0E6  ){
	    tgc4.setUnits("[ M A ]");
	}
	else if(state.getYRangeMax(2)<1.0 && state.getYRangeMax(2)>=1.0E-3  ){
	    tgc4.setUnits("[ m A ]"); 
	}
	else if(state.getYRangeMax(2)<1.0E-3 && state.getYRangeMax(2)>=1.0E-6  ){
	    tgc4.setUnits("[ \u00b5 A ]");
	} 
	else if(state.getYRangeMax(2)<1.0E-6 && state.getYRangeMax(2)>=1.0E-9  ){
	    tgc4.setUnits("[ n A ]"); 
	}
	else if(state.getYRangeMax(2)<1.0E-9 && state.getYRangeMax(2)>=1.0E-12  ){
	    tgc4.setUnits("[ p A ]");
	}
	else if(state.getYRangeMax(2)<1.0E-12 && state.getYRangeMax(2)>=1.0E-15 ){
	    tgc4.setUnits("[ f A ]");
	}
	else if(state.getYRangeMax(2)<1.0E-15 ){
	    tgc4.setUnits("[ a A ]");
	}
	
	tempvalue = Complex.Magnitude(state.Iin);
	
	if (tempvalue>=1.0 && tempvalue<1.0E3|| tempvalue==0.0){
	    tgc4.setValue("| I | = "+MaestroA.rounder(tempvalue,3)+"  [ A ]");   
	}
	else if(tempvalue<1.0E6 && tempvalue>=1.0E3  ){
	    tgc4.setValue("| I | = "+MaestroA.rounder(tempvalue/1.0E3,3)+"  [ k A ]");   
	}
	else if(tempvalue>=1.0E6  ){
	    tgc4.setValue("| I | = "+MaestroA.rounder(tempvalue/1.0E6,3)+"  [ M A ]");   
	}
	else if(tempvalue<1.0 && tempvalue>=1.0E-3  ){
	    tgc4.setValue("| I | = "+MaestroA.rounder(tempvalue*1.0E3,3)+"  [ m A ]");   
	}
	else if(tempvalue<1.0E-3 && tempvalue>=1.0E-6  ){
	    tgc4.setValue("| I | = "+MaestroA.rounder(tempvalue*1.0E6,3)+"  [ \u00b5 A ]");   
	}
	else if(tempvalue<1.0E-6 && tempvalue>=1.0E-9  ){
	    tgc4.setValue("| I | = "+MaestroA.rounder(tempvalue*1.0E9,3)+"  [ n A ]");   
	}
	else if(tempvalue<1.0E-9 && tempvalue>=1.0E-12  ){
	    tgc4.setValue("| I | = "+MaestroA.rounder(tempvalue*1.0E12,3)+"  [ p A ]");   
	}
	else if(tempvalue<1.0E-12 &&  tempvalue>=1.0E-15){
	    tgc4.setValue("| I | = "+MaestroA.rounder(tempvalue*1.0E15,3)+"  [ f A ]");   
	}
	else if(tempvalue<1.0E-15){
	    tgc4.setValue("| I | = 0.0  [ A ]");   
	}
	
	tgc4.reset();
	tgc4.setDynamics(false);
	tgc4.setYRangeMax(state.getYRangeMax(2));
	tgc4.setYRangeMin(0.0);
	tgc4.plot(state.x,state.y2);
    }
     public synchronized void plotPower(Trans_State state){
	String alpha, Ohm, lambda, infinity, Gamma;
	    setFont(symbolfont);
	    alpha="\u03b1";
	    lambda="\u03bb";
	    Ohm="\u03a9";
	    infinity="\u221e";
	    Gamma="\uu0393";
	    setFont(labfont);
	
	 
	state.ScanPower();
	state.IsPhasorPlot = 7;
	 
	
        //tgc3.setLabelY("|V+|\u00b2 exp (2"+alpha+" l)/ Zo");
        tgc3.setLabelY("|V+|\u00b2 / Zo");
	tgc3.setTitle("< P(d) >");
	tgc3.setLabFlag(7); // Label is <P(d)>	
        
	if (state.getYRangeMax(4)>=1.0 && state.getYRangeMax(3)<1.0E3 || state.getYRangeMax(3)==0.0){
	    tgc3.setUnits("[ W ]");   
	}
	else if(state.getYRangeMax(4)<1.0E6 && state.getYRangeMax(3)>=1.0E3  ){
	    tgc3.setUnits("[ k W ]"); 
	}
	else if(state.getYRangeMax(4)>=1.0E6  ){
	    tgc3.setUnits("[ M W ]"); 
	}
	else if(state.getYRangeMax(4)<1.0 && state.getYRangeMax(4)>=1.0E-3  ){
	    tgc3.setUnits("[ m W ]"); 
	}
	else if(state.getYRangeMax(4)<1.0E-3 && state.getYRangeMax(4)>=1.0E-6  ){
	    tgc3.setUnits("[ \u00b5 W ]"); 
	}
	else if(state.getYRangeMax(4)<1.0E-6 && state.getYRangeMax(4)>=1.0E-9  ){
	    tgc3.setUnits("[ n W ]"); 
	}
	else if(state.getYRangeMax(4)<1.0E-9 && state.getYRangeMax(4)>=1.0E-12  ){
	    tgc3.setUnits("[ p W ]");   
	}
	else if(state.getYRangeMax(4)<1.0E-12 && state.getYRangeMax(4)>=1.0E-15){
	    tgc3.setUnits("[ f W ]");
	}
	else if(state.getYRangeMax(4)<1.0E-15){
	    tgc3.setUnits("[ a W ]"); 
	}
	
	
	tgc3.reset();
	tgc3.setDynamics(false);
	tgc3.setYRangeMax(state.getYRangeMax(4));
	tgc3.setYRangeMin(0.0);
	tgc3.plot(state.x,state.y1);
	
	double tempvalue;
	tempvalue = state.Power_flow;
	
	if (tempvalue>=1.0 && tempvalue<1.0E3|| tempvalue==0.0){
	    tgc3.setValue("< P > = "+MaestroA.rounder(tempvalue,3)+"  [ W ]");   
	}
	else if(tempvalue<1.0E6 && tempvalue>=1.0E3  ){
	    tgc3.setValue("< P > = "+MaestroA.rounder(tempvalue/1.0E3,3)+"  [ k W ]");   
	}
	else if(tempvalue>=1.0E6  ){
	    tgc3.setValue("< P > = "+MaestroA.rounder(tempvalue/1.0E6,3)+"  [ M W ]");   
	}
	else if(tempvalue<1.0 && tempvalue>=1.0E-3  ){
	    tgc3.setValue("< P > = "+MaestroA.rounder(tempvalue*1.0E3,3)+"  [ m W ]");   
	}
	else if(tempvalue<1.0E-3 && tempvalue>=1.0E-6  ){
	    tgc3.setValue("< P > = "+MaestroA.rounder(tempvalue*1.0E6,3)+"  [ \u00b5 W ]");   
	}
	else if(tempvalue<1.0E-6 && tempvalue>=1.0E-9  ){
	    tgc3.setValue("< P > = "+MaestroA.rounder(tempvalue*1.0E9,3)+"  [ n W ]");   
	}
	else if(tempvalue<1.0E-9 && tempvalue>=1.0E-12  ){
	    tgc3.setValue("< P > = "+MaestroA.rounder(tempvalue*1.0E12,3)+"  [ p W ]");   
	}
	else if(tempvalue<1.0E-12 &&  tempvalue>=1.0E-15){
	    tgc3.setValue("< P > = "+MaestroA.rounder(tempvalue*1.0E15,3)+"  [ f W ]");   
	}
	else if(tempvalue<1.0E-15){
	    tgc3.setValue("< P > = 0.0  [ W ]");   
	}
	
	tgc2.setLabelY(" ");
	tgc2.setUnits(" ");
		
	tgc2.setTitle("| "+Gamma+"(d) |");
	tgc2.reset();
	tgc2.setDynamics(false);
	tgc2.setLabFlag(7); // Label is |Gamma_d|
	if(state.IsLargerThanOne){
	    tgc2.setYRangeMax(2.414);
	    tgc2.setLabelY("| "+Gamma+" | > 1.0 !!!");
	}
	else{
	    tgc2.setYRangeMax(1.0);
	}
	tgc2.setYRangeMin(0.0);
	tgc2.plot(state.x,state.y2);
	
	tgc2.setValue("| "+Gamma+" | = "+MaestroA.rounder(Complex.Magnitude(state.GammaL),8));
    }
    
}
