//StepCanvas.java
/* A Java class for
 * SingleStub.java
 * Electromagnetic Transmission Line Applet
 * Applet without Smith Chart - Prepared by Umberto Ravaioli 
 * for 6th edition of Fundamentals of Applied Electromagnetics Book
 * June 2009 - All Rights Reserved
 */   

import java.awt.*;

public class StepCanvas extends Canvas{
    //private final Color bgcolor = new Color(170,200,200);
    private static final Color bgcolor = new Color(236,236,236);
    public Font titlefont, labfont, titlefont2, symbolfont, textfont, textfont3, 
            textfont4, textfont2, symbolfont3, symbolfont4, symbolfont2, normalfont,
            normalfontB, normalfont2, smallfont;
    
    private Image im;
    private Graphics buf;
    
    public String Bigomega, omega, alpha, Ohm, lambda, infinity, Gamma, epsilon;
    
    public int ystart;
    
    StateVars state;
    Stub stub;
    private int fonto;
    private int fonto2;
    private int fonto3;
       
    StepCanvas(StateVars state){
	super();
	this.state = state;
        
	setBackground(bgcolor);
        
        ystart = state.s55;
        fonto = state.font14;
        fonto2 = state.font14;
        fonto3 = state.font12;
    }
    
    @Override
        public void paint(Graphics g){
            if(im == null){
                im = createImage(getSize().width,getSize().height);
                buf = im.getGraphics();
                drawCanvas(buf);
            }
            else{
                drawCanvas(buf);
            }
            g.drawImage(im,0,0,null);
        }
        
        //Addition to reduce flicker new routine
	public void update(Graphics g){		// added to avoid clearing
	    paint(g);
	}
    
    public void drawCanvas(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);
        
        labfont = new Font("Sanserif",Font.PLAIN,state.font12);
        titlefont = new Font("Sanserif",Font.BOLD,state.font18);
        symbolfont = new Font("Serif",Font.PLAIN,state.font12);;
        normalfont = new Font("Sanserif",Font.PLAIN,state.font12);;
        normalfontB = new Font("Sanserif",Font.BOLD,state.font11);;
        normalfont2 = new Font("Sanserif",Font.PLAIN,state.font12);
        smallfont = new Font("Sanserif",Font.PLAIN,state.font10);
        
        titlefont2 = new Font("Sanserif",Font.BOLD,state.font14);
        symbolfont = new Font("Serif",Font.PLAIN,state.font15);
        textfont = new Font("Sanserif",Font.PLAIN,state.font15);
        textfont3 = new Font("Sanserif",Font.PLAIN,state.font10);
        textfont4 = new Font("Sanserif",Font.PLAIN,state.font14);
        textfont2 = new Font("Sanserif",Font.PLAIN,state.font14);
        symbolfont3 = new Font("Serif",Font.PLAIN,state.font12);
        symbolfont4 = new Font("Serif",Font.PLAIN,state.font13);
        symbolfont2 = new Font("Serif",Font.PLAIN,state.font14);
	
	FontMetrics fm;
	
        Bigomega = "\u03a9";
	omega = "\u03c9";
	alpha="\u03b1";
	lambda="\u03bb";
	Ohm="\u03a9";
	infinity="\u221e";
	Gamma="\u0393";
        epsilon="\u03b5";
        
        Graphics2D g2d = (Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
	
        switch(state.getStepNumber()){
	    case 1: step1(g); break;
	    case 2: step2(g); break;
	    case 3: step3(g); break;
	    case 4: step4(g); break;
	    case 5: step5(g); break;
	    case 6: step6(g); break;
	    case 7: step7(g); break;
	    case 8: step8(g);break;
	    case 9: step9(g);break;
	}
	    
    }
    
