import java.text.*;
import java.awt.*;
import javax.swing.*;

public class WrenDAQCounterPanel extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	protected JLabel aLabel[];
	protected JLabel aValue[];
	protected UserChannel uc;

	
	public void setPulse(int ms, int count) {
		/* update pulse and re-run evaluate(ms) */
		aValue[0].setText(uc.evaluateString(ms));

		/* period */
		aValue[1].setText(ms + " milliseconds");

		/* frequency if ms > 0 */
		if ( 0 == ms ) {
			aValue[2].setText("---");
		} else {
			double f;
			f=1.0/(ms/1000.0);
			NumberFormat dec = new DecimalFormat("0.0");

			aValue[2].setText( dec.format(f) + " hertz");
		}

		/* pulse count */
		aValue[3].setText( new Integer(count).toString() );
	}

	
	public WrenDAQCounterPanel(String title, UserChannel luc) {
		super(new GridLayout(4, 2));

		uc=luc;
		aLabel=new JLabel[4];
		aValue=new JLabel[4];

		setBackground(Color.white);
		setBorder(BorderFactory.createTitledBorder(title));

		aLabel[0]=new JLabel(uc.getName() + ": ");
		add(aLabel[0]);
		aValue[0]=new JLabel("---");
		add(aValue[0]);

		aLabel[1]=new JLabel("Last Period: ");
		add(aLabel[1]);
		aValue[1]=new JLabel("--- milliseconds");
		add(aValue[1]);

		aLabel[2]=new JLabel("Last Frequency: ");
		add(aLabel[2]);
		aValue[2]=new JLabel("--- Hz");
		add(aValue[2]);

		aLabel[3]=new JLabel("Pulse Count: ");
		add(aLabel[3]);
		aValue[3]=new JLabel("---");
		add(aValue[3]);

	}
}
