import java.awt.*;
import java.awt.event.*;

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 Font labfont, labfont2;
	protected Font titlefont;
        protected double[] DValue;
	protected int indexsize;
	PlaneWave_State state;
        
	public PR(String titulo, String[] nome, String[] unidade, PlaneWave_State state){
                super();
		setLayout(null);
                this.state = state;
                
		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;
		
                labfont=new Font("SanSerif",Font.PLAIN,state.font12);
                labfont2=new Font("SanSerif",Font.PLAIN,state.font11);
                titlefont=new Font("SanSerif",Font.BOLD,state.font16);
		
                //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 = state.s184;
                int starty = state.s35;
                int textwidth = state.s60;
                int textheight = state.s20;
                int yplus = state.s33;
                
                text1[0].setBounds(startx,starty,textwidth,textheight);
                text1[0].setFont(labfont);
		add(text1[0]);
                
                Panel pt0 = new Panel();
                    pt0.setBackground(Color.black);
                    add(pt0);
                    pt0.setBounds(startx-1,starty-1,textwidth+2,textheight+2);
                
                //starty += yplus;
                //text1[1].setBounds(startx,starty,textwidth,textheight);
		//add(text1[1]);
                
                starty += yplus;
                text1[2].setBounds(startx,starty,textwidth,textheight);
                text1[2].setFont(labfont);
		add(text1[2]);
                
                Panel pt2 = new Panel();
                    pt2.setBackground(Color.black);
                    add(pt2);
                    pt2.setBounds(startx-1,starty-1,textwidth+2,textheight+2);
                
                //starty += yplus;
                //text1[3].setBounds(startx,starty,textwidth,textheight);
		//add(text1[3]);
                
                starty += yplus;
                text1[4].setBounds(startx,starty,textwidth,textheight);
                text1[4].setFont(labfont);
		add(text1[4]);
                
                Panel pt4 = new Panel();
                    pt4.setBackground(Color.black);
                    add(pt4);
                    pt4.setBounds(startx-1,starty-1,textwidth+2,textheight+2);
                
                //starty += yplus;
                //text1[5].setBounds(startx,starty,textwidth,textheight);
		//add(text1[5]);

                starty += yplus;
                text1[6].setBounds(startx,starty,textwidth,textheight);
                text1[6].setFont(labfont);
		add(text1[6]);
                
                Panel pt6 = new Panel();
                    pt6.setBackground(Color.black);
                    add(pt6);
                    pt6.setBounds(startx-1,starty-1,textwidth+2,textheight+2);
                
                starty += yplus;
                text1[8].setBounds(startx,starty,textwidth,textheight);
                text1[8].setFont(labfont);
		add(text1[8]);
                
                Panel pt8 = new Panel();
                    pt8.setBackground(Color.black);
                    add(pt8);
                    pt8.setBounds(startx-1,starty-1,textwidth+2,textheight+2);
                
                starty += yplus;
                text1[9].setBounds(startx,starty,textwidth,textheight);
                text1[9].setFont(labfont);
		add(text1[9]);
                
                Panel pt9 = new Panel();
                    pt9.setBackground(Color.black);
                    add(pt9);
                    pt9.setBounds(startx-1,starty-1,textwidth+2,textheight+2);
                
                starty += yplus;
		b1 = new Button("Update");
		b1.setBackground(Color.white);
		b1.setFont(labfont2);
                b1.setBounds(startx,starty+state.s5,textwidth,textheight);
                add(b1);
                
                Panel pb1 = new Panel();
                    pb1.setBackground(Color.black);
                    add(pb1);
                    pb1.setBounds(startx-1,starty+state.s5-1,textwidth+2,textheight+2);
                Panel pb2 = new Panel();
                    pb2.setBackground(Color.cyan);
                    add(pb2);
                    pb2.setBounds(startx-2,starty+state.s5-2,textwidth+4,textheight+4);
                Panel pb3 = new Panel();
                    pb3.setBackground(Color.black);
                    add(pb3);
                    pb3.setBounds(startx-3,starty+state.s5-3,textwidth+6,textheight+6);
                
                //starty += yplus;
                slider1 = new Scrollbar(Scrollbar.HORIZONTAL,SCROLLMAX-1-SleepTime,1,SCROLLMIN,SCROLLMAX);
                slider1.setBounds(state.s7,starty+state.s5,state.s150,state.s15);
                slider1.setBackground(Color.white);
                //add(slider1);
                Panel p1 = new Panel();
                    p1.setBackground(Color.black);
                    //add(p1);
                    p1.setBounds(state.s7-1,starty+state.s5-1,state.s150+2,state.s15+2);
                
                //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 = state.s12;
            int starty = state.s50;
            int yplus = state.s33;         // y step down
            int xvar = state.s150;         // coordinate for long variable
            int xvar2 = state.s155;              // coordinate for short variable
            int xequal = state.s170;             // coordinate for equal sign 
            int xunit = state.s200+state.s48;    // coordinate for units
            int fonto1 = state.s11;              // font for legends
            int fonto2 = state.s12;        // font for units
            int fonto3 = state.s14;        // font for variables
            int fonto6 = state.s16;        // font for variables
            
            //g.setColor(Color.gray);
            //MaestroG.subscripterBold("Input","","",g,state.font14,startx+state.s1,startx+state.s6);
            g.setColor(Color.red.darker());
            MaestroG.subscripterBold("Input","","",g,state.font14,startx,startx+state.s5);
                
            g.setColor(Color.black);
            //g.setColor(Color.red.darker());
            MaestroG.subscripter("Frequency","","",g,fonto2,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("Dielectric Permittivity","","",g,fonto2,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.red.darker());
            MaestroG.subscripter("Voltage Amplitude","","",g,fonto2,startx,starty);
            g.setColor(Color.black);
            MaestroG.subscripterSansItalic("V","0","",g,fonto3,xvar,starty);
            MaestroG.subscripter("=","","",g,fonto2,xequal,starty);
            MaestroG.subscripter("V","","",g,fonto2,xunit,starty);
            
            starty += yplus;
            //g.setColor(Color.blue.darker());
            MaestroG.subscripter("Plates Separation","","",g,fonto2,startx,starty);
            g.setColor(Color.black);
            MaestroG.subscripterSansItalic("d","","",g,fonto6,xvar2,starty);
            MaestroG.subscripter("=","","",g,fonto2,xequal,starty);
            MaestroG.subscripter("m","","",g,fonto2,xunit,starty);
            
            starty += yplus;
            //g.setColor(Color.red.darker());
            MaestroG.subscripter("Length of Plates","","",g,fonto2,startx,starty);
            g.setColor(Color.black);
            MaestroG.subscripterSansItalic("l","","",g,fonto6,xvar2,starty);
            MaestroG.subscripter("=","","",g,fonto2,xequal,starty);
            MaestroG.subscripter("m","","",g,fonto2,xunit,starty);
            
            starty += yplus;
            //g.setColor(Color.blue.darker());
            MaestroG.subscripter("Width of Plates","","",g,fonto2,startx,starty);
            g.setColor(Color.black);
            MaestroG.subscripterSansItalic("w","","",g,fonto6,xvar2,starty);
            MaestroG.subscripter("=","","",g,fonto2,xequal,starty);
            MaestroG.subscripter("m","","",g,fonto2,xunit,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));
	}
}
