//PlaneWaveOutputPanel2.java
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;

public class PlaneWaveOutputPanel2 extends Panel implements ItemListener{
	PlaneWave_State state;
	//private static final Color bgcolor = Color.lightGray;
	private static final Color bgcolor = new Color(236,236,236);
	private static final Font labfont=new Font("SanSerif",Font.PLAIN,12);
	private static final Font symbolfont=new Font("Symbol",Font.PLAIN,12);
	private static final Font titlefont=new Font("SanSerif",Font.BOLD,16);
        
        Label titlelabel;	
	public Choice c1;
	public PlaneWaveOutputCanvasC pwocC; 
	
	public PlaneWaveOutputPanel2(PlaneWave_State state){
	    super();
	    this.state = state;
	    setBackground(bgcolor);
	    titlelabel = new Label("Output Data");
	    //add(titlelabel);
	    titlelabel.setBounds(state.s5,state.s5,state.s100,state.s40);    
	    titlelabel.setFont(titlefont);
	    
	    c1 = new Choice();
	    c1.addItem("Output1");
	    c1.addItem("Output2");
	    //add(c1);
	    c1.setBounds(state.s5,state.s50,state.s300,state.s30);
	    
	    pwocC = new PlaneWaveOutputCanvasC(state);
	    add(pwocC);
	    pwocC.setBounds(state.s5,0,state.s800+state.s26,state.s90);
	    
	    pwocC.setVisible(true);
	    //Listeners
	    c1.addItemListener(this);
	}


public void itemStateChanged(ItemEvent evt){
	ItemSelectable ie = evt.getItemSelectable();
	    if(evt.getSource()==c1){
		
	    }
    }	
}//PlaneWaveOutputPanel.java


class PlaneWaveOutputCanvasC extends Canvas{
	private Font normalfont;
	private Font normalfont2;
	
        private Font symbolfont;
	private Font subfont;
        private Font font16;
        private Font font14;
	private Font font12;
        private Font font11;
        
        PlaneWave_State state;
	private Image im;
	private Graphics buf;
    
    private BufferedImage red_angle;
    private BufferedImage blue_angle;

	public PlaneWaveOutputCanvasC(PlaneWave_State state){
	    super();
	    this.state = state;
	    getImages();
	}


    private void getImages() {
        // read in the angle images, because CHEERPJ does not render this
	//  symbol in any font!  (java to javascript converter)
        try {
	    BufferedImage img =
		ImageIO.read(getClass().getResource("red_angle.png"));
	    int targetWidth = (int) (state.sfactor * img.getWidth());
	    int targetHeight = (int) (state.sfactor * img.getHeight());
	    red_angle =
		new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_RGB);
	    Graphics2D graphics2D = red_angle.createGraphics();
	    graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
					RenderingHints.VALUE_INTERPOLATION_BILINEAR);
	    graphics2D.drawImage(img, 0, 0, targetWidth, targetHeight, 0, 0,
				 img.getWidth(), img.getHeight(), null);
	    graphics2D.dispose();

