//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 static final Color bgcolor = new Color(236,236,236);
    
    private Font titlefont, labfont, titlefont2, symbolfont, textfont, textfont3, 
            textfont4, textfont2, symbolfont3, symbolfont4, symbolfont2, normalfont,
            normalfontB, normalfont2, smallfont;
    
    public String Bigomega, omega, alpha, Ohm, lambda, infinity, Gamma, epsilon;
    
    public int ystart;
    private Image im;
    private Graphics buf;
    
    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;
        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){
	FontMetrics fmetrics;
        int xstart1 = state.s25;
	int xstart2 = state.s60;
        int xstart3 = state.s35;
	
        ystart = state.s55;
        
        g.setFont(titlefont);
	fmetrics = g.getFontMetrics();
	g.setColor(Color.red.darker());
	String titulo = "Step 1";
	String stmp;
        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);
	}
	
	//xstart1 = state.s15;
        if(state.getZL().Imaginary() >= 0.0){
            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 an inductor",xstart1+xExtra,state.s175);
        }
        else{
            g.setColor(Color.black);
            g.setFont(textfont2);
            fmetrics=g.getFontMetrics();
            
            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,state.s110);
	}
	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,state.s110);
	}
	
	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;
        
	String titulo = "First Solution";
	g.setColor(Color.red.darker());
	g.setFont(titlefont);
	FontMetrics fmetrics=g.getFontMetrics();
	g.drawString(titulo,xstart1,fmetrics.getHeight());
	
        g.setColor(Color.black);
	g.setFont(textfont4);
	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+fmetrics.getHeight());
	
	stmp = "with admittance as a reference.";
	g.drawString(stmp,xstart1,ystart+2*fmetrics.getHeight());
	
        g.setColor(Color.red.darker());
	stmp = "Click Next Step to proceed";
	g.drawString(stmp,xstart1,ystart+4*fmetrics.getHeight());
    }
        
    private void step4(Graphics g){
	
        int xstart1 = state.s25;
	int xstart2 = state.s60;
        int xstart3 = state.s35;
        
        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,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+2*fmetrics.getHeight());
            stmp = "Please, go Back to Start.";
            g.drawString(stmp,xstart1,ystart+4*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+2*fmetrics.getHeight());
            stmp = "reached.";
            g.drawString(stmp,xstart1,ystart+3*fmetrics.getHeight());

            stmp = "The first solution is at location";
            g.drawString(stmp,xstart1,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,xstart3,ystart+6*fmetrics.getHeight()-fmetrics.getHeight()/4);

            g.setColor(Color.black);
            g.setFont(textfont2);
            fmetrics=g.getFontMetrics();
            stmp = "with normalized line admittance:";
            g.drawString(stmp,xstart1,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,xstart3,state.s55+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,xstart3,ystart+8*fmetrics.getHeight()+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;
	double ytest;
        
	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 = "To cancel the imaginary part of the line";
	g.drawString(stmp,xstart1,ystart);
	ytest = state.BBs1;
        
        if(ytest > 0.0){
            stmp = "admittance we add a shunt capacitance:";
        }
        else if(ytest < 0.0){
            stmp = "admittance we add a shunt inductance:";
        }
        
	g.drawString(stmp,xstart1,ystart+fmetrics.getHeight());
        
        //----------------------------------------------------------------------
        
        if(ytest < 0.0){
	    
	    MaestroG.subsubsupSymbol2("Y","1"," = ( j "+omega+" L","1",")","-1",
                 "= - j "+MaestroA.rounder(Math.abs(ytest),5)," S   (actual)",
                 g,fonto,xstart3,ystart+3*fmetrics.getHeight());
            
			double tempore = 0.0;
			double temporal = 1.0/(2.0*Math.PI*state.frequency*Math.abs(ytest));
			int xtempore = xstart3;
			int ytempore = ystart+4*fmetrics.getHeight()+fmetrics.getHeight()/2;
			
			if(temporal < 1.0E-12 && temporal != 0.0){
			    tempore = temporal * 1.0E12;
			    MaestroG.subsup("L","1"," = "+MaestroA.rounder(tempore,5)+" x 10","-12","  H",g,fonto,xtempore, ytempore);
			}
		
			else if(temporal >= 1.0E-12 && temporal < 1.0E-9){
			    tempore = temporal * 1.0E12;
			    MaestroG.subsup("L","1"," = "+MaestroA.rounder(tempore,5)+" x 10","-12","  H",g,fonto,xtempore, ytempore);
			}
			else if(temporal >= 1.0E-9 && temporal < 1.0E-6){
			    tempore = temporal * 1.0E9;
			    MaestroG.subsup("L","1"," = "+MaestroA.rounder(tempore,5)+" x 10","-9","  H",g,fonto,xtempore, ytempore);
			}
			else if(temporal >= 1.0E-6 && temporal < 1.0E-3){
			    tempore = temporal * 1.0E6;
			    MaestroG.subsup("L","1"," = "+MaestroA.rounder(tempore,5)+" x 10","-6","  H",g,fonto,xtempore, ytempore);
			}
			else if(temporal >= 1.0E-3 && temporal < 1.0){
			    tempore = temporal * 1.0E3;
			    MaestroG.subsup("L","1"," = "+MaestroA.rounder(tempore,5)+" x 10","-3","  H",g,fonto,xtempore, ytempore);
			}
			else if(temporal >= 1.0 || temporal == 0.0){
			    tempore = temporal;
			    MaestroG.subsup("L","1"," = "+MaestroA.rounder(tempore,5)+"","","  H",g,fonto2,xtempore, ytempore);
			}
	}
	else if(ytest > 0.0){
	    MaestroG.subsubsubSymbol2("Y","1"," = j "+omega+" C","1","","",
                            "= j "+MaestroA.rounder(ytest,5)," S   (actual)",
                            g,fonto,state.s20,ystart+3*fmetrics.getHeight());
			
			double tempore = 0.0;
			double temporal = ytest/(2.0*Math.PI*state.frequency);
			int xtempore = xstart3;
			int ytempore = ystart+4*fmetrics.getHeight()+fmetrics.getHeight()/2;
			
			if(temporal < 1.0E-12 && temporal != 0.0){
			    tempore = temporal * 1.0E12;
			    MaestroG.subsup("C","1"," = "+MaestroA.rounder(tempore,5)+" x 10","-12","  F",g,fonto,xtempore, ytempore);
			}
		
			else if(temporal >= 1.0E-12 && temporal < 1.0E-9){
			    tempore = temporal * 1.0E12;
			    MaestroG.subsup("C","1"," = "+MaestroA.rounder(tempore,5)+" x 10","-12","  F",g,fonto,xtempore, ytempore);
			}
			else if(temporal >= 1.0E-9 && temporal < 1.0E-6){
			    tempore = temporal * 1.0E9;
			    MaestroG.subsup("C","1"," = "+MaestroA.rounder(tempore,5)+" x 10","-9","  F",g,fonto,xtempore, ytempore);
			}
			else if(temporal >= 1.0E-6 && temporal < 1.0E-3){
			    tempore = temporal * 1.0E6;
			    MaestroG.subsup("C","1"," = "+MaestroA.rounder(tempore,5)+" x 10","-6","  F",g,fonto,xtempore, ytempore);
			}
			else if(temporal >= 1.0E-3 && temporal < 1.0){
			    tempore = temporal * 1.0E3;
			    MaestroG.subsup("C","1"," = "+MaestroA.rounder(tempore,5)+" x 10","-3","  F",g,fonto,xtempore, ytempore);
			}
			else if(temporal >= 1.0 || temporal == 0.0){
			    tempore = temporal;
			    MaestroG.subsup("C","1"," = "+MaestroA.rounder(tempore,5)+"","","  F",g,fonto,xtempore, ytempore);
			}
	}
        
	//----------------------------------------------------------------------
	g.setColor(Color.black);
	g.setColor(Color.blue.darker());
	
	if(ytest < 0.0){
	    
	    stmp = " = - j "+MaestroA.rounder(Math.abs(state.BBs1norm),5)+"           (normalized)";
	    MaestroG.subscripter("  y","1",stmp,g,fonto,xstart3,state.s55+6*fmetrics.getHeight()+fmetrics.getHeight()/2);
	}
	else{
            stmp = " = j "+MaestroA.rounder(Math.abs(state.BBs1norm),5)+"           (normalized)";
	    MaestroG.subscripter("  y","1",stmp,g,fonto,xstart3,ystart+6*fmetrics.getHeight()+fmetrics.getHeight()/2);
	}	
    }
    
    private void step6(Graphics g){
        
        int xstart1 = state.s25;
	int xstart2 = state.s60;
        int xstart3 = state.s35;
        
	String stmp;
        
	String titulo = "Second Solution";
	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 = "There is also a solution corresponding";
	g.drawString(stmp,xstart1,ystart);
	stmp = "to the other  intersection  between  the ";
	g.drawString(stmp,xstart1,ystart+fmetrics.getHeight());
	stmp = "SWR circle and the unitary circle.";
	g.drawString(stmp,xstart1,ystart+2*fmetrics.getHeight());
	
        g.setColor(Color.red.darker());
	stmp = "Click Next Step to proceed";
	g.drawString(stmp,xstart1,ystart+4*fmetrics.getHeight());
    }
    
     private void step7(Graphics g){
         
        int xstart1 = state.s25;
	int xstart2 = state.s60;
        int xstart3 = state.s35;
        
	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,xstart1,fmetrics.getHeight());
	
        g.setColor(Color.black);
	g.setFont(textfont2);
	fmetrics=g.getFontMetrics();
	stmp = "A second shunt admittance can be inserted";
	g.drawString(stmp,xstart1,ystart);
	stmp = "at the new location:";
	g.drawString(stmp,xstart1,ystart+state.s5+fmetrics.getHeight());
	
	g.setColor(Color.blue.darker());
	stmp = " = "+MaestroA.rounder(state.dd2,4);
	MaestroG.subscripterSSSS("  d","2",stmp," "+lambda,"  from the load",g,fonto,xstart3,ystart+3*fmetrics.getHeight());
        
        g.setColor(Color.black.darker());
	stmp = "with normalized line admittance:";
	g.drawString(stmp,xstart1,ystart+5*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,xstart3,state.s55+6*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,xstart3,ystart+6*fmetrics.getHeight()+fmetrics.getHeight()/2);
	}
        
    }
       
    private void step8(Graphics g){
        
        int xstart1 = state.s25;
	int xstart2 = state.s60;
        int xstart3 = state.s35;
        
	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,xstart1,fmetrics.getHeight());
	
        g.setColor(Color.black);
	g.setFont(textfont2);
	fmetrics=g.getFontMetrics();
	stmp = "To cancel the imaginary part of the line";
	g.drawString(stmp,xstart1,ystart);
	
        ytest = state.BBs2;
        if(ytest > 0.0){
            stmp = "admittance we add a shunt capacitance:";
        }
        else if(ytest < 0.0){
            stmp = "admittance we add a shunt inductance:";
        }
        
        g.drawString(stmp,xstart1,ystart+fmetrics.getHeight());
        
        //----------------------------------------------------------------------
        
        if(ytest < 0.0){
                        double tempore = 0.0;
                        double temporal = 1.0/(2.0*Math.PI*state.frequency*Math.abs(ytest));
                        int xtempore = xstart3;
                        int ytempore = ystart+4*fmetrics.getHeight()+fmetrics.getHeight()/2;
	    
                        MaestroG.subsubsupSymbol2("Y","2"," = ( j "+omega+" L","2",")","-1",
                            "= - j "+MaestroA.rounder(Math.abs(ytest),5)," S   (actual)",
                            g,fonto,xtempore,ystart+3*fmetrics.getHeight());
			
			if(temporal < 1.0E-12 && temporal != 0.0){
			    tempore = temporal * 1.0E12;
			    MaestroG.subsup("L","2"," = "+MaestroA.rounder(tempore,5)+" x 10","-12","  H",g,fonto,xtempore, ytempore);
			}
		
			else if(temporal >= 1.0E-12 && temporal < 1.0E-9){
			    tempore = temporal * 1.0E12;
			    MaestroG.subsup("L","2"," = "+MaestroA.rounder(tempore,5)+" x 10","-12","  H",g,fonto,xtempore, ytempore);
			}
			else if(temporal >= 1.0E-9 && temporal < 1.0E-6){
			    tempore = temporal * 1.0E9;
			    MaestroG.subsup("L","2"," = "+MaestroA.rounder(tempore,5)+" x 10","-9","  H",g,fonto,xtempore, ytempore);
			}
			else if(temporal >= 1.0E-6 && temporal < 1.0E-3){
			    tempore = temporal * 1.0E6;
			    MaestroG.subsup("L","2"," = "+MaestroA.rounder(tempore,5)+" x 10","-6","  H",g,fonto,xtempore, ytempore);
			}
			else if(temporal >= 1.0E-3 && temporal < 1.0){
			    tempore = temporal * 1.0E3;
			    MaestroG.subsup("L","2"," = "+MaestroA.rounder(tempore,5)+" x 10","-3","  H",g,fonto,xtempore, ytempore);
			}
			else if(temporal >= 1.0 || temporal == 0.0){
			    tempore = temporal;
			    MaestroG.subsup("L","2"," = "+MaestroA.rounder(tempore,5)+"","","  H",g,fonto,xtempore, ytempore);
			}
	}
	else if(ytest > 0.0){
            
                        double tempore = 0.0;
			double temporal = ytest/(2.0*Math.PI*state.frequency);
			int xtempore = xstart3;
			int ytempore = ystart+4*fmetrics.getHeight()+fmetrics.getHeight()/2;
                        MaestroG.subsubsubSymbol2("Y","2"," = j "+omega+" C","2","","",
                            "= j "+MaestroA.rounder(ytest,5)," S   (actual)",
                            g,fonto,xtempore,ystart+3*fmetrics.getHeight());
			
			if(temporal < 1.0E-12 && temporal != 0.0){
			    tempore = temporal * 1.0E12;
			    MaestroG.subsup("C","2"," = "+MaestroA.rounder(tempore,5)+" x 10","-12","  F",g,fonto,xtempore, ytempore);
			}
		
			else if(temporal >= 1.0E-12 && temporal < 1.0E-9){
			    tempore = temporal * 1.0E12;
			    MaestroG.subsup("C","2"," = "+MaestroA.rounder(tempore,5)+" x 10","-12","  F",g,fonto,xtempore, ytempore);
			}
			else if(temporal >= 1.0E-9 && temporal < 1.0E-6){
			    tempore = temporal * 1.0E9;
			    MaestroG.subsup("C","2"," = "+MaestroA.rounder(tempore,5)+" x 10","-9","  F",g,fonto,xtempore, ytempore);
			}
			else if(temporal >= 1.0E-6 && temporal < 1.0E-3){
			    tempore = temporal * 1.0E6;
			    MaestroG.subsup("C","2"," = "+MaestroA.rounder(tempore,5)+" x 10","-6","  F",g,fonto,xtempore, ytempore);
			}
			else if(temporal >= 1.0E-3 && temporal < 1.0){
			    tempore = temporal * 1.0E3;
			    MaestroG.subsup("C","2"," = "+MaestroA.rounder(tempore,5)+" x 10","-3","  F",g,fonto,xtempore, ytempore);
			}
			else if(temporal >= 1.0 || temporal == 0.0){
			    tempore = temporal;
			    MaestroG.subsup("C","2"," = "+MaestroA.rounder(tempore,5)+"","","  F",g,fonto,xtempore, ytempore);
			}
	}
        
	//----------------------------------------------------------------------
        
	g.setColor(Color.black);
	//stmp = "Admittance: ";
	//g.drawString(stmp,15,ystart+4*fmetrics.getHeight()-fmetrics.getHeight()/4);
	g.setColor(Color.blue.darker());
	
    	if(ytest < 0.0){
	    
	    stmp = " = - j "+MaestroA.rounder(Math.abs(state.BBs2norm),5)+"           (normalized)";
	    MaestroG.subscripter("y","2",stmp,g,fonto,xstart3,ystart+6*fmetrics.getHeight()+fmetrics.getHeight()/2);    
	}
	else{
	    stmp = " = j "+MaestroA.rounder(Math.abs(state.BBs2norm),5)+"           (normalized)";
	    MaestroG.subscripter("y","2",stmp,g,fonto,xstart3,ystart+6*fmetrics.getHeight()+fmetrics.getHeight()/2);
	}
    }
    
    private void step9(Graphics g){
        
        int xstart1 = state.s25;
	int xstart2 = state.s60;
        int xstart3 = state.s35;
        
	String titulo = "SUMMARY";
	String stmp;
	double ytest;
	g.setColor(Color.red.darker());
	g.setFont(titlefont2);
	FontMetrics fmetrics=g.getFontMetrics();
	g.drawString(titulo,xstart1,fmetrics.getHeight());
	
	g.setFont(textfont2);
	fmetrics=g.getFontMetrics();
	
	int ystep = state.s45;
	int dystep = state.s5;
        int dystep2 = state.s8;
        int ddystep = state.s18;
	
	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("Shunt 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);
            }

            
      
      //------------------------------------------------------------------------      
            ytest = state.BBs1;
            if(ytest < 0.0){
	    
                g.setColor(Color.black);
                MaestroG.subscripter("Shunt Inductance:","","",g,sizefont,xpos0,ypos02);
            
                g.setColor(Color.blue.darker());
	    
			double tempore = 0.0;
			double temporal = 1.0/(2.0*Math.PI*state.frequency*Math.abs(ytest));
			int xtempore = xpos1;
			int ytempore = ypos2;
			
			if(temporal < 1.0E-12 && temporal != 0.0){
			    tempore = temporal * 1.0E12;
			    MaestroG.subsup("L","1"," = "+MaestroA.rounder(tempore,5)+" x 10","-12","  H",g,sizefont,xtempore, ytempore);
			}
		
			else if(temporal >= 1.0E-12 && temporal < 1.0E-9){
			    tempore = temporal * 1.0E12;
			    MaestroG.subsup("L","1"," = "+MaestroA.rounder(tempore,5)+" x 10","-12","  H",g,sizefont,xtempore, ytempore);
			}
			else if(temporal >= 1.0E-9 && temporal < 1.0E-6){
			    tempore = temporal * 1.0E9;
			    MaestroG.subsup("L","1"," = "+MaestroA.rounder(tempore,5)+" x 10","-9","  H",g,sizefont,xtempore, ytempore);
			}
			else if(temporal >= 1.0E-6 && temporal < 1.0E-3){
			    tempore = temporal * 1.0E6;
			    MaestroG.subsup("L","1"," = "+MaestroA.rounder(tempore,5)+" x 10","-6","  H",g,sizefont,xtempore, ytempore);
			}
			else if(temporal >= 1.0E-3 && temporal < 1.0){
			    tempore = temporal * 1.0E3;
			    MaestroG.subsup("L","1"," = "+MaestroA.rounder(tempore,5)+" x 10","-3","  H",g,sizefont,xtempore, ytempore);
			}
			else if(temporal >= 1.0 || temporal == 0.0){
			    tempore = temporal;
			    MaestroG.subsup("L","1"," = "+MaestroA.rounder(tempore,5)+"","","  H",g,sizefont,xtempore, ytempore);
			}
	}
	else if(ytest > 0.0){
                g.setColor(Color.black);
                MaestroG.subscripter("Shunt Capacitance:","","",g,sizefont,xpos0,ypos02);
            
                g.setColor(Color.blue.darker());
	    		
			double tempore = 0.0;
			double temporal = ytest/(2.0*Math.PI*state.frequency);
			int xtempore = xpos1;
			int ytempore = ypos2;
			
			if(temporal < 1.0E-12 && temporal != 0.0){
			    tempore = temporal * 1.0E12;
			    MaestroG.subsup("C","1"," = "+MaestroA.rounder(tempore,5)+" x 10","-12","  F",g,sizefont,xtempore, ytempore);
			}
		
			else if(temporal >= 1.0E-12 && temporal < 1.0E-9){
			    tempore = temporal * 1.0E12;
			    MaestroG.subsup("C","1"," = "+MaestroA.rounder(tempore,5)+" x 10","-12","  F",g,sizefont,xtempore, ytempore);
			}
			else if(temporal >= 1.0E-9 && temporal < 1.0E-6){
			    tempore = temporal * 1.0E9;
			    MaestroG.subsup("C","1"," = "+MaestroA.rounder(tempore,5)+" x 10","-9","  F",g,sizefont,xtempore, ytempore);
			}
			else if(temporal >= 1.0E-6 && temporal < 1.0E-3){
			    tempore = temporal * 1.0E6;
			    MaestroG.subsup("C","1"," = "+MaestroA.rounder(tempore,5)+" x 10","-6","  F",g,sizefont,xtempore, ytempore);
			}
			else if(temporal >= 1.0E-3 && temporal < 1.0){
			    tempore = temporal * 1.0E3;
			    MaestroG.subsup("C","1"," = "+MaestroA.rounder(tempore,5)+" x 10","-3","  F",g,sizefont,xtempore, ytempore);
			}
			else if(temporal >= 1.0 || temporal == 0.0){
			    tempore = temporal;
			    MaestroG.subsup("C","1"," = "+MaestroA.rounder(tempore,5)+"","","  F",g,sizefont,xtempore, ytempore);
			}
	}
        //----------------------------------------------------------------------
            
	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("Shunt 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);
            }
	
            
            //------------------------------------------------------------------------      
            ytest = state.BBs2;
            if(ytest < 0.0){
	    
                g.setColor(Color.black);
                MaestroG.subscripter("Shunt Inductance:","","",g,sizefont,xpos0,ypos04);
            
                g.setColor(Color.red.darker());
	    
			double tempore = 0.0;
			double temporal = 1.0/(2.0*Math.PI*state.frequency*Math.abs(ytest));
			int xtempore = xpos1;
			int ytempore = ypos4;
			
			if(temporal < 1.0E-12 && temporal != 0.0){
			    tempore = temporal * 1.0E12;
			    MaestroG.subsup("L","2"," = "+MaestroA.rounder(tempore,5)+" x 10","-12","  H",g,sizefont,xtempore, ytempore);
			}
		
			else if(temporal >= 1.0E-12 && temporal < 1.0E-9){
			    tempore = temporal * 1.0E12;
			    MaestroG.subsup("L","2"," = "+MaestroA.rounder(tempore,5)+" x 10","-12","  H",g,sizefont,xtempore, ytempore);
			}
			else if(temporal >= 1.0E-9 && temporal < 1.0E-6){
			    tempore = temporal * 1.0E9;
			    MaestroG.subsup("L","2"," = "+MaestroA.rounder(tempore,5)+" x 10","-9","  H",g,sizefont,xtempore, ytempore);
			}
			else if(temporal >= 1.0E-6 && temporal < 1.0E-3){
			    tempore = temporal * 1.0E6;
			    MaestroG.subsup("L","2"," = "+MaestroA.rounder(tempore,5)+" x 10","-6","  H",g,sizefont,xtempore, ytempore);
			}
			else if(temporal >= 1.0E-3 && temporal < 1.0){
			    tempore = temporal * 1.0E3;
			    MaestroG.subsup("L","2"," = "+MaestroA.rounder(tempore,5)+" x 10","-3","  H",g,sizefont,xtempore, ytempore);
			}
			else if(temporal >= 1.0 || temporal == 0.0){
			    tempore = temporal;
			    MaestroG.subsup("L","2"," = "+MaestroA.rounder(tempore,5)+"","","  H",g,sizefont,xtempore, ytempore);
			}
	}
	else if(ytest > 0.0){
                g.setColor(Color.black);
                MaestroG.subscripter("Shunt Capacitance:","","",g,sizefont,xpos0,ypos04);
            
                g.setColor(Color.red.darker());
	    		
			double tempore = 0.0;
			double temporal = ytest/(2.0*Math.PI*state.frequency);
			int xtempore = xpos1;
			int ytempore = ypos4;
			
			if(temporal < 1.0E-12 && temporal != 0.0){
			    tempore = temporal * 1.0E12;
			    MaestroG.subsup("C","2"," = "+MaestroA.rounder(tempore,5)+" x 10","-12","  F",g,sizefont,xtempore, ytempore);
			}
		
			else if(temporal >= 1.0E-12 && temporal < 1.0E-9){
			    tempore = temporal * 1.0E12;
			    MaestroG.subsup("C","2"," = "+MaestroA.rounder(tempore,5)+" x 10","-12","  F",g,sizefont,xtempore, ytempore);
			}
			else if(temporal >= 1.0E-9 && temporal < 1.0E-6){
			    tempore = temporal * 1.0E9;
			    MaestroG.subsup("C","2"," = "+MaestroA.rounder(tempore,5)+" x 10","-9","  F",g,sizefont,xtempore, ytempore);
			}
			else if(temporal >= 1.0E-6 && temporal < 1.0E-3){
			    tempore = temporal * 1.0E6;
			    MaestroG.subsup("C","2"," = "+MaestroA.rounder(tempore,5)+" x 10","-6","  F",g,sizefont,xtempore, ytempore);
			}
			else if(temporal >= 1.0E-3 && temporal < 1.0){
			    tempore = temporal * 1.0E3;
			    MaestroG.subsup("C","2"," = "+MaestroA.rounder(tempore,5)+" x 10","-3","  F",g,sizefont,xtempore, ytempore);
			}
			else if(temporal >= 1.0 || temporal == 0.0){
			    tempore = temporal;
			    MaestroG.subsup("C","2"," = "+MaestroA.rounder(tempore,5)+"","","  F",g,sizefont,xtempore, ytempore);
			}
	}
        //----------------------------------------------------------------------      
    }
}