    private void step1(Graphics g){
        
        int xstart1 = state.s25;
	int xstart2 = state.s60;
        int xstart3 = state.s35;
        
	String stmp;
        FontMetrics fmetrics;
        
        g.setColor(Color.red.darker());
	String titulo = "Step 1";
	g.setFont(titlefont);
	fmetrics=g.getFontMetrics();
	g.drawString(titulo,xstart1,fmetrics.getHeight());
	
        g.setColor(Color.black);
	g.setFont(textfont2);
	fmetrics=g.getFontMetrics();
	stmp = "- Identify normalized load impedance";
	g.drawString(stmp,xstart1,ystart);
	
	g.setColor(Color.blue.darker());
	
	if(state.getZL().Imaginary() >= 0.0){
	    MaestroG.subsubsubSymbol("Z","L"," = R","L"," + j X","L","= "+MaestroA.rounder(state.getZL().Real(),4)+" + j "+MaestroA.rounder(state.getZL().Imaginary(),4),"  "+Bigomega,g,fonto2,xstart3,ystart+state.s25);
	}
	else{
	    MaestroG.subsubsubSymbol("Z","L"," = R","L"," + j X","L","= "+MaestroA.rounder(state.getZL().Real(),4)+" - j "+MaestroA.rounder(Math.abs(state.getZL().Imaginary()),4),"  "+Bigomega,g,fonto2,xstart3,ystart+state.s25);
	}
	
	if(state.getZL().Imaginary() >= 0.0){
	    MaestroG.subsubsub("z","L"," = r","L"," + j x","L","= "+MaestroA.rounder((state.getZL().Real()/state.getZ0()),4)+" + j "+MaestroA.rounder((state.getZL().Imaginary()/state.getZ0()),4),g,fonto2,xstart3,ystart+state.s50);
	}
	else{
	    MaestroG.subsubsub("z","L"," = r","L"," + j x","L","= "+MaestroA.rounder((state.getZL().Real()/state.getZ0()),4)+" - j "+MaestroA.rounder((Math.abs(state.getZL().Imaginary())/state.getZ0()),4),g,fonto2,xstart3,ystart+state.s50);
	}
	
        if(state.getZL().Imaginary() >= 0.0){
            g.setColor(Color.black);
            //stmp = "For frequency analysis we assume";
            stmp = "- For frequency analysis, we assume R";
            
            MaestroG.subscripter(stmp,"L","",g,fonto2,xstart1,state.s135);
            int xExtra = fmetrics.stringWidth("- ");
            g.drawString("remains unchanged and we model",xstart1+xExtra,state.s155);
            g.drawString("the imaginary part as an inductor",xstart1+xExtra,state.s175);
        }
        else{
            g.setColor(Color.black);
            stmp = "- For frequency analysis, we assume R";
            MaestroG.subscripter(stmp,"L","",g,fonto2,xstart1,state.s135);
            int xExtra = fmetrics.stringWidth("- ");
            g.drawString("remains unchanged and we model",xstart1+xExtra,state.s155);
            g.drawString("the imaginary part as a capacitor",xstart1+xExtra,state.s175);
        }
    }
    
    private void step2(Graphics g){
        
        int xstart1 = state.s25;
	int xstart2 = state.s60;
        int xstart3 = state.s35;
        
	String stmp, stmp2;
	String titulo = "Step 2";
	g.setColor(Color.red.darker());
	g.setFont(titlefont);
	FontMetrics fmetrics=g.getFontMetrics();
	g.drawString(titulo,xstart1,fmetrics.getHeight());
        
	g.setColor(Color.black);
	g.setFont(textfont2);
	fmetrics=g.getFontMetrics();
	stmp = "- Plot SWR circle with radius  r = ";
	
        MaestroG.subscripterSS2(""+stmp,"","| "+Gamma+" |",g,state.font14,xstart1,ystart);
	
	g.setFont(textfont2);
	fmetrics=g.getFontMetrics();
	stmp = "- Identify normalized load admittance";
	g.drawString(stmp,xstart1,ystart+state.s30);
	
	g.setColor(Color.blue.darker());
	
	if(state.getYL().Imaginary() >= 0.0){
	    MaestroG.subsubsub("Y","L"," = G","L"," + j B","L","= "+MaestroA.rounder(state.getYL().Real(),6)+" + j "+MaestroA.rounder(state.getYL().Imaginary(),6)+" [S]",g,fonto2,xstart3,ystart+state.s70);
	}
	else{
	    MaestroG.subsubsub("Y","L"," = G","L"," + j B","L","= "+MaestroA.rounder(state.getYL().Real(),4)+" - j "+MaestroA.rounder(Math.abs(state.getYL().Imaginary()),4)+" [S]",g,fonto2,xstart3,ystart+state.s70);
	}
	
	if(state.getYL().Imaginary() >= 0.0){
	    MaestroG.subsubsub("y","L"," = g","L"," + j b","L","= "+MaestroA.rounder((state.getYL().Real()*state.getZ0()),5)+" + j "+MaestroA.rounder((state.getYL().Imaginary()*state.getZ0()),5),g,fonto2,xstart3,ystart+state.s100);
	}
	else{
	    MaestroG.subsubsub("y","L"," = g","L"," + j b","L","= "+MaestroA.rounder((state.getYL().Real()*state.getZ0()),5)+" - j "+MaestroA.rounder((Math.abs(state.getYL().Imaginary())*state.getZ0()),5),g,fonto2,xstart3,ystart+state.s100);
	}
    }
    
