import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.lang.*;

public class PR extends Panel implements ActionListener{
	//protected static final Color bgcolor = new Color(180,147,112);
	//protected static final Color bgcolor = new Color(200,200,200);
	protected static final Color bgcolor = new Color(236,236,236);
	protected TextField text1[];
	protected Label lab1[], lab2[];
	public Label titlelabel;
	public Button b1;
        private int SCROLLMIN=0, SCROLLMAX=1001;
        private int SCROLLMIN2=0, SCROLLMAX2=3601;
        public Scrollbar slider1, slider2, slider3, slider4;
	protected String titulo="Unknown Title";
	protected String[] nome;
	protected String[] unidade;
	protected static final Font labfont=new Font("SanSerif",Font.PLAIN,12);
	protected static final Font titlefont=new Font("SanSerif",Font.BOLD,16);
        protected double[] DValue;
	protected int indexsize;
	
	public PR(String titulo, String[] nome, String[] unidade){
	
		super();
		setLayout(null);
                
		this.indexsize=nome.length;
		this.titulo=titulo;
		this.nome=new String[indexsize];
		this.unidade=new String[indexsize];
		this.DValue=new double[indexsize];
		this.text1=new TextField[indexsize];
		this.lab1=new Label[indexsize];
		this.lab2=new Label[indexsize];
		int i;
		
                //titlelabel = new Label(titulo,Label.LEFT);
		//titlelabel.setBounds(0,0,50,25);   
		//titlelabel.setFont(titlefont);
		//add(titlelabel);
                
                for(i=0;i<indexsize;i++){
			this.DValue[i]=0.0;
			this.text1[i]=new TextField("0.0",8);
		}
		
		setBackground(bgcolor);
                
                int startx = 170;
                int starty = 35;
                int textwidth = 60;
                int textheight = 20;
                int yplus = 25;
                
                text1[0].setBounds(startx,starty,textwidth,textheight);
		add(text1[0]);
                
                //starty += yplus;
                //text1[1].setBounds(startx,starty,textwidth,textheight);
		//add(text1[1]);
                
                starty += yplus;
                text1[2].setBounds(startx,starty,textwidth,textheight);
		add(text1[2]);
                
                starty += yplus;
                text1[3].setBounds(startx,starty,textwidth,textheight);
		add(text1[3]);
                
                starty += yplus;
                text1[4].setBounds(startx,starty,textwidth,textheight);
		add(text1[4]);
                
                starty += yplus;
                text1[5].setBounds(startx,starty,textwidth,textheight);
		add(text1[5]);

                starty += yplus;
                text1[6].setBounds(startx,starty,textwidth,textheight);
		add(text1[6]);
                
                //starty += yplus;
                //text1[7].setBounds(startx,starty,textwidth,textheight);
		//add(text1[7]);
                
                b1 = new Button("Update");
		b1.setBackground(Color.white);
		b1.setBounds(startx,7,textwidth,textheight);
                add(b1);
              
                starty += yplus+28;
                
		
                //Listeners
		b1.addActionListener(this);
                
                slider1 = new Scrollbar(Scrollbar.HORIZONTAL,SCROLLMAX,1,SCROLLMIN,SCROLLMAX);
                slider1.setBackground(Color.white);
                slider2 = new Scrollbar(Scrollbar.HORIZONTAL,SCROLLMAX,1,SCROLLMIN,SCROLLMAX);
                slider2.setBackground(Color.white);
                slider3 = new Scrollbar(Scrollbar.HORIZONTAL,1800,1,SCROLLMIN2,SCROLLMAX2);
                slider3.setBackground(Color.white);
                slider4 = new Scrollbar(Scrollbar.HORIZONTAL,SCROLLMIN,1,SCROLLMIN2,SCROLLMAX2);
                slider4.setBackground(Color.white);
                add(slider1); add(slider2); add(slider3);
                
                slider1.setBounds(20, starty, 110, 15);
                Panel ps1 = new Panel();
                    ps1.setBackground(Color.black);
                    add(ps1);
                    ps1.setBounds(19,starty-1,112,17);
                
                slider2.setBounds(150, starty, 110, 15);
                Panel ps2 = new Panel();
                    ps2.setBackground(Color.black);
                    add(ps2);
                    ps2.setBounds(149,starty-1,112,17);
                
                starty += yplus+19;
		
                slider3.setBounds(20, starty, 240, 15);
                Panel ps3 = new Panel();
                    ps3.setBackground(Color.black);
                    add(ps3);
                    ps3.setBounds(19,starty-1,242,17);
	}
	
