//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.*;
import java.awt.event.*;
import java.applet.*;
import java.lang.*;

public class StepCanvas extends Canvas{
    //private final Color bgcolor = new Color(170,200,200);
    private static final Color bgcolor = new Color(236,236,236);
    //private static final Color bgcolor = Color.lightGray;
    private final Font titlefont = TheFonts.sanSerif18;
    private final Font titlefont2 = TheFonts.sanSerif14;
    private final Font titlefont3 = TheFonts.bold16;
    private final Font textfont = TheFonts.sanSerif15;
    private final Font symbolfont = TheFonts.serif15;
    //private final Font textfont = TheFonts.serif18;
    private final Font textfont2 = TheFonts.sanSerif13;
    private final Font textfont3 = TheFonts.sanSerif14;
    private final Font symbolfont2 = TheFonts.serif14;
    private Image im;
    private Graphics buf;
    
    public String Bigomega, omega, alpha, Ohm, lambda, infinity, Gamma, epsilon;
    
    public int ystart = 55;
    
    StateVars state;
    Stub stub;
    private int fonto = 15;
    private int fonto2 = 13;
    private int fonto3 = 11;
       
    StepCanvas(StateVars state){
	super();
	this.state = state;
	setBackground(bgcolor);
    }
    
    @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);
	
	FontMetrics fm;
	g.setFont(TheFonts.symbol15);
	fm = g.getFontMetrics();
	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){
	g.setColor(Color.red.darker());
	String titulo = "Step 1";
	String stmp;
       
	g.setFont(titlefont);
	FontMetrics fmetrics=g.getFontMetrics();
	g.drawString(titulo,14,fmetrics.getHeight());
	g.setColor(Color.black);
	g.setFont(textfont);
	fmetrics=g.getFontMetrics();
	stmp = "- Identify normalized load impedance";
	g.drawString(stmp,15,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,30,ystart+25);
	}
	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,30,ystart+25);
	}
	
	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,30,ystart+50);
	}
	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,30,ystart+50);
	}
	
        int xstart1 = 15;
        if(state.getZL().Imaginary() >= 0.0){
            g.setColor(Color.black);
            //stmp = "For frequency analysis we assume";
            stmp = "- For frequency analysis, we assume R";
            //g.drawString(stmp,15,ystart+85);
            MaestroG.subscripter(stmp,"L","",g,fonto2,xstart1,135);
            int xExtra = fmetrics.stringWidth("- ");
            g.drawString("remains unchanged and we model",xstart1+xExtra,155);
            g.drawString("the imaginary part as an inductor",xstart1+xExtra,175);
        }
        else{
            g.setColor(Color.black);
            //stmp = "For frequency analysis we assume";
            stmp = "- For frequency analysis, we assume R";
            //g.drawString(stmp,15,ystart+85);
            MaestroG.subscripter(stmp,"L","",g,fonto2,xstart1,135);
            int xExtra = fmetrics.stringWidth("- ");
            g.drawString("remains unchanged and we model",xstart1+xExtra,155);
            g.drawString("the imaginary part as a capacitor",xstart1+xExtra,175);
        }
        //g.setColor(Color.blue.darker());
        //
	//if(state.getZL().Imaginary() >= 0.0){
	//    MaestroG.subsubsubSymbol("j X","L"," = j "+omega+" L","","","","= j "+MaestroA.rounder(state.getZL().Imaginary(),4),"  "+Bigomega,g,fonto2,15,ystart+110);
	//    
	//		double tempore = 0.0;
	//		double temporal = state.getZL().Imaginary()/(2.0*Math.PI*state.frequency);
	//		int xtempore = 20;
	//		int ytempore = ystart+140;
	//		
	//		if(temporal < 1.0E-12 && temporal != 0.0){
	//		    tempore = temporal * 1.0E12;
	//		    MaestroG.subsup("L",""," = "+MaestroA.rounder(tempore,4)+" x 10","-12","  H",g,fonto2,xtempore, ytempore);
	//		}
	//	
	//		else if(temporal >= 1.0E-12 && temporal < 1.0E-9){
	//		    tempore = temporal * 1.0E12;
	//		    MaestroG.subsup("L",""," = "+MaestroA.rounder(tempore,4)+" x 10","-12","  H",g,fonto2,xtempore, ytempore);
	//		}
	//		else if(temporal >= 1.0E-9 && temporal < 1.0E-6){
	//		    tempore = temporal * 1.0E9;
	//		    MaestroG.subsup("L",""," = "+MaestroA.rounder(tempore,4)+" x 10","-9","  H",g,fonto2,xtempore, ytempore);
	//		}
	//		else if(temporal >= 1.0E-6 && temporal < 1.0E-3){
	//		    tempore = temporal * 1.0E6;
	//		    MaestroG.subsup("L",""," = "+MaestroA.rounder(tempore,4)+" x 10","-6","  H",g,fonto2,xtempore, ytempore);
	//		}
	//		else if(temporal >= 1.0E-3 && temporal < 1.0){
	//		    tempore = temporal * 1.0E3;
	//		    MaestroG.subsup("L",""," = "+MaestroA.rounder(tempore,4)+" x 10","-3","  H",g,fonto2,xtempore, ytempore);
	//		}
	//		else if(temporal >= 1.0 || temporal == 0.0){
	//		    tempore = temporal;
	//		    MaestroG.subsup("L",""," = "+MaestroA.rounder(tempore,4)+"","","  H",g,fonto2,xtempore, ytempore);
	//		}
	//}
	//else{
	//    MaestroG.subsubsupSymbol("j X","L"," = ( j "+omega+" C","",")","-1","= - j "+MaestroA.rounder(Math.abs(+state.getZL().Imaginary()),4),"  "+Bigomega,g,fonto2,15,ystart+110);
	//		
	//		double tempore = 0.0;
	//		double temporal = 1.0/(2.0*Math.PI*state.frequency*Math.abs(state.getZL().Imaginary()));
	//		int xtempore = 20;
	//		int ytempore = ystart+140;
	//		
	//		if(temporal < 1.0E-12 && temporal != 0.0){
	//		    tempore = temporal * 1.0E12;
	//		    MaestroG.subsup("C",""," = "+MaestroA.rounder(tempore,4)+" x 10","-12","  F",g,fonto2,xtempore, ytempore);
	//		}
	//	
	//		else if(temporal >= 1.0E-12 && temporal < 1.0E-9){
	//		    tempore = temporal * 1.0E12;
	//		    MaestroG.subsup("C",""," = "+MaestroA.rounder(tempore,4)+" x 10","-12","  F",g,fonto2,xtempore, ytempore);
	//		}
	//		else if(temporal >= 1.0E-9 && temporal < 1.0E-6){
	//		    tempore = temporal * 1.0E9;
	//		    MaestroG.subsup("C",""," = "+MaestroA.rounder(tempore,4)+" x 10","-9","  F",g,fonto2,xtempore, ytempore);
	//		}
	//		else if(temporal >= 1.0E-6 && temporal < 1.0E-3){
	//		    tempore = temporal * 1.0E6;
	//		    MaestroG.subsup("C",""," = "+MaestroA.rounder(tempore,4)+" x 10","-6","  F",g,fonto2,xtempore, ytempore);
	//		}
	//		else if(temporal >= 1.0E-3 && temporal < 1.0){
	//		    tempore = temporal * 1.0E3;
	//		    MaestroG.subsup("C",""," = "+MaestroA.rounder(tempore,4)+" x 10","-3","  F",g,fonto2,xtempore, ytempore);
	//		}
	//		else if(temporal >= 1.0 || temporal == 0.0){
	//		    tempore = temporal;
	//		    MaestroG.subsup("C",""," = "+MaestroA.rounder(tempore,4)+"","","  F",g,fonto2,xtempore, ytempore);
	//		}
	//}
    }
    
    private void step2(Graphics g){
	String stmp, stmp2;
	String titulo = "Step 2";
	g.setColor(Color.red.darker());
	g.setFont(titlefont);
	FontMetrics fmetrics=g.getFontMetrics();
	g.drawString(titulo,14,fmetrics.getHeight());
        
	g.setColor(Color.black);
	g.setFont(textfont);
	fmetrics=g.getFontMetrics();
	stmp = "- Plot SWR circle with radius  r = ";
	//g.drawString(stmp,15,ystart);
        
        MaestroG.subscripterSS2(""+stmp,"","| "+Gamma+" |",g,14,15,ystart);
	//g.setFont(symbolfont);
	//stmp2 = "\u0393";
	//g.drawString(stmp2,15+fmetrics.stringWidth(stmp)-15,ystart);
	
	g.setFont(textfont);
	fmetrics=g.getFontMetrics();
	stmp = "- Identify normalized load admittance";
	g.drawString(stmp,15,ystart+30);
	
	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,15,110);
	}
	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,15,110);
	}
	
	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,15,ystart+100);
	}
	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,15,ystart+100);
	}
    }
    
    private void step3(Graphics g){
	String stmp;
        
	String titulo = "First Solution";
	g.setColor(Color.red.darker());
	g.setFont(titlefont);
	FontMetrics fmetrics=g.getFontMetrics();
	g.drawString(titulo,14,fmetrics.getHeight());
	g.setColor(Color.black);
	g.setFont(textfont);
	fmetrics=g.getFontMetrics();
	stmp = "Corresponds to  the  first  intersection";
	g.drawString(stmp,15,ystart);
	
	stmp = "between SWR circle and unitary circle";
	g.drawString(stmp,15,ystart+fmetrics.getHeight());
	
	stmp = "with admittance as a reference.";
	g.drawString(stmp,15,ystart+2*fmetrics.getHeight());
	
        g.setColor(Color.red.darker());
	stmp = "Click Next Step to proceed";
	g.drawString(stmp,15,ystart+4*fmetrics.getHeight());
    }
        
    private void step4(Graphics g){
	String stmp;
        double ytest;
        
	String titulo = "Step 3  -  First Solution";
	g.setColor(Color.red.darker());
	g.setFont(titlefont);
	FontMetrics fmetrics=g.getFontMetrics();
	g.drawString(titulo,14,fmetrics.getHeight());
	g.setColor(Color.black);
	g.setFont(textfont);
	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,15,ystart+fmetrics.getHeight());
	stmp = "it cannot be matched.";
	g.drawString(stmp,15,ystart+2*fmetrics.getHeight());
	stmp = "Please, go Back to Start.";
	g.drawString(stmp,15,ystart+4*fmetrics.getHeight()+fmetrics.getHeight()/2);
      }
      else{
	stmp = "Move along the transmission line from";
	g.drawString(stmp,15,ystart);
	stmp = "load to generator until a position  with";
	g.drawString(stmp,15,ystart+fmetrics.getHeight());
	stmp = "normalized conductance   g = 1.0  is";
	g.drawString(stmp,15,ystart+2*fmetrics.getHeight());
        stmp = "reached.";
	g.drawString(stmp,15,ystart+3*fmetrics.getHeight());
        
        stmp = "The first solution is at location";
	g.drawString(stmp,15,ystart+4*fmetrics.getHeight()+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,15,ystart+6*fmetrics.getHeight()-fmetrics.getHeight()/4);
	
	g.setColor(Color.black);
	//stmp = "You can insert a stub at this location.";
	//g.drawString(stmp,15,ystart+7*fmetrics.getHeight());
        
        stmp = "with normalized line admittance:";
	g.drawString(stmp,15,ystart+7*fmetrics.getHeight());
        
        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,15,55+8*fmetrics.getHeight()+fmetrics.getHeight()/2);
	}
	else{
            stmp = " = 1.0 - j "+MaestroA.rounder(Math.abs(state.BBs1norm),5); //+"           (normalized)";
	    MaestroG.subscripter("  y(d","1",")"+stmp,g,fonto,15,ystart+8*fmetrics.getHeight()+fmetrics.getHeight()/2);
	}

      }
    }
       
   
    
    private void step5(Graphics g){
	
	String titulo = "Step 4  -  First Solution";
	String stmp;
	double ytest;
        
	g.setColor(Color.red.darker());
	g.setFont(titlefont);
	FontMetrics fmetrics=g.getFontMetrics();
	g.drawString(titulo,14,fmetrics.getHeight());
	g.setColor(Color.black);
	g.setFont(textfont);
	fmetrics=g.getFontMetrics();
	stmp = "To cancel the imaginary part of the";
	g.drawString(stmp,15,ystart);
	stmp = "line admittance we add a stub with:";
	g.drawString(stmp,15,ystart+fmetrics.getHeight());
	stmp = "Length:";
	g.drawString(stmp,15,ystart+2*fmetrics.getHeight()+fmetrics.getHeight()/2);
	g.setColor(Color.blue.darker());
	stmp = " = "+MaestroA.rounder(state.LL1,4);
	//MaestroG.subscripter("               L","stub1",stmp+" "+lambda,g,fonto,15,ystart+2*fmetrics.getHeight()+fmetrics.getHeight()/2);
	MaestroG.subscripterSSSIT("               l","1",stmp+" ",""+lambda,g,fonto,15,ystart+2*fmetrics.getHeight()+fmetrics.getHeight()/2);
	
	g.setColor(Color.black);
	stmp = "Admittance: ";
	g.drawString(stmp,15,ystart+4*fmetrics.getHeight()-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,15,ystart+5*fmetrics.getHeight());
	    stmp = " = - j "+MaestroA.rounder(Math.abs(state.BBs1norm),5)+"           (normalized)";
	    MaestroG.subscripter("  y","1",stmp,g,fonto,15,55+6*fmetrics.getHeight()+fmetrics.getHeight()/2);
	}
	else{
            stmp = " = j "+MaestroA.rounder(Math.abs(state.BBs1),5)+"  S      (actual)";
	    MaestroG.subscripter("  Y","1",stmp,g,fonto,15,ystart+5*fmetrics.getHeight());
	    stmp = " = j "+MaestroA.rounder(Math.abs(state.BBs1norm),5)+"           (normalized)";
	    MaestroG.subscripter("  y","1",stmp,g,fonto,15,ystart+6*fmetrics.getHeight()+fmetrics.getHeight()/2);
	}
	
    }
    
    private void step6(Graphics g){
	String stmp;
        
	String titulo = "Second Solution";
	g.setColor(Color.red.darker());
	g.setFont(titlefont);
	FontMetrics fmetrics=g.getFontMetrics();
	g.drawString(titulo,14,fmetrics.getHeight());
	g.setColor(Color.black);
	g.setFont(textfont);
	fmetrics=g.getFontMetrics();
	stmp = "There is also a solution corresponding";
	g.drawString(stmp,15,ystart);
	stmp = "to the other  intersection  between  the ";
	g.drawString(stmp,15,ystart+fmetrics.getHeight());
	stmp = "SWR circle and the unitary circle.";
	g.drawString(stmp,15,ystart+2*fmetrics.getHeight());
	
        g.setColor(Color.red.darker());
	stmp = "Click Next Step to proceed";
	g.drawString(stmp,15,ystart+4*fmetrics.getHeight());
    }
    
     private void step7(Graphics g){
	String stmp;
        double ytest;
        
	String titulo = "Step 3  -  Second Solution";
	g.setColor(Color.red.darker());
	g.setFont(titlefont);
	FontMetrics fmetrics=g.getFontMetrics();
	g.drawString(titulo,14,fmetrics.getHeight());
	g.setColor(Color.black);
	g.setFont(textfont);
	fmetrics=g.getFontMetrics();
	
	stmp = "A second stub can be inserted at the new";
	g.drawString(stmp,15,ystart);
	stmp = "location:";
	g.drawString(stmp,15,ystart+5+fmetrics.getHeight());
	
	g.setColor(Color.blue.darker());
	stmp = " = "+MaestroA.rounder(state.dd2,4);
	MaestroG.subscripterSSSS("  d","2",stmp," "+lambda,"  from the load",g,fonto,15,ystart+25*fmetrics.getHeight()/10);
        
	g.setColor(Color.black.darker());
	stmp = "with normalized line admittance:";
	g.drawString(stmp,15,ystart+4*fmetrics.getHeight());
        
        ytest = state.BBs2;
        
        g.setColor(Color.blue.darker());
        
        if(ytest < 0.0){
	    stmp = " = 1.0 + j "+MaestroA.rounder(Math.abs(state.BBs2norm),5); //+"           (normalized)";
	    MaestroG.subscripter("  y(d","2",")"+stmp,g,fonto,15,ystart+5*fmetrics.getHeight()+fmetrics.getHeight()/2);
	}
	else{
            stmp = " = 1.0 - j "+MaestroA.rounder(Math.abs(state.BBs2norm),5); //+"           (normalized)";
	    MaestroG.subscripter("  y(d","2",")"+stmp,g,fonto,15,ystart+5*fmetrics.getHeight()+fmetrics.getHeight()/2);
	}
    }
       
    private void step8(Graphics g){
	String titulo = "Step 4  -  Second Solution";
	String stmp;
        
	double ytest;
	g.setColor(Color.red.darker());
	g.setFont(titlefont);
	FontMetrics fmetrics=g.getFontMetrics();
	g.drawString(titulo,14,fmetrics.getHeight());
	g.setColor(Color.black);
	g.setFont(textfont);
	fmetrics=g.getFontMetrics();
	stmp = "To cancel the imaginary part of the line";
	g.drawString(stmp,15,ystart);
	stmp = "admittance we add a stub with:";
	g.drawString(stmp,15,ystart+fmetrics.getHeight());
	stmp = "Length:";
	g.drawString(stmp,15,ystart+2*fmetrics.getHeight()+fmetrics.getHeight()/2);
	
	g.setColor(Color.blue.darker());
	stmp = " = "+MaestroA.rounder(state.LL2,4);
	//MaestroG.subscripter("               L","stub2",stmp+" "+lambda,g,fonto,15,ystart+2*fmetrics.getHeight()+fmetrics.getHeight()/2);
	MaestroG.subscripterSSSIT("               l","2",stmp+" ",""+lambda,g,fonto,15,ystart+2*fmetrics.getHeight()+fmetrics.getHeight()/2);
	
	g.setColor(Color.black);
	stmp = "Admittance: ";
	g.drawString(stmp,15,ystart+4*fmetrics.getHeight()-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,15,ystart+5*fmetrics.getHeight());
	    
	    stmp = " = - j "+MaestroA.rounder(Math.abs(state.BBs2norm),5)+"           (normalized)";
	    MaestroG.subscripter("  y","2",stmp,g,fonto,15,ystart+6*fmetrics.getHeight()+fmetrics.getHeight()/2);    
	}
	else{
	    stmp = " = j "+MaestroA.rounder(Math.abs(state.BBs2),5)+" S      (actual)";
	    MaestroG.subscripter("  Y","2",stmp,g,fonto,15,ystart+5*fmetrics.getHeight());
	    
	    stmp = " = j "+MaestroA.rounder(Math.abs(state.BBs2norm),5)+"           (normalized)";
	    MaestroG.subscripter("  y","2",stmp,g,fonto,15,ystart+6*fmetrics.getHeight()+fmetrics.getHeight()/2);
	}
    }
    private void step9(Graphics g){
	String titulo = "SUMMARY";
	String stmp;
	double ytest;
	g.setColor(Color.red.darker());
	g.setFont(titlefont3);
	FontMetrics fmetrics=g.getFontMetrics();
	g.drawString(titulo,14,fmetrics.getHeight());
	
	g.setFont(textfont3);
	fmetrics=g.getFontMetrics();
	
	int ystep = 45;
	int dystep = 5;
        int dystep2 = 8;
        int ddystep = 18;
	
	g.setColor(Color.blue.darker());
	stmp = "- First Solution";
	g.drawString(stmp,15,ystep);
       
            double testlength = state.d1_meters;
	    int range = 5;
	    String lambda="\u03bb";
	    
            int xpos0 = 30;
            int xpos1 = 45; 
            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 = 12;
            
            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(textfont3);
	fmetrics=g.getFontMetrics();
	
	ystep +=dystep;
	g.setColor(Color.red.darker());
	stmp = "- Second Solution";
	g.drawString(stmp,15,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);
            }
    }
    
}