    private void step3(Graphics g){
        
        int xstart1 = state.s25;
	int xstart2 = state.s60;
        int xstart3 = state.s35;
        
	String stmp;
        FontMetrics fmetrics;
        
	String titulo = "First Solution";
	g.setColor(Color.red.darker());
	g.setFont(titlefont);
	fmetrics=g.getFontMetrics();
	g.drawString(titulo,xstart1,fmetrics.getHeight());
	
        g.setColor(Color.black);
	g.setFont(textfont2);
	fmetrics=g.getFontMetrics();
        
	stmp = "Corresponds to  the  first  intersection";
	g.drawString(stmp,xstart1,ystart);
	
	stmp = "between SWR circle and unitary circle";
	g.drawString(stmp,xstart1,ystart+12*fmetrics.getHeight()/10);
	
	stmp = "with admittance as a reference.";
	g.drawString(stmp,xstart1,ystart+24*fmetrics.getHeight()/10);
	
        g.setColor(Color.red.darker());
	stmp = "Click Next Step to proceed";
	g.drawString(stmp,xstart1,ystart+48*fmetrics.getHeight()/10);
    }
        
    private void step4(Graphics g){
        
        int xstart1 = state.s25;
	int xstart2 = state.s60;
        int xstart3 = state.s35;
        
	String stmp;
        double ytest;
        FontMetrics fmetrics;
        
	String titulo = "Step 3  -  First Solution";
	g.setColor(Color.red.darker());
	g.setFont(titlefont);
	fmetrics=g.getFontMetrics();
	g.drawString(titulo,xstart1,fmetrics.getHeight());
	
        g.setColor(Color.black);
	g.setFont(textfont2);
	fmetrics=g.getFontMetrics();
        
        if(state.getZL().Real() == 0.0){
            g.setColor(Color.red);
            if(state.getZL().Imaginary() == 0.0){
                stmp = "The load is a short circuit and ";
            }
            else{
                stmp = "The load is purely imaginary and";
            }
            g.drawString(stmp,xstart1,ystart+fmetrics.getHeight());
            stmp = "it cannot be matched.";
            g.drawString(stmp,xstart1,ystart+(int)24*fmetrics.getHeight());
            stmp = "Please, go Back to Start.";
            g.drawString(stmp,xstart1,ystart+(int)48*fmetrics.getHeight()+fmetrics.getHeight()/2);
        }
        else{
            stmp = "Move along the transmission line from";
            g.drawString(stmp,xstart1,ystart);
            stmp = "load to generator until a position  with";
            g.drawString(stmp,xstart1,ystart+fmetrics.getHeight());
            stmp = "normalized conductance   g = 1.0  is";
            g.drawString(stmp,xstart1,ystart+(int)24*fmetrics.getHeight()/10);
            stmp = "reached.";
            g.drawString(stmp,xstart1,ystart+(int)36*fmetrics.getHeight()/10);
        
            stmp = "The first solution is at location";
            g.drawString(stmp,xstart1,ystart+(int)48*fmetrics.getHeight()/10+fmetrics.getHeight()/2);
	
            g.setColor(Color.blue.darker());
            stmp = " = "+MaestroA.rounder(state.dd1,4);
            MaestroG.subscripterSSSS("  d","1",stmp," "+lambda,"  from the load",g,fonto,xstart3,ystart+7*fmetrics.getHeight()-fmetrics.getHeight()/4);
	
            g.setColor(Color.black);
            
            stmp = "with normalized line admittance:";
            g.drawString(stmp,xstart1,ystart+(int)85*fmetrics.getHeight()/10);
        
            ytest = state.BBs1;
        
            g.setColor(Color.blue.darker());
        
            if(ytest < 0.0){
                stmp = " = 1.0 + j "+MaestroA.rounder(Math.abs(state.BBs1norm),5); //+"           (normalized)";
                MaestroG.subscripter("  y(d","1",")"+stmp,g,fonto,xstart3,ystart+(int)95*fmetrics.getHeight()/10+fmetrics.getHeight()/2);
            }
            else{
                stmp = " = 1.0 - j "+MaestroA.rounder(Math.abs(state.BBs1norm),5); //+"           (normalized)";
                MaestroG.subscripter("  y(d","1",")"+stmp,g,fonto,xstart3,ystart+(int)95*fmetrics.getHeight()/10+fmetrics.getHeight()/2);
            }
        }
    }
    
