//GraphCanvas.java

import java.awt.*;
import java.util.*;
//import java.lang.*;

public class GraphCanvasD extends Canvas{
    protected static final Color bgcolor = Color.lightGray;
    protected Image im;
    protected Graphics buf;
    protected final int LeftMargin = 40;
    protected final int TopSep = 40;
    protected final int BottomSep = 40;
    protected final int RightMargin = 40;
    protected int VPos=0;
    protected String XLabel, YLabel, TITLE;
    protected String X1, X2, X3;
    protected String Y1, Y2, Y3;
    protected int NumPoints;
    protected double x[];
    protected double y[];
    protected double phi_angle;
    protected double ymin, ymax;
    protected double xmin, xmax;
    protected int xx[];
    protected int yy[];
    protected int flag;
    protected int type;
    protected int NAntenna;
    protected boolean IsParabolic, PutOne, PutMore;
    protected double xRef;
    protected boolean Should_Plot_Zero_Line;
    protected boolean Should_Plot_Ref_Point;
    protected boolean IsYRangeMinSet, IsYRangeMaxSet;
    protected boolean IsXRangeMinSet, IsXRangeMaxSet;
    protected boolean IsPolar, is_theta_plane;
    protected static final Font font1 = new Font("Serif",Font.PLAIN,12);
    protected static final Font font2 = new Font("SanSerif",Font.PLAIN,11);
    
    public GraphCanvasD(){
	super();
	setBackground(bgcolor);
	XLabel="x-axis";
	YLabel="y-axis";
	TITLE ="Unknown Title";
	Y1 = " ";
	Y2 = " ";
	Y3 = " ";
	X1 = " ";
	X2 = " ";
	X3 = " ";
        NAntenna = 2;
        IsParabolic =false;
        PutOne = false;
        PutMore = false;
	NumPoints = 361;
	x = new double[NumPoints];
	y = new double[NumPoints];
	xx = new int[NumPoints];
	yy = new int[NumPoints];
	for(int i=0;i<NumPoints;i++){
	    x[i]=i;
	    y[i]=0.0;
	}
	IsYRangeMinSet=false;
	IsYRangeMaxSet=false;
	IsXRangeMinSet=false;
	IsXRangeMaxSet=false;
	IsPolar = false;
	is_theta_plane = true;
	
	xRef = 0.0;
	phi_angle = 45;
	type = 1;
	
	Should_Plot_Zero_Line = false;
	Should_Plot_Ref_Point = false;
    }
    
