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


//import maestro.lib.math.*;
//import maestro.lib.graphics.*;

public class NewGuideOutputPanel extends Panel implements ItemListener{
	NewGuide_State state;
	//private static final Color bgcolor = Color.lightGray;
	private static final Color bgcolor = new Color(236,236,221);
	private static final Font labfont=new Font("SanSerif",Font.PLAIN,12);
	private static final Font titlefont=new Font("SanSerif",Font.BOLD,16);
	private static final Font symbolfont=new Font("Serif",Font.PLAIN,12);
	
	Label titlelabel;	
	public Choice c1;
	public NewOutputCanvasA rwocA; 
	public NewOutputCanvasB rwocB; 
	public NewOutputCanvasField rwocField; 
	//public ScrollPane pane1, pane2;
	
	public NewGuideOutputPanel(NewGuide_State state){
	    super();
	    setLayout(null);
	    this.state = state;
	    setBackground(bgcolor);
	    titlelabel = new Label("Data",Label.LEFT);
	    add(titlelabel);
	    titlelabel.setBounds(20,10,100,20);    
	    titlelabel.setFont(titlefont);
	    
	    //pane1 = new ScrollPane();
	    //pane1.setBounds(2,30,297,285);
	    //add(pane1);
	    
	    //pane2  = new ScrollPane();
	    //pane2.setBounds(2,30,297,205);
	    //add(pane2);

	    c1 = new Choice();
	    c1.addItem(" Antenna Data ");
	    c1.addItem(" Field Scanner ");
	    //c1.addItem(" Discretization ");
	    //add(c1);
	    c1.setBounds(155,8,110,15);
	    
	    c1.setBackground(bgcolor.brighter());
	    
	    
	    Panel ps1 = new Panel();
	    ps1.setBackground(Color.cyan);
	    //add(ps1);
	    ps1.setBounds(153,4,104,24);
	    
	    Panel ps2 = new Panel();
	    ps2.setBackground(Color.black);
	    //add(ps2);
	    ps2.setBounds(152,3,106,26);
	    
	    rwocA = new NewOutputCanvasA(state);
	    //pane1.add(rwocA);
	    add(rwocA);
	    rwocA.setBounds(5,30,285,252);
	    
	    rwocB = new NewOutputCanvasB(state);
	    //pane2.add(rwocB);
	    add(rwocB);
	    rwocB.setBounds(5,30,285,252);
	    
	    rwocField = new NewOutputCanvasField(state);
	    //pane3.add(rwocField);
	    add(rwocField);
	    rwocField.setBounds(5,30,285,257);
	    
	    rwocA.setVisible(true);
	    rwocB.setVisible(false);
	    rwocField.setVisible(false);
	    //pane1.setVisible(true);
	    //pane2.setVisible(false);
	    //pane3.setVisible(false);
	    
	    //Listeners
	    c1.addItemListener(this);
	    state.ignition();
	}
	
    public void paint(Graphics g){
	
	g.setColor(bgcolor.darker());
	g.fillRect(0,getSize().height-2,getSize().width,2);
	g.fillRect(getSize().width-2,0,2,getSize().height);
	g.setColor(bgcolor.brighter());
	g.fillRect(0,0,2,getSize().height-1);
	g.fillRect(0,0,getSize().width-2,2);
	
    }

    public void itemStateChanged(ItemEvent evt){
	ItemSelectable ie = evt.getItemSelectable();
	    if(evt.getSource()==c1){
		if(ie.getSelectedObjects()[0]==" Antenna Data "){
		    rwocA.setVisible(true);
		    rwocB.setVisible(false);
		    rwocField.setVisible(false);
		    //pane1.setVisible(true);
		    //pane2.setVisible(false);
		    //pane3.setVisible(false);
		}
		else if(ie.getSelectedObjects()[0]==" Discretization "){
		    rwocA.setVisible(false);
		    rwocB.setVisible(true);
		    rwocField.setVisible(false);
		    //pane1.setVisible(false);
		    //pane2.setVisible(true);
		    //pane3.setVisible(false);
		}
		else if(ie.getSelectedObjects()[0]==" Field Scanner "){
		    rwocA.setVisible(false);
		    rwocB.setVisible(false);
		    rwocField.setVisible(true);
		    //pane1.setVisible(false);
		    //pane2.setVisible(false);
		    //pane3.setVisible(true);
		}
	    }
    }	
}

class NewOutputCanvasA extends Canvas{
	private static final Font normalfont = new Font("SanSerif",Font.PLAIN,12);
	private static final Font subfont    = new Font("SanSerif",Font.PLAIN,10);
	private static final Font symbolfont=new Font("Serif",Font.PLAIN,12);
	public String string_field, unit_field; 
	int x, y;
	public Complex field;
	public double fieldfar;
	NewGuide_State state;
	private Image im;
	private Graphics buf;
	public NewOutputCanvasA(NewGuide_State state){
	    super();
	    this.state = state;
	}
	
	public void paint(Graphics g){
	    if(im == null){
		im = createImage(getSize().width,getSize().height);
		buf = im.getGraphics();
		drawCanvas(buf);
	    }
	    else{
		drawCanvas(buf);
	    }
	    g.drawImage(im,0,0,null);
	}

	//Addition to reduce flicker new routine
	public void update(Graphics g){		// added to avoid clearing
	    paint(g);
	}
	
	public void clear(){
	    this.getGraphics().clearRect(0,0,getSize().width,getSize().height);
	    repaint();
	}