    private void step5(Graphics g){
	int xstart1 = state.s25;
	int xstart2 = state.s60;
        int xstart3 = state.s35;
        
	String titulo = "Step 4  -  First Solution";
	String stmp;
        FontMetrics fmetrics;
	double ytest;
        
	g.setColor(Color.red.darker());
	g.setFont(titlefont);
	fmetrics = g.getFontMetrics();
	g.drawString(titulo,xstart1,fmetrics.getHeight());
	
        g.setColor(Color.black);
	g.setFont(textfont2);
	fmetrics=g.getFontMetrics();
	
        stmp = "To cancel the imaginary part of the";
	g.drawString(stmp,xstart1,ystart);
        
	stmp = "line admittance we add a stub with:";
	g.drawString(stmp,xstart1,ystart+fmetrics.getHeight());
	
        stmp = "Length:";
	g.drawString(stmp,xstart1,ystart+(int)(24*fmetrics.getHeight()/10)+fmetrics.getHeight()/2);
	
        g.setColor(Color.blue.darker());
	stmp = " = "+MaestroA.rounder(state.LL1,4);
	MaestroG.subscripterSSSIT("               l","1",stmp+" ",""+lambda,g,fonto,xstart1,ystart+(int)(24*fmetrics.getHeight()/10)+fmetrics.getHeight()/2);
	
	g.setColor(Color.black);
	stmp = "Admittance: ";
	g.drawString(stmp,xstart1,ystart + (int)(48*fmetrics.getHeight()/10)-fmetrics.getHeight()/4);
	
        g.setColor(Color.blue.darker());
	ytest = state.BBs1;
	if(ytest < 0.0){
	    
	    stmp = " = - j "+MaestroA.rounder(Math.abs(state.BBs1),5)+" [S]      (actual)";
	    MaestroG.subscripter("  Y","1",stmp,g,fonto,xstart3,ystart+6*fmetrics.getHeight());
	    stmp = " = - j "+MaestroA.rounder(Math.abs(state.BBs1norm),5)+"           (normalized)";
	    MaestroG.subscripter("  y","1",stmp,g,fonto,xstart3,ystart+7*fmetrics.getHeight()+fmetrics.getHeight()/2);
	}
	else{
            stmp = " = j "+MaestroA.rounder(Math.abs(state.BBs1),5)+" [S]      (actual)";
	    MaestroG.subscripter("  Y","1",stmp,g,fonto,xstart3,ystart+6*fmetrics.getHeight());
	    stmp = " = j "+MaestroA.rounder(Math.abs(state.BBs1norm),5)+"           (normalized)";
	    MaestroG.subscripter("  y","1",stmp,g,fonto,xstart3,ystart+7*fmetrics.getHeight()+fmetrics.getHeight()/2);
	}	
    }
    
    private void step6(Graphics g){
        int xstart1 = state.s25;
	int xstart2 = state.s60;
        int xstart3 = state.s35;
        
	String stmp;
        FontMetrics fmetrics;
        
	String titulo = "Second Solution";
	g.setColor(Color.red.darker());
	g.setFont(titlefont);
	fmetrics = g.getFontMetrics();
	g.drawString(titulo,xstart1,fmetrics.getHeight());
	
        g.setColor(Color.black);
	g.setFont(textfont2);
	fmetrics = g.getFontMetrics();
	
        stmp = "There is also a solution corresponding";
	g.drawString(stmp,xstart1,ystart);
	
        stmp = "to the other  intersection  between  the ";
	g.drawString(stmp,xstart1,ystart+(int)12*fmetrics.getHeight()/10);
	
        stmp = "SWR circle and the unitary circle.";
	g.drawString(stmp,xstart1,ystart+(int)(24*fmetrics.getHeight()/10));
	
        g.setColor(Color.red.darker());
	stmp = "Click Next Step to proceed";
	g.drawString(stmp,xstart1,ystart+(int)(48*fmetrics.getHeight()/10));
    }
    
