// file: TogglePanel.java
//

// include the necessary system files
//
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

// include the necessary local files
//
//import Designer;
//import Constants;

// class: TogglePanel
//
// this class implements the interface to allow toggling of the analog and
// digital designs of a Designer panel
//
public class TogglePanel extends SubPanel
    implements ActionListener, Constants {
  
  // set class constants
  //

  private final static int FRAME_SEPARATION = 2;

  // declare class variables
  //
    private String[] dig_ana_choice_string = {"Analog Design", 
    					      "Digital Design"};
  private Designer designer;

    private JComboBox dig_ana_choice = new JComboBox(dig_ana_choice_string);

    //  private Choice dig_ana_choice = new Choice();

  // design type
  //
  private int design_type = Constants.DEFAULT_DESIGN;
  
  //****************************************************************
  //
  // public methods
  //
  //****************************************************************
  
  // method TogglePanel
  //
  // parameters: 
  //     Designer designer_a: (input) design panel to control
  //
  // this method initializes this class
  // 
  // returns: none
  //
  public TogglePanel(Designer designer_a, int type) {
    
    // run the constructor for the super-class
    //
    super();
    //    this.setBackground(Color.lightGray);
    // instantiate the windowed tool frame and set the design type
    //
    this.designer = designer_a;
    design_type = type;

    dig_ana_choice.addActionListener(this);
    
    // place the controls
    //
      this.place_components();
  }
  
  
  public void start () {
  }


  // method stop
  //
  // parameters: none
  //
  // this method stops the threaded object
  //
  // returns: none
  //
  public void stop () {
    

  }


  // method place_components
  //
  // parameters: (none)
  //     
  // this method places the individual controls on the panel
  // 
  // returns: none
  //
  // positions individual controls on the Control Panel
  //
    void place_components () {
    
    // supply choices for an analog or digital design
    //
  
    if (design_type == Constants.DIGITAL) {
	dig_ana_choice.setSelectedIndex(0);
    }
    else {
	dig_ana_choice.setSelectedIndex(1);
    }
    // set constraints for each control within the control panel
    //
    constrain(this, dig_ana_choice, 0, 0, 1, 1, GridBagConstraints.BOTH,
   	      GridBagConstraints.NORTH, 1.0, 1.0, FRAME_SEPARATION, 
	      FRAME_SEPARATION, FRAME_SEPARATION, FRAME_SEPARATION);
  

    // set the proper active design choice
    //
 
    this.setVisible(true); 
 
    }
   
    // method: handleEvent
  //
  // parameters: 
  //     Event event: (input) an Event object indicating the event to handle
  //
  // this method handles the various interrupt events that may occur in this
  // component
  //
  // returns: boolean
  //

    public void actionPerformed(ActionEvent e) {
	JComboBox cb = (JComboBox)e.getSource();
	
	if ((String)cb.getSelectedItem() == "Digital Design") {
	    designer.set_design_type(Constants.DIGITAL);
	}
	else 
	    if ((String)cb.getSelectedItem() == "Analog Design") {
		designer.set_design_type(Constants.ANALOG);
	    }   
	
    }
  
} // end class TogglePanel
