//CircuitCanvas.java


import java.awt.*;
import java.awt.event.*;
//import Trans_State;
public class CircuitCanvas extends Panel implements MouseListener{
	private int x[], y[];
	private Trans_State state;
	private Image im;
	private Graphics buf;
	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 double light_velocity = 3.0E8; //  Units m/s - approximate value for texbook
        
        public boolean IsFocusOn; 
	public boolean SwitchIsOpen, IsStepOn;
	public CircuitCanvas(Trans_State state){
		super();
		this.state = state;
		setBackground(bgcolor);
		x = new int[5];
		y = new int[5];
		this.addMouseListener(this);
		IsFocusOn = false;
		SwitchIsOpen = true;
		IsStepOn = true;
	}

	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){
		
                //set the arrays
		x[0] = 20;
		x[4] = getSize().width-20;
		x[2] = x[0] + 125;
		x[3] = x[4] - 28;
		x[1] = (x[0]+x[2])/2;

		y[4] = 25;
		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;

		//drawGrid(x,y,g);

		//g.clearRect(x[0],y[4]-10,x[4]-x[0],y[0]-y[4]+20);
		g.clearRect(0,0,getSize().width-1,getSize().height-1);
		
                g.setColor(Color.black);
		g.drawRect(0,0,getSize().width-1,getSize().height-1);
                
		//Horizontal axis
		drawAxis(g);
		drawAxis(g);
		//Reference
		drawRef(g);
		drawRef(g);
		//Wires
		//drawWire(x[0],y[4],x[4],y[4],1,g);
		
		drawWire(x[0],y[4],x[2]-45,y[4],1,g);
		drawWire(x[2]-20,y[4],x[4],y[4],1,g);
		drawWire(x[0],y[0],x[4]+1,y[0],1,g);
		drawWire(x[0],y[4]+1,x[0],y[0]-1,2,g);
		
		//drawWire(x[4],y[4]+1,x[4],y[4]+35,2,g);
		//drawWire(x[4],y[0],x[4],y[0]-35,2,g);
		
		//Capacitor plates
		//drawWire(x[4]-10,y[4]+36,x[4]+10,y[4]+36,1,g);
		//drawWire(x[4]-10,y[0]-36,x[4]+10,y[0]-36,1,g);
		
		//Resistance leads
		drawWire(x[4],y[4]+1,x[4],y[4]+25,2,g);
		drawWire(x[4],y[0],x[4],y[0]-25,2,g);
		
		drawWire(x[4],y[0]-25,x[4]+5,y[0]-27,5,g);
		drawWire(x[4]-5,y[0]-32,x[4]+5,y[0]-27,5,g);
		drawWire(x[4]-5,y[0]-32,x[4]+5,y[0]-37,5,g);
		drawWire(x[4]-5,y[0]-42,x[4]+5,y[0]-37,5,g);
		drawWire(x[4]-5,y[0]-42,x[4]+5,y[0]-47,5,g);
		drawWire(x[4]-5,y[0]-52,x[4]+5,y[0]-47,5,g);
		drawWire(x[4]-5,y[0]-52,x[4],y[0]-54,5,g);
		
		//Switch
		//
		//System.out.println("In circuit   "+state.SwitchIsOpen);
		if(state.SwitchIsOpen){
		    g.setColor(Color.white);
		    g.drawLine(x[2]-38,y[4]-14,x[2]-33,y[4]-19);
		    g.drawLine(x[2]-37,y[4]-14,x[2]-33,y[4]-18);
		    g.drawLine(x[2]-36,y[4]-14,x[2]-33,y[4]-17);
		    g.drawLine(x[2]-35,y[4]-14,x[2]-33,y[4]-16);
		    g.drawLine(x[2]-34,y[4]-14,x[2]-33,y[4]-15);
		    g.drawLine(x[2]-33,y[4]-14,x[2]-33,y[4]-14);
		    
		    g.setColor(Color.black);
		    g.drawLine(x[2]-33,y[4]-19,x[2]-33,y[4]-19);
		    g.drawLine(x[2]-33,y[4]-18,x[2]-33,y[4]-18);
		    g.drawLine(x[2]-33,y[4]-17,x[2]-33,y[4]-17);
		    g.drawLine(x[2]-33,y[4]-16,x[2]-33,y[4]-16);
		    g.drawLine(x[2]-33,y[4]-15,x[2]-33,y[4]-15);
		    g.drawLine(x[2]-33,y[4]-14,x[2]-33,y[4]-14);
		    
		    drawWire(x[2]-45,y[4],x[2]-29,y[4]-16,1,g);//Open
		    drawWire(x[2]-44,y[4],x[2]-28,y[4]-16,1,g);//Open
		    
                    drawConnect(x[2]-18,y[4],g);
                    drawConnect(x[2]-45,y[4],g);
                    
		    //drawCircle(x[2]-18,y[4],2,Color.black,g);
		    //drawCircle(x[2]-45,y[4],2,Color.black,g);
		}
		else
		{		    
		    g.setColor(Color.white);
		    
		    g.drawLine(x[2]-21,y[4]-5,x[2]-29,y[4]-5);
		    g.drawLine(x[2]-22,y[4]-4,x[2]-28,y[4]-4);
		    g.drawLine(x[2]-23,y[4]-3,x[2]-27,y[4]-3);
		    g.drawLine(x[2]-24,y[4]-2,x[2]-26,y[4]-2);
		    g.drawLine(x[2]-25,y[4]-1,x[2]-25,y[4]-1);
		    
		    g.setColor(Color.black);
		    
		    g.drawLine(x[2]-21,y[4]-5,x[2]-21,y[4]-5);
		    g.drawLine(x[2]-22,y[4]-4,x[2]-22,y[4]-4);
		    g.drawLine(x[2]-23,y[4]-3,x[2]-23,y[4]-3);
		    g.drawLine(x[2]-24,y[4]-2,x[2]-24,y[4]-2);
		    g.drawLine(x[2]-25,y[4]-1,x[2]-25,y[4]-1);
		    
		    drawWire(x[2]-45,y[4],x[2]-20,y[4],1,g);//Closed
		    
                    drawConnect(x[2]-18,y[4],g);
                    drawConnect(x[2]-45,y[4],g);
                    
                    //drawCircle(x[2]-18,y[4],2,Color.black,g);
		    //drawCircle(x[2]-45,y[4],2,Color.black,g);
		}
		Graphics2D g2d = (Graphics2D)g;
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
		
		//RL
		g.setColor(Color.white);
		MaestroG.subscripter("R","L","",g,11,x[4]-23,y[2]);
		MaestroG.subscripter("R","L","",g,11,x[4]-23,y[2]);
		//Zg
		draw3DRect(x[1]-25,y[4],x[2]-x[0]-70,18,ccolor1,g);	
		g.setColor(Color.white);
		MaestroG.subscripter("R","g","",g,11,x[1]-30,y[4]+2);
		MaestroG.subscripter("R","g","",g,11,x[1]-30,y[4]+2);
                
		//Vg
                drawCircle(x[0],y[2],12,ccolor1,g);
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
		
		g.setColor(Color.white);
		MaestroG.subscripter("V","g","",g,11,x[0]-6,y[2]+1);
                MaestroG.subscripter("V","g","",g,11,x[0]-6,y[2]+1);
                
		//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
		if(IsFocusOn){drawStrings(g); drawStrings(g);}
		
		g.setFont(TheFonts.sanSerif12);
		if(IsStepOn){
		    g.setColor(Color.black);
		    g.drawLine(x[0]+50,y[0]-20,x[0]+100,y[0]-20);
		    g.drawLine(x[0]+50,y[0]-17,x[0]+50,y[0]-55);
		    MaestroG.drawArrow(x[0]+50,y[0]-55,5,g);
		    MaestroG.drawArrow(x[0]+100,y[0]-20,7,g);
		    
                
                    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
		
		    g.setColor(Color.white);
		    g.drawString("t",x[0]+107,y[0]-6);
		    g.drawString("0",x[0]+47,y[0]-6);
		    MaestroG.subscripter("V","gmax","",g,12,x[0]+70,y[0]-57);
                    g.drawString("t",x[0]+107,y[0]-6);
		    g.drawString("0",x[0]+47,y[0]-6);
		    MaestroG.subscripter("V","gmax","",g,12,x[0]+70,y[0]-57);

    		    g.drawLine(x[0]+30,y[0]-20,x[0]+50,y[0]-20);
		    g.drawLine(x[0]+50,y[0]-20,x[0]+50,y[0]-50);
		    g.drawLine(x[0]+50,y[0]-50,x[0]+90,y[0]-50);
		}
		else{
		    
                    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
		
                    g.setColor(Color.yellow);
		    //g.drawLine(x[0]+80,y[0]-17,x[0]+80,y[0]-50);
		    //MaestroG.subscripter("t","p","",g,12,x[0]+77,y[0]-6);
		    //MaestroG.subscripter("t","p","",g,12,x[0]+77,y[0]-6);
                    MaestroG.subscripterSerIT("\u03c4","","",g,18,x[0]+77,y[0]-6);
                    MaestroG.subscripterSerIT("\u03c4","","",g,18,x[0]+77,y[0]-6);
                    g.setFont(TheFonts.sanSerif12);
		    
                    g.setColor(Color.black);
		    g.drawLine(x[0]+50,y[0]-20,x[0]+100,y[0]-20);
		    g.drawLine(x[0]+50,y[0]-17,x[0]+50,y[0]-55);
		    MaestroG.drawArrow(x[0]+50,y[0]-55,5,g);
		    MaestroG.drawArrow(x[0]+100,y[0]-20,7,g);
		
                    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
		
		    g.setColor(Color.white);
		    g.drawString("t",x[0]+107,y[0]-6);
		    g.drawString("0",x[0]+47,y[0]-6);
		    MaestroG.subscripter("V","gmax","",g,12,x[0]+70,y[0]-57);
		    g.drawString("t",x[0]+107,y[0]-6);
		    g.drawString("0",x[0]+47,y[0]-6);
		    MaestroG.subscripter("V","gmax","",g,12,x[0]+70,y[0]-57);
		    
		    g.drawLine(x[0]+30,y[0]-20,x[0]+50,y[0]-20);
		    g.drawLine(x[0]+50,y[0]-20,x[0]+50,y[0]-50);
		    g.drawLine(x[0]+50,y[0]-50,x[0]+80,y[0]-50);
		    g.drawLine(x[0]+80,y[0]-50,x[0]+80,y[0]-20);
		    g.drawLine(x[0]+80,y[0]-20,x[0]+100,y[0]-20);
		    
		    
		}
		
	}

	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);	
	}

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

                g2d.setPaint(Color.black);
                g.fillOval(x-tmp1/2,y-tmp1/2,tmp1,tmp1);
                g2d.setPaint(Color.white);
                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){
		
		if(mode==1){
			g.setColor(Color.white);
			g.drawLine(x1,y1,x2,y2);
			g.setColor(Color.black);
			g.drawLine(x1,y1+1,x2,y2+1);
		}
		else if(mode==2){
			g.setColor(Color.white);
			g.drawLine(x1,y1,x2,y2);
			g.setColor(Color.black);
			g.drawLine(x1+1,y1,x2+1,y2);
		}
		else if(mode==3){
			g.setColor(Color.black);
			g.drawLine(x1,y1,x2,y2);
			//g.setColor(Color.white);
			g.drawLine(x1,y1+1,x2,y2+1);
		}
                else if(mode==5){
			Graphics2D g2d = (Graphics2D)g;
                        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                        g.setColor(Color.white);
			g.drawLine(x1,y1,x2,y2);
                        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);       
		}
	}


	public void drawRef(Graphics g){
	    double testlength = (state.lineLength - state.xpos)/1000;
	    double testlength2 = (state.lineLength - state.xpos)/1000/0.0254;
	    double testprint = state.lineLength - state.xpos;
	    int xc;
	    int yc = 15;
	    int dx = 50;
	    g.setFont(TheFonts.sanSerif12);
	    FontMetrics fm = g.getFontMetrics();
	    int tx1, ty1, tx2, ty2;
		
	    tx1 = (int)(x[3] - (state.xpos/state.lineLength)*(x[3]-x[2]));
	    ty1 = y[4]-5;
	    tx2 = tx1;
	    ty2 = y[0]+5;
	    
	    if(state.xpos <=state.lineLength && state.xpos >= 0.0){
		if((tx1-x[2]) > 5){
                    g.setColor(Color.lightGray);
                    //g.drawLine(tx1,ty1,tx2,ty2);
                    g.drawLine(tx1,ty1+9,tx2,ty1+19);
                }
                
		g.setColor(Color.green);
		g.drawLine(tx1,ty1-10,tx2,ty1);
		g.drawLine(tx1,ty2+10,tx2,ty2);
		
		MaestroG.drawArrow(tx1,ty1-7,6,g);
		MaestroG.drawArrow(tx1,ty2+7,5,g);
                
                g.drawLine(x[2],y[4]+9,tx1,y[4]+9); 
                g.drawLine(x[2],y[4]+11,x[2],y[4]+7);
                if((tx1-x[2]) > 10){
                    MaestroG.drawArrow(tx1-9,y[4]+9,7,g);
                }
                
                MaestroG.subscripter("0","","",g,10,x[2]-3,y[4]+22);
	    }	    
	        
		Graphics2D g2d = (Graphics2D)g;
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
		
	    if(state.Is_Millimeter){
		
		if(state.xpos>(state.lineLength/2.0)){
		    xc = tx1+35;
		}
		else{
		    xc = tx1 - 120;
		}
		
		//MaestroG.subscripterSerIT("l","","- d",g,14,xc-25,yc);
                MaestroG.subscripterSerIT("","","z",g,14,xc-15,yc);
                
		if(testlength == 0.0){
		    g.drawString("= 0.0",xc,yc);	
		    g.drawString(" [ mm ]",xc+10+fm.stringWidth("= 0.0"),yc);
		}
	    
		else if(testlength < 1.0E-9 && testlength > 0.0){
		    g.drawString("= "+MaestroA.rounder(testprint*1.0e6,8),xc,yc);	
		    g.drawString(" [ nm ]",xc+10+fm.stringWidth("= "+MaestroA.rounder(testprint*1.0e6,8)),yc);
		}
		else if(testlength < 1.0E-6 && testlength >= 1.0E-9){
		    g.drawString("= "+MaestroA.rounder(testprint*1.0e6,5),xc,yc);	
		    g.drawString(" [ nm ]",xc+10+fm.stringWidth("= "+MaestroA.rounder(testprint*1.0e6,4)),yc);
		}
		else if(testlength < 1.0E-3 && testlength >= 1.0E-6){
		    g.drawString("= "+MaestroA.rounder(testprint*1.0e3,5),xc,yc);	
		    g.drawString(" [ \u00b5m ]",xc+10+fm.stringWidth("= "+MaestroA.rounder(testprint*1.0e3,4)),yc);
		}
		else if(testlength < 1.0 && testlength >= 1.0E-3){
		    g.drawString("= "+MaestroA.rounder(testprint,4),xc,yc);	
		    g.drawString(" [ mm ]",xc+10+fm.stringWidth("= "+MaestroA.rounder(testprint,4)),yc);
		}
		else if((testlength < 1000.0 && testlength >= 1.0 ) || testlength == 0.0){
		    g.drawString("= "+MaestroA.rounder(testprint/1000,6),xc,yc);	
		    g.drawString(" [ m ]",xc+10+fm.stringWidth("= "+MaestroA.rounder(testprint/1000,6)),yc);
		}
		else if(testlength >= 1000.0 && testlength < 1.0E6){
		    g.drawString("= "+MaestroA.rounder(testprint/1.0e6,4),xc,yc);	
		    g.drawString(" [ km ]",xc+10+fm.stringWidth("= "+MaestroA.rounder(testprint/1.0e6,4)),yc);
		}
		else if(testlength >= 1.0E6 && testlength < 1.0E9){
		    g.drawString("= "+MaestroA.rounder(testprint/1.0E9,4),xc,yc);	
		    g.drawString(" [ Mm ]",xc+10+fm.stringWidth("= "+MaestroA.rounder(testprint/1.0E9,4)),yc);
		}
		else if(testlength >= 1.0E9){
		    g.drawString("= "+MaestroA.rounder(testprint/1.0E12,4),xc,yc);	
		    g.drawString(" [ Gm ]",xc+10+fm.stringWidth("= "+MaestroA.rounder(testprint/1.0E12,4)),yc);
		}   
	    }
	    else{
		dx = 65;
		
		if(state.xpos>(state.lineLength/2.0)){
		    xc = tx1+35;
		}
		else{
		    xc = tx1 - 140;
		}
		
		//MaestroG.subscripter("x","C","",g,12,xc-15,yc);
                //MaestroG.subscripterSerIT("l","","- d",g,14,xc-25,yc);
		/*
		if(testlength == 0.0){
		    g.drawString("= 0.0",xc,yc);	
		    g.drawString("  [ mils ]",xc+10+fm.stringWidth("= 0.0"),yc);
		}
	        
		else if(testlength2 < 1.0E-9 && testlength2 > 0.0){
		    g.drawString("= "+MaestroA.rounder(testprint/0.0254*1.0e6,8),xc,yc);	
		    MaestroG.superscripter("[ 10","-6"," mils ]",g,12,xc+10+fm.stringWidth("= "+MaestroA.rounder(testprint/0.0254*1.0e6,8)),yc);
		}
		else if(testlength2 < 1.0E-6 && testlength2 >= 1.0E-9){
		    g.drawString("= "+MaestroA.rounder(testprint/0.0254*1.0e6,5),xc,yc);	
		    MaestroG.superscripter("[ 10","-6"," mils ]",g,12,xc+10+fm.stringWidth("= "+MaestroA.rounder(testprint/0.0254*1.0e6,5)),yc);
		}
		else if(testlength2 < 1.0E-3 && testlength2 >= 1.0E-6){
		    g.drawString("= "+MaestroA.rounder(testprint/0.0254*1.0e3,5),xc,yc);	
		    MaestroG.superscripter("[ 10","-3"," mils ]",g,12,xc+10+fm.stringWidth("= "+MaestroA.rounder(testprint/0.0254*1.0e3,5)),yc);
		}
		else if(testlength2 < 1.0 && testlength2 >= 1.0E-3){
		    g.drawString("= "+MaestroA.rounder(testprint/0.0254,5),xc,yc);	
		    g.drawString("  [ mils ]",xc+10+fm.stringWidth("= "+MaestroA.rounder(testprint/0.0254,4)),yc);
		}
		else if((testlength2 < 1000.0 && testlength2 >= 1.0 ) || testlength == 0.0){
		    g.drawString("= "+MaestroA.rounder(testprint/0.0254/1000,4),xc,yc);	
		    MaestroG.superscripter("[ 10","3"," mils ]",g,12,xc+10+fm.stringWidth("= "+MaestroA.rounder(testprint/0.0254/1000,4)),yc);
		}
		else if(testlength2 >= 1000.0 && testlength2 < 1.0E6){
		    g.drawString("= "+MaestroA.rounder(testprint/0.0254/1.0e6,5),xc,yc);	
		    MaestroG.superscripter("[ 10","6"," mils ]",g,12,xc+10+fm.stringWidth("= "+MaestroA.rounder(testprint/0.0254/1.0e6,4)),yc);
		}
		else if(testlength2 >= 1.0E6 && testlength2 < 1.0E9){
		    g.drawString("= "+MaestroA.rounder(testprint/0.0254/1.0E9,4),xc,yc);	
		    MaestroG.superscripter("[ 10","9"," mils ]",g,12,xc+10+fm.stringWidth("= "+MaestroA.rounder(testprint/0.0254/1.0E9,4)),yc);
		}
		else if(testlength2 >= 1.0E9){
		    g.drawString("= "+MaestroA.rounder(testprint/0.0254/1.0E12,4),xc,yc);	
		    MaestroG.superscripter("[ 10","12"," mils ]",g,12,xc+10+fm.stringWidth("= "+MaestroA.rounder(testprint/0.0254/1.0E12,4)),yc);
		} 
                 */  
	    }
	}	

	
	private void drawAxis(Graphics g){
		int ytmp;
		FontMetrics fm;
		ytmp=y[0] + 15;
		g.setColor(Color.black);
		g.drawLine(x[4],ytmp,x[0]+90,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[2]-30,ytmp,8,g);
                MaestroG.drawArrow(x[4],ytmp,7,g);
		g.setFont(TheFonts.sanSerif12);
                fm = g.getFontMetrics();
		
                Graphics2D g2d = (Graphics2D)g;
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
		
                g.setColor(Color.white);
		//g.drawString("0",x[3]-3,ytmp+fm.getHeight()+2);
                //MaestroG.subscripterSerIT("l","","",g,16,x[2]+2,ytmp+fm.getHeight());
		
                g.drawString("0",x[2]-3,ytmp+fm.getHeight());
                MaestroG.subscripterSerIT("l","","",g,16,x[3]+2,ytmp+fm.getHeight()+2);
		
		g.setFont(TheFonts.sanSerif12);
		//g.drawString("d",x[2]-40,ytmp+fm.getHeight());
		g.drawString("z",x[4],ytmp+fm.getHeight());
		
                //draw middle tick mark on length axis
		g.setColor(Color.black);
		g.drawLine((x[3]+x[2])/2,ytmp-4,(x[3]+x[2])/2,ytmp+4);
	}
	
	private void drawStrings(Graphics g){
		g.setColor(Color.white);
		g.setFont(TheFonts.sanSerif12);
		FontMetrics fm = g.getFontMetrics();
		
                Graphics2D g2d = (Graphics2D)g;
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
		
		//MaestroG.subscripter("Z","0"," = "+state.lineZ0+" \u03a9",g,12,x[2]+105,y[1]-30);
                MaestroG.subscripter("Z","0"," = "+state.lineZ0+"",g,12,x[2]+131,y[1]-10);
		g.setFont(TheFonts.serif12);
		g.drawString("\u03a9",x[2]+135+fm.stringWidth("Z0 = "+state.lineZ0),y[1]-10);
		g.setFont(TheFonts.sanSerif12);          
                
		MaestroG.subscripter("  ","r"," = "+state.epsilon_r,g,12,x[2]+131,y[1]+10);
		g.setFont(TheFonts.serif14);
		g.drawString("\u03b5",x[2]+131,y[1]+10);
		g.setFont(TheFonts.sanSerif12);
			    
		MaestroG.subscripter("V","gmax"," = "+MaestroA.rounder(state.Vg,4)+" V",g,12,x[0],y[0]+15);
		//g.drawString("V",x[0]+45,y[0]+15);
		
		MaestroG.subscripter("","",""+MaestroA.rounder(state.Rg,4),g,12,x[0]+10,13);
		g.setFont(TheFonts.serif12);
		g.drawString("\u03a9",x[0]+15+fm.stringWidth(""+MaestroA.rounder(state.Rg,4)),13);
		
                String tempo;
		
                tempo = new String("l = "+MaestroA.rounder(state.lineLength,6));
		MaestroG.subscripterSerIT2("l = ","",""+MaestroA.rounder(state.lineLength,6)+" mm",g,16,x[2]+133,getSize().height-5);
		
                // g.setFont(TheFonts.sanSerif12);
		
		//g.drawString("mm",x[2]+140+fm.stringWidth(tempo),getSize().height-5);
		g.setFont(TheFonts.sanSerif12);
		//g.drawString("  = "+	MaestroA.rounder(state.lineLength/0.0254,2)
		  //  +" mils",x[2]+164+fm.stringWidth(tempo),getSize().height-5);
		
	
	    if(Complex.Real(state.ZL)==0.0&&Complex.Imaginary(state.ZL)==0.0){ 
		MaestroG.subscripter("R","L","  = 0",g,12,x[2]+300,y[1]+10);
		g.setFont(TheFonts.serif12);
		g.drawString("    \u03a9",x[2]+340,y[1]+10);
		g.setFont(TheFonts.sanSerif10);
		g.drawString("( Short Circuit )",x[2]+300, y[1]+33);
	    }
	    else if(Complex.Real(state.YL)==0.0&&Complex.Imaginary(state.YL)==0.0){ 
		MaestroG.subscripter("R","L","  = ",g,12,x[2]+300,y[1]+10);
		
		g.setFont(TheFonts.serif12);
		g.drawString("\u221e   \u03a9",x[2]+340,y[1]+10);
		g.setFont(TheFonts.sanSerif10);
		g.drawString("( Open Circuit )",x[2]+300, y[1]+33);		
	    }
	    else{
		MaestroG.subscripter("R","L","  = "+state.Resistance+"",g,12,x[2]+300,y[1]+10);
		g.setFont(TheFonts.serif12);
		g.drawString("\u03a9",x[2]+340+fm.stringWidth(""+state.Resistance),y[1]+10);
	    }
	    
	    //Reflection coefficients
		g.setColor(Color.white);
		MaestroG.subscripter("  ","L"," = "+MaestroA.rounder(state.GammaLoad,4),g,12,x[2]+341,y[4]+30);
		MaestroG.subscripter("  ","g"," = "+MaestroA.rounder(state.GammaInput,4),g,12,x[2]+21,y[4]+30);
		g.setFont(TheFonts.serif12);
		g.drawString("\u0393",x[2]+341,y[4]+30);
		g.drawString("\u0393",x[2]+21,y[4]+30);
		g.setFont(TheFonts.sanSerif12);
		
		g.drawLine(x[2]+341,y[4]+39,x[2]+401,y[4]+39);
		g.drawLine(x[2]+21,y[4]+39,x[2]+81,y[4]+39);
		MaestroG.drawArrow(x[2]+341,y[4]+39,8,g);
		MaestroG.drawArrow(x[2]+81,y[4]+39,7,g);
		
		
	}
	public synchronized void SetSwitch(boolean SwitchIsOpen){
	    this.SwitchIsOpen = SwitchIsOpen;
	}
	
	public synchronized void setStep(boolean IsStepOn){
	    this.IsStepOn = IsStepOn;
	}
    
	
	public void mouseClicked(MouseEvent evt){
	
	}
	public void mouseEntered(MouseEvent evt){
	    //IsFocusOn = true;
	    //repaint();
	}
	public void mouseExited(MouseEvent evt){
	    //IsFocusOn = false;
	    //repaint();
    	}
	public void mousePressed(MouseEvent evt){
	
	}
	public void mouseReleased(MouseEvent evt){
	
	}
	
    
}//End of CircuitCanvs

