// file: ControlPanel.java
//

// import system files
//
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.*;
import java.util.*;
import javax.swing.border.*;

// class: ControlPanel
//
// hierarchy: JPanel->SubPanel->ControlPanel
//

//import Designer;
//import Constants;

class ControlPanel extends SubPanel implements ActionListener, Constants {
    
    // *********************************************************************
    //
    // declare local variables
    //
    // *********************************************************************
    
    // declare the card layout identifier names
    //
    String magnitudeParams = new String("Magnitude");
    String phaseParams = new String("Phase");
    String impulseParams = new String("Impulse");
    String datainputParams = new String("Input");
    
    // declare strings to label the card in the card layout scheme
    //
    String phaseTitle = new String("Phase");
    String impulseTitle = new String("Impulse");
    String magnitudeTitle = new String("Magnitude");
    String datainputTitle =  new String("Input");
    
    // declare the slider scale to be used to set the animation speed
    // 
    JLabel speed_label;
    JSlider speed;
    
    // declare the drawing panel objects 
    //
    InputPanel inputPanel;
    OutputPanel outputPanel;
    
    // declare the card to be used in the card layout scheme
    //    
    JPanel cards;
    JPanel magnitudeCard;
    JPanel phaseCard;
    JPanel impulseCard;
    JPanel datainputCard;
    
    // declare buttons to update the panel plots
    //
    JButton magnitudeUpdateButton = new JButton("Update");
    JButton phaseUpdateButton = new JButton("Update");
    JButton impulseUpdateButton = new JButton("Update");
    
    // declare components for the magnitude panel
    //
    double magnitudeXticDiv = 0.0;
    double magnitudeYticDiv = 0.0;
    double magnitudeXposDiv = 0.0;
    double magnitudeXnegDiv = 0.0;
    double magnitudeYposDiv = 0.0;
    double magnitudeYnegDiv = 0.0;
    
    JTextField magnitudeXticDivision;
    JTextField magnitudeYticDivision;
    JTextField magnitudeXposLimit;
    JTextField magnitudeXnegLimit;
    JTextField magnitudeYposLimit;
    JTextField magnitudeYnegLimit;
    
    JLabel magXticLabel = new JLabel("Freq Tic");
    JLabel magYticLabel = new JLabel("Mag Tic");
    JLabel magXnegLabel = new JLabel("Freq Min");
    JLabel magXposLabel = new JLabel("Freq Max");
    JLabel magYnegLabel = new JLabel("Mag Min");
    JLabel magYposLabel = new JLabel("Mag Max");
    
    // declare components for the phase panel
    //
    double phaseXticDiv = 0.0;
    double phaseYticDiv = 0.0;
    double phaseXposDiv = 0.0;
    double phaseXnegDiv = 0.0;
    double phaseYposDiv = 0.0;
    double phaseYnegDiv = 0.0;
    
    JTextField phaseXticDivision;
    JTextField phaseYticDivision;
    JTextField phaseXposLimit;
    JTextField phaseXnegLimit;
    JTextField phaseYposLimit;
    JTextField phaseYnegLimit;
    
    JLabel phaXticLabel = new JLabel("Freq Tic");
    JLabel phaYticLabel = new JLabel("Phase Tic");
    JLabel phaXnegLabel = new JLabel("Freq Min");
    JLabel phaXposLabel = new JLabel("Freq Max");
    JLabel phaYnegLabel = new JLabel("Phase Min");
    JLabel phaYposLabel = new JLabel("Phase Max");
    
    // declare components for the impulse panel
    //
    double impulseXticDiv = 0.0;
    double impulseYticDiv = 0.0;
    double impulseXposDiv = 0.0;
    double impulseXnegDiv = 0.0;
    double impulseYposDiv = 0.0;
    double impulseYnegDiv = 0.0;
    
    JTextField impulseXticDivision;
    JTextField impulseYticDivision;
    JTextField impulseXposLimit;
    JTextField impulseXnegLimit;
    JTextField impulseYposLimit;
    JTextField impulseYnegLimit;
    
    JLabel impXticLabel = new JLabel("Time Tic");
    JLabel impYticLabel = new JLabel("Amp Tic");
    JLabel impXnegLabel = new JLabel("Time Min");
    JLabel impXposLabel = new JLabel("Time Max");
    JLabel impYnegLabel = new JLabel("Amp Min");
    JLabel impYposLabel = new JLabel("Amp Max");
    