	public void drawCanvas(Graphics g){
            
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
	    int x, y, dx, dxx, dy, dyy;
	    double tempcap, Cond1, Res1, tempind, f_normalized;
	    //Color bgcolor = Color.lightGray;
	    Color bgcolor = new Color(236,236,221);
	    String stmp;
	    FontMetrics fm;
	    
	    double light_velocity = 1.0/Math.sqrt(state.epsilon0*state.mu0*state.epsilon_r);
	    double light_velocity0 = 1.0/Math.sqrt(state.epsilon0*state.mu0);
	    String lambda, Ohm, infinity;
	    x = 10;
	    y = 25;
	    dx = 80;
	    dxx = 15;
	    g.setFont(normalfont);
	    fm = g.getFontMetrics();
	    dy = 12;
	    dyy = dy+1;
	    
	    g.setFont(symbolfont);
	    g.getFontMetrics();
	    lambda="\u03bb";
	    Ohm="\u03a9";
	    infinity="\u221e";
	    g.setFont(normalfont);
	    g.getFontMetrics();
	    
	    g.setColor(bgcolor);
	    g.fillRect(0,0,getSize().width,getSize().height);
	    
	    g.setColor(Color.black);
	    g.drawLine(5,5,getSize().width-5,5);
	    
	    g.setColor(Color.blue);
	    g.drawString("Wavelength", x,y);
	    y +=dyy+3;
	    
	    g.setColor(Color.black);
	    g.setFont(new Font("Serif",Font.PLAIN,13));
	    g.drawString("\u03bb",x+25,y);
	    g.setFont(new Font("SanSerif",Font.PLAIN,12));
	    g.drawString("      =  "+MaestroA.rounder(state.lambda,8)+"  [ m ]",x+25,y);
	    //g.drawString("[ m ]",x+185,y);
	    y +=dyy+3;
	    
	    g.setColor(Color.blue);
	    g.drawString("Dipole Length", x,y);
	    y +=dyy+3;
	    	    
	    g.setColor(Color.black);    
	    g.setFont(new Font("Serif",Font.ITALIC,15));
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            g.drawString(" l ",x+20,y);
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            g.setFont(new Font("SanSerif",Font.PLAIN,12));
	    g.drawString("      = "+MaestroA.rounder(state.a,8)+"  "+lambda+"    = "+MaestroA.rounder(state.a * state.wavelength,8)+"  [ m ]",x+25,y);
	    //y+=dyy+3;
	     
	    //g.drawString("      = "+MaestroA.rounder(state.a * state.wavelength,8)+"  [ m ]",x+25,y);
	    
	    y +=dyy-6;
	    g.setColor(Color.red);
	    g.drawLine(5,y,getSize().width-5,y);
	    y+=dyy;
	    y+=2;
	    
	    String unit_field;
	    double exponent_factor, Reale;
	    int exponent = 0;
	    exponent_factor = 0.0;
	    
	    g.setColor(Color.blue);
	    g.drawString("Directivity", x,y);
	    //y +=dyy+3;
	    
	    g.setColor(Color.black);
	    //g.setFont(new Font("Serif",Font.PLAIN,12));
	    g.drawString("D",x+75,y);
	    g.setFont(new Font("SanSerif",Font.PLAIN,12));
	    //g.drawString("      =  "+MaestroA.rounder(state.Directivity,6),x+25,y);
	    //g.drawString("      =  "+state.Directivity,x+25,y);
	    
	    unit_field =""; 
	    Reale = state.Directivity;
	    
	    //Magnitude
	    if(Reale<1000.0 && Reale>=1.0 || Reale == 0.0){
		exponent_factor = 1.0;
		exponent = 0;
	    }
	    if(Reale<1.0 && Reale>=1.0E-3){
		exponent_factor = 1.0E-3;
		exponent = -3;
	    }
	    if(Reale<1.0E6 && Reale>=1.0E3){
		exponent_factor = 1.0E3;
		exponent = 3;
	    }
	    if(Reale<1.0E-3 && Reale>=1.0E-6){
		exponent_factor = 1.0E-6;
		exponent = -6;
	    }
	    if(Reale<1.0E9 && Reale>=1.0E6){
		exponent_factor = 1.0E6;
		exponent = 6;
	    }
	    if(Reale<1.0E-6 && Reale>=1.0E-9){
		exponent_factor = 1.0E-9;
		exponent = -9;
	    }
	    if(Reale<1.0E12 && Reale>=1.0E9){
		exponent_factor = 1.0E9;
		exponent = 9;
	    }
	    if(Reale<1.0E-9 && Reale>=1.0E-12){
		exponent_factor = 1.0E-12;
		exponent = -12;
	    }
	    if(Reale<1.0E15 && Reale>=1.0E12){
		exponent_factor = 1.0E12;
		exponent = 12;
	    }
	    if(Reale<1.0E-12 && Reale>=1.0E-15){
		exponent_factor = 1.0E-15;
		exponent = -15;
	    }
	    if(Reale<1.0E18 && Reale>=1.0E15){
		exponent_factor = 1.0E15;
		exponent = 15;
	    }
	    if(Reale<1.0E-15 && Reale>=1.0E-18){
		exponent_factor = 1.0E-18;
		exponent = -18;
	    }
	    if(Reale<1.0E21 && Reale>=1.0E18){
		exponent_factor = 1.0E18;
		exponent = 18;
	    }
	    if(Reale<1.0E-18 && Reale>=1.0E-21){
		exponent_factor = 1.0E-21;
		exponent = -21;
	    }
	    if(Reale<1.0E24 && Reale>=1.0E21){
		exponent_factor = 1.0E21;
		exponent = 21;
	    }
	    if(Reale<1.0E-21 && Reale>=1.0E-24){
		exponent_factor = 1.0E-24;
		exponent = -24;
	    }
	    if(Reale<1.0E27 && Reale>=1.0E24){
		exponent_factor = 1.0E24;
		exponent = 24;
	    }
	    if(Reale<1.0E-24 && Reale>=1.0E-27){
		exponent_factor = 1.0E-27;
		exponent = -27;
	    }
	    if(Reale<1.0E30 && Reale>=1.0E27){
		exponent_factor = 1.0E27;
		exponent = 27;
	    }
	    if(Reale<1.0E-27 && Reale>=1.0E-30){
		exponent_factor = 1.0E-30;
		exponent = -30;
	    }
	    if(Reale>1.0E30){
		exponent_factor = 1.0E30;
		exponent = 30;
	    }
	    if(Reale<1.0E-30 && Reale > 0.0){
		exponent_factor = 1.0E-30;
		exponent = -30;
	    }
	    if(exponent == 0){
	    MaestroG.superscripter("     =  "+MaestroA.rounder(Reale/exponent_factor,5)+"","",
				   " "+unit_field,g,12,x+80,y);
	    }
	    else{
	    MaestroG.superscripter("     =  "+MaestroA.rounder(Reale/exponent_factor,5)+" x 10",""+exponent,
				   " "+unit_field,g,12,x+80,y);
	    }    
	    
	    
	    y +=dyy-6;
	    g.setColor(Color.red);
	    g.drawLine(5,y,getSize().width-5,y);
	    y+=dyy;
	    y+=2;
	    
	    g.setColor(Color.blue);
	    g.drawString("Radiation Impedance", x,y);
	    y +=dyy+3;
	    
	    g.setColor(Color.black);
	    
	    MaestroG.subscripter("R","rad","",g,12,x+10,y);
	    
	    unit_field ="[ "+Ohm+" ]"; 
	    Reale = state.RadiationResistance;
	    
	    //Magnitude
	    if(Reale<1000.0 && Reale>=1.0 || Reale == 0.0){
		exponent_factor = 1.0;
		exponent = 0;
	    }
	    if(Reale<1.0 && Reale>=1.0E-3){
		exponent_factor = 1.0E-3;
		exponent = -3;
	    }
	    if(Reale<1.0E6 && Reale>=1.0E3){
		exponent_factor = 1.0E3;
		exponent = 3;
	    }
	    if(Reale<1.0E-3 && Reale>=1.0E-6){
		exponent_factor = 1.0E-6;
		exponent = -6;
	    }
	    if(Reale<1.0E9 && Reale>=1.0E6){
		exponent_factor = 1.0E6;
		exponent = 6;
	    }
	    if(Reale<1.0E-6 && Reale>=1.0E-9){
		exponent_factor = 1.0E-9;
		exponent = -9;
	    }
	    if(Reale<1.0E12 && Reale>=1.0E9){
		exponent_factor = 1.0E9;
		exponent = 9;
	    }
	    if(Reale<1.0E-9 && Reale>=1.0E-12){
		exponent_factor = 1.0E-12;
		exponent = -12;
	    }
	    if(Reale<1.0E15 && Reale>=1.0E12){
		exponent_factor = 1.0E12;
		exponent = 12;
	    }
	    if(Reale<1.0E-12 && Reale>=1.0E-15){
		exponent_factor = 1.0E-15;
		exponent = -15;
	    }
	    if(Reale<1.0E18 && Reale>=1.0E15){
		exponent_factor = 1.0E15;
		exponent = 15;
	    }
	    if(Reale<1.0E-15 && Reale>=1.0E-18){
		exponent_factor = 1.0E-18;
		exponent = -18;
	    }
	    if(Reale<1.0E21 && Reale>=1.0E18){
		exponent_factor = 1.0E18;
		exponent = 18;
	    }
	    if(Reale<1.0E-18 && Reale>=1.0E-21){
		exponent_factor = 1.0E-21;
		exponent = -21;
	    }
	    if(Reale<1.0E24 && Reale>=1.0E21){
		exponent_factor = 1.0E21;
		exponent = 21;
	    }
	    if(Reale<1.0E-21 && Reale>=1.0E-24){
		exponent_factor = 1.0E-24;
		exponent = -24;
	    }
	    if(Reale<1.0E27 && Reale>=1.0E24){
		exponent_factor = 1.0E24;
		exponent = 24;
	    }
	    if(Reale<1.0E-24 && Reale>=1.0E-27){
		exponent_factor = 1.0E-27;
		exponent = -27;
	    }
	    if(Reale<1.0E30 && Reale>=1.0E27){
		exponent_factor = 1.0E27;
		exponent = 27;
	    }
	    if(Reale<1.0E-27 && Reale>=1.0E-30){
		exponent_factor = 1.0E-30;
		exponent = -30;
	    }
	    if(Reale>1.0E30){
		exponent_factor = 1.0E30;
		exponent = 30;
	    }
	    if(Reale<1.0E-30 && Reale > 0.0){
		exponent_factor = 1.0E-30;
		exponent = -30;
	    }
	    if(exponent == 0){
	    MaestroG.superscripter("     =  "+MaestroA.rounder(Reale/exponent_factor,5)+"","",
				   " "+unit_field,g,12,x+30,y);
	    }
	    else{
	    MaestroG.superscripter("     =  "+MaestroA.rounder(Reale/exponent_factor,5)+" x 10",""+exponent,
				   " "+unit_field,g,12,x+30,y);
	    }    
	    
	    
	    
	    y +=dyy+3;
	    
	    g.setColor(Color.black);
	    
	    g.drawString("j",x+3,y);
	    MaestroG.subscripter("X","rad","",g,12,x+10,y);
	    
	    unit_field ="[ "+Ohm+" ]"; 
	    Reale = Math.abs(state.RadiationReactance);
	    
	    //Magnitude
	    if(Reale<1000.0 && Reale>=1.0 || Reale == 0.0){
		exponent_factor = 1.0;
		exponent = 0;
	    }
	    if(Reale<1.0 && Reale>=1.0E-3){
		exponent_factor = 1.0E-3;
		exponent = -3;
	    }
	    if(Reale<1.0E6 && Reale>=1.0E3){
		exponent_factor = 1.0E3;
		exponent = 3;
	    }
	    if(Reale<1.0E-3 && Reale>=1.0E-6){
		exponent_factor = 1.0E-6;
		exponent = -6;
	    }
	    if(Reale<1.0E9 && Reale>=1.0E6){
		exponent_factor = 1.0E6;
		exponent = 6;
	    }
	    if(Reale<1.0E-6 && Reale>=1.0E-9){
		exponent_factor = 1.0E-9;
		exponent = -9;
	    }
	    if(Reale<1.0E12 && Reale>=1.0E9){
		exponent_factor = 1.0E9;
		exponent = 9;
	    }
	    if(Reale<1.0E-9 && Reale>=1.0E-12){
		exponent_factor = 1.0E-12;
		exponent = -12;
	    }
	    if(Reale<1.0E15 && Reale>=1.0E12){
		exponent_factor = 1.0E12;
		exponent = 12;
	    }
	    if(Reale<1.0E-12 && Reale>=1.0E-15){
		exponent_factor = 1.0E-15;
		exponent = -15;
	    }
	    if(Reale<1.0E18 && Reale>=1.0E15){
		exponent_factor = 1.0E15;
		exponent = 15;
	    }
	    if(Reale<1.0E-15 && Reale>=1.0E-18){
		exponent_factor = 1.0E-18;
		exponent = -18;
	    }
	    if(Reale<1.0E21 && Reale>=1.0E18){
		exponent_factor = 1.0E18;
		exponent = 18;
	    }
	    if(Reale<1.0E-18 && Reale>=1.0E-21){
		exponent_factor = 1.0E-21;
		exponent = -21;
	    }
	    if(Reale<1.0E24 && Reale>=1.0E21){
		exponent_factor = 1.0E21;
		exponent = 21;
	    }
	    if(Reale<1.0E-21 && Reale>=1.0E-24){
		exponent_factor = 1.0E-24;
		exponent = -24;
	    }
	    if(Reale<1.0E27 && Reale>=1.0E24){
		exponent_factor = 1.0E24;
		exponent = 24;
	    }
	    if(Reale<1.0E-24 && Reale>=1.0E-27){
		exponent_factor = 1.0E-27;
		exponent = -27;
	    }
	    if(Reale<1.0E30 && Reale>=1.0E27){
		exponent_factor = 1.0E27;
		exponent = 27;
	    }
	    if(Reale<1.0E-27 && Reale>=1.0E-30){
		exponent_factor = 1.0E-30;
		exponent = -30;
	    }
	    if(Reale>1.0E30){
		exponent_factor = 1.0E30;
		exponent = 30;
	    }
	    if(Reale<1.0E-30 && Reale > 0.0){
		exponent_factor = 1.0E-30;
		exponent = -30;
	    }
	    
	    if(state.RadiationReactance >= 0.0){
		if(exponent == 0){
		MaestroG.superscripter("     =  j "+MaestroA.rounder(Reale/exponent_factor,5)+"","",
				   " "+unit_field,g,12,x+30,y);
		}
		else{
		MaestroG.superscripter("     =  j "+MaestroA.rounder(Reale/exponent_factor,5)+" x 10",""+exponent,
				   " "+unit_field,g,12,x+30,y);
		}    
	    }
	    else{
		if(exponent == 0){
		MaestroG.superscripter("     =  - j "+MaestroA.rounder(Reale/exponent_factor,5)+"","",
				   " "+unit_field,g,12,x+30,y);
		}
		else{
		MaestroG.superscripter("     =  - j "+MaestroA.rounder(Reale/exponent_factor,5)+" x 10",""+exponent,
				   " "+unit_field,g,12,x+30,y);
		}    
	    }
	    
	    y +=dyy-6;
	    g.setColor(Color.red);
	    g.drawLine(5,y,getSize().width-5,y);
	    y+=dyy;
	    y+=2;
	    
	    g.setColor(Color.blue);
	    g.drawString("Input Impedance", x,y);
	    y +=dyy+3;
	    
	    g.setColor(Color.black);
	    
	    
	    unit_field ="[ "+Ohm+" ]"; 
	    Reale = state.InputResistance;
	    
	    //Magnitude
	    if(Reale<1000.0 && Reale>=1.0 || Reale == 0.0){
		exponent_factor = 1.0;
		exponent = 0;
	    }
	    if(Reale<1.0 && Reale>=1.0E-3){
		exponent_factor = 1.0E-3;
		exponent = -3;
	    }
	    if(Reale<1.0E6 && Reale>=1.0E3){
		exponent_factor = 1.0E3;
		exponent = 3;
	    }
	    if(Reale<1.0E-3 && Reale>=1.0E-6){
		exponent_factor = 1.0E-6;
		exponent = -6;
	    }
	    if(Reale<1.0E9 && Reale>=1.0E6){
		exponent_factor = 1.0E6;
		exponent = 6;
	    }
	    if(Reale<1.0E-6 && Reale>=1.0E-9){
		exponent_factor = 1.0E-9;
		exponent = -9;
	    }
	    if(Reale<1.0E12 && Reale>=1.0E9){
		exponent_factor = 1.0E9;
		exponent = 9;
	    }
	    if(Reale<1.0E-9 && Reale>=1.0E-12){
		exponent_factor = 1.0E-12;
		exponent = -12;
	    }
	    if(Reale<1.0E15 && Reale>=1.0E12){
		exponent_factor = 1.0E12;
		exponent = 12;
	    }
	    if(Reale<1.0E-12 && Reale>=1.0E-15){
		exponent_factor = 1.0E-15;
		exponent = -15;
	    }
	    if(Reale<1.0E18 && Reale>=1.0E15){
		exponent_factor = 1.0E15;
		exponent = 15;
	    }
	    if(Reale<1.0E-15 && Reale>=1.0E-18){
		exponent_factor = 1.0E-18;
		exponent = -18;
	    }
	    if(Reale<1.0E21 && Reale>=1.0E18){
		exponent_factor = 1.0E18;
		exponent = 18;
	    }
	    if(Reale<1.0E-18 && Reale>=1.0E-21){
		exponent_factor = 1.0E-21;
		exponent = -21;
	    }
	    if(Reale<1.0E24 && Reale>=1.0E21){
		exponent_factor = 1.0E21;
		exponent = 21;
	    }
	    if(Reale<1.0E-21 && Reale>=1.0E-24){
		exponent_factor = 1.0E-24;
		exponent = -24;
	    }
	    if(Reale<1.0E27 && Reale>=1.0E24){
		exponent_factor = 1.0E24;
		exponent = 24;
	    }
	    if(Reale<1.0E-24 && Reale>=1.0E-27){
		exponent_factor = 1.0E-27;
		exponent = -27;
	    }
	    if(Reale<1.0E30 && Reale>=1.0E27){
		exponent_factor = 1.0E27;
		exponent = 27;
	    }
	    if(Reale<1.0E-27 && Reale>=1.0E-30){
		exponent_factor = 1.0E-30;
		exponent = -30;
	    }
	    if(Reale>1.0E30){
		exponent_factor = 1.0E30;
		exponent = 30;
	    }
	    if(Reale<1.0E-30 && Reale > 0.0){
		exponent_factor = 1.0E-30;
		exponent = -30;
	    }
	    if(exponent == 0){
		MaestroG.subscripter("R","in","",g,12,x+10,y);
		MaestroG.superscripter("     =  "+MaestroA.rounder(Reale/exponent_factor,5)+"","",
					" "+unit_field,g,12,x+30,y);
	    }
	    else if(Reale > 1.0E230){
		MaestroG.subscripter("Z","in","",g,12,x+10,y);
		MaestroG.superscripter("     =   "+infinity,"",
					"    "+unit_field,g,12,x+30,y);
	    }
	    else
	    {
	    MaestroG.subscripter("R","in","",g,12,x+10,y);
	    MaestroG.superscripter("     =  "+MaestroA.rounder(Reale/exponent_factor,5)+" x 10",""+exponent,
				   " "+unit_field,g,12,x+30,y);
	    }    
	    
	    y +=dyy+3;
	    
	    g.setColor(Color.black);
	    
	    
	    unit_field ="[ "+Ohm+" ]"; 
	    Reale = Math.abs(state.InputReactance);
	    
	    //Magnitude
	    if(Reale<1000.0 && Reale>=1.0 || Reale == 0.0){
		exponent_factor = 1.0;
		exponent = 0;
	    }
	    if(Reale<1.0 && Reale>=1.0E-3){
		exponent_factor = 1.0E-3;
		exponent = -3;
	    }
	    if(Reale<1.0E6 && Reale>=1.0E3){
		exponent_factor = 1.0E3;
		exponent = 3;
	    }
	    if(Reale<1.0E-3 && Reale>=1.0E-6){
		exponent_factor = 1.0E-6;
		exponent = -6;
	    }
	    if(Reale<1.0E9 && Reale>=1.0E6){
		exponent_factor = 1.0E6;
		exponent = 6;
	    }
	    if(Reale<1.0E-6 && Reale>=1.0E-9){
		exponent_factor = 1.0E-9;
		exponent = -9;
	    }
	    if(Reale<1.0E12 && Reale>=1.0E9){
		exponent_factor = 1.0E9;
		exponent = 9;
	    }
	    if(Reale<1.0E-9 && Reale>=1.0E-12){
		exponent_factor = 1.0E-12;
		exponent = -12;
	    }
	    if(Reale<1.0E15 && Reale>=1.0E12){
		exponent_factor = 1.0E12;
		exponent = 12;
	    }
	    if(Reale<1.0E-12 && Reale>=1.0E-15){
		exponent_factor = 1.0E-15;
		exponent = -15;
	    }
	    if(Reale<1.0E18 && Reale>=1.0E15){
		exponent_factor = 1.0E15;
		exponent = 15;
	    }
	    if(Reale<1.0E-15 && Reale>=1.0E-18){
		exponent_factor = 1.0E-18;
		exponent = -18;
	    }
	    if(Reale<1.0E21 && Reale>=1.0E18){
		exponent_factor = 1.0E18;
		exponent = 18;
	    }
	    if(Reale<1.0E-18 && Reale>=1.0E-21){
		exponent_factor = 1.0E-21;
		exponent = -21;
	    }
	    if(Reale<1.0E24 && Reale>=1.0E21){
		exponent_factor = 1.0E21;
		exponent = 21;
	    }
	    if(Reale<1.0E-21 && Reale>=1.0E-24){
		exponent_factor = 1.0E-24;
		exponent = -24;
	    }
	    if(Reale<1.0E27 && Reale>=1.0E24){
		exponent_factor = 1.0E24;
		exponent = 24;
	    }
	    if(Reale<1.0E-24 && Reale>=1.0E-27){
		exponent_factor = 1.0E-27;
		exponent = -27;
	    }
	    if(Reale<1.0E30 && Reale>=1.0E27){
		exponent_factor = 1.0E27;
		exponent = 27;
	    }
	    if(Reale<1.0E-27 && Reale>=1.0E-30){
		exponent_factor = 1.0E-30;
		exponent = -30;
	    }
	    if(Reale>1.0E30){
		exponent_factor = 1.0E30;
		exponent = 30;
	    }
	    if(Reale<1.0E-30 && Reale > 0.0){
		exponent_factor = 1.0E-30;
		exponent = -30;
	    }
	    
	if(state.InputResistance > 1.0E230){
	
	}
	else{
	    g.drawString("j",x+3,y);
	    MaestroG.subscripter("X","in","",g,12,x+10,y);
	    if(state.RadiationReactance >= 0.0){
		if(exponent == 0){
		MaestroG.superscripter("     =  j "+MaestroA.rounder(Reale/exponent_factor,5)+"","",
				   " "+unit_field,g,12,x+30,y);
		}
		else{
		MaestroG.superscripter("     =  j "+MaestroA.rounder(Reale/exponent_factor,5)+" x 10",""+exponent,
				   " "+unit_field,g,12,x+30,y);
		}    
	    }
	    else{
		if(exponent == 0){
		MaestroG.superscripter("     =  - j "+MaestroA.rounder(Reale/exponent_factor,5)+"","",
				   " "+unit_field,g,12,x+30,y);
		}
		else{
		MaestroG.superscripter("     =  - j "+MaestroA.rounder(Reale/exponent_factor,5)+" x 10",""+exponent,
				   " "+unit_field,g,12,x+30,y);
		}    
	    }
	    
	}
	    
	    y +=dyy-6;
	    g.setColor(Color.red);
	    g.drawLine(5,y,getSize().width-5,y);
	    y+=dyy;
	    y+=2;
	    
	    g.setColor(Color.blue);
	    g.drawString("Time-Average Total Radiated Power", x,y);
	    y +=dyy+3;
	    
	    g.setColor(Color.black);
	    //unit_field="[ W ]";
	    //fieldfar = state.TotalPower;
	    //stringp(g);
	    //MaestroG.subscripter("< P","tot"," >",g,12,x,y);
	    
	    
	    g.setFont(new Font("Serif",Font.PLAIN,12));
	    MaestroG.subscripter("< P","tot"," >",g,12,x,y);
	    
	    
	    unit_field ="[ W ]"; 
	    Reale = state.TotalPower;
	    
	    //Magnitude
	    if(Reale<1000.0 && Reale>=1.0 || Reale == 0.0){
		exponent_factor = 1.0;
		exponent = 0;
	    }
	    if(Reale<1.0 && Reale>=1.0E-3){
		exponent_factor = 1.0E-3;
		exponent = -3;
	    }
	    if(Reale<1.0E6 && Reale>=1.0E3){
		exponent_factor = 1.0E3;
		exponent = 3;
	    }
	    if(Reale<1.0E-3 && Reale>=1.0E-6){
		exponent_factor = 1.0E-6;
		exponent = -6;
	    }
	    if(Reale<1.0E9 && Reale>=1.0E6){
		exponent_factor = 1.0E6;
		exponent = 6;
	    }
	    if(Reale<1.0E-6 && Reale>=1.0E-9){
		exponent_factor = 1.0E-9;
		exponent = -9;
	    }
	    if(Reale<1.0E12 && Reale>=1.0E9){
		exponent_factor = 1.0E9;
		exponent = 9;
	    }
	    if(Reale<1.0E-9 && Reale>=1.0E-12){
		exponent_factor = 1.0E-12;
		exponent = -12;
	    }
	    if(Reale<1.0E15 && Reale>=1.0E12){
		exponent_factor = 1.0E12;
		exponent = 12;
	    }
	    if(Reale<1.0E-12 && Reale>=1.0E-15){
		exponent_factor = 1.0E-15;
		exponent = -15;
	    }
	    if(Reale<1.0E18 && Reale>=1.0E15){
		exponent_factor = 1.0E15;
		exponent = 15;
	    }
	    if(Reale<1.0E-15 && Reale>=1.0E-18){
		exponent_factor = 1.0E-18;
		exponent = -18;
	    }
	    if(Reale<1.0E21 && Reale>=1.0E18){
		exponent_factor = 1.0E18;
		exponent = 18;
	    }
	    if(Reale<1.0E-18 && Reale>=1.0E-21){
		exponent_factor = 1.0E-21;
		exponent = -21;
	    }
	    if(Reale<1.0E24 && Reale>=1.0E21){
		exponent_factor = 1.0E21;
		exponent = 21;
	    }
	    if(Reale<1.0E-21 && Reale>=1.0E-24){
		exponent_factor = 1.0E-24;
		exponent = -24;
	    }
	    if(Reale<1.0E27 && Reale>=1.0E24){
		exponent_factor = 1.0E24;
		exponent = 24;
	    }
	    if(Reale<1.0E-24 && Reale>=1.0E-27){
		exponent_factor = 1.0E-27;
		exponent = -27;
	    }
	    if(Reale<1.0E30 && Reale>=1.0E27){
		exponent_factor = 1.0E27;
		exponent = 27;
	    }
	    if(Reale<1.0E-27 && Reale>=1.0E-30){
		exponent_factor = 1.0E-30;
		exponent = -30;
	    }
	    if(Reale>1.0E30){
		exponent_factor = 1.0E30;
		exponent = 30;
	    }
	    if(Reale<1.0E-30 && Reale > 0.0){
		exponent_factor = 1.0E-30;
		exponent = -30;
	    }
	    if(exponent == 0){
	    MaestroG.superscripter("     =  "+MaestroA.rounder(Reale/exponent_factor,5)+"","",
				   " "+unit_field,g,12,x+30,y);
	    }
	    else{
	    MaestroG.superscripter("     =  "+MaestroA.rounder(Reale/exponent_factor,5)+" x 10",""+exponent,
				   " "+unit_field,g,12,x+30,y);
	    }   
	}
}

    class NewOutputCanvasB extends Canvas{
	private static final Font normalfont = new Font("SanSerif",Font.PLAIN,12);
	private static final Font subfont    = new Font("SanSerif",Font.PLAIN,10);
	private static final Font symbolfont=new Font("Serif",Font.PLAIN,12);
	NewGuide_State state;
	private Image im;
	private Graphics buf;
	public NewOutputCanvasB(NewGuide_State state){
	    super();
	    this.state = state;
	}
	
	public void paint(Graphics g){
	    if(im == null){
		im = createImage(getSize().width,getSize().height);
		buf = im.getGraphics();
		drawCanvas(buf);
	    }
	    else{
		drawCanvas(buf);
	    }
	    g.drawImage(im,0,0,null);
	}

	//Addition to reduce flicker new routine
	public void update(Graphics g){		// added to avoid clearing
	    paint(g);
	}
	
	public void clear(){
	    this.getGraphics().clearRect(0,0,getSize().width,getSize().height);
	    repaint();
	}


	
	public void drawCanvas(Graphics g){
	    int x, y, dx, dxx, dy, dyy;
	    double v_normalized;
	    //Color bgcolor = Color.lightGray;
	    Color bgcolor = new Color(236,236,221);
	    String stmp;
	    String lambda, Ohm;
	    FontMetrics fm;
	       
	    
	    x = 10;
	    y = 25;
	    dx = 80;
	    dxx = 15;
	    g.setFont(normalfont);
	    fm = g.getFontMetrics();
	    //dy = fm.getHeight();
	    dy = 12;
	    dyy = dy+1;
	    
	    g.setFont(symbolfont);
	    g.getFontMetrics();
	    lambda="\u03bb";
	    Ohm="\u03a9";
	    g.setFont(normalfont);
	    g.getFontMetrics();
	    	    
	    g.setColor(bgcolor);
	    g.fillRect(0,0,getSize().width,getSize().height);
	    
	    g.setColor(Color.black);
	    g.drawLine(5,5,getSize().width-5,5);
	    
	    g.setColor(Color.blue);
	    g.drawString("Wavelength", x,y);
	    y +=dyy+3;
	    
	    g.setColor(Color.black);
	    g.setFont(new Font("Serif",Font.PLAIN,12));
	    g.drawString("\u03bb",x+25,y);
	    g.setFont(new Font("SanSerif",Font.PLAIN,12));
	    g.drawString("      =  "+MaestroA.rounder(state.lambda,8)+"  [ m ]",x+25,y);
	    //g.drawString("[ m ]",x+185,y);
	    y +=dyy+3;
	    
	    g.setColor(Color.blue);
	    g.drawString("Antenna Length", x,y);
	    y +=dyy+3;
	    	    
	    g.setColor(Color.black);    
	    g.drawString(" L ",x+20,y);
	    g.drawString("      = "+MaestroA.rounder(state.a,8)+"  "+lambda,x+25,y);
	    y+=dyy+3;
	     
	    g.drawString("      = "+MaestroA.rounder(state.a * state.wavelength,8)+"  [ m ]",x+25,y);
	    
	    y +=dyy-8;
	    
	    g.setColor(Color.red);
	    g.drawLine(5,y,getSize().width-5,y);
	    y+=dyy;
	    y+=2;
	    g.setColor(Color.blue);
	    g.drawString("Discretization intervals for 3-D fields", x,y);
	    y +=dyy+3;
	    g.setColor(Color.black);
	    
	    MaestroG.subscripter("N","s"," = "+state.Nsections,g,12,x+25,y);
	    y+=dyy+5;
	    
	    g.setColor(Color.blue);
	    g.drawString("Length of discretization intervals", x,y);
	    y +=dyy+3;
	    g.setColor(Color.black);
	    
	    g.setFont(new Font("Serif",Font.PLAIN,12));
	    g.drawString("\u0394",x+25,y);
	    g.setFont(new Font("SanSerif",Font.PLAIN,12));
	    
	    MaestroG.subscripter("    z",""," = "+(MaestroA.rounder(state.DeltaZ,8))+"  [ m ]",g,12,x+25,y);
	    
	    y+=dyy+3;	    
	    g.setColor(Color.blue);
	    g.drawString("Discretization intervals for current plot", x,y);
	    y +=dyy+3;
	    
	    g.setColor(Color.black);
	    MaestroG.subscripter("N","c"," = "+(state.NsectionsLarge-1),g,12,x+25,y);
	    
	    y+=dyy-5;
	    
	    g.setColor(Color.red);
	    g.drawLine(5,y,getSize().width-5,y);
	    y+=dyy;
	    y+=2;
	    
	    g.setColor(Color.blue);
	    g.drawString("Assumptions", x,y);
	    y +=dyy+3;
	    
	    g.setColor(Color.black);
	    g.drawString("- Gap between radiating elements is neglected.", x,y);
	    y +=dyy+3;
	    
	    g.drawString("- Wire radius used only for reactance calculations.", x,y);
    }

}
class NewOutputCanvasField extends Canvas{
	private static final Font normalfont = new Font("SanSerif",Font.PLAIN,12);
	private static final Font subfont    = new Font("SanSerif",Font.PLAIN,10);
	private static final Font symbolfont=new Font("Serif",Font.PLAIN,12);
	public String string_field, unit_field; 
	int x, y;
	public Complex field;
	public double fieldfar;
	NewGuide_State state;
	private Image im;
	private Graphics buf;
	public NewOutputCanvasField(NewGuide_State state){
	    super();
	    this.state = state;
	}
	
