//NewGuideOutputPanel17.java
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.lang.*;  
//import maestro.lib.math.*;
//import maestro.lib.graphics.*;

public class NewGuideOutputPanel17 extends Panel implements ItemListener{
	NewGuide_State state;
	private static final Color bgcolor = new Color(236,236,221);
	//private static final Color bgcolor = Color.lightGray;
	private static final Font labfont=new Font("SanSerif",Font.PLAIN,12);
	
	private static final Font titlefont=new Font("SanSerif",Font.BOLD,16);
	Label titlelabel;	
	public Choice c1;
	public TitleCanvas16 tcanvas16;
	public NewOutputCanvas14P rwoc14P; 
	public NewOutputCanvas15P rwoc15P;
	public ScrollPane pane1, pane2;
	
	public NewGuideOutputPanel17(NewGuide_State state){
	    super();
	    setLayout(null);
	    this.state = state;
	    setBackground(bgcolor);
	    state.microFlag17 = false;

	    titlelabel = new Label("    Field Data",Label.LEFT);
	    //add(titlelabel);
	    titlelabel.setBounds(5,5,95,15);    
	    titlelabel.setFont(titlefont);
	    
	    pane1 = new ScrollPane();
	    pane1.setBounds(4,29,287,263);
	    add(pane1);
	    pane2  = new ScrollPane();
	    pane2.setBounds(4,29,287,263);
	    add(pane2);
	    
	    Panel pp1 = new Panel();
	    pp1.setBackground(Color.black);
	    add(pp1);
	    pp1.setBounds(4,29,288,264);
    	    
	    c1 = new Choice();
	    c1.addItem("  [ A/m ] ");
	    c1.addItem("  [ dB mA/m ]");
	    c1.addItem("  [ dB \u00b5A/m ]");
	    add(c1);
	    c1.setBounds(105,2,125,25);
	    //c1.setBackground(bgcolor.brighter());
	    
	    tcanvas16 = new TitleCanvas16(state);
	    add(tcanvas16);
	    tcanvas16.setBounds(0,0,295,25);
	    
	    rwoc14P = new NewOutputCanvas14P(state);
	    pane1.add(rwoc14P);
	    pane1.setBackground(Color.white);
	    rwoc14P.setBounds(0,50,260,5800);
	    
	    rwoc15P = new NewOutputCanvas15P(state);
	    pane2.add(rwoc15P);
	    pane2.setBackground(Color.white);
	    rwoc15P.setBounds(0,50,260,5800);
	    pane1.setVisible(true);
	    pane2.setVisible(false);
	    //Listeners
	    c1.addItemListener(this);
	}


    public void itemStateChanged(ItemEvent evt){
	ItemSelectable ie = evt.getItemSelectable();
	    if(evt.getSource()==c1){
		if(ie.getSelectedObjects()[0]=="  [ A/m ] "){
		    pane1.setVisible(true);
		    pane2.setVisible(false);
		}
		else if(ie.getSelectedObjects()[0]=="  [ dB mA/m ]"){
		    pane1.setVisible(false);
		    pane2.setVisible(true);
		    state.microFlag17 = false;
		    rwoc15P.repaint();
		}
		else if(ie.getSelectedObjects()[0]=="  [ dB \u00b5A/m ]"){
		    pane1.setVisible(false);
		    pane2.setVisible(true);
		    state.microFlag17 = true;
		    rwoc15P.repaint();
		}
	    }
    }	
}

class TitleCanvas16 extends Canvas{
	private static final Font normalfont = new Font("Serif",Font.PLAIN,12);
	private static final Font subfont    = new Font("Serif",Font.PLAIN,10);
	private static final Font normalfontB = new Font("Serif",Font.BOLD,12);
	
	private static final Font symbolfont=new Font("Serif",Font.PLAIN,16);
	private static final Font symbolfont2=new Font("Serif",Font.PLAIN,14);
	
	NewGuide_State state;
	public TitleCanvas16(NewGuide_State state){
	    super();
	    this.state = state;
	}
	
	public void paint(Graphics g){
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
	    g.setFont(symbolfont);
	    g.setColor(Color.blue);
	    g.drawString("\u03c6",20,17);
	    //g.setColor(Color.black);
	    g.drawString("\u03c6",21,17);
	    
	    //g.setFont(symbolfont2);
	    //g.drawString("\u03c6",78,22);
	    //g.drawString("\u03c6",79,22);
	    //g.setFont(normalfontB);
	    //g.drawString("| H    |",65,17);
	    MaestroG.subscripter3("| H","y"," |",g,12,65,17);
	    
	    g.setFont(new Font("Serif",Font.PLAIN,12)); 
	    g.drawString("\u03b8",235,17);
	    g.setFont(new Font("Serif",Font.PLAIN,12)); 
	    g.drawString("= 90.0\u00b0",245,17);
	    
	}
}

class NewOutputCanvas14P 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,14);
	NewGuide_State state;
	public NewOutputCanvas14P(NewGuide_State state){
	    super();
	    this.state = state;
	}
	
	public void paint(Graphics g){
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
	    int x, y, dx, dxx, dy, dyy;
	    double v_normalized, f_normalized;
	    String stmp;
	    FontMetrics fm;
	    x = 10;
	    y = 15;
	    dx = 80;
	    dxx = 15;
	    g.setFont(normalfont);
	    fm = g.getFontMetrics();
	    //dy = fm.getHeight();
	    dy = 14;
	    dyy = dy+2;
	
	    g.setColor(Color.black);
	    
	    for(int i=0;i<361;i++){
		if(i<10){
		    g.drawString("  "+i+"\u00b0",x+1,y);
		}
		else{
		    g.drawString(""+i+"\u00b0",x,y);
		}
		g.drawString(""+state.hphiy[i],x+40,y);
		y+=dyy;
	    }
	    
	}
}

class NewOutputCanvas15P extends Canvas{
	private static final Font normalfont = new Font("SanSerif",Font.PLAIN,12);
	private static final Font subfont    = new Font("SanSerif",Font.PLAIN,10);
	NewGuide_State state;
	public NewOutputCanvas15P(NewGuide_State state){
	    super();
	    this.state = state;
	}
	
	public void paint(Graphics g){
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
	    int x, y, dx, dxx, dy, dyy;
	    double v_normalized;
	    double logfactor = 20.0*0.434294481903;
	    FontMetrics fm;
	    x = 10;
	    y = 15;
	    dx = 80;
	    dxx = 15;
	    g.setFont(normalfont);
	    fm = g.getFontMetrics();
	    //dy = fm.getHeight();
	    dy = 14;
	    dyy = dy+2;
	    
	    g.setColor(Color.black);
	    	    
	    for(int i=0;i<361;i++){
		if(i<10){
		    g.drawString("  "+i+"\u00b0",x+1,y);
		}
		else{
		    g.drawString(""+i+"\u00b0",x,y);
		}
		if(!state.microFlag17){
		    g.drawString(""+logfactor*Math.log(state.hphiy[i]*1.0e3),x+40,y);
		}
		else if(state.microFlag17){
		    g.drawString(""+logfactor*Math.log(state.hphiy[i]*1.0e6),x+40,y);
		}
		y+=dyy;
	    }
	}
}
