/*
 * NewGuideCanvas.java
 */
//import java.applet.*;
//import java.lang.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.net.*;
import java.awt.event.*;


public class NewGuideCanvas extends Canvas implements MouseListener{
    private static final Color bgcolor2 = new Color(255,255,250);
    private static final Color bgcolor = Color.white;
    //private static final Color bgcolor2 = Color.gray;
    private static final int LeftMargin=20, RightMargin=10, TopMargin=10, BottomMargin=10;
    private static final Font labfont = new Font("SanSerif",Font.PLAIN,10);
    private static final Font symbfont= new Font("Serif",Font.PLAIN,12);
    private static final Font symbfont2= new Font("Serif",Font.PLAIN,14);
    private static final Font labfont2= new Font("Serif",Font.BOLD,16);
    private static final Font labfont4= new Font("Serif",Font.PLAIN,12);
    private static final Font labfont3 = new Font("SanSerif",Font.PLAIN,12);
    private int x[], y[];
    private int N_elements;
    private double frequency, epsilon_r, epsilon_r0, mu_r, phase_velocity, phase_velocity0;
    private double DipoleLength_lambda, wavelength, radius_lambda;
    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 - simplified
    
    private Image im;
    private Graphics buf;
    private String stmp;
    private double temp;
    private boolean IsFocusOn, IsTopoOn;
    public boolean Is3D;
    
    public NewGuideCanvas(){
	super();
	IsFocusOn = false;
	IsTopoOn = false;
	N_elements = 2;
	setBackground(bgcolor);
	x = new int[5];
	y = new int[5];

	//Listeners
	this.addMouseListener(this);
	
	epsilon_r = 1.0;
	epsilon_r0 = 1.0;
	mu_r = 1.0;
	frequency = 1.0E9;
	DipoleLength_lambda = 0.5;
	radius_lambda = 1.0E-5;
	
	Is3D = true;
	
	wavelength = light_velocity/frequency/Math.sqrt(epsilon_r);
	
    }