	public void paint(Graphics g){
	    if(im == null){
		im = createImage(getSize().width,getSize().height);
		buf = im.getGraphics();
		drawCanvas(buf);
	    }
	    else{
		drawCanvas(buf);
	    }
	    g.drawImage(im,0,0,null);
	}

	//Addition to reduce flicker new routine
	public void update(Graphics g){		// added to avoid clearing
	    paint(g);
	}
	
	public void clear(){
	    this.getGraphics().clearRect(0,0,getSize().width,getSize().height);
	    repaint();
	}

	public void drawCanvas(Graphics g){
            
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
	    int dx, dxx, dy, dyy;
	    double tempcap, Cond1, Res1, tempind, f_normalized;
	    //Color bgcolor = Color.lightGray;
	    Color bgcolor = new Color(236,236,221);
	    String stmp;
	    FontMetrics fm;
	    
	    double light_velocity = 1.0/Math.sqrt(state.epsilon0*state.mu0*state.epsilon_r);
	    double light_velocity0 = 1.0/Math.sqrt(state.epsilon0*state.mu0);
	    String lambda, Ohm, theta, phi, deg, angle;
	    x = 2;
	    y = 5;
	    dx = 80;
	    dxx = 15;
	    g.setFont(normalfont);
	    fm = g.getFontMetrics();
	    dy = 12;
	    dyy = dy+1;
	    
	    g.setFont(symbolfont);
	    g.getFontMetrics();
	    lambda="\u03bb";
	    Ohm="\u03a9";
	    lambda="\u03bb";
	    theta="\u03b8";
	    phi="\u03c6";
	    deg="\u00ba";
            angle="\u2220";
	    g.setFont(normalfont);
	    g.getFontMetrics();
	    
		
	    g.setColor(bgcolor);
	    g.fillRect(0,0,getSize().width,getSize().height);
	    
	   
	    g.setColor(Color.black);
	    g.drawLine(5,y,getSize().width-5,y);
	    y+=dyy;
	    y+=2;
	    g.drawString("Numerical Calculation", x,y);
	    
	    y +=dyy+6;
	    
	    g.setColor(Color.red);
	    MaestroG.subscripterSymbol("E","\u03b8","",g,12,x+5,y);
	    unit_field="[ V/m ]";
	    field = state.ethetaC;
	    
	    stringa(g);
	    y+=dyy;
	    stringe(g);
	    
	    y +=dyy+4;
	    
	    g.setColor(Color.red);
	    MaestroG.subscripterS("E","R","",g,12,x+5,y);
	    unit_field="[ V/m ]";
	    field = state.eradC;
	    stringa(g);
	    y+=dyy;
	    stringe(g);
	    
	    y +=dyy+3;
	    
	    g.setColor(Color.blue);
	    MaestroG.subscripterSymbol("H","\u03c6","",g,12,x+5,y);
	    unit_field="[ A/m ]";
	    field = state.hphigenC;
	    stringa(g);
	    y+=dyy;
	    stringe(g);
	    
	    
	    y +=dyy-8;
	    g.setColor(Color.red);
	    g.drawLine(5,y,getSize().width-5,y);
	    y+=dyy;
	    y+=2;
	    
	    g.setFont(normalfont);
	    g.getFontMetrics();
	    g.setColor(Color.black);
	    g.drawString("Far-Field Approximation", x,y);
	    
	    y +=dyy+6;
	    
	    g.setColor(Color.red);
	    MaestroG.subscripterSymbol("E","\u03b8","",g,12,x+5,y);
	    unit_field="[ V/m ]";
	    field = state.EfarC;
	    stringa(g);
	    y+=dyy;
	    stringe(g);
	    
	    y +=dyy+4;
	    
	    g.setColor(Color.red);
	    MaestroG.subscripterS("E","R","",g,12,x+5,y);
	    unit_field="[ V/m ]";
	    fieldfar = 0.0;
	    stringp(g);
	    y +=dyy+6;
	    
	    g.setColor(Color.blue);
	    MaestroG.subscripterSymbol("H","\u03c6","",g,12,x+5,y);
	    unit_field="[ A/m ]";
	    field = state.HfarC;
	    stringa(g);
	    y+=dyy;
	    stringe(g);
	    y +=5;
	    g.setColor(Color.red);
	    g.drawLine(5,y,getSize().width-5,y);
	    
	    y +=dyy+4;
	    
	    g.setFont(normalfont);
	    g.getFontMetrics();
	    g.setColor(Color.black);
	    g.drawString("Time-average Power Density", x,y);
	    
	    y +=dyy+3;
	    
	    g.setColor(new Color(150,0,0));
	    MaestroG.subscripterS("<P","R"," >",g,12,x,y);
	    unit_field="[ W/m\u00b2 ]";
	    fieldfar = state.Pfar;
	    stringp(g);
	    
	    
	}
	private void stringa(Graphics g){
	    String sign, sign2;
	    double exponent_factorR, exponent_factorI, Reale, Immaginario;
	    int exponentR, exponentI;
	    
	    //Determine sign
	    if(Complex.Imaginary(field) < 0.0){
		sign ="  - j ";
	    }
	    else{
		sign =" + j ";
	    }
	    
	    if(Complex.Real(field) < 0.0){
		sign2 =" - ";
	    }
	    else{
		sign2 ="  ";
	    }
	    
	    exponent_factorR = 0.0;
	    exponentR = 0;
	    
	    Reale = Math.abs(Complex.Real(field));
	    Immaginario = Math.abs(Complex.Imaginary(field));
	    
	    //Real Part
	    if(Reale < 1000.0 && Reale >= 1.0 || Reale == 0.0){
		exponent_factorR = 1.0;
		exponentR = 0;
	    }
	    if(Reale<1.0 && Reale>=1.0E-3){
		exponent_factorR = 1.0E-3;
		exponentR = -3;
	    }
	    if(Reale<1.0E6 && Reale>=1.0E3){
		exponent_factorR = 1.0E3;
		exponentR = 3;
	    }
	    if(Reale<1.0E-3 && Reale>=1.0E-6){
		exponent_factorR = 1.0E-6;
		exponentR = -6;
	    }
	    if(Reale<1.0E9 && Reale>=1.0E6){
		exponent_factorR = 1.0E6;
		exponentR = 6;
	    }
	    if(Reale<1.0E-6 && Reale>=1.0E-9){
		exponent_factorR = 1.0E-9;
		exponentR = -9;
	    }
	    if(Reale<1.0E12 && Reale>=1.0E9){
		exponent_factorR = 1.0E9;
		exponentR = 9;
	    }
	    if(Reale<1.0E-9 && Reale>=1.0E-12){
		exponent_factorR = 1.0E-12;
		exponentR = -12;
	    }
	    if(Reale<1.0E15 && Reale>=1.0E12){
		exponent_factorR = 1.0E12;
		exponentR = 12;
	    }
	    if(Reale<1.0E-12 && Reale>=1.0E-15){
		exponent_factorR = 1.0E-15;
		exponentR = -15;
	    }
	    if(Reale<1.0E18 && Reale>=1.0E15){
		exponent_factorR = 1.0E15;
		exponentR = 15;
	    }
	    if(Reale<1.0E-15 && Reale>=1.0E-18){
		exponent_factorR = 1.0E-18;
		exponentR = -18;
	    }
	    if(Reale<1.0E21 && Reale>=1.0E18){
		exponent_factorR = 1.0E18;
		exponentR = 18;
	    }
	    if(Reale<1.0E-18 && Reale>=1.0E-21){
		exponent_factorR = 1.0E-21;
		exponentR = -21;
	    }
	    if(Reale<1.0E24 && Reale>=1.0E21){
		exponent_factorR = 1.0E21;
		exponentR = 21;
	    }
	    if(Reale<1.0E-21 && Reale>=1.0E-24){
		exponent_factorR = 1.0E-24;
		exponentR = -24;
	    }
	    if(Reale<1.0E27 && Reale>=1.0E24){
		exponent_factorR = 1.0E24;
		exponentR = 24;
	    }
	    if(Reale<1.0E-24 && Reale>=1.0E-27){
		exponent_factorR = 1.0E-27;
		exponentR = -27;
	    }
	    if(Reale<1.0E30 && Reale>=1.0E27){
		exponent_factorR = 1.0E27;
		exponentR = 27;
	    }
	    if(Reale<1.0E-27 && Reale>=1.0E-30){
		exponent_factorR = 1.0E-30;
		exponentR = -30;
	    }
	    if(Reale>1.0E30){
		exponent_factorR = 1.0E30;
		exponentR = 30;
	    }
	    if(Reale<1.0E-30 && Reale > 0.0){
		exponent_factorR = 1.0E-30;
		exponentR = -30;
	    }
	    
	    exponent_factorI = 0.0;
	    exponentI = 0;
	    // Imaginary Part
	    if(Immaginario<1000.0 && Immaginario>=1.0 || Immaginario == 0.0){
		exponent_factorI = 1.0;
		exponentI = 0;
	    }
	    if(Immaginario<1.0 && Immaginario>=1.0E-3){
		exponent_factorI = 1.0E-3;
		exponentI = -3;
	    }
	    if(Immaginario<1.0E6 && Immaginario>=1.0E3){
		exponent_factorI = 1.0E3;
		exponentI = 3;
	    }
	    if(Immaginario<1.0E-3 && Immaginario>=1.0E-6){
		exponent_factorI = 1.0E-6;
		exponentI = -6;
	    }
	    if(Immaginario<1.0E9 && Immaginario>=1.0E6){
		exponent_factorI = 1.0E6;
		exponentI = 6;
	    }
	    if(Immaginario<1.0E-6 && Immaginario>=1.0E-9){
		exponent_factorI = 1.0E-9;
		exponentI = -9;
	    }
	    if(Immaginario<1.0E12 && Immaginario>=1.0E9){
		exponent_factorI = 1.0E9;
		exponentI = 9;
	    }
	    if(Immaginario<1.0E-9 && Immaginario>=1.0E-12){
		exponent_factorI = 1.0E-12;
		exponentI = -12;
	    }
	    if(Immaginario<1.0E15 && Immaginario>=1.0E12){
		exponent_factorI = 1.0E12;
		exponentI = 12;
	    }
	    if(Immaginario<1.0E-12 && Immaginario>=1.0E-15){
		exponent_factorI = 1.0E-15;
		exponentI = -15;
	    }
	    if(Immaginario<1.0E18 && Immaginario>=1.0E15){
		exponent_factorI = 1.0E15;
		exponentI = 15;
	    }
	    if(Immaginario<1.0E-15 && Immaginario>=1.0E-18){
		exponent_factorI = 1.0E-18;
		exponentI = -18;
	    }
	    if(Immaginario<1.0E21 && Immaginario>=1.0E18){
		exponent_factorI = 1.0E18;
		exponentI = 18;
	    }
	    if(Immaginario<1.0E-18 && Immaginario>=1.0E-21){
		exponent_factorI = 1.0E-21;
		exponentI = -21;
	    }
	    if(Immaginario<1.0E24 && Immaginario>=1.0E21){
		exponent_factorI = 1.0E21;
		exponentI = 21;
	    }
	    if(Immaginario<1.0E-21 && Immaginario>=1.0E-24){
		exponent_factorI = 1.0E-24;
		exponentI = -24;
	    }
	    if(Immaginario<1.0E27 && Immaginario>=1.0E24){
		exponent_factorI = 1.0E24;
		exponentI = 24;
	    }
	    if(Immaginario<1.0E-24 && Immaginario>=1.0E-27){
		exponent_factorI = 1.0E-27;
		exponentI = -27;
	    }
	    if(Immaginario<1.0E30 && Immaginario>=1.0E27){
		exponent_factorI = 1.0E27;
		exponentI = 27;
	    }
	    if(Immaginario<1.0E-27 && Immaginario>=1.0E-30){
		exponent_factorI = 1.0E-30;
		exponentI = -30;
	    }
	    if(Reale>1.0E30){
		exponent_factorI = 1.0E30;
		exponentI = 30;
	    }
	    if(Immaginario<1.0E-30 && Immaginario > 0.0){
		exponent_factorI = 1.0E-30;
		exponentI = -30;
	    }
	    
	    if(exponentR == 0 && exponentI == 0){
		MaestroG.doublesuperscripter(" = "+sign2+MaestroA.rounder(Reale/exponent_factorR,3)+"","",
				   ""+sign+MaestroA.rounder(Immaginario/exponent_factorI,3)+"","",
				   " "+unit_field,g,11,x+30,y);
	    }
	    else if(exponentR == 0 && exponentI != 0){
		MaestroG.doublesuperscripter(" = "+sign2+MaestroA.rounder(Reale/exponent_factorR,3)+"","",
				   ""+sign+MaestroA.rounder(Immaginario/exponent_factorI,3)+" x 10",""+exponentI,
				   " "+unit_field,g,11,x+30,y);
	    }
	    else if(exponentR != 0 && exponentI == 0){
		MaestroG.doublesuperscripter(" = "+sign2+MaestroA.rounder(Reale/exponent_factorR,3)+" x 10",""+exponentR,
				   ""+sign+MaestroA.rounder(Immaginario/exponent_factorI,3)+"","",
				   " "+unit_field,g,11,x+30,y);
	    }
	    else{
		MaestroG.doublesuperscripter(" = "+sign2+MaestroA.rounder(Reale/exponent_factorR,3)+" x 10",""+exponentR,
				   ""+sign+MaestroA.rounder(Immaginario/exponent_factorI,3)+" x 10",""+exponentI,
				   " "+unit_field,g,11,x+30,y);
	    }
	} 
	
private void stringe(Graphics g){
	    String sign, sign2;
	    double exponent_factor, Reale;
	    int exponent;
	       
	    exponent_factor = 0.0;
	    exponent = 0;
	    
	    Reale = Complex.Magnitude(field);
	    
	    //Magnitude
	    if(Reale<1000.0 && Reale>=1.0 || Reale == 0.0){
		exponent_factor = 1.0;
		exponent = 0;
	    }
	    if(Reale<1.0 && Reale>=1.0E-3){
		exponent_factor = 1.0E-3;
		exponent = -3;
	    }
	    if(Reale<1.0E6 && Reale>=1.0E3){
		exponent_factor = 1.0E3;
		exponent = 3;
	    }
	    if(Reale<1.0E-3 && Reale>=1.0E-6){
		exponent_factor = 1.0E-6;
		exponent = -6;
	    }
	    if(Reale<1.0E9 && Reale>=1.0E6){
		exponent_factor = 1.0E6;
		exponent = 6;
	    }
	    if(Reale<1.0E-6 && Reale>=1.0E-9){
		exponent_factor = 1.0E-9;
		exponent = -9;
	    }
	    if(Reale<1.0E12 && Reale>=1.0E9){
		exponent_factor = 1.0E9;
		exponent = 9;
	    }
	    if(Reale<1.0E-9 && Reale>=1.0E-12){
		exponent_factor = 1.0E-12;
		exponent = -12;
	    }
	    if(Reale<1.0E15 && Reale>=1.0E12){
		exponent_factor = 1.0E12;
		exponent = 12;
	    }
	    if(Reale<1.0E-12 && Reale>=1.0E-15){
		exponent_factor = 1.0E-15;
		exponent = -15;
	    }
	    if(Reale<1.0E18 && Reale>=1.0E15){
		exponent_factor = 1.0E15;
		exponent = 15;
	    }
	    if(Reale<1.0E-15 && Reale>=1.0E-18){
		exponent_factor = 1.0E-18;
		exponent = -18;
	    }
	    if(Reale<1.0E21 && Reale>=1.0E18){
		exponent_factor = 1.0E18;
		exponent = 18;
	    }
	    if(Reale<1.0E-18 && Reale>=1.0E-21){
		exponent_factor = 1.0E-21;
		exponent = -21;
	    }
	    if(Reale<1.0E24 && Reale>=1.0E21){
		exponent_factor = 1.0E21;
		exponent = 21;
	    }
	    if(Reale<1.0E-21 && Reale>=1.0E-24){
		exponent_factor = 1.0E-24;
		exponent = -24;
	    }
	    if(Reale<1.0E27 && Reale>=1.0E24){
		exponent_factor = 1.0E24;
		exponent = 24;
	    }
	    if(Reale<1.0E-24 && Reale>=1.0E-27){
		exponent_factor = 1.0E-27;
		exponent = -27;
	    }
	    if(Reale<1.0E30 && Reale>=1.0E27){
		exponent_factor = 1.0E27;
		exponent = 27;
	    }
	    if(Reale<1.0E-27 && Reale>=1.0E-30){
		exponent_factor = 1.0E-30;
		exponent = -30;
	    }
	    if(Reale>1.0E30){
		exponent_factor = 1.0E30;
		exponent = 30;
	    }
	    if(Reale<1.0E-30 && Reale > 0.0){
		exponent_factor = 1.0E-30;
		exponent = -30;
	    }
	    
		if(exponent == 0){
		MaestroG.superscripter(" =   "+MaestroA.rounder(Reale/exponent_factor,3)+"","",
				   " \u2220 "+MaestroA.rounder(Complex.Arg2(field),3)+" rad",g,11,x+30,y);
		}
		else{
		MaestroG.superscripter(" =   "+MaestroA.rounder(Reale/exponent_factor,3)+" x 10",""+exponent,
				   " \u2220 "+MaestroA.rounder(Complex.Arg2(field),3)+" rad",g,11,x+30,y);
		}
	} 
	