    @Override
    public void paint(Graphics g){
    
    if(im == null){
	im = createImage(getSize().width,getSize().height);
	buf = im.getGraphics();
	if(!IsPolar){
	    drawGraph(buf);
	}
	else{
	    drawGraph2(buf);
	}
    }
    if(!IsPolar){
	drawGraph(buf);
    }
    else{
	    drawGraph2(buf);
    }
    g.drawImage(im,0,0,null);
}
/*  
public void paint(Graphics g){
    
    if(im == null){
	im = createImage(getSize().width,getSize().height);
	buf = im.getGraphics();
	if(!IsPolar){
	    drawGraph(buf);
	}
    }
    if(!IsPolar){
	drawGraph(buf);
    }
    g.drawImage(im,0,0,null);
}
*/
public void drawGraph2(Graphics g){
	g.clearRect(0,0,getSize().width,getSize().height);
	//g.draw3DRect(0,0,getSize().width-1,getSize().height-1,false);
	
		int i;
		double theta;
		double geom;
		int rwidth = 296;
		int rheight = 296;
		double phi;
		phi = (double)((int)phi_angle);
		
		g.setColor(Color.lightGray);
		
		g.fill3DRect(0,0,rwidth-1,rheight-1,true);
		Graphics2D g2d = (Graphics2D)g;
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                
		g.setColor(Color.blue);
		if(type == 1){MaestroG.subscripterSymbol("F","","(\u03b8)",g,14,getSize().width-50,20);}
		if(type == 2){MaestroG.subscripter2("F","e","(\u03b8)",g,14,getSize().width-50,20);}
		if(type == 3){MaestroG.subscripter2("F","a","(\u03b8)",g,14,getSize().width-50,20);}
		if(type == 4){MaestroG.subscripter2("| E","y"," |",g,14,20,20);}
		if(type == 5){MaestroG.subscripter2("| E","z"," |",g,14,20,20);}
		if(type == 6){MaestroG.subscripterSymbol("| H","\u03c6"," |",g,14,20,20);}
		if(type == 7){MaestroG.subscripter2("| H","x"," |",g,14,20,20);}
		if(type == 8){MaestroG.subscripter2("| H","y"," |",g,14,20,20);}
    
		g.setColor(Color.white);
		//draw concentric circles
		g.drawOval((int)(rwidth*0.4),(int)(rwidth*0.4),(int)(rwidth*0.20),(int)(rwidth*0.20));
		g.drawOval((int)(rwidth*0.3),(int)(rwidth*0.3),(int)(rwidth*0.40),(int)(rwidth*0.40));
		g.drawOval((int)(rwidth*0.2),(int)(rwidth*0.2),(int)(rwidth*0.60),(int)(rwidth*0.60));
		g.drawOval((int)(rwidth*0.1),(int)(rwidth*0.1),(int)(rwidth*0.80),(int)(rwidth*0.80));
                
                //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
    
		//draw radial lines
		g.drawLine((int)(rwidth*0.1),(int)(rwidth*0.5),(int)(rwidth*0.9),(int)(rwidth*0.5));
		g.drawLine((int)(rwidth*0.5),(int)(rwidth*0.1),(int)(rwidth*0.5),(int)(rwidth*0.9));
		g.drawLine( (int)(rwidth*(0.5+0.4*(0.866))), (int)(rwidth*(0.5+0.4*(0.5))), 
                            (int)(rwidth*(0.5-0.4*(0.866))), (int)(rwidth*(0.5-0.4*(0.5))));
		g.drawLine( (int)(rwidth*(0.5-0.4*(0.866))), (int)(rwidth*(0.5+0.4*(0.5))), 
                            (int)(rwidth*(0.5+0.4*(0.866))), (int)(rwidth*(0.5-0.4*(0.5))));
		g.drawLine( (int)(rwidth*(0.5+0.4*(0.5))), (int)(rwidth*(0.5+0.4*(0.866))), 
                            (int)(rwidth*(0.5-0.4*(0.5))), (int)(rwidth*(0.5-0.4*(0.866))));
		g.drawLine( (int)(rwidth*(0.5-0.4*(0.5))), (int)(rwidth*(0.5+0.4*(0.866))), 
                            (int)(rwidth*(0.5+0.4*(0.5))), (int)(rwidth*(0.5-0.4*(0.866))));
		
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
    
		g.setColor(Color.black);
		//write the angles
		if(is_theta_plane==true)
		{	g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                        g.setColor(Color.red);
			g.setFont(new Font("Serif",Font.PLAIN,18));
			g.drawString("\u03b8",20,getSize().height-25);
			
			//g.setColor(Color.blue);
			//g.setFont(new Font("Serif",Font.PLAIN,13));
			//g.drawString("\u03c6 = "+(int)(phi)+"\u00ba",rwidth-50,20);
			
			g.setColor(Color.black);
			g.setFont(new Font("Sanserif",Font.PLAIN,11));
			g.drawString("0\u00ba",(int)(rwidth*  (0.5-0.42*(0.030))-2),(int)(rwidth*(0.5+0.42*(-1.00))));
			g.drawString("30\u00ba",(int)(rwidth* (0.5+0.42*(0.500))),(int)(rwidth*(0.5+0.44*(-0.866))));
			g.drawString("-30\u00ba",(int)(rwidth* (0.5-0.44*(0.500))-8),(int)(rwidth*(0.5+0.44*(-0.866))));
			g.drawString("60\u00ba",(int)(rwidth* (0.5+0.42*(0.866))),(int)(rwidth*(0.5+0.44*(-0.47))));
			g.drawString("-60\u00ba",(int)(rwidth* (0.5-0.44*(1.0))),(int)(rwidth*(0.5+0.44*(-0.47))));
			g.drawString("90\u00ba",(int)(rwidth* (0.5+0.42*(1.000))),(int)(rwidth*(0.5+0.42*(0.05))));
			g.drawString("-90\u00ba",(int)(rwidth* (0.5-0.46*(1.055))),(int)(rwidth*(0.5+0.45*(0.05))));
			g.drawString("120\u00ba",(int)(rwidth*(0.5+0.43*(0.866))),(int)(rwidth*(0.5+0.48*(0.50))));
			g.drawString("-120\u00ba",(int)(rwidth*(0.5-0.48*(0.95))),(int)(rwidth*(0.5+0.48*(0.50))));
			g.drawString("150\u00ba",(int)(rwidth*(0.5+0.42*(0.450))),(int)(rwidth*(0.5+0.47*(0.866))));
			g.drawString("-150\u00ba",(int)(rwidth*(0.5-0.47*(0.550))),(int)(rwidth*(0.5+0.47*(0.866))));
			g.drawString("180\u00ba",(int)(rwidth*(0.5-0.42*(0.070))+2),(int)(rwidth*(0.5+0.44*(1.05))));
                        
                        
		}
		else{   g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                        g.setColor(Color.red);
			g.setFont(new Font("Serif",Font.PLAIN,18));
			g.drawString("\u03c6",20,getSize().height-25);
			
			//g.setColor(Color.blue);
			//g.setFont(new Font("Serif",Font.PLAIN,13));
			//g.drawString("\u03b8 = 90\u00ba",rwidth-45,20);
			
			g.setFont(new Font("Sanserif",Font.PLAIN,11));
			g.setColor(Color.black);
			g.drawString("180\u00ba",(int)(rwidth*  (0.5-0.42*(0.050))),(int)(rwidth*(0.5+0.42*(-1.00))));
			g.drawString("150\u00ba",(int)(rwidth* (0.5+0.42*(0.4500))),(int)(rwidth*(0.5+0.42*(-0.866))));
			g.drawString("210\u00ba",(int)(rwidth* (0.5-0.47*(0.550))),(int)(rwidth*(0.5+0.44*(-0.866))));
			g.drawString("120\u00ba",(int)(rwidth* (0.5+0.42*(0.866))),(int)(rwidth*(0.5+0.42*(-0.50))));
			g.drawString("240\u00ba",(int)(rwidth* (0.5-0.44*(1.0))),(int)(rwidth*(0.5+0.44*(-0.47))));
			g.drawString("90\u00ba",(int)(3+rwidth* (0.5+0.41*(1.000))),(int)(rwidth*(0.5+0.42*(0.05))));
			g.drawString("270\u00ba",(int)(rwidth* (0.5-0.45*(1.10))),(int)(rwidth*(0.5+0.45*(0.05))));
			g.drawString("60\u00ba",(int)(rwidth*(0.5+0.43*(0.866))),(int)(rwidth*(0.5+0.48*(0.50))));
			g.drawString("300\u00ba",5+(int)(rwidth* (0.5-0.44*(1.0))),(int)(rwidth*(0.5+0.48*(0.50))));
			g.drawString("30\u00ba",(int)(rwidth*(0.5+0.42*(0.450))),(int)(rwidth*(0.5+0.47*(0.866))));
			g.drawString("330\u00ba",(int)(rwidth*(0.5-0.47*(0.550))),(int)(rwidth*(0.5+0.47*(0.866))));
			g.drawString("0\u00ba",(int)(rwidth*(0.5-0.2*(0.030))),(int)(rwidth*(0.5+0.44*(1.05))));
		}
		if(is_theta_plane==true){//This is the theta plane
		//draw dipole antenna 
		  //geom = (rwidth*0.16*Math.cos((phi-90)*Math.PI/180));
		    geom = 0.0;
		//top dipole
                    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
    		  
                  /*
		  g.setColor(Color.white);
		  g.drawLine((int)(rwidth*(0.5)-geom),(int)(rwidth*(0.5-0.2)),
		           (int)(rwidth*(0.5)-geom),(int)(rwidth*(0.5))-4);
		  g.setColor(Color.red);
		  g.drawLine((int)(rwidth*(0.5)-geom-1),(int)(rwidth*(0.5-0.2)),
		           (int)(rwidth*(0.5)-geom-1),(int)(rwidth*(0.5))-4);
		  g.setColor(Color.black);
		  g.drawLine((int)(rwidth*(0.5)-geom+1),(int)(rwidth*(0.5-0.2)),
		           (int)(rwidth*(0.5)-geom+1),(int)(rwidth*(0.5))-4);
		  //tip
		  g.drawLine((int)(rwidth*(0.5)-geom-1),(int)(rwidth*(0.5-0.2)),
		             (int)(rwidth*(0.5)-geom+1),(int)(rwidth*(0.5-0.2)));
			   
		//bottom dipole
		  		    
		  g.setColor(Color.white);
		  g.drawLine((int)(rwidth*(0.5)-geom),(int)(rwidth*(0.5))+4,
		           (int)(rwidth*(0.5)-geom),(int)(rwidth*(0.5+0.2)));
		  g.setColor(Color.red);
		  g.drawLine((int)(rwidth*(0.5)-geom-1),(int)(rwidth*(0.5))+4,
		           (int)(rwidth*(0.5)-geom-1),(int)(rwidth*(0.5+0.2)));
		  g.setColor(Color.black);
		  g.drawLine((int)(rwidth*(0.5)-geom+1),(int)(rwidth*(0.5))+4,
		           (int)(rwidth*(0.5)-geom+1),(int)(rwidth*(0.5+0.2)));
		  //tip
		  g.drawLine((int)(rwidth*(0.5)-geom-1),(int)(rwidth*(0.5+0.2)),
		           (int)(rwidth*(0.5)-geom+1),(int)(rwidth*(0.5+0.2)));
                           
                  */
                    g.setColor(Color.gray);
                    int endpoint = (int)(rwidth*0.2);
                    int xCenter = (int)(rwidth*(0.5)-geom);
                    int yCenter = (int)(rwidth*(0.5));
                    //g.drawLine((int)(rwidth*(0.5)-geom),(int)(rwidth*(0.5-0.2)),
		      //     (int)(rwidth*(0.5)-geom),(int)(rwidth*(0.5+0.2)));
                    if(!PutOne && !PutMore){}
                    else{ 
                        if(PutOne && !PutMore){
                            if(IsParabolic){MaestroG.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.gray);}
                            else{
                                  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                                  g.setColor(Color.white);
                                  g.drawLine((int)(rwidth*(0.5)-geom),(int)(rwidth*(0.5-0.2)),
                                           (int)(rwidth*(0.5)-geom),(int)(rwidth*(0.5))-4);
                                  g.setColor(Color.yellow);
                                  g.drawLine((int)(rwidth*(0.5)-geom-1),(int)(rwidth*(0.5-0.2)),
                                           (int)(rwidth*(0.5)-geom-1),(int)(rwidth*(0.5))-4);
                                  g.setColor(Color.black);
                                  g.drawLine((int)(rwidth*(0.5)-geom+1),(int)(rwidth*(0.5-0.2)),
                                           (int)(rwidth*(0.5)-geom+1),(int)(rwidth*(0.5))-4);
                                  //tip
                                  g.drawLine((int)(rwidth*(0.5)-geom-1),(int)(rwidth*(0.5-0.2)),
                                             (int)(rwidth*(0.5)-geom+1),(int)(rwidth*(0.5-0.2)));

                                //bottom dipole

                                  g.setColor(Color.white);
                                  g.drawLine((int)(rwidth*(0.5)-geom),(int)(rwidth*(0.5))+4,
                                           (int)(rwidth*(0.5)-geom),(int)(rwidth*(0.5+0.2)));
                                  g.setColor(Color.red);
                                  g.drawLine((int)(rwidth*(0.5)-geom-1),(int)(rwidth*(0.5))+4,
                                           (int)(rwidth*(0.5)-geom-1),(int)(rwidth*(0.5+0.2)));
                                  g.setColor(Color.black);
                                  g.drawLine((int)(rwidth*(0.5)-geom+1),(int)(rwidth*(0.5))+4,
                                           (int)(rwidth*(0.5)-geom+1),(int)(rwidth*(0.5+0.2)));
                                  //tip
                                  g.drawLine((int)(rwidth*(0.5)-geom-1),(int)(rwidth*(0.5+0.2)),
                                           (int)(rwidth*(0.5)-geom+1),(int)(rwidth*(0.5+0.2)));

                            }
                        }
                        else if(PutMore && !PutOne){
                            if(NAntenna == 1){
                                g.setColor(Color.red);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5)), 7, g);
                                g.setColor(Color.black);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5)), 7, g);
                            }
                            else if(NAntenna == 2){
                                g.setColor(Color.red);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-12, 7, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+12, 7, g);
                                g.setColor(Color.black);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-12, 7, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+12, 7, g);
                            }
                            else if(NAntenna == 3){
                                g.setColor(Color.red);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5)), 7, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-24, 7, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+24, 7, g);
                                g.setColor(Color.black);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5)), 7, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-24, 7, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+24, 7, g);
                            }
                            else if(NAntenna == 4){
                                g.setColor(Color.red);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-12, 7, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+12, 7, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-36, 7, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+36, 7, g);
                                g.setColor(Color.black);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-12, 7, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+12, 7, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-36, 7, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+36, 7, g);
                            }
                            else if(NAntenna == 5){
                                g.setColor(Color.red);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5)), 7, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-24, 7, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+24, 7, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-48, 7, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+48, 7, g);
                                g.setColor(Color.black);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5)), 7, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-24, 7, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+24, 7, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-48, 7, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+48, 7, g);
                            }
                            else if(NAntenna == 6){
                                g.setColor(Color.red);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-12, 7, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+12, 7, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-36, 7, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+36, 7, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-60, 7, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+60, 7, g);
                                g.setColor(Color.black);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-12, 7, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+12, 7, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-36, 7, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+36, 7, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-60, 7, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+60, 7, g);
                            }
                        }
                    }
                    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
		}
		else{//This is phi plane
		     // Draw cross-section line 
                  
                  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
    
		  g.setColor(Color.yellow);
		    double phi2 = phi - 90.0;
                  g.drawLine((int)((rwidth/2.0)*(1.0+0.8*Math.cos(phi2*Math.PI/180.0))),
			     (int)((rwidth/2.0)*(1.0-0.8*Math.sin(phi2*Math.PI/180.0))),
			     (int)((rwidth/2.0)*(1.0-0.8*Math.cos(phi2*Math.PI/180.0))),
			     (int)((rwidth/2.0)*(1.0+0.8*Math.sin(phi2*Math.PI/180.0))));

			// Draw wires - view from top
		  
		  
		  g.setColor(Color.red);
		  g.fillOval(
			(int)(rwidth*(0.34)-rwidth*(0.00625)),
			(int)(rwidth*(0.5)-rwidth*(0.00625)),
			(int)(rwidth*(0.025)),
			(int)(rwidth*(0.025)));
		  
		
		  g.setColor(Color.green);
		  g.fillOval(
			(int)(rwidth*(0.66)-rwidth*(0.00625)),
			(int)(rwidth*(0.5)-rwidth*(0.00625)),
			(int)(rwidth*(0.025)),
			(int)(rwidth*(0.025)));
			
		   
			//Draw view-angle arrow

		  //g.setColor(Color.white);
		  g.setColor(Color.yellow);
		  
		  Polygon s1 = new Polygon();
		  s1.addPoint((int)((rwidth/2.0)*(1.0+0.63*Math.cos((phi2-91.0)*Math.PI/180.0))),
			      (int)((rwidth/2.0)*(1.0-0.63*Math.sin((phi2-91.0)*Math.PI/180.0))));
		  
		  s1.addPoint((int)((rwidth/2.0)*(1.0+0.63*Math.cos((phi2-88.5)*Math.PI/180.0))),
			      (int)((rwidth/2.0)*(1.0-0.63*Math.sin((phi2-88.5)*Math.PI/180.0))));
		  
		  s1.addPoint((int)((rwidth/2.0)*(1.0+0.85*Math.cos((phi2-88.5)*Math.PI/180.0))),
			      (int)((rwidth/2.0)*(1.0-0.85*Math.sin((phi2-88.5)*Math.PI/180.0))));
		  s1.addPoint((int)((rwidth/2.0)*(1.0+0.85*Math.cos((phi2-91.0)*Math.PI/180.0))),
			      (int)((rwidth/2.0)*(1.0-0.85*Math.sin((phi2-91.0)*Math.PI/180.0))));
		  g.fillPolygon(s1);
		  
		  Polygon s = new Polygon();
		  s.addPoint((int)((rwidth/2.0)*(1.0+0.53*Math.cos((phi2-90.0)*Math.PI/180.0))),
			     (int)((rwidth/2.0)*(1.0-0.53*Math.sin((phi2-90.0)*Math.PI/180.0))));
		  s.addPoint((int)((rwidth/2.0)*(1.0+0.65*Math.cos((phi2-94.0)*Math.PI/180.0))),
			     (int)((rwidth/2.0)*(1.0-0.65*Math.sin((phi2-94.0)*Math.PI/180.0))));
		  s.addPoint((int)((rwidth/2.0)*(1.0+0.65*Math.cos((phi2-86.0)*Math.PI/180.0))),
			     (int)((rwidth/2.0)*(1.0-0.65*Math.sin((phi2-86.0)*Math.PI/180.0))));

		  g.fillPolygon(s);
                  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
    
                }

		//Now draw the radiation diagram
		double offset = 0.39;
		g.setColor(Color.blue);
	    if(is_theta_plane==true){
		
		//Now draw radiation patterns
		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                double theta1;
		for(i=0;i<360;i++){	
		    
		    theta=(2.0*Math.PI*i/360.0-Math.PI/2.0);
                    theta1=(2.0*Math.PI*(i+1)/360.0-Math.PI/2.0);
		    g.setColor(Color.blue);
		    g.drawLine(
			    (int)(rwidth*(0.5+offset*y[i]/ymax*Math.cos(theta))),
			    (int)(rwidth*(0.5+offset*y[i]/ymax*Math.sin(theta))),
			    (int)(rwidth*(0.5+offset*y[i+1]/ymax*Math.cos(theta1))),
			    (int)(rwidth*(0.5+offset*y[i+1]/ymax*Math.sin(theta1))));
		}
		//Add point at 360 dedgrees
		//theta=(2.0*Math.PI*359/360.0-Math.PI/2.0);
		  //  g.setColor(Color.blue);
		  //  g.drawLine(
		//	    (int)(rwidth*(0.5+offset*y[0]/ymax*Math.cos(theta))),
		//	    (int)(rwidth*(0.5+offset*y[0]/ymax*Math.sin(theta)))+1,
		//	    (int)(rwidth*(0.5+offset*y[1]/ymax*Math.cos(theta))),
		//	    (int)(rwidth*(0.5+offset*y[1]/ymax*Math.sin(theta)))+1);
		//g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
                    geom = 0;
                    g.setColor(Color.gray);
                    int endpoint = (int)(rwidth*0.2);
                    int xCenter = (int)(rwidth*(0.5)-geom);
                    int yCenter = (int)(rwidth*(0.5));
                    //g.drawLine((int)(rwidth*(0.5)-geom),(int)(rwidth*(0.5-0.2)),
		      //     (int)(rwidth*(0.5)-geom),(int)(rwidth*(0.5+0.2)));
                    if(!PutOne && !PutMore){}
                    else{ 
                        if(PutOne && !PutMore){
                            if(IsParabolic){MaestroG.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.gray);}
                            else{
                                  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                                  g.setColor(Color.white);
                                  g.drawLine((int)(rwidth*(0.5)-geom),(int)(rwidth*(0.5-0.2)),
                                           (int)(rwidth*(0.5)-geom),(int)(rwidth*(0.5))-4);
                                  g.setColor(Color.red);
                                  g.drawLine((int)(rwidth*(0.5)-geom-1),(int)(rwidth*(0.5-0.2)),
                                           (int)(rwidth*(0.5)-geom-1),(int)(rwidth*(0.5))-4);
                                  g.setColor(Color.black);
                                  g.drawLine((int)(rwidth*(0.5)-geom+1),(int)(rwidth*(0.5-0.2)),
                                           (int)(rwidth*(0.5)-geom+1),(int)(rwidth*(0.5))-4);
                                  //tip
                                  g.drawLine((int)(rwidth*(0.5)-geom-1),(int)(rwidth*(0.5-0.2)),
                                             (int)(rwidth*(0.5)-geom+1),(int)(rwidth*(0.5-0.2)));

                                //bottom dipole

                                  g.setColor(Color.white);
                                  g.drawLine((int)(rwidth*(0.5)-geom),(int)(rwidth*(0.5))+4,
                                           (int)(rwidth*(0.5)-geom),(int)(rwidth*(0.5+0.2)));
                                  g.setColor(Color.red);
                                  g.drawLine((int)(rwidth*(0.5)-geom-1),(int)(rwidth*(0.5))+4,
                                           (int)(rwidth*(0.5)-geom-1),(int)(rwidth*(0.5+0.2)));
                                  g.setColor(Color.black);
                                  g.drawLine((int)(rwidth*(0.5)-geom+1),(int)(rwidth*(0.5))+4,
                                           (int)(rwidth*(0.5)-geom+1),(int)(rwidth*(0.5+0.2)));
                                  //tip
                                  g.drawLine((int)(rwidth*(0.5)-geom-1),(int)(rwidth*(0.5+0.2)),
                                           (int)(rwidth*(0.5)-geom+1),(int)(rwidth*(0.5+0.2)));

                            }
                        }
                        else if(PutMore && !PutOne){
                            if(NAntenna == 1){
                                g.setColor(Color.yellow);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5)), 8, g);
                                g.setColor(Color.black);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5)), 8, g);
                            }
                            else if(NAntenna == 2){
                                g.setColor(Color.yellow);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-12, 8, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+12, 8, g);
                                g.setColor(Color.black);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-12, 8, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+12, 8, g);
                            }
                            else if(NAntenna == 3){
                                g.setColor(Color.yellow);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5)), 8, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-24, 8, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+24, 8, g);
                                g.setColor(Color.black);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5)), 8, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-24, 8, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+24, 8, g);
                            }
                            else if(NAntenna == 4){
                                g.setColor(Color.yellow);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-12, 8, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+12, 8, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-36, 8, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+36, 8, g);
                                g.setColor(Color.black);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-12, 8, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+12, 8, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-36, 8, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+36, 8, g);
                            }
                            else if(NAntenna == 5){
                                g.setColor(Color.yellow);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5)), 8, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-24, 8, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+24, 8, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-48, 8, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+48, 8, g);
                                g.setColor(Color.black);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5)), 8, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-24, 8, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+24, 8, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-48, 8, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+48, 8, g);
                            }
                            else if(NAntenna == 6){
                                g.setColor(Color.yellow);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-12, 8, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+12, 8, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-36, 8, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+36, 8, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-60, 8, g);
                                MaestroG.fillCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+60, 8, g);
                                g.setColor(Color.black);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-12, 8, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+12, 8, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-36, 8, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+36, 8, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))-60, 8, g);
                                MaestroG.drawCircle((int)(rwidth*(0.5)), (int)(rwidth*(0.5))+60, 8, g);
                            }
                        }
                    }
            
            
            }
	    else{
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
    
		for(i=0;i<360;i++){		
		    double phi3;
		    phi3=(2.0*Math.PI*i/360.0);
		    g.setColor(Color.blue);
		    g.drawLine(
			    (int)(rwidth*(0.5+offset*y[i]/ymax*Math.cos(phi3))),
			    (int)(rwidth*(0.5+offset*y[i]/ymax*Math.sin(phi3)))+1,
			    (int)(rwidth*(0.5+offset*y[i+1]/ymax*Math.cos(phi3))),
			    (int)(rwidth*(0.5+offset*y[i+1]/ymax*Math.sin(phi3)))+1); 
		}
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
    
	    }
	
}