    public void drawCanvas(Graphics g){
	
	setBackground(bgcolor2);
	g.clearRect(0,0,getSize().width,getSize().height);
	g.setColor(Color.black);
	
	    draw3D(g);
	    
    }
    
    
    private void drawWire(int x1, int y1, int x2, int y2, int mode, Graphics g){
        Graphics2D g2d = (Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
    
		//g.setColor(Color.white);
		g.setColor(Color.gray);
		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);
		}
    }

    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.setColor(Color.gray);
		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.setColor(Color.gray);
		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 draw3D(Graphics g){    
	Graphics2D g2d = (Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
    
	//Draw the background
		
		g.setColor(Color.black);
		//set the arrays
		x[0] = getSize().width/2;
		x[1] = x[0] -7;
		x[2] = getSize().width-50;
		
		y[0] = getSize().height-20;
		y[1] = getSize().height/2;

		g.clearRect(0,0,getSize().width-1,getSize().height-1);
		
                /*
                if(IsTopoOn){
		    if(!IsFocusOn){
			g.setColor(Color.blue);
			g.drawString("Click to show ",getSize().width*2/3+2,getSize().height*3/4);
			g.drawString("angles reference",getSize().width*2/3+2,getSize().height*3/4+11);
		    }
		    else{
			g.setColor(Color.red);
			g.drawString("Click to show ",getSize().width*2/3+2,getSize().height*3/4);
			g.drawString("dipole diagram",getSize().width*2/3+2,getSize().height*3/4+11);
			
		    }
		}
                 */
		
                //----------------------------------------------------------
		String lambda, rho;
		g.setFont(symbfont2);
		g.getFontMetrics();
		lambda="\u03bb";
		rho ="\u03c1";
		
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
		/*
                g.setColor(Color.blue);
		g.setFont(new Font("Serif",Font.ITALIC,15));
                g.getFontMetrics();
		g.drawString("d",x[0]+30,15);
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
		g.setFont(new Font("SanSerif",Font.PLAIN,12));
		g.getFontMetrics();
		g.drawString("   = "+MaestroA.rounder(DipoleLength_lambda,4)+"  "+lambda,x[0]+30,15);
		*/
                
	    if(IsFocusOn){
                // this is disabled here
	    }
	    else{	
		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
		//Arc for theta
		int xCenter = getSize().width/2;//x[0];
		int yCenter = y[1];
		int Radius = 15;
		int beginAngle = 90;
		int Angle = -120;
		int raio = 2*Radius;
		
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                
                // theta angle arc
                g.setColor(Color.cyan);
		g.fillArc(xCenter-Radius,yCenter-Radius,raio,raio,beginAngle,Angle);
		g.setColor(Color.black);
		g.drawArc(xCenter-Radius,yCenter-Radius,raio,raio,beginAngle,Angle);
		
                // theta angle symbol
                g.setColor(Color.blue);
		g.setFont(new Font("Serif",Font.ITALIC,15));
		g.drawString("\u03b8",x[0]+30,y[1]+14);
		g.setFont(new Font("SanSerif",Font.PLAIN,12));
		g.setColor(Color.black);
                
                int endpoint = 75;
                //draw paraboloid profile - just paint an arc
		g.setColor(Color.black);
		//g.drawArc(xCenter-25,yCenter-50,50,100,100,160);
		
                //drawArcThick(g, (double)(xCenter-endpoint/3), (double)(yCenter-endpoint), (double)(2*endpoint)*5.0/10.0, (double)(2*endpoint), 110.0, 140.0, 3, Color.lightGray);
                
                // phi angle symbol
		//g.setColor(Color.blue);
		//g.setFont(new Font("Serif",Font.PLAIN,15));
		//g.drawString("\u03c6",x[0]-14,y[1]+25);
		//g.setFont(new Font("SanSerif",Font.PLAIN,11));
		
		//draw axes
		g.setColor(Color.gray);
		g.drawLine(x[0],20,x[0],y[0]); 
		MaestroG.drawArrow(x[0],20,5,g);
		g.drawLine(x[0],y[1],x[0],y[1]+15);
		//g.drawString("x",x[0]-12,20);
		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                //MaestroG.subscripterSymbol3("r","a","",g,16,x[0]-20,20);
		
                // do it twice, due to smoothing 
		MaestroG.subscripter("0","","",g,14,x[1]-10,yCenter+5);
                MaestroG.subscripter("x","","",g,14,x[2]+10,y[1]-9);
                //MaestroG.subscripterSymbol3("a","","",g,14,x[1]-10,yCenter-endpoint+5);
                MaestroG.subscripter("0","","",g,14,x[1]-10,yCenter+5);
                MaestroG.subscripter("x","","",g,14,x[2]+10,y[1]-9);
                //MaestroG.subscripterSymbol3("a","","",g,14,x[1]-10,yCenter-endpoint+5);
                MaestroG.subscripter("z","","",g,14,x[0]-20,20);
                MaestroG.subscripter("z","","",g,14,x[0]-20,20);
                
                g.drawLine(x[1]+2,y[1],x[2]+10,y[1]);
		MaestroG.drawArrow(x[2]+10,y[1],7,g);
		//g.drawLine(x[1]+2,yCenter-endpoint,xCenter,yCenter-endpoint);  // tick mark
		
                /*
	    //draw antenna  ----------------------------------------------------
		//draw measurement arrows
		g.setColor(Color.gray);
		int xarrow = x[0]-70;
		
		g.drawLine(xarrow,y[1]-endpoint,xarrow,y[1]+endpoint);
		MaestroG.drawArrow(xarrow,y[1]-(endpoint-10),5,g);
		MaestroG.drawArrow(xarrow,y[1]+(endpoint-10),6,g);
		MaestroG.drawArrow(xarrow,y[1]-10,6,g);
		MaestroG.drawArrow(xarrow,y[1]+10,5,g);
		g.drawLine(xarrow-5,y[1],xarrow+5,y[1]);
		g.drawLine(xarrow-5,y[1]-endpoint,xarrow+5,y[1]-endpoint);
		g.drawLine(xarrow-5,y[1]+endpoint,xarrow+5,y[1]+endpoint);
		
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
		g.setColor(Color.blue);
		g.setFont(new Font("Serif",Font.ITALIC,15));
		g.drawString("d",xarrow+10,y[1]-endpoint/2);
		
                g.setFont(new Font("Serif",Font.PLAIN,12));
                g.drawString("__",xarrow+7,y[1]-endpoint/2);
		g.drawString("2",xarrow+10,y[1]-endpoint/2+13);
		//g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
                g.setFont(new Font("Serif",Font.ITALIC,15));
		g.drawString("d",xarrow+10,y[1]+endpoint/2);
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                g.setFont(new Font("Serif",Font.PLAIN,12));
		g.drawString("__",xarrow+7,y[1]+endpoint/2);
		g.drawString("2",xarrow+10,y[1]+endpoint/2+13);
		g.setFont(new Font("SanSerif",Font.PLAIN,12));
		*/
		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                g.setColor(Color.red);
		
                int xtip, ytip;
                xtip = x[0]+75;
                ytip = y[1]+45;
                
                //radial line to point P
		g.drawLine(x[0],y[1],xtip,ytip);
		
		//draw Field vectors
		g.setColor(Color.red);
		//E_theta
		g.drawLine(xtip,ytip,xtip-12,ytip+20);
		g.drawLine(xtip-12,ytip+20,xtip-10,ytip+10);
		g.drawLine(xtip-12,ytip+20,xtip-4,ytip+13);
		
		MaestroG.subscripterSymbol2("E","\u03b8","",g,14,xtip,ytip+20);
		
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
		//point P
		g.setColor(Color.green);
		MaestroG.fillCircle(xtip,ytip,6,g);
		g.setColor(Color.black);
		MaestroG.drawCircle(xtip,ytip,6,g);
                
                
                // draw array
                int xleft = 50;
                int yshift = 10;
                int xCenterN = xCenter - xleft;
                if(N_elements == 1){
                    g.setColor(Color.yellow);
                    MaestroG.fillCircle(xCenter, yCenter, 8, g);
                    g.setColor(Color.black);
                    MaestroG.drawCircle(xCenter, yCenter, 8, g);
                }
                else if(N_elements == 2){
                    g.setColor(Color.yellow);
                    MaestroG.fillCircle(xCenter, yCenter-16, 8, g);
                    MaestroG.fillCircle(xCenter, yCenter+16, 8, g);
                    g.setColor(Color.black);
                    MaestroG.drawCircle(xCenter, yCenter-16, 8, g);
                    MaestroG.drawCircle(xCenter, yCenter+16, 8, g);
                    
                    g.setColor(Color.gray);
                    g.drawLine(xCenterN, yCenter-16, xCenterN, yCenter+16);
                    MaestroG.drawArrow(xCenterN,yCenter-16+yshift,5,g);
                    MaestroG.drawArrow(xCenterN,yCenter+16-yshift,6,g);
                    
                    //end lines
                    g.drawLine(xCenterN-5,yCenter-16,xCenterN+5,yCenter-16);
                    g.drawLine(xCenterN-5,yCenter+16,xCenterN+5,yCenter+16);
                    
                    g.setColor(Color.black);
                    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                    MaestroG.subscripterSymbol2("d","","",g,14,xCenterN-15,yCenter+5);
                }
                else if(N_elements == 3){
                    g.setColor(Color.yellow);
                    MaestroG.fillCircle(xCenter, yCenter, 8, g);
                    MaestroG.fillCircle(xCenter, yCenter-32, 8, g);
                    MaestroG.fillCircle(xCenter, yCenter+32, 8, g);
                    g.setColor(Color.black);
                    MaestroG.drawCircle(xCenter, yCenter, 8, g);
                    MaestroG.drawCircle(xCenter, yCenter-32, 8, g);
                    MaestroG.drawCircle(xCenter, yCenter+32, 8, g);
                    
                    g.setColor(Color.gray);
                    g.drawLine(xCenter-xleft, yCenter-32, xCenter-xleft, yCenter+32);
                    MaestroG.drawArrow(xCenterN,yCenter+yshift,5,g);
                    MaestroG.drawArrow(xCenterN,yCenter-yshift,6,g);
                    MaestroG.drawArrow(xCenterN,yCenter-32+yshift,5,g);
                    MaestroG.drawArrow(xCenterN,yCenter+32-yshift,6,g);
                    // end lines
                    g.drawLine(xCenterN-5,yCenter,xCenterN+5,yCenter);
                    g.drawLine(xCenterN-5,yCenter-32,xCenterN+5,yCenter-32);
                    g.drawLine(xCenterN-5,yCenter+32,xCenterN+5,yCenter+32);
                    
                    g.setColor(Color.black);
                    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                    MaestroG.subscripterSymbol2("d","","",g,14,xCenterN-15,yCenter+5+16);
                    MaestroG.subscripterSymbol2("d","","",g,14,xCenterN-15,yCenter+5-16);
                }
                else if(N_elements == 4){
                    g.setColor(Color.yellow);
                    MaestroG.fillCircle(xCenter, yCenter-16, 8, g);
                    MaestroG.fillCircle(xCenter, yCenter+16, 8, g);
                    MaestroG.fillCircle(xCenter, yCenter-48, 8, g);
                    MaestroG.fillCircle(xCenter, yCenter+48, 8, g);
                    g.setColor(Color.black);
                    MaestroG.drawCircle(xCenter, yCenter-16, 8, g);
                    MaestroG.drawCircle(xCenter, yCenter+16, 8, g);
                    MaestroG.drawCircle(xCenter, yCenter-48, 8, g);
                    MaestroG.drawCircle(xCenter, yCenter+48, 8, g);
                    
                    g.setColor(Color.gray);
                    g.drawLine(xCenter-xleft, yCenter-48, xCenter-xleft, yCenter+48);
                    MaestroG.drawArrow(xCenterN,yCenter-16+yshift,5,g);
                    MaestroG.drawArrow(xCenterN,yCenter+16-yshift,6,g);
                    MaestroG.drawArrow(xCenterN,yCenter-16-yshift,6,g);
                    MaestroG.drawArrow(xCenterN,yCenter+16+yshift,5,g);
                    MaestroG.drawArrow(xCenterN,yCenter-48+yshift,5,g);
                    MaestroG.drawArrow(xCenterN,yCenter+48-yshift,6,g);
                    
                    // end lines
                    g.drawLine(xCenterN-5,yCenter-16,xCenterN+5,yCenter-16);
                    g.drawLine(xCenterN-5,yCenter+16,xCenterN+5,yCenter+16);
                    g.drawLine(xCenterN-5,yCenter-48,xCenterN+5,yCenter-48);
                    g.drawLine(xCenterN-5,yCenter+48,xCenterN+5,yCenter+48);
                    
                    g.setColor(Color.black);
                    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                    MaestroG.subscripterSymbol2("d","","",g,14,xCenterN-15,yCenter+5);
                    MaestroG.subscripterSymbol2("d","","",g,14,xCenterN-15,yCenter+5-32);
                    MaestroG.subscripterSymbol2("d","","",g,14,xCenterN-15,yCenter+5+32);
                }
                else if(N_elements == 5){
                    g.setColor(Color.yellow);
                    MaestroG.fillCircle(xCenter, yCenter, 8, g);
                    MaestroG.fillCircle(xCenter, yCenter-32, 8, g);
                    MaestroG.fillCircle(xCenter, yCenter+32, 8, g);
                    MaestroG.fillCircle(xCenter, yCenter-64, 8, g);
                    MaestroG.fillCircle(xCenter, yCenter+64, 8, g);
                    g.setColor(Color.black);
                    MaestroG.drawCircle(xCenter, yCenter, 8, g);
                    MaestroG.drawCircle(xCenter, yCenter-32, 8, g);
                    MaestroG.drawCircle(xCenter, yCenter+32, 8, g);
                    MaestroG.drawCircle(xCenter, yCenter-64, 8, g);
                    MaestroG.drawCircle(xCenter, yCenter+64, 8, g);
                    
                    g.setColor(Color.gray);
                    g.drawLine(xCenter-xleft, yCenter-64, xCenter-xleft, yCenter+64);
                    MaestroG.drawArrow(xCenterN,yCenter+yshift,5,g);
                    MaestroG.drawArrow(xCenterN,yCenter-yshift,6,g);
                    MaestroG.drawArrow(xCenterN,yCenter-32+yshift,5,g);
                    MaestroG.drawArrow(xCenterN,yCenter+32-yshift,6,g);
                    MaestroG.drawArrow(xCenterN,yCenter-32-yshift,6,g);
                    MaestroG.drawArrow(xCenterN,yCenter+32+yshift,5,g);
                    MaestroG.drawArrow(xCenterN,yCenter-64+yshift,5,g);
                    MaestroG.drawArrow(xCenterN,yCenter+64-yshift,6,g);
                    
                    
                    g.drawLine(xCenterN-5,yCenter,xCenterN+5,yCenter);
                    g.drawLine(xCenterN-5,yCenter-32,xCenterN+5,yCenter-32);
                    g.drawLine(xCenterN-5,yCenter+32,xCenterN+5,yCenter+32);
                    g.drawLine(xCenterN-5,yCenter-64,xCenterN+5,yCenter-64);
                    g.drawLine(xCenterN-5,yCenter+64,xCenterN+5,yCenter+64);
                    g.setColor(Color.black);
                    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                    MaestroG.subscripterSymbol2("d","","",g,14,xCenterN-15,yCenter+5+16);
                    MaestroG.subscripterSymbol2("d","","",g,14,xCenterN-15,yCenter+5-16);
                    MaestroG.subscripterSymbol2("d","","",g,14,xCenterN-15,yCenter+5+48);
                    MaestroG.subscripterSymbol2("d","","",g,14,xCenterN-15,yCenter+5-48);
                }
                else if(N_elements == 6){
                    g.setColor(Color.yellow);
                    MaestroG.fillCircle(xCenter, yCenter-16, 8, g);
                    MaestroG.fillCircle(xCenter, yCenter+16, 8, g);
                    MaestroG.fillCircle(xCenter, yCenter-48, 8, g);
                    MaestroG.fillCircle(xCenter, yCenter+48, 8, g);
                    MaestroG.fillCircle(xCenter, yCenter-80, 8, g);
                    MaestroG.fillCircle(xCenter, yCenter+80, 8, g);
                    g.setColor(Color.black);
                    MaestroG.drawCircle(xCenter, yCenter-16, 8, g);
                    MaestroG.drawCircle(xCenter, yCenter+16, 8, g);
                    MaestroG.drawCircle(xCenter, yCenter-48, 8, g);
                    MaestroG.drawCircle(xCenter, yCenter+48, 8, g);
                    MaestroG.drawCircle(xCenter, yCenter-80, 8, g);
                    MaestroG.drawCircle(xCenter, yCenter+80, 8, g);
                    
                    g.setColor(Color.gray);
                    g.drawLine(xCenter-xleft, yCenter-80, xCenter-xleft, yCenter+80);
                    MaestroG.drawArrow(xCenterN,yCenter-16+yshift,5,g);
                    MaestroG.drawArrow(xCenterN,yCenter+16-yshift,6,g);
                    MaestroG.drawArrow(xCenterN,yCenter-16-yshift,6,g);
                    MaestroG.drawArrow(xCenterN,yCenter+16+yshift,5,g);
                    MaestroG.drawArrow(xCenterN,yCenter-48+yshift,5,g);
                    MaestroG.drawArrow(xCenterN,yCenter+48-yshift,6,g);
                    MaestroG.drawArrow(xCenterN,yCenter-48-yshift,6,g);
                    MaestroG.drawArrow(xCenterN,yCenter+48+yshift,5,g);
                    MaestroG.drawArrow(xCenterN,yCenter-80+yshift,5,g);
                    MaestroG.drawArrow(xCenterN,yCenter+80-yshift,6,g);
                    
                    // end lines
                    g.drawLine(xCenterN-5,yCenter-16,xCenterN+5,yCenter-16);
                    g.drawLine(xCenterN-5,yCenter+16,xCenterN+5,yCenter+16);
                    g.drawLine(xCenterN-5,yCenter-48,xCenterN+5,yCenter-48);
                    g.drawLine(xCenterN-5,yCenter+48,xCenterN+5,yCenter+48);
                    g.drawLine(xCenterN-5,yCenter-80,xCenterN+5,yCenter-80);
                    g.drawLine(xCenterN-5,yCenter+80,xCenterN+5,yCenter+80);
                    
                    g.setColor(Color.black);
                    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                    MaestroG.subscripterSymbol2("d","","",g,14,xCenterN-15,yCenter+5);
                    MaestroG.subscripterSymbol2("d","","",g,14,xCenterN-15,yCenter+5-32);
                    MaestroG.subscripterSymbol2("d","","",g,14,xCenterN-15,yCenter+5+32);
                    MaestroG.subscripterSymbol2("d","","",g,14,xCenterN-15,yCenter+5-64);
                    MaestroG.subscripterSymbol2("d","","",g,14,xCenterN-15,yCenter+5+64);
                }

		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
        
	    }
    }
    
    private void drawArcThick(Graphics g, double xCenter, double yCenter, double Radius, double Radius2, double startangle, double endangle, int thick, Color color){
	
        Graphics2D g2d = (Graphics2D)g;
        g2d.setPaint(color);
        g2d.setStroke(new BasicStroke(thick));
        
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        Arc2D.Double arc_one = new Arc2D.Double(xCenter,yCenter,Radius,Radius2,startangle,endangle,0);
        g2d.draw(arc_one);
  
        g2d.setStroke(new BasicStroke(1));
        //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
}


    
    public synchronized void setFrequency(double frequency){
	this.frequency = frequency;
    }
    
    public synchronized void setEpsilon(double epsilon_r){
	this.epsilon_r = epsilon_r;
    }
    
    public synchronized void setEpsilon0(double epsilon_r0){
	this.epsilon_r0 = epsilon_r0;
    }
    
    public synchronized void setMu(double mu){
	this.mu_r = mu;
    }
    
    public synchronized void setElements(int N_elements){
	this.N_elements = N_elements;
    }
    
    public synchronized void set3D(boolean Is3D){
	this.Is3D = Is3D;
    }
    
    public synchronized void setAntennaLength(double DipoleLength_lambda){
	this.DipoleLength_lambda = DipoleLength_lambda;
    }
    
    public synchronized void setAntennaRadius(double radius_lambda){
	this.radius_lambda = radius_lambda;
    }
    
    @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);
    }
    
    
    @Override
    public void update(Graphics g){
	paint(g);
    }
    
    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){}
}
