//NewGuideOutputPanel14.java
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.lang.*;  
//import maestro.lib.math.*;
//import maestro.lib.graphics.*;

public class NewGuideOutputPanel14c extends Panel implements ItemListener{
	NewGuide_State state;
	private static final Color bgcolor = new Color(236,236,221);
	private Font labfont=new Font("SanSerif",Font.PLAIN,12);
	private Font titlefont=new Font("SanSerif",Font.BOLD,16);
	Label titlelabel;	
	public Choice c1;
	public TitleCanvas13c tcanvas13c;
	public NewOutputCanvas8Pc rwoc8Pc; 
	public NewOutputCanvas9Pc rwoc9Pc;
	
	public NewGuideOutputPanel14c(NewGuide_State state){
	    super();
	    setLayout(null);
	    this.state = state;
            
            labfont=new Font("SanSerif",Font.PLAIN,state.font12);
            titlefont=new Font("SanSerif",Font.BOLD,state.font16);
            
	    setBackground(bgcolor);
	    state.microFlag14c = false;

	    titlelabel = new Label("    Field Data",Label.LEFT);
	    //add(titlelabel);
	    titlelabel.setBounds(state.s5,state.s5,state.s95,state.s15);
	    titlelabel.setFont(titlefont);
	    	    
	    c1 = new Choice();
	    c1.addItem("  [ A/m ] ");
	    c1.addItem("  [ dB mA/m ]");
	    c1.addItem("  [ dB \u00b5A/m ]");
	    add(c1);
	    c1.setBounds(state.s105,state.s2,state.s125,state.s25);
	    c1.setFont(new Font("SanSerif",Font.PLAIN,state.font11));
	    
	    tcanvas13c = new TitleCanvas13c(state);
	    add(tcanvas13c);
	    tcanvas13c.setBounds(0,0,state.s200+state.s95,state.s25);
	    
	    rwoc8Pc = new NewOutputCanvas8Pc(state);
	    rwoc8Pc.setVisible(true);
	    rwoc9Pc = new NewOutputCanvas9Pc(state);
	    rwoc8Pc.setVisible(false);
	    this.add(rwoc8Pc);
	    this.add(rwoc9Pc);
	    
	    rwoc8Pc.setBounds(state.s4,state.s29,state.s200+state.s87,state.s200+state.s63);
	    rwoc9Pc.setBounds(state.s4,state.s29,state.s200+state.s87,state.s200+state.s63);
	    
	    //Listeners
	    c1.addItemListener(this);
	}

    public void itemStateChanged(ItemEvent evt){
	ItemSelectable ie = evt.getItemSelectable();
	    if(evt.getSource()==c1){
		if(ie.getSelectedObjects()[0]=="  [ A/m ] "){
		    rwoc8Pc.setVisible(true);
		    rwoc9Pc.setVisible(false);
		}
		else if(ie.getSelectedObjects()[0]=="  [ dB mA/m ]"){
		    rwoc8Pc.setVisible(false);
		    rwoc9Pc.setVisible(true);
		    state.microFlag14c = false;
		    rwoc9Pc.repaint_data();
		}
		//else if(ie.getSelectedObjects()[0]=="  [ dB \u00b5A/m ]"){
		else {
		    rwoc8Pc.setVisible(false);
		    rwoc9Pc.setVisible(true);
		    state.microFlag14c = true;
		    rwoc9Pc.repaint_data();
		}
	    }
    }	
}

class TitleCanvas13c extends Canvas{
	private Font normalfont = new Font("Serif",Font.PLAIN,12);
	private Font subfont    = new Font("Serif",Font.PLAIN,10);
	private Font normalfontB = new Font("Serif",Font.BOLD,12);
	
	private Font symbolfont=new Font("Serif",Font.PLAIN,16);
	private Font symbolfont2=new Font("Serif",Font.PLAIN,14);
	
	NewGuide_State state;
	public TitleCanvas13c(NewGuide_State state){
	    super();
	    this.state = state;
	}
	
	public void paint(Graphics g){
            normalfont = new Font("Serif",Font.PLAIN,state.font12);
            subfont    = new Font("Serif",Font.PLAIN,state.font10);
            normalfontB = new Font("Serif",Font.BOLD,state.font12);
            
            symbolfont = new Font("Serif",Font.PLAIN,state.font16);
            symbolfont2 = new Font("Serif",Font.PLAIN,state.font14);
	
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
	    g.setFont(symbolfont);
	    g.setColor(Color.blue);
	    g.drawString("\u03c6",state.s20,state.s17);
	    g.drawString("\u03c6",state.s21,state.s17);
	    
	    g.setFont(symbolfont2);
	    g.drawString("\u03b8",state.s79,state.s22);
	    g.setFont(normalfontB);
	    g.drawString("| H    |",state.s65,state.s17);
	    
	    g.setFont(new Font("Serif",Font.PLAIN,state.font12)); 
	    g.drawString("\u03b8",state.s200+state.s35,state.s17);
	    g.setFont(new Font("Serif",Font.PLAIN,state.font12)); 
	    g.drawString("= 90.0\u00b0",state.s200+state.s45,state.s17);
	}
}

class NewOutputCanvas8Pc extends TextArea {
    private Font normalfont = new Font("SanSerif",Font.PLAIN,12);
    private Font subfont    = new Font("SanSerif",Font.PLAIN,10);
    private Font symbolfont=new Font("Serif",Font.PLAIN,14);
    NewGuide_State state;
    
    public NewOutputCanvas8Pc(NewGuide_State state){
	super("",80,80,TextArea.SCROLLBARS_VERTICAL_ONLY);
	this.state = state;
	setBackground(Color.white);
    }
    
    public void repaint_data() {
	setText("");
	for(int i=0;i<361;i++){
	    if(i<10){
		append("   "+i+"\u00b0      "+state.hphithetaM[i]+"\n");
	    }
	    else{
		append("  "+i+"\u00b0      "+state.hphithetaM[i]+"\n");
	    }
	}
    }		  	
}

class NewOutputCanvas9Pc extends TextArea {
	private Font normalfont = new Font("SanSerif",Font.PLAIN,12);
	private Font subfont    = new Font("SanSerif",Font.PLAIN,10);
	NewGuide_State state;
	
        public NewOutputCanvas9Pc(NewGuide_State state){
	    super("",80,80,TextArea.SCROLLBARS_VERTICAL_ONLY);
	    this.state = state;
	    setBackground(Color.white);
	}
    
    public void repaint_data() {
	setText("");

	double logfactor = 20.0*0.434294481903;
	for(int i=0;i<361;i++){
	    if(i<10){
		append("   "+i+"\u00b0");
	    }
	    else{
		append("  "+i+"\u00b0");
	    }
	    if(!state.microFlag14c){
		append("      "+logfactor*Math.log(state.hphithetaM[i]*1.0e3)+"\n");
	    }
	    else if(state.microFlag14c){
		append("      "+logfactor*Math.log(state.hphithetaM[i]*1.0e6)+"\n");
	    }
	}
    }	
}
