//CircuitCanvas.java
/* A Java class for
 * LossyWide.java
 * Electromagnetic Transmission Line Applet
 * Applet without Smith Chart - Prepared by Umberto Ravaioli 
 * for 6th edition of Fundamentals of Applied Electromagnetics Book
 * May 2009 - All Rights Reserved
 */ 
import java.awt.*;
import java.awt.event.*;

//import Trans_State;
public class CircuitCanvas extends Canvas implements MouseListener{
    private static final boolean doubleGreenColorStuff = false;

	private int x[], y[];
	private Trans_State state;
	private Image im;
	private Graphics buf;
	private static final Font labfont = new Font("SanSerif",Font.BOLD,10);
	private static final Color bgcolor = Color.gray;
	private static final Color ccolor1 = new Color(50,204,153);
	private static final double epsilon0 = 8.8541878176E-12; // Units: F/m
	private static final double mu0 = 1.25663706144E-6; //      Units H/m
	private static final double light_velocity = Math.sqrt(1.0/(epsilon0*mu0)); //  Units m/s
	
    //private static final Font normalfont = new Font("SanSerif",Font.PLAIN,12);
    //private static final Font normalfont11 = new Font("SanSerif",Font.PLAIN,11);
    //private static final Font subfont    = new Font("SanSerif",Font.PLAIN,10);
    //private static final Font symbolfont=new Font("Serif",Font.PLAIN,14);
    public static  Font normalfont;
    public static  Font normalfont11;
    public static  Font subfont;
    public static  Font symbolfont;
	private static String alpha, Ohm, lambda, infinity, Gamma, epsilon;
	
	private boolean IsFocusOn, IsTopoOn;
	public CircuitCanvas(Trans_State state){
		super();
		this.state = state;
		setBackground(bgcolor);
		x = new int[5];
		y = new int[5];
		this.addMouseListener(this);
		IsFocusOn = false;
	}

	public void update(Graphics g){
		paint(g);
	}

	public void paint(Graphics g){
		if(im == null){
			im = createImage(getSize().width,getSize().height);
			buf = im.getGraphics();
			drawCircuit(buf);
		}
		else{
			drawCircuit(buf);
		}
		g.drawImage(im,0,0,null);
	}
	
	public void drawCircuit(Graphics g){
            
                Graphics2D g2d = (Graphics2D)g;
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                
		//set the arrays
		x[0] = 20;
		x[4] = getSize().width-20;
		x[2] = x[0] + 50;
		x[3] = x[4] - 20;
		x[1] = (x[0]+x[2])/2;

		y[4] = 30;
		y[0] = getSize().height-35;
		y[2] = (y[4]+y[0])/2;
		y[3] = (y[4]+y[2])/2;
		y[1] = (y[0]+y[2])/2;
		
		
		g.clearRect(0,0,getSize().width-1,getSize().height-1);
		g.setColor(Color.black);
                g.drawRect(0,0,getSize().width-1,getSize().height-1);
                
		//Reference
		drawRef(g);
		
		//Wires
		drawWire(x[0],y[4],x[4],y[4],1,g);
		drawWire(x[0],y[0],x[4],y[0],1,g);
		drawWire(x[0],y[4]+1,x[0],y[0]-2,2,g);
		drawWire(x[4],y[4]+1,x[4],y[0]-1,2,g);

		//Horizontal axis
		drawAxis(g);
		
		//ZL
		draw3DRect(x[4],y[2],18,y[1]-y[3],ccolor1,g);
		g.setColor(Color.black);
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
		MaestroG.subscripter("Z","L","",g,11,x[4]-7,y[2]+2);
		//Zg
		draw3DRect(x[1],y[4],x[2]-x[0]-20,18,ccolor1,g);	
		g.setColor(Color.black);
		
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                MaestroG.subscripter("Z","g","",g,11,x[1]-5,y[4]+2);
		//Vg
		
                //Graphics2D g2d = (Graphics2D)g;
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                drawCircle(x[0],y[2],12,ccolor1,g);
                //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
		g.setColor(Color.black);
		MaestroG.subscripter("V","g","",g,11,x[0]-6,y[2]+1);
		//g.setFont(new Font("SanSerif",Font.BOLD,16));
		//g.drawString("~",x[0]-5,y[2]+5);
		

		//Connections
		drawConnect(x[2],y[4],g);
		drawConnect(x[2],y[0],g);
		drawConnect(x[3],y[4],g);
		drawConnect(x[3],y[0],g);

		//Draw parameter strings
		drawStrings(g);
                // Smoothing washes out white fonts on dark background
                // print again to reinforce
                drawStrings(g);
		/*
		if(IsFocusOn){drawStrings(g);
		    if(IsTopoOn){
			g.setFont(labfont);
			g.setColor(Color.white);
			//g.fillRect(getSize().width-80,2,75,22);
			//g.setColor(Color.red);
						
			//g.drawString("Click to hide",getSize().width-75,11);
			//g.drawString("details",getSize().width-75,21);
		    }
		}
		else{
		    if(IsTopoOn){
			g.setFont(labfont);
			g.setColor(Color.white);
			//g.fillRect(getSize().width-80,2,75,22);
			
			//g.setColor(Color.blue);
			//g.drawString("Click to show",getSize().width-75,11);
			//g.drawString("details",getSize().width-75,21);
		    }
		}
		*/
		
	}