    private void step7(Graphics g){
        int xstart1 = state.s25;
	int xstart2 = state.s60;
        int xstart3 = state.s35;
        
	String stmp;
        FontMetrics fmetrics;
        double ytest;
        
	String titulo = "Step 3  -  Second Solution";
	g.setColor(Color.red.darker());
	g.setFont(titlefont);
	fmetrics = g.getFontMetrics();
	g.drawString(titulo,xstart1,fmetrics.getHeight());
	
        g.setColor(Color.black);
	g.setFont(textfont2);
	fmetrics=g.getFontMetrics();
	
	stmp = "A second stub can be inserted at the new";
	g.drawString(stmp,xstart1,ystart);
	
        stmp = "location:";
	g.drawString(stmp,xstart1,ystart+(int)(12*fmetrics.getHeight()/10));
	
	g.setColor(Color.blue.darker());
	stmp = " = "+MaestroA.rounder(state.dd2,4);
	MaestroG.subscripterSSSS("  d","2",stmp," "+lambda,"  from the load",g,fonto,xstart3,ystart+(int)(24*fmetrics.getHeight()/10));
        
	g.setColor(Color.black.darker());
	stmp = "with normalized line admittance:";
	g.drawString(stmp,xstart1,ystart+(int)(36*fmetrics.getHeight()/10+fmetrics.getHeight()/2));
        
        ytest = state.BBs2;
        
        g.setColor(Color.blue.darker());
        
        if(ytest < 0.0){
	    stmp = " = 1.0 + j "+MaestroA.rounder(Math.abs(state.BBs2norm),5);
	    MaestroG.subscripter("  y(d","2",")"+stmp,g,fonto,xstart3,ystart+5*fmetrics.getHeight()+fmetrics.getHeight()/2);
	}
	else{
            stmp = " = 1.0 - j "+MaestroA.rounder(Math.abs(state.BBs2norm),5);
	    MaestroG.subscripter("  y(d","2",")"+stmp,g,fonto,xstart3,ystart+5*fmetrics.getHeight()+fmetrics.getHeight()/2);
	}
    }
       
    private void step8(Graphics g){
        int xstart1 = state.s25;
	int xstart2 = state.s60;
        int xstart3 = state.s35;
        
	String stmp;
        FontMetrics fmetrics;
	double ytest;
	
        g.setColor(Color.red.darker());
	String titulo = "Step 4  -  Second Solution";
	g.setFont(titlefont);
	fmetrics = g.getFontMetrics();
	g.drawString(titulo,xstart1,fmetrics.getHeight());
	
        g.setColor(Color.black);
	g.setFont(textfont);
	fmetrics=g.getFontMetrics();
	stmp = "To cancel the imaginary part of the line";
	g.drawString(stmp,xstart1,ystart);
        
	stmp = "admittance we add a stub with:";
	g.drawString(stmp,xstart1,ystart+(int)(12*fmetrics.getHeight()/10));
	
        stmp = "Length:";
	g.drawString(stmp,xstart1,ystart+(int)(24*fmetrics.getHeight()/10+fmetrics.getHeight()/2));
	
	g.setColor(Color.blue.darker());
	stmp = " = "+MaestroA.rounder(state.LL2,4);
	MaestroG.subscripterSSSIT("               l","2",stmp+" ",""+lambda,g,fonto,xstart1,ystart+(int)(24*fmetrics.getHeight()/10+fmetrics.getHeight()/2));
	
	g.setColor(Color.black);
	stmp = "Admittance: ";
	g.drawString(stmp,xstart1,ystart+(int)(48*fmetrics.getHeight()/10-fmetrics.getHeight()/4));
	
        g.setColor(Color.blue.darker());
	ytest = state.BBs2;

    	if(ytest < 0.0){    
	    stmp = " = - j "+MaestroA.rounder(Math.abs(state.BBs2),5)+" [S]      (actual)";
	    MaestroG.subscripter("  Y","2",stmp,g,fonto,xstart3,ystart+6*fmetrics.getHeight());
	    
	    stmp = " = - j "+MaestroA.rounder(Math.abs(state.BBs2norm),5)+"           (normalized)";
	    MaestroG.subscripter("  y","2",stmp,g,fonto,xstart3,ystart+7*fmetrics.getHeight()+fmetrics.getHeight()/2);    
	}
	else{
	    stmp = " = j "+MaestroA.rounder(Math.abs(state.BBs2),5)+" [S]      (actual)";
	    MaestroG.subscripter("  Y","2",stmp,g,fonto,xstart3,ystart+6*fmetrics.getHeight());
	    
	    stmp = " = j "+MaestroA.rounder(Math.abs(state.BBs2norm),5)+"           (normalized)";
	    MaestroG.subscripter("  y","2",stmp,g,fonto,xstart3,ystart+7*fmetrics.getHeight()+fmetrics.getHeight()/2);
	}
    }
    
