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;
        public Scrollbar slider1;
        public int SCROLLMIN=750, SCROLLMAX=1001;
        private int SleepTime = 50;
        
	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 = 184;
                int starty = 40;
                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]);
                
                starty += yplus-7;
		b1 = new Button("Update");
		b1.setBackground(Color.white);
		b1.setBounds(startx,starty+5,textwidth,textheight);
                add(b1);
                
                slider1 = new Scrollbar(Scrollbar.HORIZONTAL,SCROLLMAX-1-SleepTime,1,SCROLLMIN,SCROLLMAX);
                slider1.setBounds(7,starty+5,150,15);
                slider1.setBackground(Color.white);
                add(slider1);
                Panel p1 = new Panel();
                    p1.setBackground(Color.black);
                    add(p1);
                    p1.setBounds(6,starty+4,152,17);
                
                
                //Listeners
		b1.addActionListener(this);
	}
	
	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 = 12;
            int starty = 55;
            int yplus = 25;         // y step down
            int xvar = 150;         // coordinate for long variable
            int xvar2 = 155;        // coordinate for short variable
            int xequal = 170;       // coordinate for equal sign 
            int xunit = 248;        // coordinate for units
            int fonto1 = 11;        // font for legends
            int fonto2 = 12;        // font for units
            int fonto3 = 14;        // font for variables
            int fonto6 = 16;        // 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("E-field Amplitude (z=0)","","",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("E-field 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,fonto6,xvar2,starty); // Lower case "L" not a "one"
            MaestroG.subscripter("=","","",g,fonto2,xequal,starty);
            MaestroG.subscripterSans("\u03bb","","",g,fonto2,xunit,starty);
            
            starty += yplus-10;
            //g.setColor(Color.blue.darker());
            //MaestroG.subscripter("[A] & [B] Windows","","",g,fonto1,startx,starty);
            //g.setColor(Color.black);
            //MaestroG.subscripterSansItalic("Area","","",g,fonto3,xvar-10,starty);
            //MaestroG.subscripter("=","","",g,fonto2,xequal,starty);
            //MaestroG.subscripter("m\u00b2","","",g,fonto2,xunit,starty);
            
            int textwidth = 80;
            int textheight = 20;
            starty += yplus-10;
            startx = 180;
               //box around update button
            g.drawRect(startx+1,starty,textwidth-15,textheight+5);
            //------------------------------------------------------------------
            g.setColor(Color.black);
            int sety = starty+30;
            int sety2 = starty+25;
            MaestroG.subscripter("Animation speed","","",g,10,40,sety);
            
            g.setColor(Color.blue.darker());
            MaestroG.drawArrowtip(15,sety2,8,g);
            MaestroG.drawArrowtip(22,sety2,8,g);

            g.setColor(Color.red.darker());
            MaestroG.drawArrowtip(142,sety2,7,g);
            MaestroG.drawArrowtip(149,sety2,7,g);
            //------------------------------------------------------------------
        }
        	
	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));
	}
}