	private void drawGrid(int [] x,int [] y,Graphics g){
		g.setColor(Color.yellow);
		for(int i = 0 ; i< 5; i++){
			g.drawLine(x[0],y[i],x[4],y[i]);
			g.drawLine(x[i],y[0],x[i],y[4]);
		}
	}


	private void draw3DRect(int x, int y, int width, int height, Color c, Graphics g){
		g.setColor(c);
		g.fillRect(x-width/2,y-height/2,width,height);
		g.setColor(Color.white);
		g.drawLine(x-width/2,y-height/2,x+width/2,y-height/2);
		g.drawLine(x-width/2,y-height/2,x-width/2,y+height/2);
		g.setColor(Color.black);
		g.drawLine(x-width/2,y+height/2,x+width/2,y+height/2);
		g.drawLine(x+width/2,y-height/2,x+width/2,y+height/2);
	}
	
	private void drawRect(int x, int y, int width, int height, Color c, Graphics g){
		g.setColor(c);
		g.fillRect(x-width/2,y-height/2,width,height);
	}
	

	private void drawCircle(int x, int y, int radius, Color c, Graphics g){
		g.setColor(c);
		g.fillOval(x-radius,y-radius,2*radius,2*radius);
		g.setColor(Color.white);
		g.drawOval(x-radius,y-radius,2*radius,2*radius);
		g.setColor(Color.black);
		g.drawArc(x-radius-1,y-radius-1,2*radius+2,2*radius+2,30,-120);
		/*
		g.setColor(c.brighter());
		g.drawArc(x-radius,y-radius,2*radius,2*radius,60,120);
		*/
	}

	private void drawConnect(int x, int y, Graphics g){
		int tmp1, tmp2;
		tmp1 = 7;
		tmp2 = 5;
		//drawRect(x,y,tmp1,tmp1,Color.white,g);
		//drawRect(x,y,tmp2,tmp2,Color.black,g);
                
                Graphics2D g2d = (Graphics2D)g;
               
                g2d.setStroke(new BasicStroke(1));
        
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
                g2d.setPaint(Color.white);
                g.fillOval(x-tmp1/2,y-tmp1/2,tmp1,tmp1);
                g2d.setPaint(Color.black);
                g.fillOval(x-tmp2/2,y-tmp2/2,tmp2,tmp2);
	
                g2d.setStroke(new BasicStroke(1));
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
	}

	private void drawWire(int x1, int y1, int x2, int y2, int mode, Graphics g){
		g.setColor(Color.white);
		g.drawLine(x1,y1,x2,y2);
		if(mode==1){
			g.setColor(Color.black);
			g.drawLine(x1,y1+1,x2,y2+1);
		}
		else if(mode==2){
			g.setColor(Color.black);
			g.drawLine(x1+1,y1,x2+1,y2);
		}
	}

	

