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 PlaneWaveCanvas extends Canvas{
    
    //private static final Color bgcolor = new Color(255,255,255);
    private static final Color bgcolor = new Color(255,255,245);
    
    private static final Color rotorcolor = Color.green;
   
    private double zmax, zmin, ymax, ymin, xmax, xmin, pmax, pmin;
    private boolean IsYRangeMaxSet, IsYRangeMinSet, IsXRangeMaxSet, IsXRangeMinSet; 
    private boolean IsZRangeMaxSet, IsZRangeMinSet, IsPRangeMaxSet, IsPRangeMinSet;
    //private int LeftMargin=125, RightMargin=110, TopMargin=70, BottomMargin=70;
    private int Orth_Axis_Front=63, Orth_Axis_Back=63; //Size of orthogonal axis (y-direction);
    private int axis_one_ref, axis_two_ref, down = 165, down2 = 100, down3 = 160;
    int yshift = 250;
    private int LeftMargin=90, RightMargin=85, TopMargin=60, TopMargin2=TopMargin+yshift, 
                BottomMargin=210, BottomMargin2=-40;
    
    private boolean IsEquivalent = false;
    private boolean refz;
    
    private double zpos[];   //position of the reference planes
    private double alpha, beta, frequency, total_length, wt, wavelength, Ex, Hy, Pz, skin_depth;
    private static final String znames[] ={"A", "B"};
    private int WIDTH, HEIGHT, SkinZ1_z, SkinZ1_x, SkinZ2_z, SkinZ2_x;
    private int PSkinZ1_z, PSkinZ1_x, PSkinZ2_z, PSkinZ2_x;
    private String Z1, Z2, Z3, X1, X2, X3, X4, TITLE, legend1, legend2;
    private Image im;
    private Graphics buf;
    private int VPos = 0;
   
    private static final Font TitleFont = new Font("SanSerif",Font.BOLD,16);
    private static final Font TitleFont2 = new Font("SanSerif",Font.BOLD,20);
    private static final Font LabelFont = new Font("SanSerif",Font.PLAIN,11);
    private double[] z;
    //private double myangle = 135.0+45;
    private double[] EField_z, HField_z, PField_z;
    private int[] Field_zx, Field_zx_old, Decay1, Decay1B, Decay2, Decay2B; 
    private int[] Field_zy, Field_zy_old;
    private int[] Field_zp, Field_zp_old, Decay3; 
    
    private int[] zx, zx_old, zy, zy_old, zy2, zy2B;
    private int current_z;
    private double H_ratio, E_ratio, P_ratio;
    private int N;
    private static final double theta = 135.*Math.PI / 180.0;//0.75
    
    private double sintheta = Math.sin(theta);
    private double costheta = Math.cos(theta);
    private boolean IsTraceOn, IsCleanUpOn, IsDynamic,IsPhasorOn, IsSkinDepthOn, IsEon, IsHon;
    private int nlines = 8;
    private double angle = 135.0;
    private double costhetanew,sinthetanew;   
    public boolean SliceIt = false;
    
    public PlaneWaveCanvas(){
	super();
	N = 360;
	setBackground(bgcolor);
	 
	double frequency = 1.0E9;
	alpha = 0.0;
	wavelength = 1.0/Math.sqrt(8.8541878176E-12*1.25663706144E-6)/frequency;
	total_length =1.0;
	Ex = 1.0;
	Hy = Ex/Math.sqrt(1.25663706144/8.8541878176E-6/9.0);
        Pz = Ex;//normalize to Ex
        //costheta = Math.cos(myangle*Math.PI/180.0);    
	//sintheta = Math.cos(myangle*Math.PI/180.0);    
	costhetanew = Math.cos(angle*Math.PI/180.0);    
	sinthetanew = Math.sin(angle*Math.PI/180.0);
        wt = 0.0;
	Z1 = "0";
	Z2 = "L";
	Z3 = "     z";
	X1 = "  ";
	X2 = "  ";
	TITLE = "  ";
	IsYRangeMaxSet = false;
	IsYRangeMinSet = false;
	IsXRangeMaxSet = false;
	IsXRangeMinSet = false;
        IsPRangeMaxSet = true;
	IsPRangeMinSet = true;
	IsTraceOn = false;
	IsCleanUpOn = false;
	IsDynamic = false;
	IsPhasorOn = true;
        IsSkinDepthOn = true;
        
        xmax = 2.0;
	xmin = -2.0;
	ymax = 2.0;
	ymin = -2.0;
        pmax = Pz;
        pmin = -Pz;
        
	zmax = 1.0;
	zmin = 0.0;
        skin_depth = Double.POSITIVE_INFINITY;
        
        IsEon = true;
        IsHon = false;
        refz =false;
        
	axis_one_ref = (int)(0.85*getSize().height/2);
	axis_two_ref  = (int)(0.85*getSize().height/2);
        
        Orth_Axis_Front = (int)(0.55*getSize().height/2);
	Orth_Axis_Back  = (int)(0.55*getSize().height/2);
        
        H_ratio = 0.55/0.85;
        E_ratio = 0.75/0.85;
        P_ratio = 0.75/0.85;
        try{
	    z = new double[N];
	    EField_z = new double[N];
	    HField_z = new double[N];
            PField_z = new double[N];
	    Field_zx = new int[N];
	    Field_zx_old = new int[N];
	    Decay1 = new int[N];
	    Decay2 = new int[N];
            Decay1B = new int[N];
	    Decay2B = new int[N];
            
            Decay3 = new int[N];
	    Field_zy = new int[N];
	    Field_zy_old = new int[N];
            Field_zp = new int[N];
	    Field_zp_old = new int[N];
	    zx = new int[N];
	    zx_old = new int[N];
	    zy = new int[N];
	    zy2 = new int[N];
            zy2B = new int[N];
	    zy_old = new int[N];
	}
	catch(Exception e){e.printStackTrace();}
	for(int i = 0; i < z.length; i++){
	    z[i] = (double)i;
	    EField_z[i] = 0.0;
	    HField_z[i] = 0.0;
            PField_z[i] = 0.0;
	    Field_zx[i] = 0;
	    Field_zx_old[i] = 0;
            Field_zp[i] = 0;
	    Field_zp_old[i] = 0;
	    Decay1[i] = 0;
	    Decay2[i] = 0;
            Decay1B[i] = 0;
	    Decay2B[i] = 0;
            
            Decay3[i] = 0;
	    zx[i] = i;
	    zx_old[i] = i;
	    zy[i] = i;
	    zy_old[i] = i;
	    zy2[i] =i;
            zy2B[i] =i;
	}
	//Positions of reference planes
	zpos = new double[2];
	
	//Position of rotor
	current_z = 0;
	
    }
    
    public void paint(Graphics g){
	if(im == null){
	    im = createImage(getSize().width,getSize().height);
	    buf = im.getGraphics();
	    drawGraph(buf);
	}
	else{
	 drawGraph(buf);
	}
	g.drawImage(im,0,0,null);
    }
    
    public void drawGraph(Graphics g){
	g.draw3DRect(0,0,getSize().width-1,getSize().height-1,false);
	
	if(!IsDynamic){
	    g.clearRect(0,0,getSize().width,getSize().height);
	}
        g.clearRect(0,0,getSize().width,getSize().height);
	//g.clearRect(0,0,LeftMargin-1,getSize().height-1);
	//g.clearRect(0,0,getSize().width-1,TopMargin-1);
	g.setColor(Color.black);
	
	g.draw3DRect(0,0,getSize().width-1,getSize().height-1,false);
	
        //drawAxis(g);
	//labelDetect();
	//drawZeroLine(g);
	//drawLabels(g);
        drawCircuit(g);
	drawPoints(g,1);
        drawCircuit2(g);
	//drawLabels(g);
	//drawRotor(g);
    }
       
    private synchronized void drawCircuit(Graphics g){
        
	int ytop = 20*getSize().height/100;
        int ybottom = 80*getSize().height/100;
        
        int xleft = getSize().width/8;
        int xright = 6*getSize().width/8;
        
        int plate1_y = ytop+25*(ybottom-ytop)/100;
        int plate2_y = ytop+75*(ybottom-ytop)/100;
        int xsize = 2*getSize().width/3;
        int ysize = getSize().height/10;
        
        Graphics2D g2d = (Graphics2D)g;
        // wire connecting to bottom plate - must be drawn first
        drawLineThick(g,(double)xright,(double)plate2_y,(double)xright,(double)ybottom,3,Color.black);
        drawCircleThick(g, xright, plate2_y, 3, 6, Color.black);
        
        g.setColor(new Color(200,200,200));
        int rule; 
        float alphaG = 0.5f;
        rule = AlphaComposite.SRC_OVER;
        
        int xx1 = xright-xsize/4;
        int xx2 = xright+xsize/4;
        int yy1 = plate1_y-ysize/2;
        int yy2 = plate1_y+ysize/2;
        int yy3 = plate2_y-ysize/2;
        int yy4 = plate2_y+ysize/2;
        
        
        //----------------------------------------------------------------------
        Color labcolor = new Color(180, 180, 180);
        g.setColor(labcolor);
        // thickness of capacitor arrows
        drawLineThick(g,(double)xx2+2,(double)yy1+5,(double)xx2+30,(double)yy1+5,1,labcolor);
        drawLineThick(g,(double)xx2+2,(double)yy3-5,(double)xx2+30,(double)yy3-5,1,labcolor);
        drawLineThick(g,(double)xx2+15,(double)yy1+5,(double)xx2+15,(double)yy3-5,1,labcolor);
        
        MaestroG.drawArrowtip(xx2+15, yy1+15, 5, g);
        MaestroG.drawArrowtip(xx2+15, yy3-15, 6, g);
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        MaestroG.subscripterSansItalic3("d","","",g,24,xx2+20,yy1+(plate2_y-plate1_y)/2);
        
        drawLineThick(g,(double)xx1,(double)yy2,(double)xx1,(double)yy2-30,1,labcolor);
        drawLineThick(g,(double)xx1+xsize/8,(double)yy1,(double)xx1+xsize/8,(double)yy1-30,1,labcolor);
        drawLineThick(g,(double)xx2,(double)yy1,(double)xx2,(double)yy1-30,1,labcolor);
        
        MaestroG.subscripterSansItalic3("w","","",g,24,xx1+xsize/16-20,yy2-(yy2-yy1)/2-25);
        drawLineThick(g,(double)xx1,(double)yy2-15,(double)xx1+xsize/8,(double)yy1-15,1,labcolor);
        //draw oblique arrow heads
		Polygon pX = new Polygon();
                //draw oblique arrow head        
                pX.addPoint(xx1+xsize/8,yy1-15);
		pX.addPoint(xx1+xsize/8-4,yy1-15+6);
		pX.addPoint(xx1+xsize/8-6,yy1-15+2);
                g.drawPolygon(pX);
		g.fillPolygon(pX);
                
                Polygon pY = new Polygon();
                //draw oblique arrow head        
                pY.addPoint(xx1,yy2-15);
		pY.addPoint(xx1+6,yy2-15-2);
		pY.addPoint(xx1+4,yy2-15-6);
                g.drawPolygon(pY);
		g.fillPolygon(pY);
        
        MaestroG.subscripterSansItalic3("l","","",g,24,xx1+xsize/8+(xx2-xx1-xsize/8)/2,yy1-20);
        drawLineThick(g,(double)xx1+xsize/8,(double)yy1-15,(double)xx2,(double)yy1-15,1,labcolor);
        MaestroG.drawArrowtip(xx1+xsize/8+10, yy1-15, 8, g);
        MaestroG.drawArrowtip(xx2-10, yy1-15, 7, g);
        
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
        //----------------------------------------------------------------------
                
        //Thickness of capacitor plates (hidden edges)           
        g.setColor(new Color(190,140,80));
        // top plate
        //g.fillRect(xx1+xsize/8,yy1+1,38*xsize/100-1,5);
        
        // bottom plate
        g.fillRect(xx1+xsize/8,yy3-5,38*xsize/100-1,5);
        
        // Side plate
        g.setColor(new Color(220,230,245));
        Polygon face4 = new Polygon();
                    face4.addPoint(xx1,yy2);
                    face4.addPoint(xx1+xsize/8,yy1);
                    face4.addPoint(xx1+xsize/8,yy3);
                    face4.addPoint(xx1,yy4);
                    g.drawPolygon(face4);
                    g.fillPolygon(face4);
        g.setColor(Color.black);
                    //g.drawPolygon(face4);
                    
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
        /*
        if(SliceIt){
            g.setColor(new Color(220,220,220));
            g2d.setComposite(AlphaComposite.getInstance(rule, 0.85f));

            Polygon Slice = new Polygon();
                        Slice.addPoint(xx1+xsize/16,((yy2+(yy4-yy2)/2)+(yy1+(yy3-yy1)/2))/2);
                        Slice.addPoint(xx1+xsize/8,yy1+(yy3-yy1)/2);
                        Slice.addPoint(xx2,yy1+(yy3-yy1)/2);
                        Slice.addPoint(xx2-xsize/16,((yy2+(yy4-yy2)/2)+(yy1+(yy3-yy1)/2))/2);
                        
            //g2d.setComposite(AlphaComposite.getInstance(rule, 1.0f));
            //drawLineThickDashed(g,(double)xx1,yy2+(yy4-yy2)/2,xx2-xsize/8,yy2+(yy4-yy2)/2,1,Color.black);
            //drawLineThickDashed(g,(double)xx1,yy2+(yy4-yy2)/2,xx1+xsize/8,yy1+(yy3-yy1)/2,1,Color.black);
            //drawLineThickDashed(g,xx2,yy1+(yy3-yy1)/2,xx1+xsize/8,yy1+(yy3-yy1)/2,1,Color.black);
            //drawLineThickDashed(g,xx2,yy1+(yy3-yy1)/2,xx2-xsize/8,yy2+(yy4-yy2)/2,1,Color.black);
        }
        */
        
        g2d.setComposite(AlphaComposite.getInstance(rule, alphaG));
        
        // Bottom plate
        g.setColor(new Color(190,140,80));
        Polygon plate2 = new Polygon();
                    plate2.addPoint(xx1,yy4);
                    plate2.addPoint(xx1+xsize/8,yy3);
                    plate2.addPoint(xx2,yy3);
                    plate2.addPoint(xx2-xsize/8,yy4);
                    g.drawPolygon(plate2);
                    g.fillPolygon(plate2);
                    g.setColor(Color.black);
                    g.drawPolygon(plate2);
        
        
        g2d.setComposite(AlphaComposite.getInstance(rule,1.0f));
        
        g.setColor(new Color(80,60,20));
        Polygon pla3 = new Polygon();
                    pla3.addPoint(xx1,yy2);
                    pla3.addPoint(xx1+xsize/8,yy1);
                    pla3.addPoint(xx1+xsize/8,yy1+5);
                    pla3.addPoint(xx1,yy2+5);
                    //g.drawPolygon(pla3);
                    //g.fillPolygon(pla3);
                             
        Polygon pla4 = new Polygon();
                    pla4.addPoint(xx1,yy4-5);
                    pla4.addPoint(xx1+xsize/8,yy3-5);
                    pla4.addPoint(xx1+xsize/8,yy3);
                    pla4.addPoint(xx1,yy4);
                    g.drawPolygon(pla4);
                    g.fillPolygon(pla4);
        
        g2d.setComposite(AlphaComposite.getInstance(rule, 0.85f));
        //g.setColor(new Color(230,230,230));
        g.setColor(new Color(190,140,80));
        Polygon plate1 = new Polygon();
                    plate1.addPoint(xx1,yy2);
                    plate1.addPoint(xx1+xsize/8,yy1);
                    plate1.addPoint(xx2,yy1);
                    plate1.addPoint(xx2-xsize/8,yy2);
                    //g.drawPolygon(plate1);
                    //g.fillPolygon(plate1);
                    g.setColor(Color.black);
                    //g.drawPolygon(plate1);
        
        g2d.setComposite(AlphaComposite.getInstance(rule, 0.8f));            
        g.setColor(new Color(230,230,255));
        Polygon face1 = new Polygon();
                    face1.addPoint(xx1,yy2);
                    face1.addPoint(xx2-xsize/8,yy2);
                    face1.addPoint(xx2-xsize/8,yy4);
                    face1.addPoint(xx1,yy4);
                    g.drawPolygon(face1);
                    g.fillPolygon(face1);
                    g.setColor(Color.black);
                    g.drawPolygon(face1);
                    
        g2d.setComposite(AlphaComposite.getInstance(rule, 0.8f));            
        g.setColor(new Color(200,200,225));
        Polygon face2 = new Polygon();
                    face2.addPoint(xx2-xsize/8,yy2);
                    face2.addPoint(xx2,yy1);
                    face2.addPoint(xx2,yy3);
                    face2.addPoint(xx2-xsize/8,yy4);
                    //g.drawPolygon(face2);
                    //g.fillPolygon(face2);
                    g.setColor(Color.black);
                    //g.drawPolygon(face2);
                    
        //Thickness of capacitor plates (visible edges)            
        g.setColor(new Color(220,170,110));
        //g.fillRect(xx1,yy2+1,38*xsize/100-1,5);
        
        g2d.setComposite(AlphaComposite.getInstance(rule, 1.0f));            
        g.fillRect(xx1,yy4-5,38*xsize/100-1,5);
        g2d.setComposite(AlphaComposite.getInstance(rule, 0.8f));            
        
        g.setColor(new Color(150,100,40));
        Polygon pla1 = new Polygon();
                    pla1.addPoint(xx2-xsize/8,yy2);
                    pla1.addPoint(xx2,yy1);
                    pla1.addPoint(xx2,yy1+5);
                    pla1.addPoint(xx2-xsize/8,yy2+5);
                    //g.drawPolygon(pla1);
                    //g.fillPolygon(pla1);
                             
        Polygon pla2 = new Polygon();
                    pla2.addPoint(xx2-xsize/8,yy4-5);
                    pla2.addPoint(xx2,yy3-5);
                    pla2.addPoint(xx2,yy3);
                    pla2.addPoint(xx2-xsize/8,yy4);
                    g.drawPolygon(pla2);
                    g.fillPolygon(pla2);
         
        if(SliceIt){
            g.setColor(new Color(220,220,220));
            g2d.setComposite(AlphaComposite.getInstance(rule, 0.85f));

            Polygon Slice = new Polygon();
                        Slice.addPoint(xx1+xsize/16,((yy2+(yy4-yy2)/2)+(yy1+(yy3-yy1)/2))/2);
                        Slice.addPoint(xx1+xsize/8,yy1+(yy3-yy1)/2);
                        Slice.addPoint(xx2,yy1+(yy3-yy1)/2);
                        Slice.addPoint(xx2-xsize/16,((yy2+(yy4-yy2)/2)+(yy1+(yy3-yy1)/2))/2);
                        g.drawPolygon(Slice);
                        g.fillPolygon(Slice);
            
            g2d.setComposite(AlphaComposite.getInstance(rule, 1.0f));
            //drawLineThickDashed(g,(double)xx1,yy2+(yy4-yy2)/2,xx2-xsize/8,yy2+(yy4-yy2)/2,1,Color.black);
            //drawLineThickDashed(g,(double)xx1,yy2+(yy4-yy2)/2,xx1+xsize/8,yy1+(yy3-yy1)/2,1,Color.black);
            //drawLineThickDashed(g,xx2,yy1+(yy3-yy1)/2,xx1+xsize/8,yy1+(yy3-yy1)/2,1,Color.black);
            //drawLineThickDashed(g,xx2,yy1+(yy3-yy1)/2,xx2-xsize/8,yy2+(yy4-yy2)/2,1,Color.black);
        }            
                    
        g2d.setComposite(AlphaComposite.getInstance(rule, 1.0f));
        double VRadius = 35.0; //for the voltage generator
        double VCentery = ytop + (ybottom - ytop)/2; // vertical position of voltage generator 
        
        // circuit wires -------------------------------------------------------
        // Wires connecting to the voltage generator
        drawLineThick(g,(double)xleft,(double)ytop,(double)xleft,(double)VCentery - VRadius,3,Color.black);
        drawLineThick(g,(double)xleft,(double)VCentery + VRadius,(double)xleft,(double)ybottom,3,Color.black);
        
        drawLineThick(g,(double)xleft,(double)ytop,(double)xright,(double)ytop,3,Color.black);
        drawLineThick(g,(double)xleft,(double)ybottom,(double)xright,(double)ybottom,3,Color.black);
        // wire connecting to top plate
        drawLineThick(g,(double)xright,(double)ytop,(double)xright,(double)plate1_y,3,Color.black);
        drawCircleThick(g, xright, plate1_y, 3, 6, Color.black);
        
        //----------------------------------------------------------------------
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        if(SliceIt){
            g.setColor(Color.red.darker());
            MaestroG.subscripterSansItalic3("S","2","",g,22,xx1-40,yy1+60*(plate2_y-plate1_y)/80);
        }
        g.setColor(Color.red);
        MaestroG.subscripterSansItalic3("E","","",g,22,xx1+xsize/8,yy4+25);
        MaestroG.subscripterSansItalic3("V","S","",g,22,40,yy1+70*(plate2_y-plate1_y)/80);
        
        g.setColor(Color.blue.darker());
        MaestroG.subscripterSansItalic3("I","2d","",g,22,xright+10,yy4+25);
        //Voltage generator
        drawCircleThick(g, xleft, VCentery, VRadius, 6, Color.blue);
        
        drawLineThick(g,(double)xx2,(double)yy3+10,(double)xx2,(double)yy3+50,2,Color.black);
        drawLineThick(g,(double)xx2,(double)yy3+50,(double)xx2-5,(double)yy3+40,2,Color.black);
        drawLineThick(g,(double)xx2,(double)yy3+50,(double)xx2+5,(double)yy3+40,2,Color.black);
        MaestroG.subscripterSansItalic3("y","","",g,22,xx2+15,yy3+55);
        
        g.setColor(Color.gray);
        //MaestroG.subscripterB("Capacitance","","",g,14,xright,20);
        MaestroG.subscripternew2("C = ","\u03b5","o","\u03b5","r"," (","l \u00d7 w",")","/d","",g,20,xright,45); // NOTE "l" is a lower case L, not "one"
        int delx = (xright+xsize/8-xx1)/100;
        int yA = yy2+17; int yB = yy4-5;
        if(Math.sin(wt) > 0){
            //g.setColor(new Color(255,255-(int)(Math.sin(wt)*255),255-(int)(Math.sin(wt)*255)));
            g2d.setComposite(AlphaComposite.getInstance(rule, (float)(Math.abs(Math.sin(wt)))));
            g.setColor(Color.red);
            g.setFont(TitleFont);
            g.drawString("+", xx1+14*delx, yA);
            g.drawString("+", xx1+29*delx, yA);
            g.drawString("+", xx1+44*delx, yA);
            g.drawString("+", xx1+59*delx, yA);
            g.drawString("+", xx1+74*delx, yA);
            g.drawString("+", xx1+89*delx, yA);
            
            //g.setColor(new Color(255-(int)(Math.sin(wt)*255),255-(int)(Math.sin(wt)*255),255));
            g.setColor(Color.blue);
            g.setFont(TitleFont2);
            g.drawString("-", xx1+14*delx, yB);
            g.drawString("-", xx1+29*delx, yB);
            g.drawString("-", xx1+44*delx, yB);
            g.drawString("-", xx1+59*delx, yB);
            g.drawString("-", xx1+74*delx, yB);
            g.drawString("-", xx1+89*delx, yB);
            
        }
        else if(Math.sin(wt) < 0){
            g2d.setComposite(AlphaComposite.getInstance(rule, (float)(Math.abs(Math.sin(wt)))));
            //g.setColor(new Color(255+(int)(Math.sin(wt)*255),255+(int)(Math.sin(wt)*255),255));
            g.setColor(Color.blue);
            g.setFont(TitleFont2);
            g.drawString("-", xx1+14*delx, yA);
            g.drawString("-", xx1+29*delx, yA);
            g.drawString("-", xx1+44*delx, yA);
            g.drawString("-", xx1+59*delx, yA);
            g.drawString("-", xx1+74*delx, yA);
            g.drawString("-", xx1+89*delx, yA);
            
            //g.setColor(new Color(255,255+(int)(Math.sin(wt)*255),255+(int)(Math.sin(wt)*255)));
            g.setColor(Color.red);
            g.setFont(TitleFont);
            g.drawString("+", xx1+14*delx, yB);
            g.drawString("+", xx1+29*delx, yB);
            g.drawString("+", xx1+44*delx, yB);
            g.drawString("+", xx1+59*delx, yB);
            g.drawString("+", xx1+74*delx, yB);
            g.drawString("+", xx1+89*delx, yB);
        }
        g2d.setComposite(AlphaComposite.getInstance(rule, 1.0f));
        //==============================================================
                // surface cross-section
                g.setColor(Color.blue.darker());
                int newzpos1 = 60;
                int myX2 = plate2_y + 220*(plate2_y-plate1_y)/300;
                double shiftup = 100*(plate2_y-plate1_y)/100-1;
                
                MaestroG.subscripterSansItalic3("I","1c","",g,22,(int)(myX2-shiftup+40),newzpos1-25);
                if(SliceIt){
                    g.setColor(Color.red.darker());
                    MaestroG.subscripterSansItalic3("S","1","",g,22,(int)(myX2-shiftup),newzpos1+120);
                }
                newzpos1 = getSize().height - 60;
                g.setColor(Color.blue.darker());
                MaestroG.subscripterSansItalic3("I","3c","",g,22,(int)(myX2-shiftup+40),newzpos1+30);
                if(SliceIt){
                    g.setColor(Color.red.darker());
                    MaestroG.subscripterSansItalic3("S","3","",g,22,(int)(myX2-shiftup),newzpos1-120);
                }
                
                g.setColor(Color.blue.darker());
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                MaestroG.subsubsubSansItalic3("I","1c"," = I","3c"," = I","2d",g,22,(int)(xright),newzpos1+30);
                //==============================================================
                
    }
    
    
    private synchronized void drawCircuit2(Graphics g){
        
	int ytop = 20*getSize().height/100;
        int ybottom = 80*getSize().height/100;
        
        int xleft = getSize().width/8;
        int xright = 6*getSize().width/8;
        
        int plate1_y = ytop+25*(ybottom-ytop)/100;
        int plate2_y = ytop+75*(ybottom-ytop)/100;
        int xsize = 2*getSize().width/3;
        int ysize = getSize().height/10;
        
        Graphics2D g2d = (Graphics2D)g;
        
        g.setColor(new Color(200,200,200));
        int rule; 
        float alphaG = 0.5f;
        rule = AlphaComposite.SRC_OVER;
        
        int xx1 = xright-xsize/4;
        int xx2 = xright+xsize/4;
        int yy1 = plate1_y-ysize/2;
        int yy2 = plate1_y+ysize/2;
        int yy3 = plate2_y-ysize/2;
        int yy4 = plate2_y+ysize/2;
        
        
        //----------------------------------------------------------------------
        
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
        //----------------------------------------------------------------------
        
        g.setColor(new Color(200,200,225));
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        if(SliceIt){
            g.setColor(new Color(220,220,220));
            g2d.setComposite(AlphaComposite.getInstance(rule, 0.85f));

            Polygon Slice = new Polygon();

                        //Slice.addPoint(xx1,yy2+(yy4-yy2)/2);
                        //Slice.addPoint(xx1+xsize/8,((yy2+(yy4-yy2)/2)+(yy1+(yy3-yy1)/2))/2);
                        Slice.addPoint(xx1,yy2+(yy4-yy2)/2);
                        Slice.addPoint(xx1+xsize/16,((yy2+(yy4-yy2)/2)+(yy1+(yy3-yy1)/2))/2);
                        Slice.addPoint(xx2-xsize/16,((yy2+(yy4-yy2)/2)+(yy1+(yy3-yy1)/2))/2);
                        Slice.addPoint(xx2-xsize/8,yy2+(yy4-yy2)/2);
                        g.drawPolygon(Slice);
                        g.fillPolygon(Slice);
            g2d.setComposite(AlphaComposite.getInstance(rule, 1.0f));
            if(SliceIt){
                drawLineThickDashed(g,(double)xx1,yy2+(yy4-yy2)/2,xx1+xsize/8,yy1+(yy3-yy1)/2,1,Color.gray);
                drawLineThickDashed(g,xx2,yy1+(yy3-yy1)/2,xx1+xsize/8,yy1+(yy3-yy1)/2,1,Color.gray);
            }
            //drawLineThickDashed(g,(double)xx1,yy2+(yy4-yy2)/2,xx2-xsize/8,yy2+(yy4-yy2)/2,1,Color.black);
            //drawLineThickDashed(g,(double)xx1,yy2+(yy4-yy2)/2,xx1+xsize/8,yy1+(yy3-yy1)/2,1,Color.black);
            //drawLineThickDashed(g,xx2,yy1+(yy3-yy1)/2,xx1+xsize/8,yy1+(yy3-yy1)/2,1,Color.black);
            //drawLineThickDashed(g,xx2,yy1+(yy3-yy1)/2,xx2-xsize/8,yy2+(yy4-yy2)/2,1,Color.black);
        }
        
        // vertical right side
        g2d.setComposite(AlphaComposite.getInstance(rule, 0.75f));            
        g.setColor(new Color(200,200,225));
        Polygon face2 = new Polygon();
                    face2.addPoint(xx2-xsize/8,yy2);
                    face2.addPoint(xx2,yy1);
                    face2.addPoint(xx2,yy3);
                    face2.addPoint(xx2-xsize/8,yy4);
                    g.drawPolygon(face2);
                    g.fillPolygon(face2);
                    g.setColor(Color.black);
                    g.drawPolygon(face2);
                    
        g2d.setComposite(AlphaComposite.getInstance(rule, 0.8f));            
        
        g.setColor(new Color(150,100,40));
        Polygon pla2 = new Polygon();
                    pla2.addPoint(xx2-xsize/8,yy4-5);
                    pla2.addPoint(xx2,yy3-5);
                    pla2.addPoint(xx2,yy3);
                    pla2.addPoint(xx2-xsize/8,yy4);
                    g.drawPolygon(pla2);
                    g.fillPolygon(pla2);
        g2d.setComposite(AlphaComposite.getInstance(rule, 0.8f));
        if(SliceIt){
            drawLineThickDashed(g,xx2,yy1+(yy3-yy1)/2,xx2-xsize/8,yy2+(yy4-yy2)/2,1,Color.black);
            drawLineThickDashed(g,(double)xx1,yy2+(yy4-yy2)/2,xx2-xsize/8,yy2+(yy4-yy2)/2,1,Color.black);
        }
        //----------------------------------------------------------------------
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        // permittivity symbol
        g.setColor(Color.black);
        MaestroG.subscripterSansItalic3("\u03b5","r","",g,24,xx2-30,yy1+(plate2_y-plate1_y)/2-20);
        
        g2d.setComposite(AlphaComposite.getInstance(rule, alphaG));
        
        // Bottom plate
        g.setColor(new Color(190,140,80));
        Polygon plate2 = new Polygon();
                    plate2.addPoint(xx1,yy4);
                    plate2.addPoint(xx1+xsize/8,yy3);
                    plate2.addPoint(xx2,yy3);
                    plate2.addPoint(xx2-xsize/8,yy4);
                    //g.drawPolygon(plate2);
                    //g.fillPolygon(plate2);
        g.setColor(Color.black);
                    //g.drawPolygon(plate2);
        
        
        g2d.setComposite(AlphaComposite.getInstance(rule,1.0f));
        
        // left inside edge of top plate
        g.setColor(new Color(80,60,20));
        Polygon pla3 = new Polygon();
                    pla3.addPoint(xx1,yy2);
                    pla3.addPoint(xx1+xsize/8,yy1);
                    pla3.addPoint(xx1+xsize/8,yy1+5);
                    pla3.addPoint(xx1,yy2+5);
                    //g.drawPolygon(pla3);
                    //g.fillPolygon(pla3);
                             
        Polygon pla4 = new Polygon();
                    pla4.addPoint(xx1,yy4-5);
                    pla4.addPoint(xx1+xsize/8,yy3-5);
                    pla4.addPoint(xx1+xsize/8,yy3);
                    pla4.addPoint(xx1,yy4);
                    //g.drawPolygon(pla4);
                    //g.fillPolygon(pla4);
        
        g2d.setComposite(AlphaComposite.getInstance(rule, 0.65f));
        //g.setColor(new Color(230,230,230));
        g.setColor(new Color(200,150,90));
        Polygon plate1 = new Polygon();
                    plate1.addPoint(xx1,yy2);
                    plate1.addPoint(xx1+xsize/8,yy1);
                    plate1.addPoint(xx2,yy1);
                    plate1.addPoint(xx2-xsize/8,yy2);
                    g.drawPolygon(plate1);
                    g.fillPolygon(plate1);
                    g.setColor(Color.black);
                    g.drawPolygon(plate1);
        
        g2d.setComposite(AlphaComposite.getInstance(rule, 0.6f));            
        Polygon face1 = new Polygon();
                    face1.addPoint(xx1,yy2);
                    face1.addPoint(xx2-xsize/8,yy2);
                    face1.addPoint(xx2-xsize/8,yy4);
                    face1.addPoint(xx1,yy4);
                    g.setColor(Color.black);
                    g.drawPolygon(face1);
        
        g2d.setComposite(AlphaComposite.getInstance(rule, 1.0f));            
                    
        //Thickness of capacitor plates (visible edges)            
        g.setColor(new Color(220,170,110));
        g.fillRect(xx1,yy2+1,38*xsize/100-1,5);
        
        g.setColor(new Color(150,100,40));
        Polygon pla1 = new Polygon();
                    pla1.addPoint(xx2-xsize/8,yy2);
                    pla1.addPoint(xx2,yy1);
                    pla1.addPoint(xx2,yy1+5);
                    pla1.addPoint(xx2-xsize/8,yy2+5);
                    g.drawPolygon(pla1);
                    g.fillPolygon(pla1);
                             
        
        double VRadius = 35.0; //for the voltage generator
        double VCentery = ytop + (ybottom - ytop)/2; // vertical position of voltage generator 
        
        // wire connecting to top plate
        drawLineThick(g,(double)xright,(double)ytop,(double)xright,(double)plate1_y,3,Color.black);
        drawCircleThick(g, xright, plate1_y, 3, 6, Color.black);
        
        
        
    }
    //==========================================================================
    
    public synchronized void ignition(){
	Orth_Axis_Front = (int)(0.55*getSize().height/2);
	Orth_Axis_Back  = (int)(0.55*getSize().height/2);
         
        VPos = getSize().height - BottomMargin;
	WIDTH = getSize().width - LeftMargin -RightMargin;
	HEIGHT = VPos - TopMargin;
		
	N = z.length;
	//Find the boundaries for data
	if(!IsXRangeMaxSet){ xmax = MaestroA.getMax(EField_z);}
	if(!IsXRangeMinSet){ xmin = MaestroA.getMin(EField_z);}
		
    	if(!IsYRangeMaxSet){ ymax = MaestroA.getMax(HField_z);}
	if(!IsYRangeMinSet){ ymin = MaestroA.getMin(HField_z);}
	
        if(!IsZRangeMaxSet){ zmax = z[z.length-1];}
	if(!IsZRangeMinSet){ zmin = z[0]; }
	
	//Confine data
	MaestroA.confiner(z,zmax,zmin);
	MaestroA.confiner(HField_z,ymax,ymin);
	MaestroA.confiner(EField_z,xmax,xmin);
        MaestroA.confiner(PField_z,pmax,pmin);
	int myY;
	
        for(int i = 0; i < zx.length; i++){
		zx[i] = (int)MaestroA.mapper(z[i],(double)(getSize().width-RightMargin),(double)LeftMargin,zmax,zmin);
		Field_zx[i] = (int)MaestroA.mapper(EField_z[i],(double)TopMargin,(double)(getSize().height-BottomMargin),xmax,xmin);
		Field_zp[i] = (int)MaestroA.mapper(PField_z[i],(double)TopMargin2,
                              (double)(getSize().height-BottomMargin2),pmax,pmin);
                
		zy[i] = zx[i] + (int)MaestroA.mapper(costhetanew*HField_z[i],Orth_Axis_Front,-Orth_Axis_Back,ymax,ymin);	
    		Field_zy[i] = (int)MaestroA.mapper(sinthetanew*HField_z[i],(double)TopMargin,(double)getSize().height-BottomMargin,ymin,ymax);
        } 	
        
    }
    
    private synchronized void drawRotor(Graphics g){
        Graphics2D g2d = (Graphics2D)g;
        
	int myX, myZ;
	int current_z;
	int yref = TopMargin+(getSize().height-BottomMargin-TopMargin)/2;
        
        g.setColor(rotorcolor);
	for(int i = 0; i< 1 ; i++){ // i<1 only shows one thick line ; i<2 also shows thick line at end of domain
            current_z = (int)(zpos[i]*(zx.length)/(zmax-zmin));
            if(current_z>=zx.length){current_z = zx.length-1;}
            if(current_z<0){current_z=0;}

                myX = (int)MaestroA.mapper(0,(double)TopMargin,(double)VPos,xmax,xmin);
                myZ = (int)MaestroA.mapper(z[current_z],(double)(getSize().width-RightMargin),(double)LeftMargin,zmax,zmin);
                if(IsEon){// electric field
                    if(Field_zx[current_z] < yref){
                        drawLineThick(g,zx[current_z],Field_zx[current_z]+1,myZ,myX,3,Color.red.brighter());
                    }
                    else{
                        drawLineThick(g,zx[current_z],Field_zx[current_z]-1,myZ,myX,3,Color.red.brighter());
                    }
                }
                
                int axis2 = 100;
                // cursor line
                float[] dashPattern2 = {5,5};
                g2d.setStroke(new BasicStroke(1.0F,BasicStroke.CAP_BUTT,BasicStroke.JOIN_MITER,10.0F,dashPattern2,0));
                if(i==0){
                    g.setColor(Color.lightGray);
                   
                    if(refz){
                        g.drawLine(myZ-1,60,myZ-1,yref + axis2); 
                        g.drawLine(myZ-1,yref + axis2 + 35,myZ-1,getSize().height-55); 
                    }
                }
                g2d.setStroke(new BasicStroke(1.0F,BasicStroke.CAP_BUTT,BasicStroke.JOIN_MITER));
        }
    }
    
    private synchronized void drawPoints(Graphics g, int tipo){
        Graphics2D g2d = (Graphics2D)g;
          
	switch(tipo){
	    case 1:
		{
		   g.setColor(Color.black);
		   g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
                      //g.drawPolyline(zx,Field_zx,zx.length);
                        for(int i = 0; i < zx.length-1; i++){
			    //g.drawLine(zx[i],Field_zx[i],zx[i+1],Field_zx[i+1]);
                            drawLineThick(g,(double)zx[i],(double)Field_zx[i],(double)zx[i+1],(double)Field_zx[i+1],2,Color.black);
                        }
                    drawRefPoints(g);
                    g.setColor(Color.black);
		}
		break;
	    case 2:
		g.setColor(bgcolor);
                if(IsEon){g.drawPolyline(zx_old,Field_zx_old,zx_old.length);} // draw electri field
                if(IsHon){g.drawPolyline(zy_old,Field_zy_old,zy_old.length);} // draw magnetic field
		g.drawPolyline(zx_old,Field_zp_old,zx_old.length); // draw power
                break;
	}
    }
    
    private synchronized void drawRefPoints(Graphics g){
	Graphics2D g2d = (Graphics2D)g;
        int rule; 
        float alphaG = 0.7f;
        rule = AlphaComposite.SRC_OVER;
        g2d.setComposite(AlphaComposite.getInstance(rule, alphaG));
        
        int myX2;
	
        int Len = 20;
        int ytop = getSize().height/6;
        int ybottom = 5*getSize().height/6;
        
        int xleft = getSize().width/8;
        int xright = 6*getSize().width/8;
        int plate1_y = ytop+(ybottom-ytop)/3;
        int plate2_y = ytop+2*(ybottom-ytop)/3;
        int xsize = 2*getSize().width/8;
        int ysize = getSize().height/10;
        
        int xx1 = xright-xsize/4;
        int xx2 = xright+xsize/4;
        int yy1 = plate1_y-ysize/2;
        int yy2 = plate1_y+ysize/2;
        int yy3 = plate2_y-ysize/2;
        int yy4 = plate2_y+ysize/2;
        
        myX2 = plate2_y + 220*(plate2_y-plate1_y)/300;
        
        int Narrows = 7;
        int zpos1 = xright - xsize/2;
        
        for(int i = 0; i < Narrows; i++){    
            g.setColor(Color.magenta.darker()); // this is for current
            zpos1 = xright - 60*xsize/100 + i*xsize/Narrows;
            
            int myE = 90;
            double checkE = Math.abs(Field_zp[myE]- myX2);
            double check2E = checkE/(double)Len;
            double check = Math.abs(Field_zp[0]- myX2);
            double check2 = check/(double)Len;
            int mythick = 2;
            
            double Ax = 3.0;
            double Ay = 6.0;
            int tx = (int)(Ax*check2);
            int ty = (int)(Ay*check2);
            
            int txE = (int)(Ax*check2E);
            int tyE = (int)(Ay*check2E);
            
            double shiftup = 100*(plate2_y-plate1_y)/100-1;
            
            Color mycolor = Color.red;
            Color mycolor2 = Color.blue;
            
            int tune1, tune2;
            tune1 = xsize/8+11;
            tune2 = (yy4-yy2)/4-2;
            
            // ELECTRIC FIELD VECTOR LINES IN CAPACITOR
            if(i != 3){
                g2d.setComposite(AlphaComposite.getInstance(rule, alphaG));
                if(Field_zp[myE] < myX2){
                    if(checkE > Len){
                        drawLineThick(g,(double)zpos1+tune1,(double)Field_zp[myE]-shiftup-tune2,(double)zpos1-Ax+tune1,(double)Field_zp[myE]+Ay-shiftup-tune2,mythick,mycolor);
                        drawLineThick(g,(double)zpos1+tune1,(double)Field_zp[myE]-shiftup-tune2,(double)zpos1+Ax+tune1,(double)Field_zp[myE]+Ay-shiftup-tune2,mythick,mycolor);
                    }
                    else{
                        drawLineThick(g,(double)zpos1+tune1,(double)Field_zp[myE]-shiftup-tune2,(double)(zpos1-txE)+tune1,(double)(Field_zp[myE]+tyE)-shiftup-tune2,mythick,mycolor);
                        drawLineThick(g,(double)zpos1+tune1,(double)Field_zp[myE]-shiftup-tune2,(double)(zpos1+txE)+tune1,(double)(Field_zp[myE]+tyE)-shiftup-tune2,mythick,mycolor);
                    }
                }
                else{
                    if(checkE > Len){
                        drawLineThick(g,(double)zpos1+tune1,(double)Field_zp[myE]-shiftup-tune2,(double)zpos1-Ax+tune1,(double)Field_zp[myE]-Ay-shiftup-tune2,mythick,mycolor);
                        drawLineThick(g,(double)zpos1+tune1,(double)Field_zp[myE]-shiftup-tune2,(double)zpos1+Ax+tune1,(double)Field_zp[myE]-Ay-shiftup-tune2,mythick,mycolor);
                    }
                    else{
                        drawLineThick(g,(double)zpos1+tune1,(double)Field_zp[myE]-shiftup-tune2,(double)(zpos1-txE)+tune1,(double)(Field_zp[myE]-tyE)-shiftup-tune2,mythick,mycolor);
                        drawLineThick(g,(double)zpos1+tune1,(double)Field_zp[myE]-shiftup-tune2,(double)(zpos1+txE)+tune1,(double)(Field_zp[myE]-tyE)-shiftup-tune2,mythick,mycolor);
                    }
                }
                drawLineThick(g,(double)zpos1+tune1,(double)Field_zp[myE]-shiftup-tune2,(double)zpos1+tune1,myX2-shiftup-((double)Field_zp[myE]-myX2)-1-tune2,mythick,mycolor);
            }
            else{ // DISPLACEMENT CURRENT VECTOR IN CAPACITOR
                g2d.setComposite(AlphaComposite.getInstance(rule, alphaG));
                if(Field_zp[0] < myX2){
                    if(check > Len){
                        drawLineThick(g,(double)zpos1+tune1,(double)Field_zp[0]-shiftup-tune2,(double)zpos1-2*Ax+tune1,(double)Field_zp[0]+2*Ay-shiftup-tune2,4,mycolor2);
                        drawLineThick(g,(double)zpos1+tune1,(double)Field_zp[0]-shiftup-tune2,(double)zpos1+2*Ax+tune1,(double)Field_zp[0]+2*Ay-shiftup-tune2,4,mycolor2);
                    }
                    else{
                        drawLineThick(g,(double)zpos1+tune1,(double)Field_zp[0]-shiftup-tune2,(double)(zpos1-2*tx)+tune1,(double)(Field_zp[0]+2*ty)-shiftup-tune2,4,mycolor2);
                        drawLineThick(g,(double)zpos1+tune1,(double)Field_zp[0]-shiftup-tune2,(double)(zpos1+2*tx)+tune1,(double)(Field_zp[0]+2*ty)-shiftup-tune2,4,mycolor2);
                    }
                }
                else{
                    if(check > Len){
                        drawLineThick(g,(double)zpos1+tune1,(double)Field_zp[0]-shiftup-tune2,(double)zpos1-2*Ax+tune1,(double)Field_zp[0]-2*Ay-shiftup-tune2,4,mycolor2);
                        drawLineThick(g,(double)zpos1+tune1,(double)Field_zp[0]-shiftup-tune2,(double)zpos1+2*Ax+tune1,(double)Field_zp[0]-2*Ay-shiftup-tune2,4,mycolor2);
                    }
                    else{
                        drawLineThick(g,(double)zpos1+tune1,(double)Field_zp[0]-shiftup-tune2,(double)(zpos1-2*tx)+tune1,(double)(Field_zp[0]-2*ty)-shiftup-tune2,4,mycolor2);
                        drawLineThick(g,(double)zpos1+tune1,(double)Field_zp[0]-shiftup-tune2,(double)(zpos1+2*tx)+tune1,(double)(Field_zp[0]-2*ty)-shiftup-tune2,4,mycolor2);
                    }
                }
                drawLineThick(g,(double)zpos1+tune1,(double)Field_zp[0]-shiftup-tune2,(double)zpos1+tune1,myX2-shiftup-((double)Field_zp[0]-myX2)-1-tune2,4,mycolor2);
                
            }
            
            g2d.setComposite(AlphaComposite.getInstance(rule, 1.0f));
            
            //  CURRENT DIRECT PATH ON TOP WIRE
            int newzpos1 = 60;
                
                if(Field_zp[0] < myX2){
                    if(check > Len){
                        drawLineThick(g,(double)Field_zp[0]-shiftup,(double)newzpos1,(double)Field_zp[0]+2*Ay-shiftup,(double)newzpos1-2*Ax,4,mycolor2);
                        drawLineThick(g,(double)Field_zp[0]-shiftup,(double)newzpos1,(double)Field_zp[0]+2*Ay-shiftup,(double)newzpos1+2*Ax,4,mycolor2);
                    }
                    else{
                        drawLineThick(g,(double)Field_zp[0]-shiftup,(double)newzpos1,(double)(Field_zp[0]+2*ty)-shiftup,(double)(newzpos1-2*tx),4,mycolor2);
                        drawLineThick(g,(double)Field_zp[0]-shiftup,(double)newzpos1,(double)(Field_zp[0]+2*ty)-shiftup,(double)(newzpos1+2*tx),4,mycolor2);
                    }
                }
                else{
                    if(check > Len){
                        drawLineThick(g,(double)Field_zp[0]-shiftup,(double)newzpos1,(double)Field_zp[0]-2*Ay-shiftup,(double)newzpos1-2*Ax,4,mycolor2);
                        drawLineThick(g,(double)Field_zp[0]-shiftup,(double)newzpos1,(double)Field_zp[0]-2*Ay-shiftup,(double)newzpos1+2*Ax,4,mycolor2);
                    }
                    else{
                        drawLineThick(g,(double)Field_zp[0]-shiftup,(double)newzpos1,(double)(Field_zp[0]-2*ty)-shiftup,(double)(newzpos1-2*tx),4,mycolor2);
                        drawLineThick(g,(double)Field_zp[0]-shiftup,(double)newzpos1,(double)(Field_zp[0]-2*ty)-shiftup,(double)(newzpos1+2*tx),4,mycolor2);
                    }
                }
                
                drawLineThick(g,(double)Field_zp[0]-shiftup,(double)newzpos1,myX2-shiftup-((double)Field_zp[0]-myX2)-1,(double)newzpos1,4,mycolor2);
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                
                if(SliceIt){
                    drawLineThickDashed(g,myX2-shiftup,(double)newzpos1-40.0,myX2-shiftup,(double)newzpos1+90.0,1,Color.green.darker());
                    
                    g2d.setComposite(AlphaComposite.getInstance(rule, 0.75f));            
                    g.setColor(new Color(230,230,230));
                    Polygon surf1 = new Polygon();
                    surf1.addPoint((int)(myX2-shiftup-20),(int)(newzpos1-30.0));
                    surf1.addPoint((int)(myX2-shiftup+20),(int)(newzpos1-50.0));
                    surf1.addPoint((int)(myX2-shiftup+20),(int)(newzpos1+80.0));
                    surf1.addPoint((int)(myX2-shiftup-20),(int)(newzpos1+100.0));
                    g.drawPolygon(surf1);
                    g.fillPolygon(surf1);
                    g.setColor(Color.black);
                    g.drawPolygon(surf1);
                    // wire above surface
                    drawLineThick(g,myX2-shiftup,(double)(20*getSize().height/100),myX2-shiftup+50,(double)(20*getSize().height/100),3,Color.black);
                    // curent above surface
                    g2d.setComposite(AlphaComposite.getInstance(rule, 1.0f));
                    if((myX2-shiftup)>(myX2-shiftup-((double)Field_zp[0]-myX2)-1)){
                        drawLineThick(g,myX2-shiftup,(double)newzpos1,(double)Field_zp[0]-shiftup,(double)newzpos1,4,mycolor2);
                        if(check > Len){
                            drawLineThick(g,(double)Field_zp[0]-shiftup,(double)newzpos1,(double)Field_zp[0]-2*Ay-shiftup,(double)newzpos1-2*Ax,4,mycolor2);
                            drawLineThick(g,(double)Field_zp[0]-shiftup,(double)newzpos1,(double)Field_zp[0]-2*Ay-shiftup,(double)newzpos1+2*Ax,4,mycolor2);
                        }
                        else{
                            drawLineThick(g,(double)Field_zp[0]-shiftup,(double)newzpos1,(double)(Field_zp[0]-2*ty)-shiftup,(double)(newzpos1-2*tx),4,mycolor2);
                            drawLineThick(g,(double)Field_zp[0]-shiftup,(double)newzpos1,(double)(Field_zp[0]-2*ty)-shiftup,(double)(newzpos1+2*tx),4,mycolor2);
                        }   
                    }
                    else{
                        drawLineThick(g,myX2-shiftup,(double)newzpos1,myX2-shiftup-((double)Field_zp[0]-myX2)-1,(double)newzpos1,4,mycolor2);
                    }
                }
                 
                //  CURRENT RETURN PATH ON LOWER WIRE
                newzpos1 = getSize().height - 60;
                
                double shiftup2;
                int tune = 11; // to position arrowhead properly
                if(Field_zp[0] < myX2){
                    if(check > Len){
                        shiftup2 = shiftup+tune;
                        drawLineThick(g,myX2-shiftup2-((double)Field_zp[0]-myX2)-1+2*Ay,(double)newzpos1,myX2-shiftup2-((double)Field_zp[0]-myX2)-1,(double)newzpos1-2*Ax,4,mycolor2);
                        drawLineThick(g,myX2-shiftup2-((double)Field_zp[0]-myX2)-1+2*Ay,(double)newzpos1,myX2-shiftup2-((double)Field_zp[0]-myX2)-1,(double)newzpos1+2*Ax,4,mycolor2);
                    }
                    else{
                        shiftup2 = shiftup+tune;
                        drawLineThick(g,myX2-shiftup2-((double)Field_zp[0]-myX2)-1+2*Ay,(double)newzpos1,myX2-shiftup2-((double)Field_zp[0]-myX2)-1+2*(Ay-ty),(double)(newzpos1-2*tx),4,mycolor2);
                        drawLineThick(g,myX2-shiftup2-((double)Field_zp[0]-myX2)-1+2*Ay,(double)newzpos1,myX2-shiftup2-((double)Field_zp[0]-myX2)-1+2*(Ay-ty),(double)(newzpos1+2*tx),4,mycolor2);
                    }
                }
                else{
                    if(check > Len){
                        shiftup2 = shiftup-tune;
                        drawLineThick(g,myX2-shiftup2-((double)Field_zp[0]-myX2)-1-2*Ay,(double)newzpos1,myX2-shiftup2-((double)Field_zp[0]-myX2)-1,(double)newzpos1-2*Ax,4,mycolor2);
                        drawLineThick(g,myX2-shiftup2-((double)Field_zp[0]-myX2)-1-2*Ay,(double)newzpos1,myX2-shiftup2-((double)Field_zp[0]-myX2)-1,(double)newzpos1+2*Ax,4,mycolor2);
                    }
                    else{
                        shiftup2 = shiftup-tune;
                        drawLineThick(g,myX2-shiftup2-((double)Field_zp[0]-myX2)-1-2*Ay,(double)newzpos1,myX2-shiftup2-((double)Field_zp[0]-myX2)-1-2*(Ay-ty),(double)(newzpos1-2*tx),4,mycolor2);
                        drawLineThick(g,myX2-shiftup2-((double)Field_zp[0]-myX2)-1-2*Ay,(double)newzpos1,myX2-shiftup2-((double)Field_zp[0]-myX2)-1-2*(Ay-ty),(double)(newzpos1+2*tx),4,mycolor2);
                    }
                }
                
                drawLineThick(g,(double)Field_zp[0]-shiftup,(double)newzpos1,myX2-shiftup-((double)Field_zp[0]-myX2)-1,(double)newzpos1,4,mycolor2);
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                
                // surface cross-section
                if(SliceIt){
                    drawLineThickDashed(g,myX2-shiftup,(double)newzpos1+40.0,myX2-shiftup,(double)newzpos1-90.0,1,Color.green.darker());
                    
                    //LOWER WIRE CURRENT
                    g2d.setComposite(AlphaComposite.getInstance(rule, 0.75f));            
                    g.setColor(new Color(230,230,230));
                    Polygon surf2 = new Polygon();
                    surf2.addPoint((int)(myX2-shiftup-20),(int)(newzpos1+50.0));
                    surf2.addPoint((int)(myX2-shiftup+20),(int)(newzpos1+30.0));
                    surf2.addPoint((int)(myX2-shiftup+20),(int)(newzpos1-100.0));
                    surf2.addPoint((int)(myX2-shiftup-20),(int)(newzpos1-80.0));
                    g.drawPolygon(surf2);
                    g.fillPolygon(surf2);
                    g.setColor(Color.black);
                    g.drawPolygon(surf2);
                    // wire above surface
                    drawLineThick(g,myX2-shiftup,(double)(80*getSize().height/100),myX2-shiftup+50,(double)(80*getSize().height/100),3,Color.black);
                    // curent above surface
                    g2d.setComposite(AlphaComposite.getInstance(rule, 1.0f));
                    if((myX2-shiftup)>(myX2-shiftup-((double)Field_zp[0]-myX2)-1)){
                        drawLineThick(g,myX2-shiftup,(double)newzpos1,(double)Field_zp[0]-shiftup,(double)newzpos1,4,mycolor2);
                    }
                    else{
                        drawLineThick(g,myX2-shiftup,(double)newzpos1,myX2-shiftup-((double)Field_zp[0]-myX2)-1,(double)newzpos1,4,mycolor2);
                        if(check > Len){
                        shiftup2 = shiftup+tune;
                        drawLineThick(g,myX2-shiftup2-((double)Field_zp[0]-myX2)-1+2*Ay,(double)newzpos1,myX2-shiftup2-((double)Field_zp[0]-myX2)-1,(double)newzpos1-2*Ax,4,mycolor2);
                        drawLineThick(g,myX2-shiftup2-((double)Field_zp[0]-myX2)-1+2*Ay,(double)newzpos1,myX2-shiftup2-((double)Field_zp[0]-myX2)-1,(double)newzpos1+2*Ax,4,mycolor2);
                    }
                    else{
                        shiftup2 = shiftup+tune;
                        drawLineThick(g,myX2-shiftup2-((double)Field_zp[0]-myX2)-1+2*Ay,(double)newzpos1,myX2-shiftup2-((double)Field_zp[0]-myX2)-1+2*(Ay-ty),(double)(newzpos1-2*tx),4,mycolor2);
                        drawLineThick(g,myX2-shiftup2-((double)Field_zp[0]-myX2)-1+2*Ay,(double)newzpos1,myX2-shiftup2-((double)Field_zp[0]-myX2)-1+2*(Ay-ty),(double)(newzpos1+2*tx),4,mycolor2);
                    }
                    }
                }
                
        }
    }
    
    private void drawLineThick(Graphics g, double x1, double y1, double x2, double y2, int thick, Color color){
	
        Graphics2D g2d = (Graphics2D)g;
        g2d.setPaint(color);
        g2d.setStroke(new BasicStroke(thick,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
        
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
        Line2D.Double line = new Line2D.Double(x1,y1,x2,y2);
        g2d.draw(line);
  
        g2d.setStroke(new BasicStroke(1));
        //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
    }
    
    public static void drawLineThickDashed(Graphics g, double x1, double y1, double x2, double y2, int thick, Color color){
	
        Graphics2D g2d = (Graphics2D)g;
        g2d.setPaint(color);
        float[] dashPattern = {10,10};// Add these lines to make line dotted
        g2d.setStroke(new BasicStroke(thick,BasicStroke.CAP_BUTT,BasicStroke.JOIN_MITER,10.0F,dashPattern,0));
        
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
        Line2D.Double line = new Line2D.Double(x1,y1,x2,y2);
        g2d.draw(line);
  
        g2d.setStroke(new BasicStroke(1));
        //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
    }
    

    private void labelDetect(){
	X1 = "E (x, t)";
	X2 = "H (y, t)";
    }
    
    private void drawLabels(Graphics g){
	String tmp;
	int yref = TopMargin+(getSize().height-BottomMargin-TopMargin)/2;
        
        g.setFont(LabelFont);
	FontMetrics fm = g.getFontMetrics();
	
        g.setColor(Color.black);
        Graphics2D g2d = (Graphics2D)g;
	g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        // z axis legends
        tmp = Z1;
	MaestroG.subscripter(tmp,"","",g,13,LeftMargin-3*fm.stringWidth(tmp)/2,VPos+fm.getHeight()-5+down);
        tmp = Z2+" = "+total_length+" \u03bb";
	MaestroG.subscripterSansItalic6("h",""," = "+MaestroA.rounder(total_length,6)," \u03bb",g,13,getSize().width-RightMargin-fm.stringWidth(tmp)/3+2,VPos+fm.getHeight()-5+down);
	g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
        g.setFont(LabelFont);
        g.setColor(Color.red);
        
        tmp="Ex( t )";
	if(IsEon){MaestroG.subscripter("E","x","(t)",g,13,LeftMargin-fm.stringWidth(tmp)-20,TopMargin+fm.getHeight());
        	  //MaestroG.subscripterSansItalic3("E","x","( t )",g,15,LeftMargin-fm.stringWidth(tmp)-20,TopMargin+fm.getHeight());
        }

        g.setColor(Color.blue);
	if(IsHon){MaestroG.subscripter("H","y","(t)",g,13,12,yref+10);
                //MaestroG.subscripterSansItalic3("H","y","( t )",g,15,12,yref+10);
        }
        
        g.setColor(Color.magenta.darker());
	MaestroG.subscripter("J","x","(z,t)",g,13,LeftMargin-fm.stringWidth(tmp)-20,Decay3[0]);
        //MaestroG.subscripterSansItalic3("J","x","(z,t)",g,15,LeftMargin-fm.stringWidth(tmp)-25,Decay3[0]);
        g.setColor(Color.black);
	MaestroG.subscripterSansItalic3("z","","",g,16,getSize().width-55,yref-5);
        MaestroG.subscripterSansItalic3("z","","",g,16,getSize().width-55,VPos+down2-10);
        
        
    }
    
    private void drawZeroLine(Graphics g){
	int myX;
	myX = (int)MaestroA.mapper(0,(double)TopMargin,(double)VPos,xmax,xmin);
	g.setColor(Color.red);
	g.drawLine(LeftMargin+1,myX,getSize().width-RightMargin-1,myX);
    }
    
    
    public synchronized void reset(){
	IsYRangeMaxSet = false;
	IsYRangeMinSet = false;
	IsXRangeMaxSet = false;
	IsXRangeMinSet = false;
        IsPRangeMaxSet = false;
	IsPRangeMinSet = false;
	IsZRangeMinSet = false;
	IsZRangeMaxSet = false;
	IsTraceOn = false;
	IsCleanUpOn = false;
    }
    
    public synchronized void cleanUp(){
	IsCleanUpOn=true;
    }
    
    public synchronized void setYRangeMax(double ymax){
	this.ymax = ymax;
	IsYRangeMaxSet = true;
    }
    
    public synchronized void setYRangeMin(double ymin){
	this.ymin = ymin;
	IsYRangeMinSet = true;
    }
    
    public synchronized void setZRangeMax(double zmax){
	this.zmax = zmax;
	IsZRangeMaxSet = true;
    }
    
    public synchronized void setZRangeMin(double zmin){
	this.zmin = zmin;
	IsZRangeMinSet = true;
    }
    
    public synchronized void setXRangeMax(double xmax){
	this.xmax = xmax;
	IsXRangeMaxSet = true;
    }
    
    public synchronized void setXRangeMin(double xmin){
	this.xmin = xmin;
	IsXRangeMinSet = true;
    }
    
    public synchronized void setTrace(boolean IsTraceOn){
	this.IsTraceOn = IsTraceOn;
	this.clean_memory();
    }
    
    public synchronized void setDynamics(boolean IsDynamic){
	this.IsDynamic = IsDynamic;
    }
    

    public void update(Graphics g){
	if(!IsDynamic){
	    paint(g);
	    return;
	}
	if(IsDynamic && IsTraceOn){g.clipRect(LeftMargin+1,TopMargin+1,WIDTH-1,HEIGHT-1);}
	if(IsCleanUpOn){
	    g.clearRect(0,0,getSize().width,getSize().height);
	    IsCleanUpOn = false;
	    //drawAxis(g);
	    //drawLabels(g);
            drawCircuit(g);
	}
	drawZeroLine(g);
	if(!IsTraceOn){
	    //drawPoints(g,2);//This cleans the previous graph
            drawCircuit(g);//This cleans the previous graph
	}
	//drawPoints(g,1);//This draws the new graph
	//drawAxis(g);
	//drawRotor(g);
	drawCircuit(g);
        
        push();
    }
    
    
    public synchronized void plot(double xdata[], double tEField_z[], double tHField_z[], double tPField_z[], double tau){
   
        
	if(N != xdata.length){
	    N = xdata.length;
	    z = new double[N];
	    EField_z = new double[N];
	    HField_z = new double[N];
	    PField_z = new double[N];
	    zx = new int[N];
	    zy = new int[N];
	}
	for(int i = 0; i < N; i++){
	    z[i] = xdata[i];
	    EField_z[i] = tEField_z[i] * E_ratio;
	    HField_z[i] = tHField_z[i] * H_ratio ;
	    PField_z[i] = tPField_z[i] * P_ratio ;
	}
	//ignition();
	
	N = z.length;
	//Find the boundaries for data
	if(!IsXRangeMaxSet){ xmax = MaestroA.getMax(EField_z);}
	if(!IsXRangeMinSet){ xmin = MaestroA.getMin(EField_z);}
		
    	if(!IsYRangeMaxSet){ ymax = MaestroA.getMax(HField_z);}
	if(!IsYRangeMinSet){ ymin = MaestroA.getMin(HField_z);}
	if(!IsPRangeMaxSet){ pmax = MaestroA.getMax(PField_z);}
	if(!IsPRangeMinSet){ pmin = MaestroA.getMin(PField_z);}
	
	if(!IsZRangeMaxSet){ zmax = z[z.length-1];}
	if(!IsZRangeMinSet){ zmin = z[0]; }
	
	//Confine data
	MaestroA.confiner(z,zmax,zmin);
	MaestroA.confiner(HField_z,ymax,ymin);
	MaestroA.confiner(EField_z,xmax,xmin);
        MaestroA.confiner(PField_z,pmax,pmin);
        
	int myY;
	double Deltax = total_length*wavelength/zx.length;
	double angle = 140.0;
	double costhetanew,sinthetanew;
        
        costhetanew = Math.cos(angle*Math.PI/180.0);    
	sinthetanew = Math.sin(angle*Math.PI/180.0);
        int yref = TopMargin+(getSize().height-BottomMargin-TopMargin)/2;
        
        int ytop = getSize().height/6;
        int ybottom = 5*getSize().height/6;
        
        int xleft = getSize().width/8;
        int xright = 6*getSize().width/8;
        
        int plate1_y = ytop+(ybottom-ytop)/3;
        int plate2_y = ytop+2*(ybottom-ytop)/3;
        int xsize = 2*getSize().width/3;
        int ysize = getSize().height/10;    
        
        double VRadiusy = 15.0; //for the voltage generator
        double VRadiusx = 25.0; //for the voltage generator
        double VCentery = ytop + (ybottom - ytop)/2; // vertical position of voltage generator 
	
        for(int i = 0; i < zx.length; i++){
		double Factor1 = Ex*Math.exp(-alpha*Deltax*i);
		double Factor2 = Hy*Math.exp(-alpha*Deltax*i);
		double Factor3 = Ex*Math.exp(-alpha*Deltax*i);
                zx[i] = (int)MaestroA.mapper(z[i],(double)xleft+VRadiusx,(double)xleft-VRadiusx,zmax,zmin);
		//Field_zx[i] = (int)MaestroA.mapper(EField_z[i],(double)TopMargin,(double)(getSize().height-BottomMargin),xmax,xmin);
                Field_zx[i] = (int)MaestroA.mapper(EField_z[i],(double)VCentery-VRadiusy,(double)VCentery+VRadiusy,xmax,xmin);
                
		Decay1[i] = (int)MaestroA.mapper(Factor1*E_ratio,(double)TopMargin,(double)(getSize().height-BottomMargin),xmax,xmin);
		Decay1B[i] = yref + (yref - Decay1[i]);
                Field_zp[i] = (int)MaestroA.mapper(PField_z[i],(double)TopMargin2,(double)(getSize().height-BottomMargin2-80),pmax,pmin);
		Decay3[i] = (int)MaestroA.mapper(Factor3*E_ratio,(double)TopMargin2,(double)(getSize().height-BottomMargin2-80),pmax,pmin);
		
		zy[i] = zx[i] + (int)MaestroA.mapper(costhetanew*HField_z[i],Orth_Axis_Front,-Orth_Axis_Back,ymax,ymin);	
		
    		Field_zy[i] = (int)MaestroA.mapper(sinthetanew*HField_z[i],(double)TopMargin,(double)getSize().height-BottomMargin,ymin,ymax);
		zy2[i] = zx[i] + (int)MaestroA.mapper(costhetanew*Factor2*H_ratio,Orth_Axis_Front,-Orth_Axis_Back,ymax,ymin);	
		Decay2[i] = (int)MaestroA.mapper(sinthetanew*Factor2*H_ratio,(double)TopMargin,(double)getSize().height-BottomMargin,ymin,ymax);
                zy2B[i] = zx[i] - (int)MaestroA.mapper(costhetanew*Factor2*H_ratio,Orth_Axis_Front,-Orth_Axis_Back,ymax,ymin);	
		Decay2B[i] = (int)MaestroA.mapper(-sinthetanew*Factor2*H_ratio,(double)TopMargin,(double)getSize().height-BottomMargin,ymin,ymax);
	} 
        
	repaint();
    }
    
    private void drawCircleThick(Graphics g, double xCenter, double yCenter, double Radius, int thick, Color color){
	
        Graphics2D g2d = (Graphics2D)g;
        g2d.setPaint(color);
        g2d.setStroke(new BasicStroke(thick, BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL));
        
        //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
        Ellipse2D.Double circle = new Ellipse2D.Double(xCenter-Radius,yCenter-Radius,2*Radius,2*Radius);
        g2d.draw(circle);
        g2d.setStroke(new BasicStroke(1));
        //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
}
    
    private synchronized void push(){
	if(zx.length != zx_old.length){
	    zx_old = new int[zx.length];
	    zy_old = new int[zx.length];
	    Field_zx_old = new int[zx.length];
	    Field_zy_old = new int[zx.length];
            Field_zp_old = new int[zx.length];
	}
    
	for(int i = 0; i < zx.length; i++){
	    zx_old[i] = zx[i];
	    zy_old[i] = zy[i];
	    Field_zx_old[i] = Field_zx[i];
	    Field_zy_old[i] = Field_zy[i];
            Field_zp_old[i] = Field_zp[i];
	}
    }
    
     private void clean_memory(){
	if(zx.length != zx_old.length){
	    zx_old = new int[zx.length];
	    zy_old = new int[zx.length];
	    Field_zx_old = new int[zx.length];
            Field_zy_old = new int[zx.length];
            Field_zp_old = new int[zx.length];
	}
    
	for(int i = 0; i < zx.length; i++){
	    zx_old[i] = zx[i];
	    zy_old[i] = zy[i];
	    Field_zx_old[i] = 0;
	    Field_zy_old[i] = 0;
            Field_zp_old[i] = 0;
	}
    }
    
    
    public synchronized void setTitle(String TITLE){
	this.TITLE = TITLE;
    }
    
    public synchronized void setLabels(String Z1, String Z2, String X1, String X2){
	this.Z1 = Z1;
	this.Z2 = Z2;
	this.X1 = X1;
	this.X2 = X2;
    }
    
    public synchronized void setMargins(int LeftMargin, int RightMargin, int TopMargin, int BottomMargin){
	this.LeftMargin = LeftMargin;
	this.RightMargin = RightMargin;
	this.TopMargin = TopMargin;
	this.BottomMargin = BottomMargin;
    }
    
    public synchronized void setPlanes(double zpos1, double zpos2, boolean refz){
	this.zpos[0] = zpos1;
	this.zpos[1] = zpos2;
        this.refz = refz;
    }
    
    public synchronized void setRotor(int current_z){
	this.current_z = current_z;
	if(current_z >= zx.length){ current_z = zx.length-1; }
    }
    
    public synchronized void setAlpha(double alpha, double beta, double frequency, double wt){
	this.alpha = alpha;
        this.beta = beta;
        this.frequency = frequency;
        this.wt = wt;
        //System.out.println(wt);
    }
    
    public synchronized void setSkinDepth(double skin_depth){
	this.skin_depth = skin_depth;
    }
    
    public synchronized void setWavelength(double wavelength){
	this.wavelength = wavelength;
    }
    
    public synchronized void setLength(double total_length){
	this.total_length = total_length;
    }
    
    public synchronized void setLines(int nlines){
	this.nlines = nlines;
    }
    
    public synchronized void setEx(double Ex){
	this.Ex = Ex;
    }
    
    public synchronized void setHy(double Hy){
	this.Hy = Hy;
    }
    
    public synchronized void setPz(double Pz){
	this.Pz = Pz;
        this.pmax = Pz;
        this.pmin = -Pz;
    }
    
    public synchronized void setPhasor(boolean IsPhasorOn){
	this.IsPhasorOn = IsPhasorOn;
    }
    
    public synchronized void setSections(boolean SliceIt){
	this.SliceIt = SliceIt;
    }
    
    public synchronized void setEon(boolean IsEon){
	this.IsEon = IsEon;
    }
    
    public synchronized void setHon(boolean IsHon){
	this.IsHon = IsHon;
    }
    
    public synchronized void setSkinDepthOn(boolean IsSkinDepthOn){
	this.IsSkinDepthOn = IsSkinDepthOn;
    } 
    
    public synchronized void setEquivalent(boolean IsEquivalent){
	this.IsEquivalent = IsEquivalent;
    }
    
}