    //declare components for datainput panel
    //
    private String freq_string = new String("Frequency"); 
    private String band_string = new String("Bandwidth");
    private String sf_string = new String("Sample Freq");
    private String range_string = new String("Freq  Range");
    private String dc_gain_string = new String("DC Gain");
    
    JLabel band_label = new JLabel(band_string);
    JLabel freq_label = new JLabel(freq_string);
    JLabel sf_range_label = new JLabel(sf_string);
    JLabel dc_gain_label = new JLabel(dc_gain_string); 
    
    JTextField sf_area = new JTextField(String.valueOf
					(Constants.DEFAULT_SAMPLE_FREQ),5); 
    private JTextField dc_gain_area = new JTextField(String.valueOf(1), 5);
    
    
    JTextField entry_text_0 = new JTextField(String.valueOf(
							    Constants.DEFAULT_SAMPLE_FREQ), 5);
    JTextField entry_text_1 = new JTextField(String.valueOf(
							    Constants.DEFAULT_SAMPLE_FREQ), 5);
    
    // declare the default fonts
    //
    Font currentFont = getFont();
    Font newFont = new Font(currentFont.getName(), currentFont.getStyle(), 12);
    
    // *********************************************************************
    //
    // declare class constructors
    //
    // *********************************************************************
    
    // sets the size background properties and layout manager
    //
    ControlPanel ()  {
	super();
	
	// create a border around the control panel
	//
	setBorder(BorderFactory.createEtchedBorder());
	
	instantiate();
    }
    
    ControlPanel ( OutputPanel out , InputPanel in)  {
	super();
	
	// create a border around the control panel
	//
	setBorder(BorderFactory.createEtchedBorder());
	instantiate();
	outputPanel = out;
	inputPanel = in;
    }
    
    // *********************************************************************
    //
    // declare local methods
    //
    // *********************************************************************
    
