// file: Designer.java
//

// include the necessary system files
//
import java.awt.*;
import javax.swing.*;
import java.lang.*;
import javax.swing.border.*;
import java.util.*;

// comment Constants, as java1.4 doesnot work for it  
// include the necessary local files
// import Constants;
//

// class: Designer
//
// this class implements a tool which allows the user to place poles
// and zeros on a pole-zero map interactively and view the effects of
// these poles and zeros on the frequency response and the impulse
// response
//
public class Designer extends SubPanel implements Constants {
    
    // set class variables
    //
    private int design_type = Constants.DEFAULT_DESIGN;
    
    // declare the various panels
    //
    public InputPanel input_panel;
    public OutputPanel output_panel;
    public ControlPanel input_params;
    
    // declare the default fonts
    //
    Font currentFont = getFont();
    Font newFont = new Font(currentFont.getName(), currentFont.getStyle(), 12);
    //*****************************************************************
    //
    // constructor methods
    //
    //*****************************************************************
    
    // method: Designer
    //
    // parameters: none
    // 
    // this method constructs the default Designer object
    //
    public Designer(int type) {
	
	// run the constructor for the super-class
	//
	super();
	
	// set the design type
	//
	design_type = type;
	
	// run the initializations
	//
	this.add_components();
    }
    
    
    //***************************************************************
    //
    // private methods
    //
    //***************************************************************
    
    
    // method: add_components
    //
    // parameters: none
    // 
    // this method initializes the gui components of the class
    //
    // returns: boolean
    //  
    private boolean add_components() {
	
	// initialize the components
	//
	output_panel = new OutputPanel(design_type, Constants.DEFAULT_SAMPLE_FREQ,
				       new PoleZero[1]);
	input_panel = new InputPanel(output_panel,design_type);
	
	input_params = new ControlPanel(output_panel,input_panel);
	
	// add the control and results panels to this
	//
	
	input_params.constrain(this, input_params, 0, 0, 1, 1, 
			       GridBagConstraints.BOTH, 
			       GridBagConstraints.NORTHWEST, 
			       0.3, 1.0, 5,5,5,5);
	
	constrain(this, input_panel, 1, 0, GridBagConstraints.REMAINDER, 1,
		  GridBagConstraints.BOTH, GridBagConstraints.NORTH,
		  1.0, 1.0, 5,5,5,5); 
	
	
	
	constrain(this, output_panel, 0, 1, GridBagConstraints.REMAINDER, 1,
		  GridBagConstraints.BOTH, GridBagConstraints.SOUTH,
		  1.0, 3.0, 5, 5, 5, 5);
	
	input_params.add_components();
	
	// 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 components of this object
	//
	input_panel.start();
	output_panel.start();
	
    }
    
    
    // method stop
    //
    // parameters: none
    //
    // this method stops the threaded object
    //
    // returns: none
    //
    public void stop () {
	
	// stop the components of this object
	//
	input_panel.stop();
	output_panel.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;
	    input_panel.set_design_type(design_type);
	    output_panel.set_design_type(design_type);
	    input_params.set_design_type(design_type);
	    return true;
	}
	else {
	    return false;
	}
    }

    // method: get_design_type 
    //
    // parameters: none
    //
    // this is a method to get the design type.  the current design type will
    // be returned
    //
    // returns: integer
    //
    public int get_design_type() {
	return design_type;
    }
    
} // end class Designer