	    img = ImageIO.read(getClass().getResource("blue_angle.png"));
	    targetWidth = (int) (state.sfactor * img.getWidth());
	    targetHeight = (int) (state.sfactor * img.getHeight());
	    blue_angle =
		new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_RGB);
	    graphics2D = blue_angle.createGraphics();
	    graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
					RenderingHints.VALUE_INTERPOLATION_BILINEAR);
	    graphics2D.drawImage(img, 0, 0, targetWidth, targetHeight, 0, 0,
				 img.getWidth(), img.getHeight(), null);
	    graphics2D.dispose();
	    
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
	
	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);
	}
	
	//Addition to reduce flicker new routine
	public void update(Graphics g){		// added to avoid clearing
	    paint(g);
	}

	public void drawGraph(Graphics g){
	    normalfont = new Font("SanSerif",Font.PLAIN,state.font11);
            normalfont2 = new Font("SanSerif",Font.PLAIN,state.font12);
	
            symbolfont = new Font("Serif",Font.PLAIN,state.font11);
            subfont = new Font("SanSerif",Font.PLAIN,state.font10);
            font16 = new Font("SanSerif",Font.BOLD,state.font16);
            font14 = new Font("SanSerif",Font.BOLD,state.font14);
            font12 = new Font("SanSerif",Font.BOLD,state.font12);
            font11 = new Font("SanSerif",Font.PLAIN,state.font11);
            
            int x, xnew, xshift, xshiftf, xshift2, xshift3, y, dx, dxx, dy, dyy;
	    double v_normalized, frequency, f_normalized;
	    FontMetrics fm;
	    double temp, temp2;
	    double Efield, Hfield, Ephase, Hphase;
            String unita;
            int fonto = state.font11;
            frequency = state.frequency;
            
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            int xpos2 = state.s300;
            int xpos3 = state.s600;
            
	    x = xpos2 + state.s30;
            xshift = state.s20;
            xshiftf = xshift + state.s5;
            
            xshift2 = state.s50;
            xshift3 = state.s24;
	    y = state.s15;
	    dx = state.s50;
	    dxx = state.s15;
	    xnew = state.s10;
	    
	    g.setFont(normalfont2);
	    fm = g.getFontMetrics();
	    dy = fm.getHeight()-state.s1;
	    dyy = dy + state.s3;
	    g.clearRect(0,0,getSize().width,getSize().height);
            
            g.setColor(Color.white);
            g.fillRect(state.s200+state.s88,0,state.s200+state.s50,state.s40);
            
            g.setColor(Color.blue.darker());
            g.drawRect(state.s200+state.s88,0,state.s200+state.s50,state.s40);
            
	    g.setColor(Color.black);
	    //g.drawString("Cross-section A",x,y);	
            
            g.setColor(Color.black);
	
            if(frequency < 1.0E3){
                f_normalized = frequency;
                MaestroG.subscripterSansItalic2("f",""," = "+MaestroA.rounder(f_normalized,6)+"  Hz","",g,state.font12,x+xshiftf,y);	
            }
            else if(frequency < 1.0E6 && frequency >= 1.0E3  ){
                f_normalized = frequency/1.0E3;
                MaestroG.subscripterSansItalic2("f",""," = "+MaestroA.rounder(f_normalized,6)+"  kHz","",g,state.font12,x+xshiftf,y);
            }
            else if(frequency < 1.0E9 && frequency >= 1.0E6 ){
                f_normalized = frequency/1.0E6;
                MaestroG.subscripterSansItalic2("f",""," = "+MaestroA.rounder(f_normalized,6)+"  MHz","",g,state.font12,x+xshiftf,y);
            }
            else if(frequency < 1.0E12 && frequency >= 1.0E9 ){
                f_normalized = frequency/1.0E9;
                MaestroG.subscripterSansItalic2("f",""," = "+MaestroA.rounder(f_normalized,6)+"  GHz","",g,state.font12,x+xshiftf,y);
            }
            else if(frequency < 1.0E15 && frequency >= 1.0E12 ){
                f_normalized = frequency/1.0E12;
                MaestroG.subscripterSansItalic2("f",""," = "+MaestroA.rounder(f_normalized,6)+"  THz","",g,state.font12,x+xshiftf,y);
            }
            else if(frequency < 1.0E18 && frequency >= 1.0E15 ){
                f_normalized = frequency/1.0E15;
                MaestroG.subsupspecial2("f",""," = "+MaestroA.rounder(f_normalized,2)+" x 10","3","  THz",g,state.font12,x+xshiftf,y);
            }
            else if(frequency < 1.0E21 && frequency >= 1.0E18 ){
                f_normalized = frequency/1.0E18;
                MaestroG.subsupspecial2("f",""," = "+MaestroA.rounder(f_normalized,2)+" x 10","6","  THz",g,state.font12,x+xshiftf,y);
            }
            else if(frequency < 1.0E24 && frequency >= 1.0E21 ){
                f_normalized = frequency/1.0E21;
                MaestroG.subsupspecial2("f",""," = "+MaestroA.rounder(f_normalized,2)+" x 10","9","  THz",g,state.font12,x+xshiftf,y);
            }
                
            y += dyy;
	    
            temp2 = state.total_length*state.wavelength;
            temp = temp2;
            int stringo;
            fonto = state.font12;
            
            stringo = fm.stringWidth("L = "+MaestroA.rounder(state.total_length,6)+" \u03bb ");
            MaestroG.subscripterSansItalic6("l",""," = "+MaestroA.rounder(state.total_length,6)+" ","\u03bb",g,fonto,x+xshift,y);
            xnew = x + xshift + stringo;
                    if(temp2 >= 1.0E12){
			temp = temp2/1.0E12;
			MaestroG.superscripter("  = "+MaestroA.rounder(temp,1)+" x 10","9"," [ km ]",g,fonto,xnew,y);
		    }
		    else if(temp2 < 1.0e12 && temp2 >= 1.0e9){
			temp = temp2/1.0E9;
                        MaestroG.superscripter("  = "+MaestroA.rounder(temp,1)+" x 10","6"," [ km ]",g,fonto,xnew,y);
		    }
		    else if(temp2 < 1.0e9 && temp2 >= 1.0e6){
			temp = temp2/1.0E6;
                        MaestroG.superscripter("  = "+MaestroA.rounder(temp,1)+" x 10","3"," [ km ]",g,fonto,xnew,y);
		    }
		    else if(temp2 < 1.0E6 && temp2 >= 1.0E3){
			temp = temp2/1.0E3;
                        MaestroG.superscripter("  = "+MaestroA.rounder(temp,3),""," [ km ]",g,fonto,xnew,y);
		    }
		    else if(temp2 < 1.0E3 && temp2 >= 1.0){
                        MaestroG.superscripter("  = "+MaestroA.rounder(temp,5),""," [ m ]",g,fonto,xnew,y);
		    }
		    else if(temp2 <1.0 && temp2 >= 1.0E-2){
			temp = temp2*1.0E2;
                        MaestroG.superscripter("  = "+MaestroA.rounder(temp,5),""," [ cm ]",g,fonto,xnew,y);
		    }
		    else if(temp2 <1.0E-2 && temp2 >= 1.0E-4){
			temp = temp2*1.0E3;
                        MaestroG.superscripter("  = "+MaestroA.rounder(temp,5),""," [ mm ]",g,fonto,xnew,y);
		    }
		    else if(temp2 < 1.0E-4 && temp2 >=1.0E-6 ){
			temp = temp2*1.0E6;
                        MaestroG.superscripter("  = "+MaestroA.rounder(temp,5),""," [ \u00b5 m ]",g,fonto,xnew,y);
		    }
		    else if(temp2 < 1.0E-6 && temp2 >=1.0E-9){
			temp = temp2*1.0E9;
                        MaestroG.superscripter("  = "+MaestroA.rounder(temp,5),""," [ nm ]",g,fonto,xnew,y);
		    }
		    else if(temp2 < 1.0E-9 && temp2 >=1.0E-12){
			temp = temp2*1.0E12;
                        MaestroG.superscripter("  = "+MaestroA.rounder(temp,5)+" x 10","-3"," [ nm ]",g,fonto,xnew,y);
		    }	   
		    else if(temp2 < 1.0E-12 && temp2 >=1.0E-15){
			temp = temp2*1.0E15;
			MaestroG.superscripter("  = "+MaestroA.rounder(temp,5)+" x 10","-6"," [ nm ]",g,fonto,xnew,y);
                    }
		    else if(temp2 < 1.0E-15 && temp2 > 0.0){
			temp = temp2*1.0E18;
                        MaestroG.superscripter("  = "+MaestroA.rounder(temp,5)+" x 10","-9"," [ nm ]",g,fonto,xnew,y);
		    }
		    else if(temp2 == 0.0){
                        MaestroG.superscripter("  = "+MaestroA.rounder(temp2,3),""," [ m ]",g,fonto,xnew,y);
		    }
            
            fonto = state.font11;
            x = state.s20;
            y = state.s10;
            g.setFont(normalfont);
	    fm = g.getFontMetrics();
	    
	    temp2 = state.zpos[0]*state.wavelength;
            temp = temp2;
            //int stringo;
            stringo = fm.stringWidth("zA = "+MaestroA.rounder(state.zpos[0],6)+" \u03bb    ");
            MaestroG.subscripterBold("A )","","",g,state.font12,state.s10,y);
	    MaestroG.subscripterSanSym2("z","A"," = "+MaestroA.rounder(state.zpos[0],6)," \u03bb",g,fonto,x+xshift,y);
            //y += dy;         
            xnew = x + xshift + stringo;
                    if(temp2 >= 1.0E12){
			temp = temp2/1.0E12;
			MaestroG.superscripter(" = "+MaestroA.rounder(temp,1)+" x 10","9"," [ km ]",g,fonto,xnew,y);
		    }
		    else if(temp2 < 1.0e12 && temp2 >= 1.0e9){
			temp = temp2/1.0E9;
                        MaestroG.superscripter(" = "+MaestroA.rounder(temp,1)+" x 10","6"," [ km ]",g,fonto,xnew,y);
		    }
		    else if(temp2 < 1.0e9 && temp2 >= 1.0e6){
			temp = temp2/1.0E6;
                        MaestroG.superscripter(" = "+MaestroA.rounder(temp,1)+" x 10","3"," [ km ]",g,fonto,xnew,y);
		    }
		    else if(temp2 < 1.0E6 && temp2 >= 1.0E3){
			temp = temp2/1.0E3;
                        MaestroG.superscripter(" = "+MaestroA.rounder(temp,3),""," [ km ]",g,fonto,xnew,y);
		    }
		    else if(temp2 < 1.0E3 && temp2 >= 1.0){
                        MaestroG.superscripter(" = "+MaestroA.rounder(temp,5),""," [ m ]",g,fonto,xnew,y);
		    }
		    else if(temp2 <1.0 && temp2 >= 1.0E-2){
			temp = temp2*1.0E2;
                        MaestroG.superscripter(" = "+MaestroA.rounder(temp,5),""," [ cm ]",g,fonto,xnew,y);
		    }
		    else if(temp2 <1.0E-2 && temp2 >= 1.0E-4){
			temp = temp2*1.0E3;
                        MaestroG.superscripter(" = "+MaestroA.rounder(temp,5),""," [ mm ]",g,fonto,xnew,y);
		    }
		    else if(temp2 < 1.0E-4 && temp2 >=1.0E-6 ){
			temp = temp2*1.0E6;
                        MaestroG.superscripter(" = "+MaestroA.rounder(temp,5),""," [ \u00b5 m ]",g,fonto,xnew,y);
		    }
		    else if(temp2 < 1.0E-6 && temp2 >=1.0E-9){
			temp = temp2*1.0E9;
                        MaestroG.superscripter(" = "+MaestroA.rounder(temp,5),""," [ nm ]",g,fonto,xnew,y);
		    }
		    else if(temp2 < 1.0E-9 && temp2 >=1.0E-12){
			temp = temp2*1.0E12;
                        MaestroG.superscripter(" = "+MaestroA.rounder(temp,5)+" x 10","-3"," [ nm ]",g,fonto,xnew,y);
		    }	   
		    else if(temp2 < 1.0E-12 && temp2 >=1.0E-15){
			temp = temp2*1.0E15;
			MaestroG.superscripter(" = "+MaestroA.rounder(temp,5)+" x 10","-6"," [ nm ]",g,fonto,xnew,y);
                    }
		    else if(temp2 < 1.0E-15 && temp2 > 0.0){
			temp = temp2*1.0E18;
                        MaestroG.superscripter(" = "+MaestroA.rounder(temp,5)+" x 10","-9"," [ nm ]",g,fonto,xnew,y);
		    }
		    else if(temp2 == 0.0){
                        MaestroG.superscripter(" = "+MaestroA.rounder(temp2,3),""," [ m ]",g,fonto,xnew,y);
		    }
            
                int xVec, yVec, i;
		String stmp1, stmp2;
		int cwidth = state.s5;
	  	
                y += dy + state.s5;
                
                g.setColor(Color.red);
                unita = "  [ V / m ]";
                Efield = state.Ex*Math.exp(-state.alpha*state.zpos[0]*state.wavelength);
                Ephase = -state.beta*state.zpos[0]*state.wavelength+state.Phix;
                
		MaestroG.subscripter("| E","A"," |",g,fonto,x+xshift3,y);
                printdata(Efield,g,fonto,x+xshift2,y,unita);
                
                y+= dy + state.s2;
                
                //MaestroG.subscripterPhase("E","A","",g,fonto,x+xshift,y);
                //MaestroG.subscripter("\u2220 E","A","",g,fonto,x+xshift,y);
		MaestroG.ImgSubTxt(red_angle," E","A","",g,fonto,x+xshift,y,this);
		
		MaestroG.subscripter("  =  ","",""+MaestroA.rounder(Ephase,5)+" [ rad ]",g,fonto,x+xshift2,y);
                
                y += dy + state.s2;
                
                g.setColor(Color.blue);
                unita = "  [ A / m ]";
                Hfield = state.Hy*Math.exp(-state.alpha*state.zpos[0]*state.wavelength);
                Hphase = -state.beta*state.zpos[0]*state.wavelength+state.Phix-state.wave_impedance.Arg2();
                
                MaestroG.subscripter("| H","A"," |",g,fonto,x+xshift3,y);
		printdata(Hfield,g,fonto,x+xshift2,y,unita);
                 
                y+= dy + state.s2;
                
                //MaestroG.subscripter("\u2220 H","A","",g,fonto,x+xshift,y);
		MaestroG.ImgSubTxt(blue_angle," H","A","",g,fonto,x+xshift,y,this);
		
		MaestroG.subscripter("  =  ","",""+MaestroA.rounder(Hphase,5)+" [ rad ]",g,fonto,x+xshift2,y);
                
            g.setColor(Color.red.darker());
	    
            y =state.s10;
            x = xpos3;
            
            temp2 = state.zpos[1]*state.wavelength;
            temp = temp2;
            
            stringo = fm.stringWidth("zB = "+MaestroA.rounder(state.zpos[1],6)+" \u03bb    ");
            MaestroG.subscripterBold("B )","","",g,state.font12,xpos3-state.s10,y);
	    
	    MaestroG.subscripterSanSym2("z","B"," = "+MaestroA.rounder(state.zpos[1],6)," \u03bb",g,fonto,x+xshift,y);
                     
            xnew = x + xshift + stringo;
                    if(temp2 >= 1.0E12){
			temp = temp2/1.0E12;
			MaestroG.superscripter(" = "+MaestroA.rounder(temp,1)+" x 10","9"," [ km ]",g,fonto,xnew,y);
		    }
		    else if(temp2 < 1.0e12 && temp2 >= 1.0e9){
			temp = temp2/1.0E9;
                        MaestroG.superscripter(" = "+MaestroA.rounder(temp,1)+" x 10","6"," [ km ]",g,fonto,xnew,y);
		    }
		    else if(temp2 < 1.0e9 && temp2 >= 1.0e6){
			temp = temp2/1.0E6;
                        MaestroG.superscripter(" = "+MaestroA.rounder(temp,1)+" x 10","3"," [ km ]",g,fonto,xnew,y);
		    }
		    else if(temp2 < 1.0E6 && temp2 >= 1.0E3){
			temp = temp2/1.0E3;
                        MaestroG.superscripter(" = "+MaestroA.rounder(temp,3),""," [ km ]",g,fonto,xnew,y);
		    }
		    else if(temp2 < 1.0E3 && temp2 >= 1.0){
                        MaestroG.superscripter(" = "+MaestroA.rounder(temp,5),""," [ m ]",g,fonto,xnew,y);
		    }
		    else if(temp2 <1.0 && temp2 >= 1.0E-2){
			temp = temp2*1.0E2;
                        MaestroG.superscripter(" = "+MaestroA.rounder(temp,5),""," [ cm ]",g,fonto,xnew,y);
		    }
		    else if(temp2 <1.0E-2 && temp2 >= 1.0E-4){
			temp = temp2*1.0E3;
                        MaestroG.superscripter(" = "+MaestroA.rounder(temp,5),""," [ mm ]",g,fonto,xnew,y);
		    }
		    else if(temp2 < 1.0E-4 && temp2 >=1.0E-6 ){
			temp = temp2*1.0E6;
                        MaestroG.superscripter(" = "+MaestroA.rounder(temp,5),""," [ \u00b5 m ]",g,fonto,xnew,y);
		    }
		    else if(temp2 < 1.0E-6 && temp2 >=1.0E-9){
			temp = temp2*1.0E9;
                        MaestroG.superscripter(" = "+MaestroA.rounder(temp,5),""," [ nm ]",g,fonto,xnew,y);
		    }
		    else if(temp2 < 1.0E-9 && temp2 >=1.0E-12){
			temp = temp2*1.0E12;
                        MaestroG.superscripter(" = "+MaestroA.rounder(temp,5)+" x 10","-3"," [ nm ]",g,fonto,xnew,y);
		    }	   
		    else if(temp2 < 1.0E-12 && temp2 >=1.0E-15){
			temp = temp2*1.0E15;
			MaestroG.superscripter(" = "+MaestroA.rounder(temp,5)+" x 10","-6"," [ nm ]",g,fonto,xnew,y);
                    }
		    else if(temp2 < 1.0E-15 && temp2 > 0.0){
			temp = temp2*1.0E18;
                        MaestroG.superscripter(" = "+MaestroA.rounder(temp,5)+" x 10","-9"," [ nm ]",g,fonto,xnew,y);
		    }
		    else if(temp2 == 0.0){
                        MaestroG.superscripter(" = "+MaestroA.rounder(temp2,3),""," [ m ]",g,fonto,xnew,y);
		    }
            
                y += dy + state.s5;
                
                g.setColor(Color.red);
		//MaestroG.subscripter("| E |","B"," = "+MaestroA.rounder(state.Ex*Math.exp(-state.alpha*state.zpos[1]*state.wavelength),6)+"  [ V / m ]",g,fonto,x+xshift,y);
		unita = "  [ V / m ]";
                
                Efield = state.Ex*Math.exp(-state.alpha*state.zpos[1]*state.wavelength);
		Ephase = -state.beta*state.zpos[1]*state.wavelength+state.Phix;
		
                MaestroG.subscripter("| E","B"," |",g,fonto,x+xshift3,y);
		printdata(Efield,g,fonto,x+xshift2,y,unita);
                
                y+= dy + state.s2;
                
                //MaestroG.subscripter("\u2220 E","B","",g,fonto,x+xshift,y);
		MaestroG.ImgSubTxt(red_angle," E","B","",g,fonto,x+xshift,y,this);
		
		MaestroG.subscripter("  =  ","",""+MaestroA.rounder(Ephase,5)+" [ rad ]",g,fonto,x+xshift2,y);
                                
                g.setColor(Color.blue);
                y += dy + state.s2;
                unita = "  [ A / m ]";
                Hfield = state.Hy*Math.exp(-state.alpha*state.zpos[1]*state.wavelength);
                Hphase = -state.beta*state.zpos[1]*state.wavelength+state.Phix-state.wave_impedance.Arg2();
                
                MaestroG.subscripter("| H","B"," |",g,fonto,x+xshift3,y);
		printdata(Hfield,g,fonto,x+xshift2,y,unita);
                
                y+= dy + state.s2;
                
                //MaestroG.subscripter("\u2220 H","B","",g,fonto,x+xshift,y);
		MaestroG.ImgSubTxt(blue_angle," H","B","",g,fonto,x+xshift,y,this);
		
		MaestroG.subscripter("  =  ","",""+MaestroA.rounder(Hphase,5)+" [ rad ]",g,fonto,x+xshift2,y);
                
                int yphasor = state.s60;
                int xphasor = getSize().width/2-state.s1;
                int xborder = state.s10;
                int yborder = state.s5;
                
                String stringa = " Phasor fields on selected phase planes ";
                
                g.setColor(Color.black);
                g.setFont(font11);
                fm = g.getFontMetrics();
                
                int widephasor = fm.stringWidth(stringa);
                int heightphasor = state.s11;
                
                int x1 = xphasor-widephasor/2-xborder+widephasor+2*xborder;
                int y1 = yphasor-heightphasor/2;
                int x2 = xphasor-widephasor/2-xborder+widephasor+2*xborder+state.s30;
                int x3 = xphasor-widephasor/2-xborder;
                int x4 = xphasor-widephasor/2-xborder-state.s30;
                
                g.setColor(Color.white);
                g.fillRect(xphasor-widephasor/2-xborder,yphasor-heightphasor-yborder,widephasor+2*xborder,heightphasor+2*yborder);
                g.setColor(Color.black);
                g.drawRect(xphasor-widephasor/2-xborder,yphasor-heightphasor-yborder,widephasor+2*xborder,heightphasor+2*yborder);
                g.drawLine(x3,y1,x4,y1);
                g.drawLine(x1,y1,x2,y1);
                //MaestroG.drawArrow(x2,y1,7,g);
                //MaestroG.drawArrow(x4,y1,8,g);
                
                MaestroG.drawArrowScaled(x2,y1,3,2*state.sfactor,g);
                MaestroG.drawArrowScaled(x4,y1,4,2*state.sfactor,g);
                
                g.drawString(stringa,xphasor-widephasor/2,yphasor);
	} 
        
        public static void printdata(double field, Graphics g, int fonto, int xinit2, int y, String unita){
            if(field < 1.0e-15 && field != 0.0){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e16,5)+"  x  10","-16"," "+unita,g,fonto,xinit2,y);
	    }
            if(field == 0.0){
		MaestroG.superscripter("  =  0.0",""," "+unita,g,fonto,xinit2,y);
	    }
            if(field >= 1.0e-15 && field < 1.0e-14){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e15,5)+"  x  10","-15"," "+unita,g,fonto,xinit2,y);
	    }
            if(field >= 1.0e-14 && field < 1.0e-13){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e14,5)+"  x  10","-14"," "+unita,g,fonto,xinit2,y);
	    }
            if(field >= 1.0e-13 && field < 1.0e-12){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e13,5)+"  x  10","-13"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e-12 && field < 1.0e-11){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e12,5)+"  x  10","-12"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e-11 && field < 1.0e-10){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e11,5)+"  x  10","-11"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e-10 && field < 1.0e-9){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e10,5)+"  x  10","-10"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e-9 && field < 1.0e-8){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e9,5)+"  x  10","-9"," "+unita,g,fonto,xinit2,y);
	    }
	    
	    if(field >= 1.0e-8 && field < 1.0e-7){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e8,5)+"  x  10","-8"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e-7 && field < 1.0e-6){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e7,5)+"  x  10","-7"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e-6 && field < 1.0e-5){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e6,5)+"  x  10","-6"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e-5 && field < 1.0e-4){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e5,5)+"  x  10","-5"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e-4 && field < 1.0e-3){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e4,5)+"  x  10","-4"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e-3 && field < 1.0e-2){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e3,5)+"  x  10","-3"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e-2 && field < 1.0e-1){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e2,5)+"  x  10","-2"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e-1 && field < 1.0){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e1,5)+"  x  10","-1"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0 && field < 1.0e1){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field,5)+"  ",""," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e1 && field < 1.0e2){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field,5)+"  ",""," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e2 && field < 1.0e3){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e-2,5)+"  x  10","2"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e3 && field < 1.0e4){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e-3,5)+"  x  10","3"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e4 && field < 1.0e5){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e-4,5)+"  x  10","4"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e5 && field < 1.0e6){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e-5,5)+"  x  10","5"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e6 && field < 1.0e7){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e-6,5)+"  x  10","6"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e7 && field < 1.0e8){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e-7,5)+"  x  10","7"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e8 && field < 1.0e9){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e-8,5)+"  x  10","8"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e9 && field < 1.0e10){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e-9,5)+"  x  10","9"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e10 && field < 1.0e11){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e-10,5)+"  x  10","10"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e11 && field < 1.0e12){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e-11,5)+"  x  10","11"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e12 && field < 1.0e13){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e-12,5)+"  x  10","12"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e13 && field < 1.0e14){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e-13,5)+"  x  10","13"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e14 && field < 1.0e15){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e-14,5)+"  x  10","14"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e15 && field < 1.0e16){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e-15,5)+"  x  10","15"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e16 && field < 1.0e17){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e-16,5)+"  x  10","16"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e17 && field < 1.0e18){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e-17,5)+"  x  10","17"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e18 && field < 1.0e19){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e-18,5)+"  x  10","18"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e19 && field < 1.0e20){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e-19,5)+"  x  10","19"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e20 && field < 1.0e21){
		MaestroG.superscripter("  =  "+MaestroA.rounder(field*1.0e-20,5)+"  x  10","20"," "+unita,g,fonto,xinit2,y);
	    }
	    if(field >= 1.0e21){
		MaestroG.superscripter("  =  "+field+"",""," "+unita,g,fonto,xinit2,y);
	    }
        }
}