public void drawGraph(Graphics g){
	g.clearRect(0,0,getSize().width,getSize().height);
    	drawAxis(g);
	if(Should_Plot_Zero_Line){plotZeroLine(g);}
	//g.draw3DRect(0,0,getSize().width-1,getSize().height-1,false);
	drawTitle(g);
        plotPoints(g);
	if(Should_Plot_Ref_Point){plotRefPoint(g);}
	
}

protected void ignition(){
    int height=getSize().height;
    int width=getSize().width;
    if(!IsYRangeMinSet){ymin = MaestroA.getMin(y);}
    if(!IsYRangeMaxSet){ymax = MaestroA.getMax(y);}
    if(!IsXRangeMaxSet){xmax = x[x.length-1];}
    if(!IsXRangeMinSet){xmin = x[0];}
    if(IsYRangeMinSet || IsYRangeMaxSet){
	MaestroA.confiner(y,ymax,ymin);
    }
    if(IsXRangeMinSet || IsXRangeMaxSet){
	MaestroA.confiner(x,xmax,xmin);
    }
    
    
    if(ymin==ymax){ymax=2*ymin+1;}
    for(int i=0;i<xx.length;i++){
	xx[i]= (int)MaestroA.mapper(x[i],(double)(width-RightMargin),(double)(LeftMargin),xmax,xmin);
	//yy[i]= (int)MaestroA.mapper(y[i],(double)TopSep,(double)(height-BottomSep),ymax,ymin);
     
    if(i<=180){
	    yy[i]= (int)MaestroA.mapper(y[i+180],(double)TopSep,(double)(height-BottomSep),ymax,ymin);
	}
	else if(i>180){
	    yy[i]= (int)MaestroA.mapper(y[i-180],(double)TopSep,(double)(height-BottomSep),ymax,ymin);
	}
	
    }
    X1 = "-180";
    X2 ="180";
    
    X3="|";
    Y1=""+MaestroA.rounder(ymin,3);
    
    if(ymax < 1.0e230){
	if(ymax >= 1.0e-3){
	    Y2=""+MaestroA.rounder(ymax,5);
	    flag = 0;
	}
	else if(ymax >= 1.0e-4 && ymax < 1.0e-3){
	    Y2=""+MaestroA.rounder(ymax*1.0e4,5);
	    flag = 4;
	}
	else if(ymax >= 1.0e-5 && ymax < 1.0e-4){
	    Y2=""+MaestroA.rounder(ymax*1.0e5,4);
	    flag = 5;
	}
	else if(ymax >= 1.0e-6 && ymax < 1.0e-5){
	    Y2=""+MaestroA.rounder(ymax*1.0e6,4);
	    flag = 6;
	}
	else if(ymax >= 1.0e-7 && ymax < 1.0e-6){
	    Y2=""+MaestroA.rounder(ymax*1.0e7,4);
	    flag = 7;
	}
	else if(ymax >= 1.0e-8 && ymax < 1.0e-7){
	    Y2=""+MaestroA.rounder(ymax*1.0e8,4);
	    flag = 8;
	}
	else if(ymax >= 1.0e-9 && ymax < 1.0e-8){
	    Y2=""+MaestroA.rounder(ymax*1.0e9,4);
	    flag = 9;
	}
	else if(ymax >= 1.0e-10 && ymax < 1.0e-9){
	    Y2=""+MaestroA.rounder(ymax*1.0e10,4);
	    flag = 10;
	}
	else if(ymax >= 1.0e-11 && ymax < 1.0e-10){
	    Y2=""+MaestroA.rounder(ymax*1.0e11,4);
	    flag = 11;
	}
	else if(ymax >= 1.0e-12 && ymax < 1.0e-11){
	    Y2=""+MaestroA.rounder(ymax*1.0e12,4);
	    flag = 12;
	}
	else if(ymax >= 1.0e-13 && ymax < 1.0e-12){
	    Y2=""+MaestroA.rounder(ymax*1.0e13,4);
	    flag = 13;
	}
	else if(ymax >= 1.0e-14 && ymax < 1.0e-13){
	    Y2=""+MaestroA.rounder(ymax*1.0e14,4);
	    flag = 14;
	}
	else if(ymax >= 1.0e-15 && ymax < 1.0e-14){
	    Y2=""+MaestroA.rounder(ymax*1.0e15,4);
	    flag = 14;
	}
	else if(ymax >= 1.0e-16 && ymax < 1.0e-15){
	    Y2=""+MaestroA.rounder(ymax*1.0e16,4);
	    flag = 16;
	}
	else if(ymax >= 1.0e-17 && ymax < 1.0e-16){
	    Y2=""+MaestroA.rounder(ymax*1.0e17,4);
	    flag = 17;
	}
	else if(ymax >= 1.0e-18 && ymax < 1.0e-17){
	    Y2=""+MaestroA.rounder(ymax*1.0e18,4);
	    flag = 18;
	}
	else if(ymax >= 1.0e-19 && ymax < 1.0e-18){
	    Y2=""+MaestroA.rounder(ymax*1.0e19,4);
	    flag = 19;
	}
	else if(ymax >= 1.0e-20 && ymax < 1.0e-19){
	    Y2=""+MaestroA.rounder(ymax*1.0e20,4);
	    flag = 20;
	}
	else if(ymax < 1.0e-20){
	    Y2=""+ymax;
	    flag = 0;
	}
    }
    else{
	Y2="\u221e";
	flag = 0;
    }
    Y3="_";
    
}