	public void drawRef(Graphics g){
	  if(state.xpos <=state.lineLength && state.xpos >= 0.0){
		int tx1, ty1a, ty1b, tx2, ty2a, ty2b;
		tx1 = (int)(x[3] - (state.xpos/state.lineLength)*(x[3]-x[2]));
		//System.out.println(" Circuit - xpos"+state.xpos+" linelength  "+state.lineLength);
		ty1a = y[4]-5;
		ty2a = y[4]+15;
		tx2 = tx1;
		ty1b = y[0]-15;
		ty2b = y[0]+5;
		
		g.setColor(Color.black);
		g.drawLine(tx1+1,ty1a,tx2+1,ty2a);
		MaestroG.drawArrow(tx1+1,ty2a-5,5,g);
		g.drawLine(tx1+1,ty1b,tx2+1,ty2b);
		MaestroG.drawArrow(tx1+1,ty1b+5,6,g);
		
		g.setColor(Color.green);
		g.drawLine(tx1,ty1a,tx2,ty2a);
		MaestroG.drawArrow(tx1,ty2a-5,5,g);
		g.drawLine(tx1,ty1b,tx2,ty2b);
		MaestroG.drawArrow(tx1,ty1b+5,6,g);
		
		
          }
	}	
	
	private void drawAxis(Graphics g){
		int ytmp;
		FontMetrics fm;
		ytmp=y[0] + 15;
		g.setColor(Color.black);
		g.drawLine(x[4],ytmp,x[0],ytmp);
		g.drawLine(x[2],ytmp-4,x[2],ytmp+4);
		g.drawLine(x[3],ytmp-4,x[3],ytmp+4);
		//Arrowhead
		MaestroG.drawArrow(x[0],ytmp,8,g);
		g.setFont(new Font("SanSerif",Font.PLAIN,11));
		fm = g.getFontMetrics();
		g.setColor(Color.white);
		//g.drawString("d",x[2]-2,ytmp+fm.getHeight()+2);
		g.drawString("d = 0",x[3]-10,ytmp+fm.getHeight()+2);
		g.setFont(new Font("SanSerif",Font.PLAIN,12));
		//g.drawString("d",15,ytmp+fm.getHeight()+2);
		
	}
	