    // method: instantiate
    //
    // arguments: none
    // return   : none
    //
    // instantiate components and add action listeners where necessary
    //
    private void instantiate() {
	
	// create a card layout to put the control and parameter items
	//
	cards = new JPanel();
	cards.setLayout(new CardLayout());
	
	// create a panel for the magnitude parameters
	//
	magnitudeCard = new JPanel();
	
	// create a panel for the phase parameters
	//
	phaseCard = new JPanel();
	
	// create a panel for the output parameters
	//
	impulseCard = new JPanel();
	
	// create a panel for input parameters
	//
	datainputCard = new JPanel();
	
	// set label default fonts and color for the labels
	//
	magXticLabel.setFont(newFont);
	magXticLabel.setForeground(Color.black);
	magYticLabel.setFont(newFont);
	magYticLabel.setForeground(Color.black);
	magXnegLabel.setFont(newFont);
	magXnegLabel.setForeground(Color.black);
	magXposLabel.setFont(newFont);
	magXposLabel.setForeground(Color.black);
	magYnegLabel.setFont(newFont);
	magYnegLabel.setForeground(Color.black);
	magYposLabel.setFont(newFont);
	magYposLabel.setForeground(Color.black);
	
	phaXticLabel.setFont(newFont);
	phaXticLabel.setForeground(Color.black);
	phaYticLabel.setFont(newFont);
	phaYticLabel.setForeground(Color.black);
	phaXnegLabel.setFont(newFont);
	phaXnegLabel.setForeground(Color.black);
	phaXposLabel.setFont(newFont);
	phaXposLabel.setForeground(Color.black);
	phaYnegLabel.setFont(newFont);
	phaYnegLabel.setForeground(Color.black);
	phaYposLabel.setFont(newFont);
	phaYposLabel.setForeground(Color.black);
	
	impXticLabel.setFont(newFont);
	impXticLabel.setForeground(Color.black);
	impYticLabel.setFont(newFont);
	impYticLabel.setForeground(Color.black);
	impXnegLabel.setFont(newFont);
	impXnegLabel.setForeground(Color.black);
	impXposLabel.setFont(newFont);
	impXposLabel.setForeground(Color.black);
	impYnegLabel.setFont(newFont);
	impYnegLabel.setForeground(Color.black);
	impYposLabel.setFont(newFont);
	impYposLabel.setForeground(Color.black);
	
	band_label.setFont(newFont);
	band_label.setForeground(Color.black);
	freq_label.setFont(newFont);
	freq_label.setForeground(Color.black);
	sf_range_label.setFont(newFont);
	sf_range_label.setForeground(Color.black);
	dc_gain_label.setFont(newFont);
	dc_gain_label.setForeground(Color.black);
	
	// set the default fonts for the update buttons
	//
	magnitudeUpdateButton.setFont(newFont);
	phaseUpdateButton.setFont(newFont);
	impulseUpdateButton.setFont(newFont);
	
	// create the textfields for the magnitude panel
	//
	magnitudeXticDivision = new JTextField("0.25",5);
	magnitudeYticDivision = new JTextField("10.0", 5);
	magnitudeXposLimit = new JTextField("0.5",5);
	magnitudeXnegLimit = new JTextField("-0.5",5);
	magnitudeYposLimit = new JTextField("40.0", 5);
	magnitudeYnegLimit = new JTextField("-40.0", 5);
	
	// create the textfields for the phase panel
	//
	phaseXticDivision = new JTextField("0.25", 5);
	phaseYticDivision = new JTextField("0.75", 5);
	phaseXposLimit = new JTextField("0.5", 5);
	phaseXnegLimit = new JTextField("-0.5", 5);
	phaseYposLimit = new JTextField("3.14", 5);
	phaseYnegLimit = new JTextField("-3.14", 5);
	
	// create the textfields for the output panel
	//
	impulseXticDivision = new JTextField("0.25", 5);
	impulseYticDivision = new JTextField("0.25", 5);
	impulseXposLimit = new JTextField("1.0", 5);
	impulseXnegLimit = new JTextField("0.0", 5);
	impulseYposLimit = new JTextField("1.0", 5);
	impulseYnegLimit = new JTextField("-1.0", 5);
	
	// set up the update for the magnitude panel and define the actions 
	// to take place when the button is clicked on
	//
	magnitudeUpdateButton.addActionListener(new ActionListener() {
	    public void actionPerformed(ActionEvent e) {
		
		// make sure the value is a valid double
		//
		try {
		    magnitudeXticDiv = Double.valueOf(magnitudeXticDivision.
						      getText()).doubleValue();
		    if(magnitudeXticDiv < 0) {
			magnitudeXticDiv = 0.25;
			magnitudeXticDivision.setText("0.25");
		    }
		}
		catch (java.lang.NumberFormatException event) {
		    magnitudeXticDiv = 0.25;
		    magnitudeXticDivision.setText("0.25");
		}
		try {
		    magnitudeYticDiv = Double.valueOf(magnitudeYticDivision.
						      getText()).doubleValue();
		    if(magnitudeYticDiv < 0) {
			magnitudeYticDiv = 0.25;
			magnitudeYticDivision.setText("0.25");
		    }
		}
		catch (java.lang.NumberFormatException event) {
		    magnitudeYticDiv = 0.25;
		    magnitudeYticDivision.setText("0.25");
		}
		try {
		    magnitudeXposDiv = Double.valueOf(magnitudeXposLimit.
						      getText()).doubleValue();
		}
		catch (java.lang.NumberFormatException event) {
		}
		
		try {
		    magnitudeXnegDiv = Double.valueOf(magnitudeXnegLimit.
						      getText()).doubleValue();
		}
		catch (java.lang.NumberFormatException event) {
		}	      
		try {
		    magnitudeYposDiv = Double.valueOf(magnitudeYposLimit.
						      getText()).doubleValue();
		}
		catch (java.lang.NumberFormatException event) {
		}
		try {
		    magnitudeYnegDiv = Double.valueOf(magnitudeYnegLimit.
						      getText()).doubleValue();
		}
		catch (java.lang.NumberFormatException event) {
		}
		
		// set the scale for the plot
		//
		outputPanel.mag_response.x_axis.setXMax(magnitudeXposDiv);
		outputPanel.mag_response.x_axis.setXMin(magnitudeXnegDiv);
		outputPanel.mag_response.x_axis.setXTic(magnitudeXticDiv);
		outputPanel.mag_response.x_axis.resetXRange();
		
		outputPanel.mag_response.y_axis.setYMax(magnitudeYposDiv);
		outputPanel.mag_response.y_axis.setYMin(magnitudeYnegDiv);
		outputPanel.mag_response.y_axis.setYTic(magnitudeYticDiv);
		outputPanel.mag_response.y_axis.resetYRange();
		
		outputPanel.mag_response.get_range(magnitudeXposDiv,
						   magnitudeXnegDiv,magnitudeXticDiv,
						   magnitudeYposDiv,magnitudeYnegDiv,
						   magnitudeYticDiv);
		// update the scales to the appropriate values
		//
		outputPanel.mag_response.repaint();
	    }
	});
	
	// set up the update for the phase panel and define the actions 
	// to take place when the button is clicked on
	//
	phaseUpdateButton.addActionListener(new ActionListener() {
	    public void actionPerformed(ActionEvent e) {
		
		// make sure the value is a valid double
		//
		try {
		    phaseXticDiv = Double.valueOf(phaseXticDivision.
						  getText()).doubleValue();
		    if(phaseXticDiv < 0) {
			phaseXticDiv = 0.25;
			phaseXticDivision.setText("0.25");
		    }
		}
		catch (java.lang.NumberFormatException event) {
		    phaseXticDiv = 0.25;
		    phaseXticDivision.setText("0.25");
		}
		try {
		    phaseYticDiv = Double.valueOf(phaseYticDivision.
						  getText()).doubleValue();
		    if(phaseYticDiv < 0) {
			phaseYticDiv = 0.25;
			phaseYticDivision.setText("0.25");
		    }
		}
		catch (java.lang.NumberFormatException event) {
		    phaseYticDiv = 0.25;
		    phaseYticDivision.setText("0.25");
		}
		try {
		    phaseXposDiv = Double.valueOf(phaseXposLimit.
						  getText()).doubleValue();
		}
		catch (java.lang.NumberFormatException event) {
		}
		try {
		    phaseXnegDiv = Double.valueOf(phaseXnegLimit.
						  getText()).doubleValue();
		}
		catch (java.lang.NumberFormatException event) {
		}	      
		try {
		    phaseYposDiv = Double.valueOf(phaseYposLimit.
						  getText()).doubleValue();
		}
		catch (java.lang.NumberFormatException event) {
		}
		try {
		    phaseYnegDiv = Double.valueOf(phaseYnegLimit.
						  getText()).doubleValue();
		}
		catch (java.lang.NumberFormatException event) {
		}
		
		// set the scale for the plot
		//
		outputPanel.phase_response.x_axis.setXMax(phaseXposDiv);
		outputPanel.phase_response.x_axis.setXMin(phaseXnegDiv);
		outputPanel.phase_response.x_axis.setXTic(phaseXticDiv);
		outputPanel.phase_response.x_axis.resetXRange();
		
		outputPanel.phase_response.y_axis.setYMax(phaseYposDiv);
		outputPanel.phase_response.y_axis.setYMin(phaseYnegDiv);
		outputPanel.phase_response.y_axis.setYTic(phaseYticDiv);
		outputPanel.phase_response.y_axis.resetYRange();
		
		outputPanel.phase_response.get_range(phaseXposDiv,phaseXnegDiv,
						     phaseXticDiv,phaseYposDiv,
						     phaseYnegDiv,phaseYticDiv);
		// update the scales to the appropriate values
		//
		outputPanel.phase_response.repaint();
	    }
	});
	
	// set up the update for the output panel and define the actions 
	// to take place when the button is clicked on
	//
	impulseUpdateButton.addActionListener(new ActionListener() {
	    public void actionPerformed(ActionEvent e) {
		
		// make sure the value is a valid double
		//
		try {
		    impulseXticDiv = Double.valueOf(impulseXticDivision.
						    getText()).doubleValue();
		    if(impulseXticDiv < 0) {
			impulseXticDiv = 0.25;
			impulseXticDivision.setText("0.25");
		    }
		}
		catch (java.lang.NumberFormatException event) {
		    impulseXticDiv = 0.25;
		    impulseXticDivision.setText("0.25");
		}
		try {
		    impulseYticDiv = Double.valueOf(impulseYticDivision.
						    getText()).doubleValue();
		    if(impulseYticDiv < 0) {
			impulseYticDiv = 0.25;
			impulseYticDivision.setText("0.25");
		    }
		}
		catch (java.lang.NumberFormatException event) {
		    impulseYticDiv = 0.25;
		    impulseYticDivision.setText("0.25");
		}
		try {
		    impulseXposDiv = Double.valueOf(impulseXposLimit.
						    getText()).doubleValue();
		}
		catch (java.lang.NumberFormatException event) {
		}
		try {
		    impulseXnegDiv = Double.valueOf(impulseXnegLimit.
						    getText()).doubleValue();
		}
		catch (java.lang.NumberFormatException event) {
		}	      
		try {
		    impulseYposDiv = Double.valueOf(impulseYposLimit.
						    getText()).doubleValue();
		}
		catch (java.lang.NumberFormatException event) {
		}
		try {
		    impulseYnegDiv = Double.valueOf(impulseYnegLimit.
						    getText()).doubleValue();
		}
		catch (java.lang.NumberFormatException event) {
		}
		
		// set the scale for the plot
		//
		outputPanel.impulse_response.x_axis.setXMax(impulseXposDiv);
		outputPanel.impulse_response.x_axis.setXMin(impulseXnegDiv);
		outputPanel.impulse_response.x_axis.setXTic(impulseXticDiv);
		outputPanel.impulse_response.x_axis.resetXRange();
		
		outputPanel.impulse_response.y_axis.setYMax(impulseYposDiv);
		outputPanel.impulse_response.y_axis.setYMin(impulseYnegDiv);
		outputPanel.impulse_response.y_axis.setYTic(impulseYticDiv);
		outputPanel.impulse_response.y_axis.resetYRange();
		
		outputPanel.impulse_response.get_range(impulseXposDiv,
						       impulseXnegDiv,impulseXticDiv,
						       impulseYposDiv,impulseYnegDiv,
						       impulseYticDiv);
		// update the scales to the appropriate values
		//
		outputPanel.impulse_response.repaint();
	    }
	});
	
	// add action listeners to textfields
	//
	dc_gain_area.addActionListener(this);
	dc_gain_area.setActionCommand("dc_gain");
	sf_area.addActionListener(this);
	sf_area.setActionCommand("sf_area");
    }
    
