//PR.java

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.lang.*;
public class PR2 extends Panel implements ActionListener{
	
        private static final Color bgcolor = new Color(236,236,236);
	private static final Color tinta = new Color(236,236,236);
	protected TextField text1[];
	protected Label lab1[], lab2[];
	public Label titlelabel;
	public Button b1;
	protected String titulo="Unknown Title";
	protected String[] nome;
	protected String[] unidade;
	protected static final Font labfont=TheFonts.sanSerif12;
	protected static final Font titlefont=TheFonts.bold16;
        protected double[] DValue;
	protected int indexsize;
	
	public PR2(String titulo, String[] nome, String[] unidade){
		super();
		
                //setLayout(gb); // no use on the MAC - MAC sucks!!!!
                
                setLayout(null);
		
                int xstart = 100;
                int ystart = 40;
                int deltay = 22;
                int xwide = 80;
                int xwide2 = 50;
                int ywide = 18;
		int yb1 = ystart;
                
                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.CENTER);
		titlelabel.setBounds(5,15,300,25);   
		titlelabel.setFont(titlefont);
                add(titlelabel);               
		
		for(i=0;i<indexsize;i++){
			this.nome[i]=nome[i];
			this.unidade[i]=unidade[i];
			this.DValue[i]=0.0;

			this.text1[i]=new TextField("0.0",8);
			this.lab1[i]=new Label(nome[i],Label.RIGHT);
			this.lab2[i]=new Label(unidade[i],Label.LEFT);
			this.lab1[i].setFont(labfont);
			this.lab2[i].setFont(labfont);
                        
                        add(this.text1[i]);
                        add(this.lab2[i]);
			text1[i].setBounds(xstart,ystart+i*deltay,xwide,ywide);
			lab2[i].setBounds(xstart+xwide+5,ystart+i*deltay,xwide2,ywide);
		        
                        yb1+=deltay;
		}
		
		setBackground(bgcolor);
		
		b1 = new Button("Update");
		b1.setBackground(bgcolor);
                add(b1);
               
                b1.setBounds(xstart,yb1,xwide,25);
		
		//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,getSize().height);
	    g.setColor(bgcolor.darker());
	    g.fillRect(0,getSize().height-2,getSize().width,2);
	    g.fillRect(getSize().width-2,0,2,getSize().height);
	    g.setColor(bgcolor.brighter());
	    g.fillRect(0,0,2,getSize().height-1);
	    g.fillRect(0,0,getSize().width-2,2);
            
            g.setColor(Color.black);
            MaestroG.subscripter("V","gmax"," =",g,12,42,55);
            MaestroG.subscripter("R","g","  =",g,12,60,78);

	}
	
	
	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));
	}
	
	public synchronized void setStrings(String nome[], String unidade[]){
		for(int i=0;i<nome.length;i++){
			this.nome[i]=nome[i];
			this.unidade[i]=unidade[i];
			lab1[i].setText(nome[i]);
			lab2[i].setText(unidade[i]);
		}
		
	}
}