	private void drawStrings(Graphics g){ 
		int xd, yd, dx;
		
                Graphics2D g2d = (Graphics2D)g;
                
                
		g.setColor(Color.white);
		FontMetrics fm = g.getFontMetrics();
		
		g.setFont(symbolfont);
		alpha="\u03b1";
		lambda="\u03bb";
		Ohm="\u03a9";
		infinity="\u221e";
		Gamma="\uu0393"; 
		epsilon="\u03b5";
		g.setFont(normalfont);
                fm = g.getFontMetrics();
		
	    xd = getSize().width/3+1;
	    yd = 20;
	    dx = 35;
	
	    double testlength = state.xpos*state.wavelength;
	    int range = 7;
	    if(state.lineLength < 1.0){
		range = 7;
	    }
	    else if(state.lineLength >= 1.0 && state.lineLength < 10.0){
		range = 6;
	    }
	    else if(state.lineLength >= 10.0 && state.lineLength < 100.0){
		range = 5;
	    }
	    else if(state.lineLength >= 100.0 && state.lineLength < 1000.0){
		range = 4;
	    }
	    else if(state.lineLength >= 1000.0 && state.lineLength < 10000.0){
		range = 3;
	    }
	    else if(state.lineLength >= 10000.0 && state.lineLength < 100000.0){
		range = 2;
	    }
	    else if(state.lineLength >= 100000.0){
		range = 1;
	    }
	    
            
            if (doubleGreenColorStuff) {

            // No smoothing for green fonts of gray background
            g.setColor(Color.black);
            
          //if(state.xpos == 0.0){
            //MaestroG.subscripterSymMiddle2("z   = "+MaestroA.rounder(state.xpos,range)+" ","","",lambda,"  = "+MaestroA.rounder(state.xpos*state.wavelength,6)+" m",g,11,xd+dx,yd);	
          //}
          //else
          {  
            if(testlength < 1.0E-9 && testlength > 0.0){
		MaestroG.subscripterSymMiddle2("d  = "+MaestroA.rounder(state.xpos,range),"","",lambda,"  = "+MaestroA.rounder(state.xpos*state.wavelength*1.0e9,8)+" nm",g,11,xd+dx,yd);	
            }
	    else if(testlength < 1.0E-6 && testlength >= 1.0E-9){
		MaestroG.subscripterSymMiddle2("d  = "+MaestroA.rounder(state.xpos,range),"","",lambda,"  = "+MaestroA.rounder(state.xpos*state.wavelength*1.0e9,4)+" nm",g,11,xd+dx,yd);	
            }
	    else if(testlength < 1.0E-3 && testlength >= 1.0E-6){
		MaestroG.subscripterSymMiddle2("d  = "+MaestroA.rounder(state.xpos,range),"","",lambda,"  = "+MaestroA.rounder(state.xpos*state.wavelength*1.0e6,4)+" \u00b5m",g,11,xd+dx,yd);	
	    }
	    else if(testlength < 1.0 && testlength >= 1.0E-3){
		MaestroG.subscripterSymMiddle2("d  = "+MaestroA.rounder(state.xpos,range),"","",lambda,"  = "+MaestroA.rounder(state.xpos*state.wavelength*1000.0,4)+" mm",g,11,xd+dx,yd);
            }
	    else if((testlength < 1000.0 && testlength >= 1.0 ) || testlength == 0.0){
		MaestroG.subscripterSymMiddle2("d  = "+MaestroA.rounder(state.xpos,range),"","",lambda,"  = "+MaestroA.rounder(state.xpos*state.wavelength,6)+" m",g,11,xd+dx,yd);	
            }
	    else if(testlength >= 1000.0 && testlength < 1.0E6){
		MaestroG.subscripterSymMiddle2("d  = "+MaestroA.rounder(state.xpos,range),"","",lambda,"  = "+MaestroA.rounder(state.xpos*state.wavelength/1.0e3,4)+" km",g,11,xd+dx,yd);	
            }
	    else if(testlength >= 1.0E6 && testlength < 1.0E9){
		MaestroG.superscripterSymFirst("d  = "+MaestroA.rounder(state.xpos,range),lambda,"  = "+MaestroA.rounder(state.xpos*state.wavelength/1.0e6,4)+" x 10","3"," km",g,11,xd+dx,yd);	
            }
	    else if(testlength >= 1.0E9){
		MaestroG.superscripterSymFirst("d  = "+MaestroA.rounder(state.xpos,range),lambda,"  = "+MaestroA.rounder(state.xpos*state.wavelength/1.0e9,4)+" x 10","6"," km",g,11,xd+dx,yd);
            }
          }


            }  // end of if doubleGreenColorStuff
	    yd-=1;
	    xd = getSize().width/3;
	    //Repaint to avoid color to be too fuzzy on dark background after smoothing
            g.setColor(Color.green);
	  
          //if(state.xpos == 0.0){
            //  MaestroG.subscripterSymMiddle2("z   = "+MaestroA.rounder(state.xpos,range)+" ","","",lambda,"  = "+MaestroA.rounder(state.xpos*state.wavelength,6)+" m",g,11,xd+dx,yd);	  
          //}
          //else
            {
                
	    if(testlength < 1.0E-9 && testlength > 0.0){
		MaestroG.subscripterSymMiddle2("d  = "+MaestroA.rounder(state.xpos,range),"","",lambda,"  = "+MaestroA.rounder(state.xpos*state.wavelength*1.0e9,8)+" nm",g,11,xd+dx,yd);	
            }
	    else if(testlength < 1.0E-6 && testlength >= 1.0E-9){
		MaestroG.subscripterSymMiddle2("d  = "+MaestroA.rounder(state.xpos,range),"","",lambda,"  = "+MaestroA.rounder(state.xpos*state.wavelength*1.0e9,4)+" nm",g,11,xd+dx,yd);	
            }
	    else if(testlength < 1.0E-3 && testlength >= 1.0E-6){
		MaestroG.subscripterSymMiddle2("d  = "+MaestroA.rounder(state.xpos,range),"","",lambda,"  = "+MaestroA.rounder(state.xpos*state.wavelength*1.0e6,4)+" \u00b5m",g,11,xd+dx,yd);	
	    }
	    else if(testlength < 1.0 && testlength >= 1.0E-3){
		MaestroG.subscripterSymMiddle2("d  = "+MaestroA.rounder(state.xpos,range),"","",lambda,"  = "+MaestroA.rounder(state.xpos*state.wavelength*1000.0,4)+" mm",g,11,xd+dx,yd);
            }
	    else if((testlength < 1000.0 && testlength >= 1.0 ) || testlength == 0.0){
		MaestroG.subscripterSymMiddle2("d  = "+MaestroA.rounder(state.xpos,range),"","",lambda,"  = "+MaestroA.rounder(state.xpos*state.wavelength,6)+" m",g,11,xd+dx,yd);	
            }
	    else if(testlength >= 1000.0 && testlength < 1.0E6){
		MaestroG.subscripterSymMiddle2("d  = "+MaestroA.rounder(state.xpos,range),"","",lambda,"  = "+MaestroA.rounder(state.xpos*state.wavelength/1.0e3,4)+" km",g,11,xd+dx,yd);	
            }
	    else if(testlength >= 1.0E6 && testlength < 1.0E9){
		MaestroG.superscripterSymFirst("d  = "+MaestroA.rounder(state.xpos,range),lambda,"  = "+MaestroA.rounder(state.xpos*state.wavelength/1.0e6,4)+" x 10","3"," km",g,11,xd+dx,yd);	
            }
	    else if(testlength >= 1.0E9){
		MaestroG.superscripterSymFirst("d  = "+MaestroA.rounder(state.xpos,range),lambda,"  = "+MaestroA.rounder(state.xpos*state.wavelength/1.0e9,4)+" x 10","6"," km",g,11,xd+dx,yd);
            }
          }
            
            //smoothing
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
	    g.setColor(Color.white);
		
		int xZ0 = getSize().width/3+dx;
		int yZ0 = y[2]-10;//getSize().height*20/100+30;
		MaestroG.subscripterSymMiddle2("Z","0"," = "+state.Z0.toString(Complex.CARTESIAN,3)+"   ",Ohm,"",g,12,xZ0,yZ0);
				
		int xeps = getSize().width/3+dx;
		int yeps = yZ0+25;
		// epsilon
		MaestroG.subscripterSymFirst2(epsilon,"r"," = "+MaestroA.rounder(state.epsilon_r,4),g,12,xeps+3,yeps);
		
                g.setFont(normalfont);
                fm = g.getFontMetrics();
		
		//frequency
		//int x0 = x[2]+35;
		//int y0 = 20;
                int x0 = 2*getSize().width/3;
                int y0 = y[2]-10;
		
                double f_normalized;
		double frequency = state.frequency;
	
		if(frequency < 1.0E3){
		    f_normalized = frequency;
		    g.drawString("    =  "+MaestroA.rounder(f_normalized,6)+"  Hz",x0,y0);	
		}
		else if(frequency < 1.0E6 && frequency >= 1.0E3  ){
		    f_normalized = frequency/1.0E3;
		    g.drawString("    =  "+MaestroA.rounder(f_normalized,6)+"  kHz",x0,y0);	
		}
		else if(frequency < 1.0E9 && frequency >= 1.0E6 ){
		    f_normalized = frequency/1.0E6;
		    g.drawString("    =  "+MaestroA.rounder(f_normalized,6)+"  MHz",x0,y0);	
		}
		else if(frequency < 1.0E12 && frequency >= 1.0E9 ){
		    f_normalized = frequency/1.0E9;
		    g.drawString("    =  "+MaestroA.rounder(f_normalized,6)+"  GHz",x0,y0);	
		}
		else if(frequency < 1.0E15 && frequency >=1.0E12 ){
		    f_normalized = frequency/1.0E12;
		    g.drawString("   =  "+MaestroA.rounder(f_normalized,6)+"  THz",x0,y0);	
		}
		else{
		    f_normalized = frequency/1.0E12;
		    g.drawString("    =  "+MaestroA.rounder(f_normalized,6)+"  THz",x0,y0);
		}
		
		//MaestroG.subscripterIT("f","o","",g,12,x0-2,y0);
		MaestroG.subscripterIT("f","","",g,12,x0-2,y0);  // NEW
                
                int ylambda = y0+25;
                
                MaestroG.subscripterSanSym2("","","",""+lambda,g,12,x0-5,ylambda);
            
	    testlength = state.wavelength;
	        g.setFont(normalfont);
                fm = g.getFontMetrics();
		
	    if(testlength < 1.0E-9 && testlength > 0.0){
		g.drawString("    = "+MaestroA.rounder(state.wavelength*1.0e9,8)+"  nm",x0,ylambda);	
	    }
	    else if(testlength < 1.0E-6 && testlength >= 1.0E-9){
		g.drawString("    = "+MaestroA.rounder(state.wavelength*1.0e9,4)+"  nm",x0,ylambda);	
	    }
	    else if(testlength < 1.0E-3 && testlength >= 1.0E-6){
		g.drawString("    = "+MaestroA.rounder(state.wavelength*1.0e6,4)+"  \u00b5m",x0,ylambda);	
	    }
	    else if(testlength < 1.0 && testlength >= 1.0E-3){
		g.drawString("    = "+MaestroA.rounder(state.wavelength*1000,4)+"  mm",x0,ylambda);	
	    }
	    else if((testlength < 1000.0 && testlength >= 1.0 ) || testlength == 0.0){
		g.drawString("    = "+MaestroA.rounder(state.wavelength,6)+"  m",x0,ylambda);	
	    }
	    else if(testlength >= 1000.0 && testlength < 1.0E6){
		g.drawString("    = "+MaestroA.rounder(state.wavelength/1000.0,4)+"  km",x0,ylambda);	
	    }
	    else if(testlength >= 1.0E6 && testlength < 1.0E9){
		//g.drawString("    = "+MaestroA.rounder(state.wavelength/1.0E6,4)+"   [ Mm ]",x+dxxxx,y);	
                MaestroG.superscripter("    = "+MaestroA.rounder(state.wavelength/1.0E6,4)+" x 10","3"," km",g,12,x0,ylambda);
	    }
	    else if(testlength >= 1.0E9){
		//g.drawString("    = "+MaestroA.rounder(state.wavelength/1.0E9,4)+"   [ Gm ]",x+dxxxx,y);	
                MaestroG.superscripter("= "+MaestroA.rounder(state.wavelength/1.0E9,4)+" x 10","6"," km",g,12,x0,ylambda);
	    }
		
		
		// generator
		MaestroG.subscripterWavy("V","g"," = "+state.generator.getVg().toString()+"  V",g,12,x[2]+5,y[2]+13);
		//MaestroG.subscripter("Z","g"," = "+state.generator.getZg().toString()+"  [ "+Ohm+" ]",g,12,x[2]+5,y[2]-10+6);
		MaestroG.subscripterSymMiddle2("Z","g"," = "+state.generator.getZg().toString()+"   ",Ohm,"",g,12,x[2]+5,y[2]-10);
		
                String tempo;
		// line length
		tempo = new String("  d =  "+MaestroA.rounder(state.lineLength,6)+" "+lambda);
		MaestroG.subscripterSymMiddle2("  d =  "+MaestroA.rounder(state.lineLength,6)+" ","","",lambda,"",g,11,x[2]-10,getSize().height-3);	
           
		testlength=state.lineLength*state.wavelength;
		g.setFont(normalfont11);
                fm = g.getFontMetrics();
		
                if(testlength < 1.0E-9 && testlength >0.0 ){
		    g.drawString("=  "+	MaestroA.rounder(state.lineLength*state.wavelength*1.0E9,8)
			+" nm",x[2]-2+fm.stringWidth(tempo),getSize().height-3);
		}
		else if(testlength < 1.0E-6 && testlength >= 1.0E-9 ){
		    g.drawString("=  "+	MaestroA.rounder(state.lineLength*state.wavelength*1.0E9,4)
			+" nm",x[2]-2+fm.stringWidth(tempo),getSize().height-3);
		}
		else if(testlength < 1.0E-3 && testlength >= 1.0E-6 ){
		    g.drawString("=  "+	MaestroA.rounder(state.lineLength*state.wavelength*1.0E6,4)
			+" \u00b5m",x[2]-2+fm.stringWidth(tempo),getSize().height-3);
		}
		else if(testlength < 1.0 && testlength >= 1.0E-3 ){
		    g.drawString("=  "+	MaestroA.rounder(state.lineLength*state.wavelength*1000,4)
			+" mm",x[2]-2+fm.stringWidth(tempo),getSize().height-3);
		}
		else if((testlength < 1000.0 && testlength >= 1.0 ) || testlength == 0.0){
		    g.drawString("=  "+	MaestroA.rounder(state.lineLength*state.wavelength,6)
			+" m",x[2]-2+fm.stringWidth(tempo),getSize().height-3);
		}
		else if(testlength < 1.0E6 && testlength >=1.0E3){
		    g.drawString("=  "+	MaestroA.rounder(state.lineLength*state.wavelength/1000,4)
			+" km",x[2]-2+fm.stringWidth(tempo),getSize().height-3);
		}
		else if(testlength < 1.0E9 && testlength >=1.0E6){
		    MaestroG.superscripter("=  "+MaestroA.rounder(state.lineLength*state.wavelength/1.0E6,4)+" x 10","3"," km",g,11,x[2]-2+fm.stringWidth(tempo),getSize().height-3);
                }
		else if(testlength >=1.0E9){
		    MaestroG.superscripter("=  "+MaestroA.rounder(state.lineLength*state.wavelength/1.0E9,4)+" x 10","6"," km",g,11,x[2]-2+fm.stringWidth(tempo),getSize().height-3);
		}
		
		// load
		int xZL = getSize().width*75/100;
		int yZL = y[4]-10;
		
		if(Complex.Real(state.YL)==0.0&&Complex.Imaginary(state.YL)==0.0){ 
		
                    MaestroG.subscripterInfinityThree("Z","L"," =  ","", "     (Open Circuit)",g,12,xZL+5,yZL);
	        }
		else if(Complex.Real(state.ZL)==0.0&&Complex.Imaginary(state.ZL)==0.0){ 
		MaestroG.subscripter("Z","L"," = 0    ( Short Circuit )",g,12,xZL+5,yZL);
		}
		else{
		
                MaestroG.subscripterSymMiddle2("Z","L"," = "+state.ZL.toString(Complex.CARTESIAN,3)+"   ",Ohm,"",g,12,xZL+5,yZL);
		
		}

	}
	
	public void mouseClicked(MouseEvent evt){
	    if(IsFocusOn){
		IsFocusOn = false;
		repaint();
	    }
	
	    else{
		IsFocusOn = true;
		repaint();
	    }
    
	}
    
	public void mouseEntered(MouseEvent evt){
	    IsTopoOn = true;
	    repaint();
	}
	public void mouseExited(MouseEvent evt){
	    IsTopoOn = false;
	    repaint();
	}
	public void mousePressed(MouseEvent evt){}
	public void mouseReleased(MouseEvent evt){}
    
}//End of CircuitCanvs