	public void paint(Graphics g){
            
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
            g.clearRect(0,0,getSize().width-2,getSize().height);
            
            int startx = 15;
            int starty = 48;
            int yplus = 25;         // y step down
            int xvar = 140;         // coordinate for long variable
            int xvar2 = 145;        // coordinate for short variable
            int xequal = 159;       // coordinate for equal sign 
            int xunit = 235;        // coordinate for units
            int fonto1 = 11;        // font for legends
            int fonto2 = 12;        // font for units
            int fonto3 = 14;        // font for variables
            
            g.setColor(Color.gray);
            MaestroG.subscripterBold("Input","","",g,14,startx+1,startx+6);
            g.setColor(Color.red.darker());
            MaestroG.subscripterBold("Input","","",g,14,startx,startx+5);
                
            g.setColor(Color.red.darker());
            MaestroG.subscripter("Frequency","","",g,fonto1,startx,starty);
            g.setColor(Color.black);
            MaestroG.subscripterSansItalic("f","","",g,fonto3,xvar2,starty);
            MaestroG.subscripter("=","","",g,fonto2,xequal,starty);
            MaestroG.subscripter("[ Hz ]","","",g,fonto2,xunit,starty);
            
            /*
            starty += yplus;
            g.setColor(Color.blue.darker());
            MaestroG.subscripter("Conductivity","","",g,fonto1,startx,starty);
            g.setColor(Color.black);
            MaestroG.subscripterSansItalic("\u03c3","","",g,fonto3,xvar2,starty);
            MaestroG.subscripter("=","","",g,fonto2,xequal,starty);
            MaestroG.subscripter("[ S / m ]","","",g,fonto2,xunit,starty);
            */
            
            starty += yplus;
            g.setColor(Color.red.darker());
            MaestroG.subscripter("Relative Permittivity","","",g,fonto1,startx,starty);
            g.setColor(Color.black);
            MaestroG.subscripterSansItalic("\u03b5","r","",g,fonto3,xvar,starty);
            MaestroG.subscripter("=","","",g,fonto2,xequal,starty);
            //MaestroG.subscripter("","","",g,fonto2,xunit,starty);
            
            starty += yplus;
            g.setColor(Color.blue.darker());
            MaestroG.subscripter("Relative Permeability","","",g,fonto1,startx,starty);
            g.setColor(Color.black);
            MaestroG.subscripterSansItalicNudge("\u03bc","r","",g,fonto3,xvar,starty);
            MaestroG.subscripter("=","","",g,fonto2,xequal,starty);
            //MaestroG.subscripter("","","",g,fonto2,xunit,starty);
            
            starty += yplus;
            g.setColor(Color.red.darker());
            MaestroG.subscripter("Reference Amplitude","","",g,fonto1,startx,starty);
            g.setColor(Color.black);
            MaestroG.subscripterSansItalic("E","o","",g,fonto3,xvar,starty);
            MaestroG.subscripter("=","","",g,fonto2,xequal,starty);
            MaestroG.subscripter("[ V / m ]","","",g,fonto2,xunit,starty);
            
            starty += yplus;
            g.setColor(Color.blue.darker());
            MaestroG.subscripter("Reference Phase (z=0)","","",g,fonto1,startx,starty);
            g.setColor(Color.black);
            MaestroG.subscripterSansItalic("\u03c6","","",g,fonto3,xvar2,starty);
            MaestroG.subscripter("=","","",g,fonto2,xequal,starty);
            MaestroG.subscripter("[ rad ]","","",g,fonto2,xunit,starty);
            
            starty += yplus;
            g.setColor(Color.red.darker());
            MaestroG.subscripter("Length Displayed","","",g,fonto1,startx,starty);
            g.setColor(Color.black);
            MaestroG.subscripterSansItalic("l","","",g,fonto3+2,xvar2,starty);
            MaestroG.subscripter("=","","",g,fonto2,xequal,starty);
            MaestroG.subscripterSans("[ \u03bb ]","","",g,fonto3,xunit,starty);
            
            //starty += yplus;
            //starty += yplus;
            
            /*
            g.setColor(Color.blue.darker());
            MaestroG.subscripter("[A] & [B] Windows","","",g,fonto1,startx,starty);
            g.setColor(Color.black);
            MaestroG.subscripterSansItalic("S","","",g,fonto3,xvar2,starty);
            MaestroG.subscripter("=","","",g,fonto2,xequal,starty);
            MaestroG.subscripter("[ m\u00b2 ]","","",g,fonto2,xunit,starty);
            */
            
            g.setColor(Color.lightGray);
            g.drawLine(10,starty+13,getSize().width-10,starty+13);

            int textwidth = 80;
            int textheight = 20;
            startx = 170;
            g.drawRect(startx-3,5,textwidth-15,textheight+4);
            
            starty += yplus+5;
            startx = 30;
               
            g.setColor(Color.red.darker());
            double value;
            value = (double)(slider1.getValue()*0.001);
            MaestroG.subsubItalic("E","x"," = "+MaestroA.rounder(value,3)," E","o","",g,14,startx,starty);
            
            value = (double)(slider2.getValue()*0.001);
            MaestroG.subsubItalic("E","y"," = "+MaestroA.rounder(value,3)," E","o","",g,14,startx+130,starty);
            
            starty += yplus+19;
            startx = 70;
            g.setColor(Color.blue.darker());
            value = (double)(slider3.getValue()*0.1-180.0);
            MaestroG.subsubItalic2("\u03c6 ( E","y"," ) - \u03c6 ( E","x"," )",
                                   " = "+MaestroA.rounder(value,3),"\u00ba",g,14,startx,starty);
        }
        	
	public void actionPerformed(ActionEvent evt){
		if(evt.getSource() == b1){
		  for(int i=0;i<indexsize;i++){
		  	DValue[i]=Double.valueOf(text1[i].getText()).doubleValue();
                  }
		}
	}
	
        public double getValue(int i){
		return DValue[i];	
        }

        public synchronized void setValue(double D,int i){
		text1[i].setText(String.valueOf(D));
	}
}

