// file: InputPanel.java
//

// include the necessary system files
//
//import java.awt.*;
import javax.swing.*;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.event.*;
import java.awt.Graphics;
import java.awt.Color;
// include the necessary local files
//
//import Constants;

// class: InputPanel
//
// this class implements a tool which controls the input to a pole-zero
// map it allows the user to place poles and zeros.
//
public class InputPanel extends SubPanel implements Constants{
    
    // declare the gui components of the class
    //
    private DataDisplayPanel data_display;
    public DataInputPanel data_input;
    public  PzmapPanel pz_map;
    
    // declare the output panel to correspond with
    //
    private OutputPanel output;
    
    // the layout manager for each of the containers
    //
    // private GridBagLayout gridbag = new GridBagLayout();
    
    // variable to hold the design type
    //
    private int design_type = Constants.DEFAULT_DESIGN;
    
    //*****************************************************************
    //
    // constructor methods
    //
    //*****************************************************************
    
    
    // method: InputPanel
    //
    // parameters: none
    // 
    // this method constructs the default InputPanel object
    //
    public InputPanel(OutputPanel output_a, int type) {
	
	// call the super-class constructor
	//
	super();
	
	// create a border around the input panel
	//
	setBorder(BorderFactory.createEtchedBorder());
	
	// set the design_type
	//
	design_type = type;
	
	// set the output panel
	//
	output = output_a;
	
	// run the initializations
	//
	this.add_components();
	//    this.setBackground(Color.blue);    
    }
    
    
    //***************************************************************
    //
    // private methods
    //
    //***************************************************************
    
    
    // method: add_components
    //
    // parameters: none
    // 
    // this method initializes the gui components of the class
    //
    // returns: boolean
    //  
    private boolean add_components() {
	
	// initialize the gui components
	//
	data_display = new DataDisplayPanel(design_type);
	pz_map = new PzmapPanel(output, data_display, design_type);
	data_input = new DataInputPanel(pz_map, design_type);
	
	// place the data_input panel to the upper-left
	//
	//constrain(this, data_input, 0, 0, 1, 1, GridBagConstraints.HORIZONTAL,
	//      GridBagConstraints.NORTHWEST, 0.0, 0.0, 2,
	//      2, Constants.INSET_SIZE, Constants.INSET_SIZE);
	
	// place the data_display panel to the lower-left
	//
	
	constrain(this, data_display, 0,0,  1, 1, GridBagConstraints.BOTH,
		  GridBagConstraints.NORTHWEST, 3.8, 7.0, Constants.INSET_SIZE,
		  0, 0, Constants.INSET_SIZE);
	
	// place the pz_map panel to the right
	//
	
	constrain(this, pz_map, 1, 0, GridBagConstraints.REMAINDER,
		  GridBagConstraints.REMAINDER, GridBagConstraints.BOTH,
		  GridBagConstraints.NORTHWEST, 10.2, 1.0, 2,2,3,3);
	
	// exit gracefully
	//
	return true;
	
    }
    
    
    //****************************************************************
    //
    // public methods
    //
    //****************************************************************
    
    
    // method start
    //
    // parameters: none
    //
    // this method starts or restarts the threaded object
    //
    // returns: none
    //
    public void start () {
	
	// start the threaded sub-components
	//
	data_input.start();
	pz_map.start();
	
    }
    
    
    // method stop
    //
    // parameters: none
    //
    // this method stops the threaded object
    //
    // returns: none
    //
    public void stop () {
	
	// stop the components of this object
	//
	data_input.stop();
	pz_map.stop();
	
    }
    
    
    // method: set_design_type 
    //
    // parameters:
    //     integer new_type: (input) design type to change to
    //
    // this is a method to set the design type.  the design type will
    // be set to the value passed in to new_type
    //
    // returns: boolean
    //
    public boolean set_design_type(int new_type) {
	
	// make sure the new_type is valid, then set the design_type
	// variable, and return a boolean value which indicates whether
	// or not the new_type was valid.  note:  this assumes that 
	// the design_type is currently a valid value
	//
	if((new_type == Constants.DIGITAL) || (new_type == Constants.ANALOG)) {
	    design_type = new_type;
	    data_input.set_design_type(design_type);
	    return true;
	}
	else {
	    return false;
	}
    }
    
} // end class InputPanel