protected void plotZeroLine(Graphics g){
    if(ymin*ymax>0){return;}
    FontMetrics fm = g.getFontMetrics();
    g.setFont(font1);
    int yyy;
    yyy = (int)MaestroA.mapper(0.0,(double)TopSep,(double)(getSize().height-BottomSep),ymax,ymin);
    g.setColor(Color.red);
    g.drawLine(LeftMargin,yyy,getSize().width-RightMargin,yyy);
    g.drawString("0",LeftMargin-fm.stringWidth("0"),yyy+fm.getHeight()/3);
    //g.setColor(Color.yellow);
}

public synchronized void plotZeroLine(boolean Should_Plot_Zero_Line){
    this.Should_Plot_Zero_Line = Should_Plot_Zero_Line;
}

protected void plotRefPoint(Graphics g){
    int myX=0, myY=0, i;
    i = (int)((NumPoints-1)*(xRef-x[0])/(x[x.length-1]-x[0]));
    if(i<0) {i = 0;}
    if(i>=NumPoints){i=NumPoints-1;}
    myX = (int)MaestroA.mapper(xRef,(double)(getSize().width-RightMargin),(double)(LeftMargin),xmax,xmin);
    if(y[i]>0.0){
	myY = (int)MaestroA.mapper(y[i],(double)TopSep,(double)(getSize().height-BottomSep),ymax,ymin);
    }
    else{
	myY =getSize().height-BottomSep ;
    }
    Graphics2D g2d = (Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
    
    g.setColor(Color.white);
    g.drawLine(myX,myY,myX,getSize().height-BottomSep+5);
    
    g.setColor(Color.red);
    MaestroG.fillCircle(myX,myY,6,g);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
    
}


public synchronized void plotRefPoint(boolean Should_Plot_Ref_Point){
    this.Should_Plot_Ref_Point = Should_Plot_Ref_Point;
}

protected void plotPoints(Graphics g){
    ignition();
    Graphics2D g2d = (Graphics2D)g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
    g.setColor(Color.white);
    g.drawPolyline(xx,yy,xx.length);
}

protected void drawTitle(Graphics g){
    Graphics2D g2d = (Graphics2D)g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                
    FontMetrics fm = g.getFontMetrics();
    g.setFont(font1);
    g.setColor(Color.white);
    //g.drawString(XLabel,(getSize().width-fm.stringWidth(XLabel))/2,getSize().height-BottomSep+3*fm.getHeight()/2);
    g.drawString(XLabel,(getSize().width-fm.stringWidth(XLabel))/2+60,getSize().height-BottomSep+3*fm.getHeight()/2+5);
    g.drawString(YLabel,LeftMargin-30,getSize().height/2);
    g.setColor(Color.white);
    g.drawString(TITLE,(getSize().width)*70/100,TopSep/2-3);
    
    if(type == 1){MaestroG.subscripterSymbol("| E","\u03b8"," |",g,14,getSize().width-50,16);}
    if(type == 2){MaestroG.subscripter2("| E","R"," |",g,14,LeftMargin+13,16);}
    if(type == 3){MaestroG.subscripter2("| E","x"," |",g,14,LeftMargin+13,16);}
    if(type == 4){MaestroG.subscripter2("| E","y"," |",g,14,LeftMargin+13,16);}
    if(type == 5){MaestroG.subscripter2("| E","z"," |",g,14,LeftMargin+13,16);}
    if(type == 6){MaestroG.subscripterSymbol("| H","\u03c6"," |",g,14,LeftMargin+13,16);}
    if(type == 7){MaestroG.subscripter2("| H","x"," |",g,14,LeftMargin+13,16);}
    if(type == 8){MaestroG.subscripter2("| H","y"," |",g,14,LeftMargin+13,16);}
    
    g.setFont(font1);   
    g.setColor(Color.yellow);
    
    g.drawString(X1,LeftMargin-11,getSize().height-BottomSep+3*fm.getHeight()/2);
    g.drawString(X2,getSize().width-RightMargin-fm.stringWidth(X2)+10,getSize().height-BottomSep+3*fm.getHeight()/2);
    
    // horizontal tick marks.  Using fonts (above) DOES NOT WORK on Mac - Mac sucks!!!!!
    g.drawLine(LeftMargin,getSize().height-BottomSep,LeftMargin,getSize().height-BottomSep+6);
    g.drawLine(LeftMargin+(getSize().width-RightMargin-LeftMargin)/2,getSize().height-BottomSep,
               LeftMargin+(getSize().width-RightMargin-LeftMargin)/2,getSize().height-BottomSep+6);
    g.drawLine(getSize().width-RightMargin,getSize().height-BottomSep,
               getSize().width-RightMargin,getSize().height-BottomSep+6);
    g.drawLine(LeftMargin-6,getSize().height-BottomSep,LeftMargin,getSize().height-BottomSep);
    g.drawLine(LeftMargin,TopSep,LeftMargin-6,TopSep);
    
    g.drawString("0",(getSize().width-RightMargin + LeftMargin-1)/2-1,getSize().height-BottomSep+3*fm.getHeight()/2);
    g.drawString(Y1,10,getSize().height-BottomSep+5);
    
    if(fm.stringWidth(Y2)>(LeftMargin-10)){
	
	if(flag == 0){
	    g.drawString(Y2,5,TopSep-4);	    
	}
	else{
	    
	    MaestroG.superscripter2(Y2+" 10","-"+flag,"",g,12,5,TopSep-4);
	}
    }
    else{
	if(flag == 0){
	    g.drawString(Y2,Math.max(4,LeftMargin-fm.stringWidth(Y2))-7,TopSep-4);    
	}
	else{
	    
	    MaestroG.superscripter2(Y2+" 10","-"+flag,"",g,12,LeftMargin+5,TopSep-4);
	}
    }
    //g.drawString(Y3,LeftMargin-6,getSize().height-BottomSep-2);
    //g.drawString(Y3,LeftMargin-6,TopSep-2);
}

protected void drawAxis(Graphics g){
    VPos = getSize().height-BottomSep;
    g.setColor(Color.yellow);
    //Vertical Axis
    g.drawLine(LeftMargin,TopSep-1,LeftMargin,getSize().height-BottomSep);
    //g.drawLine(LeftMargin,TopSep/2,LeftMargin,getSize().height-BottomSep);
    //MaestroG.drawArrow(LeftMargin,TopSep/2,1,g);
    //Horizontal Axis
    g.drawLine(LeftMargin,VPos,getSize().width-RightMargin+10,VPos);
    MaestroG.drawArrow(getSize().width-RightMargin+10,VPos,7,g);
}

public final synchronized void setXLabel(String XLabel){
    this.XLabel=XLabel;
}

public final synchronized void setYLabel(String YLabel){
    this.YLabel=YLabel;
} 

public final synchronized void setTitle(String TITLE){
    this.TITLE = TITLE;
}

public final synchronized void setLabels(String TITLE, String YLabel, String XLabel){
    this.TITLE=TITLE;
    this.YLabel = YLabel;
    this.XLabel = XLabel;
}
 
public void plot(double[] xdata, double[] ydata){
    if(NumPoints != xdata.length){
	NumPoints = xdata.length;
	x = new double[NumPoints];
	y = new double[NumPoints];
	xx = new int[NumPoints];
	yy = new int[NumPoints];
    }
    for(int i = 0; i < NumPoints; i++){
	x[i] = xdata[i];
	y[i] = ydata[i];
    }
    repaint();
}

public void setPolar(boolean IsPolar){
    this.IsPolar = IsPolar;
}

public void setPhiAngle(double phi_angle){
    this.phi_angle=phi_angle;
}

public void setType(int type){
    this.type=type;
}

public void setAntennas(int NAntenna, boolean IsParabolic, boolean PutOne, boolean PutMore){
    this.NAntenna = NAntenna;
    this.IsParabolic = IsParabolic;
    this.PutOne = PutOne;
    this.PutMore = PutMore;
}

public void setYRange(double ymax, double ymin){
    IsYRangeMaxSet=true;
    IsYRangeMinSet=true;
    this.ymax=ymax;
    this.ymin=ymin;
}

public void setYRangeMin(double ymin){
    IsYRangeMinSet=true;
    this.ymin=ymin;
}

public void setYRangeMax(double ymax){
    IsYRangeMaxSet=true;
    this.ymax=ymax;
}

public void setAuto(){
    IsYRangeMaxSet=false;
    IsYRangeMinSet=false;
    IsXRangeMaxSet=false;
    IsXRangeMinSet=false;
}

public synchronized void setRefPoint(double xRef){
    this.xRef = xRef;
}

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


}