    // method: add_components 
    //
    // arguments: none
    // return   : none
    //
    // positions individual controls on the Control Panel
    //
    void add_components() {
	
	// set the container layout for the components
	//
	GridBagLayout gridbag = new GridBagLayout();
	GridBagConstraints c = new GridBagConstraints();
	
	// define constraints for all components
	//
	c.weightx = 1.0;
	c.weighty = 1.0;
	c.gridheight = 1;
	c.anchor = GridBagConstraints.WEST;
	c.fill = GridBagConstraints.HORIZONTAL;
	
	// add components to the magnitude panel
	//
	c.gridx = 0;
	c.gridy = 0;
	c.gridwidth = 1;
	magnitudeCard.setLayout(gridbag);
	gridbag.setConstraints(magXnegLabel, c);
	magnitudeCard.add(magXnegLabel);
	
	c.gridx = 1;
	c.gridwidth = GridBagConstraints.REMAINDER;
	gridbag.setConstraints(magnitudeXnegLimit, c);
	magnitudeCard.add(magnitudeXnegLimit);
	
	c.gridx = 0;
	c.gridy = 1;
	c.gridwidth = 1;
	gridbag.setConstraints(magXposLabel, c);
	magnitudeCard.add(magXposLabel);
	
	c.gridx = 1;
	c.gridwidth = GridBagConstraints.REMAINDER;
	gridbag.setConstraints(magnitudeXposLimit, c);
	magnitudeCard.add(magnitudeXposLimit);
	
	c.gridx = 0;
	c.gridy = 2;
	c.gridwidth = 1;
	gridbag.setConstraints(magXticLabel, c);
	magnitudeCard.add(magXticLabel);
	
	c.gridx = 1;
	c.gridwidth = GridBagConstraints.REMAINDER;
	gridbag.setConstraints(magnitudeXticDivision, c);
	magnitudeCard.add(magnitudeXticDivision);
	
	c.gridx = 0;
	c.gridy = 3;
	c.gridwidth = 1;
	gridbag.setConstraints(magYnegLabel, c);
	magnitudeCard.add(magYnegLabel);
	
	c.gridx = 1;
	c.gridwidth = GridBagConstraints.REMAINDER;
	gridbag.setConstraints(magnitudeYnegLimit, c);
	magnitudeCard.add(magnitudeYnegLimit);
	
	c.gridx = 0;
	c.gridy = 4;
	c.gridwidth = 1;
	gridbag.setConstraints(magYposLabel, c);
	magnitudeCard.add(magYposLabel);
	
	c.gridx = 1;
	c.gridwidth = GridBagConstraints.REMAINDER;
	gridbag.setConstraints(magnitudeYposLimit, c);
	magnitudeCard.add(magnitudeYposLimit);
	
	c.gridx = 0;
	c.gridy = 5;
	c.gridwidth = 1;
	gridbag.setConstraints(magYticLabel, c);
	magnitudeCard.add(magYticLabel);
	
	c.gridx = 1;
	c.gridwidth = GridBagConstraints.REMAINDER;
	gridbag.setConstraints(magnitudeYticDivision, c);
	magnitudeCard.add(magnitudeYticDivision);
	
	c.gridx = 0;
	c.gridy = 6;
	c.anchor = GridBagConstraints.CENTER;
	c.gridwidth = GridBagConstraints.REMAINDER;
	gridbag.setConstraints(magnitudeUpdateButton, c);
	magnitudeCard.add(magnitudeUpdateButton);
	
	// add components to the phase panel
	//
	c.gridx = 0;
	c.gridy = 0;
	c.gridwidth = 1;
	phaseCard.setLayout(gridbag);
	gridbag.setConstraints(phaXnegLabel, c);
	phaseCard.add(phaXnegLabel);
	
	c.gridx = 1;
	c.gridwidth = GridBagConstraints.REMAINDER;
	gridbag.setConstraints(phaseXnegLimit, c);
	phaseCard.add(phaseXnegLimit);
	
	c.gridx = 0;
	c.gridy = 1;
	c.gridwidth = 1;
	gridbag.setConstraints(phaXposLabel, c);
	phaseCard.add(phaXposLabel);
	
	c.gridx = 1;
	c.gridwidth = GridBagConstraints.REMAINDER;
	gridbag.setConstraints(phaseXposLimit, c);
	phaseCard.add(phaseXposLimit);
	
	c.gridx = 0;
	c.gridy = 2;
	c.gridwidth = 1;
	gridbag.setConstraints(phaXticLabel, c);
	phaseCard.add(phaXticLabel);
	
	c.gridx = 1;
	c.gridwidth = GridBagConstraints.REMAINDER;
	gridbag.setConstraints(phaseXticDivision, c);
	phaseCard.add(phaseXticDivision);
	
	c.gridx = 0;
	c.gridy = 3;
	c.gridwidth = 1;
	gridbag.setConstraints(phaYnegLabel, c);
	phaseCard.add(phaYnegLabel);
	
	c.gridx = 1;
	c.gridwidth = GridBagConstraints.REMAINDER;
	gridbag.setConstraints(phaseYnegLimit, c);
	phaseCard.add(phaseYnegLimit);
	
	c.gridx = 0;
	c.gridy = 4;
	c.gridwidth = 1;
	gridbag.setConstraints(phaYposLabel, c);
	phaseCard.add(phaYposLabel);
	
	c.gridx = 1;
	c.gridwidth = GridBagConstraints.REMAINDER;
	gridbag.setConstraints(phaseYposLimit, c);
	phaseCard.add(phaseYposLimit);
	
	c.gridx = 0;
	c.gridy = 5;
	c.gridwidth = 1;
	gridbag.setConstraints(phaYticLabel, c);
	phaseCard.add(phaYticLabel);
	
	c.gridx = 1;
	c.gridwidth = GridBagConstraints.REMAINDER;
	gridbag.setConstraints(phaseYticDivision, c);
	phaseCard.add(phaseYticDivision);
	
	c.gridx = 0;
	c.gridy = 6;
	c.anchor = GridBagConstraints.CENTER;
	c.gridwidth = GridBagConstraints.REMAINDER;
	gridbag.setConstraints(phaseUpdateButton, c);
	phaseCard.add(phaseUpdateButton);
	
	// add components to the impulse panel
	//
	c.gridx = 0;
	c.gridy = 0;
	c.gridwidth = 1;
	impulseCard.setLayout(gridbag);
	gridbag.setConstraints(impXnegLabel, c);
	impulseCard.add(impXnegLabel);
	
	c.gridx = 1;
	c.gridwidth = GridBagConstraints.REMAINDER;
	gridbag.setConstraints(impulseXnegLimit, c);
	impulseCard.add(impulseXnegLimit);
	
	c.gridx = 0;
	c.gridy = 1;
	c.gridwidth = 1;
	gridbag.setConstraints(impXposLabel, c);
	impulseCard.add(impXposLabel);
	
	c.gridx = 1;
	c.gridwidth = GridBagConstraints.REMAINDER;
	gridbag.setConstraints(impulseXposLimit, c);
	impulseCard.add(impulseXposLimit);
	
	c.gridx = 0;
	c.gridy = 2;
	c.gridwidth = 1;
	gridbag.setConstraints(impXticLabel, c);
	impulseCard.add(impXticLabel);
	
	c.gridx = 1;
	c.gridwidth = GridBagConstraints.REMAINDER;
	gridbag.setConstraints(impulseXticDivision, c);
	impulseCard.add(impulseXticDivision);
	
	c.gridx = 0;
	c.gridy = 3;
	c.gridwidth = 1;
	gridbag.setConstraints(impYnegLabel, c);
	impulseCard.add(impYnegLabel);
	
	c.gridx = 1;
	c.gridwidth = GridBagConstraints.REMAINDER;
	gridbag.setConstraints(impulseYnegLimit, c);
	impulseCard.add(impulseYnegLimit);
	
	c.gridx = 0;
	c.gridy = 4;
	c.gridwidth = 1;
	gridbag.setConstraints(impYposLabel, c);
	impulseCard.add(impYposLabel);
	
	c.gridx = 1;
	c.gridwidth = GridBagConstraints.REMAINDER;
	gridbag.setConstraints(impulseYposLimit, c);
	impulseCard.add(impulseYposLimit);
	
	c.gridx = 0;
	c.gridy = 5;
	c.gridwidth = 1;
	gridbag.setConstraints(impYticLabel, c);
	impulseCard.add(impYticLabel);
	
	c.gridx = 1;
	c.gridwidth = GridBagConstraints.REMAINDER;
	gridbag.setConstraints(impulseYticDivision, c);
	impulseCard.add(impulseYticDivision);
	
	c.gridx = 0;
	c.gridy = 6;
	c.anchor = GridBagConstraints.CENTER;
	c.gridwidth = GridBagConstraints.REMAINDER;
	gridbag.setConstraints(impulseUpdateButton, c);
	impulseCard.add(impulseUpdateButton);
	
	//add components to the DataInput panel
	//
	c.gridx = 0;
	c.gridy = 0;
	c.gridwidth = 1;
	datainputCard.setLayout(gridbag);
	gridbag.setConstraints(freq_label, c);
	datainputCard.add(freq_label);
	
	c.gridx = 1;
	c.gridwidth = GridBagConstraints.REMAINDER;
	gridbag.setConstraints(entry_text_0, c);
	datainputCard.add(entry_text_0);
	
	c.gridx = 0;
	c.gridy = 1;
	c.gridwidth = GridBagConstraints.REMAINDER;
	gridbag.setConstraints(band_label, c);
	datainputCard.add(band_label);
	
	c.gridx = 1;
	c.gridwidth = 1;
	gridbag.setConstraints(entry_text_1, c);
	datainputCard.add(entry_text_1);
	
	c.gridx = 0;
	c.gridy = 2;
	c.gridwidth = 1;
	gridbag.setConstraints(sf_range_label, c);
	datainputCard.add(sf_range_label);
	
	c.gridx = 1;
	c.gridwidth = GridBagConstraints.REMAINDER;
	gridbag.setConstraints(sf_area, c);
	datainputCard.add(sf_area);
	
	c.gridx = 0;
	c.gridy = 3;
	c.gridwidth = 1;
	gridbag.setConstraints(dc_gain_label, c);
	datainputCard.add(dc_gain_label);
	
	c.gridx = 1;
	c.gridwidth = GridBagConstraints.REMAINDER;
	gridbag.setConstraints(dc_gain_area, c);
	datainputCard.add(dc_gain_area);
	
	// add title borders to each card in the layout
	//
	Border titleBorder = BorderFactory.createTitledBorder(
							      BorderFactory.createEmptyBorder(), 
							      magnitudeTitle, 
							      TitledBorder.LEFT, 
							      TitledBorder.ABOVE_TOP, 
							      newFont, 
							      Color.black);
	magnitudeCard.setBorder(titleBorder);
	
	titleBorder = BorderFactory.createTitledBorder(
						       BorderFactory.createEmptyBorder(), 
						       phaseTitle, 
						       TitledBorder.LEFT, 
						       TitledBorder.ABOVE_TOP, 
						       newFont, 
						       Color.black);
	phaseCard.setBorder(titleBorder);
	
	titleBorder = BorderFactory.createTitledBorder(
						       BorderFactory.createEmptyBorder(), 
						       impulseTitle, 
						       TitledBorder.LEFT, 
						       TitledBorder.ABOVE_TOP, 
						       newFont, 
						       Color.black);
	impulseCard.setBorder(titleBorder);
	
	titleBorder = BorderFactory.createTitledBorder(
						       BorderFactory.createEmptyBorder(), 
						       datainputTitle, 
						       TitledBorder.LEFT, 
						       TitledBorder.ABOVE_TOP, 
						       newFont, 
						       Color.black);
	datainputCard.setBorder(titleBorder);
	
	// add the control and parameters panel to the card
	//
	cards.add(datainputCard, datainputParams);
	cards.add(magnitudeCard, magnitudeParams);
	cards.add(phaseCard, phaseParams);
	cards.add(impulseCard, impulseParams);
	
	// add the cards and the main panel to content pane
	//
	constrain(this, cards, 0, 0,1, 1, 
		  GridBagConstraints.BOTH,
		  GridBagConstraints.NORTHWEST, 0.2, 1.0,5,5,5,5);
	
    }
    