    private void step9(Graphics g){
        
        int xstart1 = state.s25;
	int xstart2 = state.s60;
        int xstart3 = state.s35;
	
	String stmp;
        FontMetrics fmetrics;
	double ytest;
	
        g.setColor(Color.red.darker());
	g.setFont(titlefont2);
	fmetrics = g.getFontMetrics();
	String titulo = "SUMMARY";
        g.drawString(titulo,xstart1,fmetrics.getHeight());
	
	int ystep = state.s45;
	int dystep = state.s5;
        int dystep2 = state.s8;
        int ddystep = state.s18;
	
	g.setFont(textfont2);
	fmetrics=g.getFontMetrics();
        
        g.setColor(Color.blue.darker());
	stmp = "- First Solution";
	g.drawString(stmp,xstart1,ystep);
       
            double testlength = state.d1_meters;
	    int range = 5;
	    String lambda="\u03bb";
	    
            int xpos0 = state.s30;
            int xpos1 = state.s45; 
            int ypos01 = ystep + ddystep;
            int ypos1 = ypos01 + ddystep; 
            int ypos02 = ypos1+ ddystep + dystep2;
            int ypos2 = ypos02 + ddystep;
            
            int ypos00 = ypos2 + ddystep + dystep2;
            int ypos03 = ypos00 + ddystep;
            int ypos3 = ypos03 + ddystep;
            int ypos04 = ypos3 + ddystep + dystep2;
            int ypos4 = ypos04 + ddystep;
            
            int sizefont = state.font12;
            
            g.setColor(Color.black);
            MaestroG.subscripter("Stub Location:","","",g,sizefont,xpos0,ypos01);
            
            g.setColor(Color.blue.darker());
            if(testlength < 1.0E-9 && testlength > 0.0){
		MaestroG.subscripterSymMiddle2("d","1"," = "+MaestroA.rounder(state.dd1,range),lambda,"  = "+MaestroA.rounder(state.d1_meters*1.0e9,8)+" nm",g,sizefont,xpos1,ypos1);	
            }
	    else if(testlength < 1.0E-6 && testlength >= 1.0E-9){
		MaestroG.subscripterSymMiddle2("d","1"," = "+MaestroA.rounder(state.dd1,range),lambda,"  = "+MaestroA.rounder(state.d1_meters*1.0e9,4)+" nm",g,sizefont,xpos1,ypos1);	
            }
	    else if(testlength < 1.0E-3 && testlength >= 1.0E-6){
		MaestroG.subscripterSymMiddle2("d","1"," = "+MaestroA.rounder(state.dd1,range),lambda,"  = "+MaestroA.rounder(state.d1_meters*1.0e6,4)+" \u00b5m",g,sizefont,xpos1,ypos1);	
	    }
	    else if(testlength < 1.0 && testlength >= 1.0E-3){
		MaestroG.subscripterSymMiddle2("d","1"," = "+MaestroA.rounder(state.dd1,range),lambda,"  = "+MaestroA.rounder(state.d1_meters*1000.0,4)+" mm",g,sizefont,xpos1,ypos1);
            }
	    else if((testlength < 1000.0 && testlength >= 1.0 ) || testlength == 0.0){
		MaestroG.subscripterSymMiddle2("d","1"," = "+MaestroA.rounder(state.dd1,range),lambda,"  = "+MaestroA.rounder(state.d1_meters,6)+" m",g,sizefont,xpos1,ypos1);	
            }
	    else if(testlength >= 1000.0 && testlength < 1.0E6){
		MaestroG.subscripterSymMiddle2("d","1"," = "+MaestroA.rounder(state.dd1,range),lambda,"  = "+MaestroA.rounder(state.d1_meters/1.0e3,4)+" km",g,sizefont,xpos1,ypos1);	
            }
	    else if(testlength >= 1.0E6 && testlength < 1.0E9){
		MaestroG.subSymsup("d","1"," = "+MaestroA.rounder(state.dd1,range),lambda,"  = "+MaestroA.rounder(state.d1_meters/1.0e6,4)+" x 10","3"," km",g,sizefont,xpos1,ypos1);
            }
	    else if(testlength >= 1.0E9){
		MaestroG.subSymsup("d","1"," = "+MaestroA.rounder(state.dd1,range),lambda,"  = "+MaestroA.rounder(state.d1_meters/1.0e9,4)+" x 10","6"," km",g,sizefont,xpos1,ypos1);
            }

            g.setColor(Color.black);
            MaestroG.subscripter("Stub Length:","","",g,sizefont,xpos0,ypos02);
            
            g.setColor(Color.blue.darker());
            
            testlength = state.L1_meters;
            
            // NOTE :  first "l" is lower case "L" not a one.  Second "1" is subscript "one"
            if(testlength < 1.0E-9 && testlength > 0.0){
		MaestroG.subscripterSymMiddle2IT("l","1"," = "+MaestroA.rounder(state.LL1,range),lambda,"  = "+MaestroA.rounder(state.L1_meters*1.0e9,8)+" nm",g,sizefont,xpos1,ypos2);	
            }
	    else if(testlength < 1.0E-6 && testlength >= 1.0E-9){
		MaestroG.subscripterSymMiddle2IT("l","1"," = "+MaestroA.rounder(state.LL1,range),lambda,"  = "+MaestroA.rounder(state.L1_meters*1.0e9,4)+" nm",g,sizefont,xpos1,ypos2);	
            }
	    else if(testlength < 1.0E-3 && testlength >= 1.0E-6){
		MaestroG.subscripterSymMiddle2IT("l","1"," = "+MaestroA.rounder(state.LL1,range),lambda,"  = "+MaestroA.rounder(state.L1_meters*1.0e6,4)+" \u00b5m",g,sizefont,xpos1,ypos2);	
	    }
	    else if(testlength < 1.0 && testlength >= 1.0E-3){
		MaestroG.subscripterSymMiddle2IT("l","1"," = "+MaestroA.rounder(state.LL1,range),lambda,"  = "+MaestroA.rounder(state.L1_meters*1000.0,4)+" mm",g,sizefont,xpos1,ypos2);
            }
	    else if((testlength < 1000.0 && testlength >= 1.0 ) || testlength == 0.0){
		MaestroG.subscripterSymMiddle2IT("l","1"," = "+MaestroA.rounder(state.LL1,range),lambda,"  = "+MaestroA.rounder(state.L1_meters,6)+" m",g,sizefont,xpos1,ypos2);	
            }
	    else if(testlength >= 1000.0 && testlength < 1.0E6){
		MaestroG.subscripterSymMiddle2IT("l","1"," = "+MaestroA.rounder(state.LL1,range),lambda,"  = "+MaestroA.rounder(state.L1_meters/1.0e3,4)+" km",g,sizefont,xpos1,ypos2);	
            }
	    else if(testlength >= 1.0E6 && testlength < 1.0E9){
		MaestroG.subSymsup("l","1"," = "+MaestroA.rounder(state.LL1,range),lambda,"  = "+MaestroA.rounder(state.L1_meters/1.0e6,4)+" x 10","3"," km",g,sizefont,xpos1,ypos2);
            }
	    else if(testlength >= 1.0E9){
		MaestroG.subSymsup("l","1"," = "+MaestroA.rounder(state.LL1,range),lambda,"  = "+MaestroA.rounder(state.L1_meters/1.0e9,4)+" x 10","6"," km",g,sizefont,xpos1,ypos2);
            }

	g.setFont(textfont2);
	fmetrics=g.getFontMetrics();
	
	ystep +=dystep;
	g.setColor(Color.red.darker());
	stmp = "- Second Solution";
	g.drawString(stmp,xstart1,ypos00);
	
        
            g.setColor(Color.black);
            MaestroG.subscripter("Stub Location:","","",g,sizefont,xpos0,ypos03);
            
            g.setColor(Color.red.darker());
            
            testlength = state.d2_meters;
            if(testlength < 1.0E-9 && testlength > 0.0){
		MaestroG.subscripterSymMiddle2("d","2"," = "+MaestroA.rounder(state.dd2,range),lambda,"  = "+MaestroA.rounder(state.d2_meters*1.0e9,8)+" nm",g,sizefont,xpos1,ypos3);	
            }
	    else if(testlength < 1.0E-6 && testlength >= 1.0E-9){
		MaestroG.subscripterSymMiddle2("d","2"," = "+MaestroA.rounder(state.dd2,range),lambda,"  = "+MaestroA.rounder(state.d2_meters*1.0e9,4)+" nm",g,sizefont,xpos1,ypos3);	
            }
	    else if(testlength < 1.0E-3 && testlength >= 1.0E-6){
		MaestroG.subscripterSymMiddle2("d","2"," = "+MaestroA.rounder(state.dd2,range),lambda,"  = "+MaestroA.rounder(state.d2_meters*1.0e6,4)+" \u00b5m",g,sizefont,xpos1,ypos3);	
	    }
	    else if(testlength < 1.0 && testlength >= 1.0E-3){
		MaestroG.subscripterSymMiddle2("d","2"," = "+MaestroA.rounder(state.dd2,range),lambda,"  = "+MaestroA.rounder(state.d2_meters*1000.0,4)+" mm",g,sizefont,xpos1,ypos3);
            }
	    else if((testlength < 1000.0 && testlength >= 1.0 ) || testlength == 0.0){
		MaestroG.subscripterSymMiddle2("d","2"," = "+MaestroA.rounder(state.dd2,range),lambda,"  = "+MaestroA.rounder(state.d2_meters,6)+" m",g,sizefont,xpos1,ypos3);	
            }
	    else if(testlength >= 1000.0 && testlength < 1.0E6){
		MaestroG.subscripterSymMiddle2("d","2"," = "+MaestroA.rounder(state.dd2,range),lambda,"  = "+MaestroA.rounder(state.d2_meters/1.0e3,4)+" km",g,sizefont,xpos1,ypos3);	
            }
	    else if(testlength >= 1.0E6 && testlength < 1.0E9){
		MaestroG.subSymsup("d","2"," = "+MaestroA.rounder(state.dd2,range),lambda,"  = "+MaestroA.rounder(state.d2_meters/1.0e6,4)+" x 10","3"," km",g,sizefont,xpos1,ypos3);
            }
	    else if(testlength >= 1.0E9){
		MaestroG.subSymsup("d","2"," = "+MaestroA.rounder(state.dd2,range),lambda,"  = "+MaestroA.rounder(state.d2_meters/1.0e9,4)+" x 10","6"," km",g,sizefont,xpos1,ypos3);
            }
	
            g.setColor(Color.black);
            MaestroG.subscripter("Stub Length:","","",g,sizefont,xpos0,ypos04);
            
            g.setColor(Color.red.darker());
            
            testlength = state.L1_meters;
            
            // NOTE:  "l" is lower case "L" not a one
            if(testlength < 1.0E-9 && testlength > 0.0){
		MaestroG.subscripterSymMiddle2IT("l","2"," = "+MaestroA.rounder(state.LL2,range),lambda,"  = "+MaestroA.rounder(state.L2_meters*1.0e9,8)+" nm",g,sizefont,xpos1,ypos4);	
            }
	    else if(testlength < 1.0E-6 && testlength >= 1.0E-9){
		MaestroG.subscripterSymMiddle2IT("l","2"," = "+MaestroA.rounder(state.LL2,range),lambda,"  = "+MaestroA.rounder(state.L2_meters*1.0e9,4)+" nm",g,sizefont,xpos1,ypos4);	
            }
	    else if(testlength < 1.0E-3 && testlength >= 1.0E-6){
		MaestroG.subscripterSymMiddle2IT("l","2"," = "+MaestroA.rounder(state.LL2,range),lambda,"  = "+MaestroA.rounder(state.L2_meters*1.0e6,4)+" \u00b5m",g,sizefont,xpos1,ypos4);	
	    }
	    else if(testlength < 1.0 && testlength >= 1.0E-3){
		MaestroG.subscripterSymMiddle2IT("l","2"," = "+MaestroA.rounder(state.LL2,range),lambda,"  = "+MaestroA.rounder(state.L2_meters*1000.0,4)+" mm",g,sizefont,xpos1,ypos4);
            }
	    else if((testlength < 1000.0 && testlength >= 1.0 ) || testlength == 0.0){
		MaestroG.subscripterSymMiddle2IT("l","2"," = "+MaestroA.rounder(state.LL2,range),lambda,"  = "+MaestroA.rounder(state.L2_meters,6)+" m",g,sizefont,xpos1,ypos4);	
            }
	    else if(testlength >= 1000.0 && testlength < 1.0E6){
		MaestroG.subscripterSymMiddle2IT("l","2"," = "+MaestroA.rounder(state.LL2,range),lambda,"  = "+MaestroA.rounder(state.L2_meters/1.0e3,4)+" km",g,sizefont,xpos1,ypos4);	
            }
	    else if(testlength >= 1.0E6 && testlength < 1.0E9){
		MaestroG.subSymsupIT("l","2"," = "+MaestroA.rounder(state.LL2,range),lambda,"  = "+MaestroA.rounder(state.L2_meters/1.0e6,4)+" x 10","3"," km",g,sizefont,xpos1,ypos4);
            }
	    else if(testlength >= 1.0E9){
		MaestroG.subSymsupIT("l","2"," = "+MaestroA.rounder(state.LL2,range),lambda,"  = "+MaestroA.rounder(state.L2_meters/1.0e9,4)+" x 10","6"," km",g,sizefont,xpos1,ypos4);
            }
    } 
}