	private void stringm(Graphics g){
	    String sign;
	    double exponent_factor, Reale;
	    int exponent;
	    
	    //Determine sign
	    if(fieldfar < 0.0){
		sign ="  - j ";
	    }
	    else{
		sign ="   j ";
	    }
	       
	    exponent_factor = 0.0;
	    exponent = 0;
	    
	    Reale = Math.abs(fieldfar);
	    
	    //Magnitude
	    if(Reale<1000.0 && Reale>=1.0 || Reale == 0.0){
		exponent_factor = 1.0;
		exponent = 0;
	    }
	    if(Reale<1.0 && Reale>=1.0E-3){
		exponent_factor = 1.0E-3;
		exponent = -3;
	    }
	    if(Reale<1.0E6 && Reale>=1.0E3){
		exponent_factor = 1.0E3;
		exponent = 3;
	    }
	    if(Reale<1.0E-3 && Reale>=1.0E-6){
		exponent_factor = 1.0E-6;
		exponent = -6;
	    }
	    if(Reale<1.0E9 && Reale>=1.0E6){
		exponent_factor = 1.0E6;
		exponent = 6;
	    }
	    if(Reale<1.0E-6 && Reale>=1.0E-9){
		exponent_factor = 1.0E-9;
		exponent = -9;
	    }
	    if(Reale<1.0E12 && Reale>=1.0E9){
		exponent_factor = 1.0E9;
		exponent = 9;
	    }
	    if(Reale<1.0E-9 && Reale>=1.0E-12){
		exponent_factor = 1.0E-12;
		exponent = -12;
	    }
	    if(Reale<1.0E15 && Reale>=1.0E12){
		exponent_factor = 1.0E12;
		exponent = 12;
	    }
	    if(Reale<1.0E-12 && Reale>=1.0E-15){
		exponent_factor = 1.0E-15;
		exponent = -15;
	    }
	    if(Reale<1.0E18 && Reale>=1.0E15){
		exponent_factor = 1.0E15;
		exponent = 15;
	    }
	    if(Reale<1.0E-15 && Reale>=1.0E-18){
		exponent_factor = 1.0E-18;
		exponent = -18;
	    }
	    if(Reale<1.0E21 && Reale>=1.0E18){
		exponent_factor = 1.0E18;
		exponent = 18;
	    }
	    if(Reale<1.0E-18 && Reale>=1.0E-21){
		exponent_factor = 1.0E-21;
		exponent = -21;
	    }
	    if(Reale<1.0E24 && Reale>=1.0E21){
		exponent_factor = 1.0E21;
		exponent = 21;
	    }
	    if(Reale<1.0E-21 && Reale>=1.0E-24){
		exponent_factor = 1.0E-24;
		exponent = -24;
	    }
	    if(Reale<1.0E27 && Reale>=1.0E24){
		exponent_factor = 1.0E24;
		exponent = 24;
	    }
	    if(Reale<1.0E-24 && Reale>=1.0E-27){
		exponent_factor = 1.0E-27;
		exponent = -27;
	    }
	    if(Reale<1.0E30 && Reale>=1.0E27){
		exponent_factor = 1.0E27;
		exponent = 27;
	    }
	    if(Reale<1.0E-27 && Reale>=1.0E-30){
		exponent_factor = 1.0E-30;
		exponent = -30;
	    }
	    if(Reale>1.0E30){
		exponent_factor = 1.0E30;
		exponent = 30;
	    }
	    if(Reale<1.0E-30 && Reale > 0.0){
		exponent_factor = 1.0E-30;
		exponent = -30;
	    }
	    
		if(exponent == 0){
		MaestroG.superscripter(" =  "+sign+MaestroA.rounder(Reale/exponent_factor,3)+"","",
				   " "+unit_field,g,11,x+30,y);
		}
		else{
		MaestroG.superscripter(" =  "+sign+MaestroA.rounder(Reale/exponent_factor,3)+" x 10",""+exponent,
				   " "+unit_field,g,11,x+30,y);
		}
	} 
	private void stringp(Graphics g){
	    String sign, sign2;
	    double exponent_factor, Reale;
	    int exponent;
	       
	    exponent_factor = 0.0;
	    exponent = 0;
	    
	    Reale = fieldfar;
	    
	    //Magnitude
	    if(Reale<1000.0 && Reale>=1.0 || Reale == 0.0){
		exponent_factor = 1.0;
		exponent = 0;
	    }
	    if(Reale<1.0 && Reale>=1.0E-3){
		exponent_factor = 1.0E-3;
		exponent = -3;
	    }
	    if(Reale<1.0E6 && Reale>=1.0E3){
		exponent_factor = 1.0E3;
		exponent = 3;
	    }
	    if(Reale<1.0E-3 && Reale>=1.0E-6){
		exponent_factor = 1.0E-6;
		exponent = -6;
	    }
	    if(Reale<1.0E9 && Reale>=1.0E6){
		exponent_factor = 1.0E6;
		exponent = 6;
	    }
	    if(Reale<1.0E-6 && Reale>=1.0E-9){
		exponent_factor = 1.0E-9;
		exponent = -9;
	    }
	    if(Reale<1.0E12 && Reale>=1.0E9){
		exponent_factor = 1.0E9;
		exponent = 9;
	    }
	    if(Reale<1.0E-9 && Reale>=1.0E-12){
		exponent_factor = 1.0E-12;
		exponent = -12;
	    }
	    if(Reale<1.0E15 && Reale>=1.0E12){
		exponent_factor = 1.0E12;
		exponent = 12;
	    }
	    if(Reale<1.0E-12 && Reale>=1.0E-15){
		exponent_factor = 1.0E-15;
		exponent = -15;
	    }
	    if(Reale<1.0E18 && Reale>=1.0E15){
		exponent_factor = 1.0E15;
		exponent = 15;
	    }
	    if(Reale<1.0E-15 && Reale>=1.0E-18){
		exponent_factor = 1.0E-18;
		exponent = -18;
	    }
	    if(Reale<1.0E21 && Reale>=1.0E18){
		exponent_factor = 1.0E18;
		exponent = 18;
	    }
	    if(Reale<1.0E-18 && Reale>=1.0E-21){
		exponent_factor = 1.0E-21;
		exponent = -21;
	    }
	    if(Reale<1.0E24 && Reale>=1.0E21){
		exponent_factor = 1.0E21;
		exponent = 21;
	    }
	    if(Reale<1.0E-21 && Reale>=1.0E-24){
		exponent_factor = 1.0E-24;
		exponent = -24;
	    }
	    if(Reale<1.0E27 && Reale>=1.0E24){
		exponent_factor = 1.0E24;
		exponent = 24;
	    }
	    if(Reale<1.0E-24 && Reale>=1.0E-27){
		exponent_factor = 1.0E-27;
		exponent = -27;
	    }
	    if(Reale<1.0E30 && Reale>=1.0E27){
		exponent_factor = 1.0E27;
		exponent = 27;
	    }
	    if(Reale<1.0E-27 && Reale>=1.0E-30){
		exponent_factor = 1.0E-30;
		exponent = -30;
	    }
	    if(Reale>1.0E30){
		exponent_factor = 1.0E30;
		exponent = 30;
	    }
	    if(Reale<1.0E-30 && Reale > 0.0){
		exponent_factor = 1.0E-30;
		exponent = -30;
	    }
	    
		if(exponent == 0){
		MaestroG.superscripter(" =    "+MaestroA.rounder(Reale/exponent_factor,3)+"","",
				   " "+unit_field,g,11,x+30,y);
		}
		else{
		MaestroG.superscripter(" =    "+MaestroA.rounder(Reale/exponent_factor,3)+" x 10",""+exponent,
				   " "+unit_field,g,11,x+30,y);
		}
	} 
	
}
   