    // method: actionPerformed
    //
    // arguments: (ActionEvent) e
    // return   : none
    //
    // Controls the action of the combination boxes.  Sets the info
    // to the info_box for displaying experiment and data information
    // to the user.
    //
    public void actionPerformed(ActionEvent event) {
	if (event.getActionCommand().equals("sf_area")) {
	    sf_area.requestFocus();
	    // make sure the value is a valid double
	    //
	    double new_sf = 0.0;
	    try {
		new_sf = Double.valueOf(sf_area.getText()).doubleValue();
	    } 
	    catch(java.lang.NumberFormatException e) {
	    }
	    this.inputPanel.pz_map.set_sample_frequency(new_sf);
	    outputPanel.impulse_response.clear_flag = true;
	    
	}
	//else if (event.getActionCommand().equals("dc")) {
	//
	else {
	    
	    // make sure the value is a valid double
	    //
	    double new_dc_gain = 0.0;
	    dc_gain_area.requestFocus();
	    try {
		new_dc_gain = Double.valueOf(dc_gain_area.getText()).doubleValue();
	    } 
	    catch(java.lang.NumberFormatException e) {
	    }
	    this.inputPanel.pz_map.set_dc_gain(new_dc_gain);
	    
	}
	// this method is required to be present
    } 
    
    // method: setDecimal
    //
    // arguments:
    //   double doubleNumber: input digit to be rounded off
    //   int decimalPlaces: number of significant to round the input digit 
    //
    // return :
    //    double result: the rounded off input digit
    //
    // method takes in a input digit (double) and rounds the input digit
    // to the number of speified significant places specified
    //
    public double SetDecimal(double doubleNumber, int decimalPlaces) {
	
        int wholeNumber = (int)doubleNumber;
        double pastDecimal = ((doubleNumber - wholeNumber) * 
			      Math.pow(10,decimalPlaces));
        int roundedDecimal = (int)Math.round(pastDecimal);
        int combine = (int)(wholeNumber * 
			    Math.pow(10,decimalPlaces)+roundedDecimal);
        double result = combine / Math.pow(10,decimalPlaces);
        return result;
    }

    public boolean set_design_type(int new_type) {

	if (new_type == Constants.DIGITAL) {
	    sf_range_label.setText(sf_string);
	}
	else {
	    sf_range_label.setText(range_string);
	}

	return true;
    }
    
}
//
// end of file
