// file: SubConfigBox.java
//

// import java libraries
//
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import java.util.*;
import java.io.*;
import java.lang.*;
import javax.swing.plaf.*;

public class SubConfigBox extends JDialog implements ActionListener, Constants {

    // ---------------------------------------------------
    //
    // declare class member data
    //
    // ---------------------------------------------------

    // set the current vertex that is in focus
    //
    private Vertex currVertexFocus = null;
    
    // data from the parsed text file
    //
    Data data = null;
    
    // scroll pane to hold all the parameter fields
    //
    JScrollPane scroll_pane = null;

    // panel to hold all the config data fields
    // to be mounted in a scrollable pane
    //
    JPanel config_panel = null;

    // Parent dialogue
    //
    JDialog parent = null;

    // global representation of the transform type we are dealing with
    //
    Vertex  cfgVertexFocus;

    // transform tyoe this subclass represents
    //
    Vertex subVertex;

    // button to get values an return to process design box
    //
    JButton save_button = null;
    JButton cancel_button = null;
    JButton default_button = null;
    JButton help_button = null;
    JButton config_button = null;

    //Vector to store information for determing sub parameters
    //
    Vector subparamInfo =  new Vector(5,5);

    // vector of labels and data blocks (text fields, selection blocks,
    // check boxes, etc..)
    //
    Vector enteredData = null;
    Vector blockType = null;
    Vector labelReference = null;

    // vector of subclass vertices
    //
    Vector config_vertices = null;

    // Max number of subparam
    //
    int max_subparam = 0;

    // total number of subclasses (to prevent re-adding to the subclass vector)
    //
    int max_subclass = 1;

   // parameter button
    //
    Vertex buttonParam = null;

    // maximum font size for the componets
    //
    private static final int MAX_FONT_SIZE = (int)12;
    
    // ---------------------------------------------------
    //
    // declare class constructors
    //
    // ---------------------------------------------------

    // method: SubConfigBox
    //
    // arguments: none
    // returns  : none
    //
    public SubConfigBox(JDialog par, Data d, Vertex subclass, Vertex process) {

	// invoke the parent default constructor
	//
	//super("Subclass Configuration Box");
	parent = par;
	setModal(true);
	Point xy = parent.getLocation();
	setLocation((int)xy.getX() + 100,(int)xy.getY() + 200);

	// make the passed Data object available globally
	//
	data = d;
	
	// initialize the enteredData and labelReference vectors for use
	//
	enteredData = new Vector(5,5);
	labelReference = new Vector(5,5);
	blockType = new Vector(5,5);
	
	// give the name of the transfrom in question over to its global 
	// counterpart
	//
	subVertex = subclass;
	cfgVertexFocus = process;

	// create this new panel with gridbag layout
	//
	config_panel = new JPanel();
	addConfig();

	// set the sizes of the scroll pane and configuration panel
	//
	int height = labelReference.size() * 25 + 75;
	int width = 335 + 55;

	config_panel.setSize(width, height);
	config_panel.setMinimumSize(new Dimension(width,height));
	config_panel.setPreferredSize(new Dimension(width,height));
	config_panel.setMaximumSize(new Dimension(width,height));
	
	// add the scroll pane to the frame
	//
	this.getContentPane().add(config_panel, BorderLayout.NORTH);

	// create, configure, and place a border on the config pane
	//
	String border_title = 
	    new String(subVertex.association + " Configuration:");

	BorderUIResource.TitledBorderUIResource border =
	    new BorderUIResource.TitledBorderUIResource(border_title);
	border.setTitleFont(newFont);
	border.setTitleColor(Color.black);
	config_panel.setBorder(border);


    }

    
    // ---------------------------------------------------
    //
    // declare class methods
    //
    // ---------------------------------------------------

    // method:  addConfig()
    //
    // arguments:  none
    // return: none
    //
    //  dynamically adds and constrains all objects on the JPanel
    //
    public void addConfig() {

	GridBagLayout gridbag = new GridBagLayout();
	config_panel.setLayout(gridbag);

	// to simplify the creation, the data vectors will be trimmed to only
	// include the transform we're looking at and saved into these three
	// vectors for use in a bit
	//
	Vector labels = new Vector(5,5);
	Vector types = new Vector(5,5);
	Vector values = new Vector(5,5);	
	String transform = subVertex.association;
	int subclassIndex = 0;

	for(int j=data.association.indexOf(transform); 
	    j <= data.association.lastIndexOf(transform);
	    j++) {
	    if(j != -1) {
		labels.add(data.name.get(j));
		types.add(data.type.get(j));
		values.add(data.values.get(j));
	    }
	}

	// maximum width of any JTextField or JComboBox
	// will set all to this width once they have been added
	//
	int maxwidth = 0;
	int maxheight = 0;

	// run through these and add labels and input fields as appropriate
	//
	for(int i=0; i < labels.size(); i++) {

	    // add a label for all labels except the images
	    //
	    if(types.get(i).equals("image") == false){
		String configLabel = (String)labels.get(i);
		JLabel jlabel = new JLabel((String)labels.get(i));
		if(configLabel.equals("configuration")) {
		    jlabel = new JLabel("");
		}
		jlabel.setFont(newFont);
		jlabel.setForeground(Color.black);
		constrain(config_panel,jlabel, gridbag, 0, i,
			  1, 1, 1, 0, GridBagConstraints.WEST);
		labelReference.add(jlabel);
	    }
	    else {
		
		// keep data alligned so changing values is done easily
		// while holding onto these image files
		//
		enteredData.add("image");
		labelReference.add("image");
		blockType.add("image");
	    }
	
	    // add a drop down list for the enumerated values with first
	    // option from file being initially selected
	    //
	    if(types.get(i).equals("enum")){

		//create a drop down list to allow selection from
		//
		JComboBox select = new JComboBox();
		
		constrain(config_panel,select, gridbag, 3, i,
			  1, 1, 1, 0, GridBagConstraints.EAST);
		
		// retrieve and add all possible values to this list
		//
		Vector enum_values = (Vector)values.get(i);
		for(int j=0; j < enum_values.size(); j++) {
		    select.addItem(enum_values.get(j));
		}
		enteredData.add(select);
		blockType.add("enum");
		select.setSelectedItem(subVertex.values.get(i));
		select.setFont(newFont);
		select.setForeground(Color.black);
	    }
	    // make a check box for a boolean type
	    //
	    else if (types.get(i).equals("boolean")){

		//create the check box
		//
		String value = (String)(subVertex.values.get(i));
		
		// get the default value for the button
		//
		boolean value2;
		if (value.equals("true"))
		    value2 = true;
		else
		    value2 = false;

		JCheckBox checkBox = new JCheckBox("", value2);
		constrain(config_panel, checkBox, gridbag, 3, i,
			  1,1,1,0,GridBagConstraints.EAST);
		enteredData.add(checkBox);
		blockType.add("boolean");
	    }
	  
	    // add another pop up frame to set parameters for the class
	    //
	    else if (types.get(i).equals("param")) {

		    String image_name = null;
		    String image_association= null;

		    // tells the program which transform it is looking to match
		    //
		    image_association = (String)values.get(i);

		    // scans through the association until it 
		    // finds the smallIcon key
		    //
		    for(int j=data.association.indexOf(image_association); 
			j <= data.association.lastIndexOf(image_association);
			j++) {
			if(j != -1) {
			    
			    if(((String)(data.name.get(j))).
			       equals("iconSmall")) {
		
				// sets the image_name to the value 
				// held in small icon
				//
				image_name = (String)data.values.get(j);
			    }
			}
		    }
		    
		    // check to see if the file exists. If it does not exist,
		    // use a default image.
		    //
		    if(image_name != null){
			File image_file = new File(image_name);
			if (image_file.exists() == false)
			    image_name = GUI_PATH + "/images_small/default.gif";
		    }
		    else {
			image_name = GUI_PATH + "/images_small/default.gif";
		    }

		    image_name = GUI_PATH+"/lib/images/isip_transform_builder/icons/algorithm_00.gif";
		    
		    // create the icons for the config panel
		    //
		    ImageIcon icon = new ImageIcon(image_name);
		    
		    // create the button for the config panel
		    //
		    buttonParam = new Vertex("  Configure ");
		    buttonParam.association = image_association;

		    // to simplify the creation, the data vectors will 
		    // be trimmed to only include the transform we're
		    // looking at and saved into these three vectors
		    // for use in a bit
		    //
		    Vector labels2 = new Vector(5,5);
		    Vector types2 = new Vector(5,5);
		    Vector values2 = new Vector(5,5);
		    
		    for(int j=data.association.indexOf(image_association); 
			j <= data.association.lastIndexOf(image_association);
			j++) {
			if(j != -1) {
			    labels2.add(data.name.get(j));
			    types2.add(data.type.get(j));
			    values2.add(data.values.get(j));
			}
		    }
		    	 
		    // initialize the vertex to the default values for its type
		    //
		    //button.initializeConfig(labels2, values2, types2,
		    //		    image_association, data);
		   
		    // add subparam button to the vector
		    //
		    subVertex.subparam.add(buttonParam);
		    
		    // add the vertex to the button panel
		    //
		    enteredData.add(buttonParam);
		    blockType.add("Vertex");
		    max_subparam++;
	    }

	    // add another pop up frame to set parameters for the class
	    //
	    else if (types.get(i).equals("class")) {

		String image_name = null;
		String image_association= null;

		// tells the program which transform it is looking to match
		//
		image_association = (String)values.get(i);

		// scans through the association until it finds the
		// smallIcon key
		//
		for(int j=data.association.indexOf(image_association); 
		    j <= data.association.lastIndexOf(image_association);
		    j++) {
		    if(j != -1) {
	   
			if(((String)(data.name.get(j))).equals("iconSmall")) {

			    // sets the image_name to the value 
			    // held in small icon
			    //
			    image_name = (String)data.values.get(j);
			}
		    }
		}

		// check to see if the file exists. If it does not exist,
		// use a default image.
		//
		if(image_name != null){
		    File image_file = new File(image_name);
		    if (image_file.exists() == false) {
			image_name = DEFAULT_PATH + "default.gif";
		    }
		}
		else {
		    image_name = DEFAULT_PATH + "default.gif";
		}

		// create the icons for the config panel
		//
		ImageIcon icon = new ImageIcon(image_name);
		
		// create the button for the config panel
		//
		Vertex button = new Vertex(icon, ALGORITHM);

		// to simplify the creation, the data vectors will be
		// trimmed to only include the transform we're looking at
		// and saved into these three vectors for use in a bit
		//
		Vector labels2 = new Vector(5,5);
		Vector types2 = new Vector(5,5);
		Vector values2 = new Vector(5,5);

		for(int j=data.association.indexOf(image_association); 
		    j <= data.association.lastIndexOf(image_association);
		    j++) {
		    if(j != -1) {
			labels2.add(data.name.get(j));
			types2.add(data.type.get(j));
			values2.add(data.values.get(j));
		    }
		}

		// initialize the vertex to the default values for its type
		//
		button.initializeConfig(labels2, values2, types2,
				      image_association, data);
		
		// attach an action listener to the button
		//
		button.setActionCommand("class");
		button.addActionListener(this);

		// add subclass button to the vector
		//
		subVertex.subclass.add(button);
		
		// add the vertex to the button panel
		//
		constrain(config_panel,button, gridbag, 3, i,
			  1, 1, 1, 0, GridBagConstraints.EAST);
		enteredData.add(button);
		blockType.add("Vertex");
	    }
	    
	    // take care of anything of type text
	    //
	    else if (types.get(i).equals("text")) {

		JTextField TextField = 
		    new JTextField(((String)subVertex.values.get(i)), 8);
		constrain(config_panel,TextField, gridbag, 3, i,
			  1, 1, 1, 0, GridBagConstraints.EAST);
		enteredData.add(TextField);
		blockType.add("text");
		TextField.setFont(newFont);
		TextField.setForeground(Color.black);
	    }

	    // take care of type vector
	    //
	    else if (types.get(i).equals("vector")) {
		JTextField TextField = 
		    new JTextField(((String)subVertex.values.get(i)), 8);
		TextField.setFont(newFont);
		TextField.setForeground(Color.black);
		constrain(config_panel,TextField, gridbag, 3, i,
			  1, 1, 1, 0, GridBagConstraints.EAST);
		enteredData.add(TextField);
		blockType.add("vector");
	    }

	    // take care of anything of type double
	    //
	    else if (types.get(i).equals("double")) {

		JTextField TextField = 
		    new JTextField(((String)subVertex.values.get(i)), 8);
		constrain(config_panel,TextField, gridbag, 3, i,
			  1, 1, 1, 0, GridBagConstraints.EAST);
		enteredData.add(TextField);
		blockType.add("double");
		TextField.setFont(newFont);
		TextField.setForeground(Color.black);
	    }
	    
	    // creation of input box for unsigned int
	    //
	    else if (types.get(i).equals("unsigned-integer")) {

		JTextField TextField = 
		    new JTextField(((String)subVertex.values.get(i)), 8);
		constrain(config_panel,TextField, gridbag, 3, i,
			  1, 1, 1, 0, GridBagConstraints.EAST);
		enteredData.add(TextField);
		blockType.add("unsigned-integer");
		TextField.setFont(newFont);
		TextField.setForeground(Color.black);
	    }

	    // creation of input box for image
	    //
	    else if (types.get(i).equals("image")) {
		// do nothing in this case
	    }

	    // creation of input box for float
	    //
	    else if (types.get(i).equals("float")) {

		JTextField TextField = 
		    new JTextField(((String)subVertex.values.get(i)), 8);
		constrain(config_panel,TextField, gridbag, 3, i,
			  1, 1, 1, 0, GridBagConstraints.EAST);
		enteredData.add(TextField);
		blockType.add("float");
		TextField.setFont(newFont);
		TextField.setForeground(Color.black);
	    } 

	    // creation of input box for int
	    //
	    else if (types.get(i).equals("integer")) {

		JTextField TextField = 
		    new JTextField(((String)subVertex.values.get(i)), 8);
		constrain(config_panel,TextField, gridbag, 3, i,
			  1, 1, 1, 0, GridBagConstraints.EAST);
		enteredData.add(TextField);
		blockType.add("integer");
		TextField.setFont(newFont);
		TextField.setForeground(Color.black);
	    }

	    // !!! unexpected data type
	    //
	    else {
		System.err.println();
		System.err.println("---------------------------------------");
		System.err.println("Error - Unexpected data type in file resource.txt: " + types.get(i));
		System.err.println("---------------------------------------");
		System.exit(0);
	    }

	    // check to see if the width of a JComboBox or JTextField
	    // is wider than maxwidth and if it is, give that value to 
	    // maxwidth
	    //
    	    String type = (String)blockType.get(i);

	    if((!type.equals("Vertex") &&
		(!type.equals("image")) &&
		(!type.equals("boolean")))) {

		Dimension size = (Dimension)((JComponent)enteredData.
					     get(i)).getPreferredSize();
		int width = (int)size.getWidth();
		int height = (int)size.getHeight();
		if( width > maxwidth) {
		    maxwidth = width;
		    maxheight = height;
		}
	    }
	}

	for(int i = 0; i < blockType.size(); i++) {
	    String type = (String)blockType.get(i);
	    if((!type.equals("Vertex") &&
		(!type.equals("image")) &&
		(!type.equals("boolean")))) {
		Dimension size = new Dimension(maxwidth, maxheight);
		((JComponent)enteredData.get(i)).
		    setPreferredSize(size);
		((JComponent)enteredData.get(i)).
		    setMinimumSize(size);
	    }
	}

	// create a button panel to place all buttons on so proper spacing 
	// can be acheived
		
	JPanel button_panel = new JPanel();
	if( max_subparam > 0) {

	    // create a button panel to place all buttons on so proper spacing 
	    // can be acheived
	    //	
	    button_panel.setLayout(new GridLayout(1,4, 1, 1));
	    
	    // create the configure button and add the appropriate action handler
	    //
	    config_button = new JButton("Configure");
  	    button_panel.add(config_button);
	    config_button.addActionListener(this);
	    config_button.setActionCommand("param");
	    config_button.setFont(newFont);
	
	    // create the return button and add the appropriate action handler
	    //
	    save_button = new JButton("Save");
	    button_panel.add(save_button);
	    save_button.addActionListener(this);
	    save_button.setActionCommand("update");
	    save_button.setFont(newFont);
	
	    // create the cancel button and add to subpanel
	    //
	    cancel_button = new JButton("Cancel");
	    button_panel.add(cancel_button);
	    cancel_button.addActionListener(this);
	    cancel_button.setActionCommand("cancel");
	    cancel_button.setFont(newFont);

	    // create the help button and add to subpanel
	    //
	    help_button = new JButton("Help");
	    button_panel.add(help_button);
	    help_button.addActionListener(this);
	    help_button.setActionCommand("help");
	    help_button.setFont(newFont);
	}
	else {

	    // create a button panel to place all buttons on so proper spacing 
	    // can be acheived
	    //	
	    button_panel.setLayout(new GridLayout(1,4, 1, 1));
	    
	    // create the return button and add the appropriate action handler
	    //
	    save_button = new JButton("Save");
	    button_panel.add(save_button);
	    save_button.addActionListener(this);
	    save_button.setActionCommand("update");
	    save_button.setFont(newFont);
		
	    // create the cancel button and add to subpanel
	    //
	    cancel_button = new JButton("Cancel");
	    button_panel.add(cancel_button);
	    cancel_button.addActionListener(this);
	    cancel_button.setActionCommand("cancel");
	    cancel_button.setFont(newFont);
		
	    // create the default button and add to subpanel
	    //
	    default_button = new JButton("  Default ");
	    button_panel.add(default_button);
	    default_button.addActionListener(this);
	    default_button.setActionCommand("default");
	    default_button.setFont(newFont);
		
	    // create the help button and add to subpanel
	    //
	    help_button = new JButton("Help");
	    button_panel.add(help_button);
	    help_button.addActionListener(this);
	    help_button.setActionCommand("help");
	    help_button.setFont(newFont);		
	}

	constrain(config_panel, button_panel, gridbag, 0, labels.size()+1,
		  GridBagConstraints.REMAINDER,1,1,1,
		  GridBagConstraints.SOUTH);
    }

    // method: constrain
    //
    // arguments:
    //    JPanel container      :  panel being added to
    //    Component button      :  what is being added to the panel
    //    GridBagLayout gridbag :  gridbag layout for config panel
    //    int gridx             :  the x grid position of the constraint
    //    int gridy             :  the y grid position of the constraint
    //    int gridwidth         :  the number of gridspaces wide to constrain
    //    int gridheight        :  the number of gridspaces tall to constrain
    //    int weightx           :  the horizontal weighting of the constraint
    //    int weighty           :  the vertical weighting of the constraint
    //    int anchor            :  which side of the constraint to anchor to
    //
    // return  :  none
    //
    //  places all the proper input items onto the config panel 
    //  for configuring any transform
    // 
    public void constrain(JPanel container,Component button, 
			  GridBagLayout gridbag, int gridx,int gridy, 
			  int gridwidth, int gridheight,
			  int weightx, int weighty, int anchor){
	GridBagConstraints c = new GridBagConstraints();
	c.gridx = gridx;
	c.gridy = gridy;
	c.gridwidth = gridwidth;
	c.gridheight = gridheight;
	c.weightx = weightx;
	c.weighty = weighty;
	c.anchor = anchor;
	gridbag.setConstraints(button, c);
	container.add(button);
    }

     // method: validation
    //
    // arguments:  none
    //
    // return:  boolean 
    //
    // checks to make sure that all configuration data has been input properly
    // and if it has, make the changes to the referrign vertex 
    // 
    public boolean validation() {
	
	subparamInfo =  new Vector(5,5);

	for(int i=0; i < labelReference.size(); i++) {
	    
	    if(blockType.get(i).equals("Vertex")) {
		break;
	    }
	    
	    if(blockType.get(i).equals("enum")) {
		
		// set the vertex's value to match the newly selected one
		//
		subparamInfo.add((String)((JComboBox)enteredData.get(i)).
				     getSelectedItem());
	    }
	}

	for(int i=0; i < labelReference.size(); i++) {
	    
	    // code to use if the data is a text field
	    //
	    if (blockType.get(i).equals("text")) {
		subVertex.values.set(i,
				   ((JTextField)enteredData.get(i)).getText());
	    }

	    // code to use if the data is a vector field
	    //
	    if (blockType.get(i).equals("vector")) {
		subVertex.values.set(i,
				   ((JTextField)enteredData.get(i)).getText());
	    }
	    
	    // code to use if the data is an enumerated type
	    //
	    if(blockType.get(i).equals("enum")) {
		
		// set the vertex's value to match the newly selected one
		//
		subVertex.values.
		    set(i,(String)((JComboBox)enteredData.get(i)).
			getSelectedItem());
	    }
	    
	    // code to get information from a check box
	    //
	    if (blockType.get(i).equals("boolean")) {
		
		boolean status = ((JCheckBox)enteredData.get(i)).isSelected();
		String value = new String();
		if(status)
		    value = "true";
		else
		    value = "false";
		subVertex.values.set(i,value);
	    }

	    // code to get information from a float variable
	    //
	    if (blockType.get(i).equals("float")) {
		String text = ((JTextField)enteredData.get(i)).getText();
		try {
		    float value = Float.valueOf(text).floatValue();
		    subVertex.values.set(i, text);
		}
		catch (java.lang.NumberFormatException event) {
		    JFrame frame = new JFrame("Warning");
		    String warningMessage = new 
			String("The value entered for " + 
			       subVertex.names.get(i) + 
			       " is not a floating point number.");
		    JOptionPane.showMessageDialog(frame, warningMessage);
		    return false;
		}
	    }

	    // code to get information from a double variable
	    //
	    if (blockType.get(i).equals("double")) {
		String text = ((JTextField)enteredData.get(i)).getText();
		try {
		    double value = Double.valueOf(text).doubleValue();
		    subVertex.values.set(i, text);
		}
		catch (java.lang.NumberFormatException event) {
		    JFrame frame = new JFrame("Warning");
		    String warningMessage = new 
			String("The value entered for " + 
			       subVertex.names.get(i) + 
			       " is not a floating point number.");
		    JOptionPane.showMessageDialog(frame, warningMessage);
		    return false;
		}
	    }
	    
	    // code to get information from an unsigned integer variable
	    //
	    if (blockType.get(i).equals("unsigned-integer")) {
		String text = ((JTextField)enteredData.get(i)).getText();
		try {
		    int value = Integer.valueOf(text).intValue();
		    if (value >= 0) {
			subVertex.values.set(i, text);
		    } else {
			JFrame frame = new JFrame("Warning");
			String warningMessage = new 
			    String("The value entered for " + 
				   subVertex.names.get(i) + 
				   " is not an unsigned integer.");
			JOptionPane.showMessageDialog(frame,warningMessage);
			return false;
		    }
		}
		catch (java.lang.NumberFormatException event) {
		    JFrame frame = new JFrame("Warning");
		    String warningMessage = new 
			String("The value entered for " + 
			       subVertex.names.get(i) + 
			       " is not an unsigned integer.");
		    JOptionPane.showMessageDialog(frame, warningMessage);
		    return false;
		}
	    }

	    // code to get information from an integer variable
	    //
	    if (blockType.get(i).equals("integer")) {
		String text = ((JTextField)enteredData.get(i)).getText();
		try {
		    int value = Integer.valueOf(text).intValue();
		    subVertex.values. set(i, text);
		}
		catch (java.lang.NumberFormatException event) {
		    JFrame frame = new JFrame("Warning");
		    String warningMessage = new 
			String("The value entered for " + 
			       subVertex.names.get(i) + 
			       " is not an integer.");
		    JOptionPane.showMessageDialog(frame, warningMessage);
		    return false;
		}
	    }
	}
	return true;
    }
    
    // method: actionPerformed
    //
    // arguments:
    //    ActionEvent e: event that was fired
    //
    // return   : none
    //
    // listens for actions taking place on the components
    //
    public void actionPerformed(ActionEvent e)
    {
	if(e.getActionCommand().equals("update")){
	   	    
	    // validate the inputs and if they are all valid, 
	    // dispose of the box
	    //	    
	    if(validation()) {		
		this.dispose();		
		parent.setModal(true);
	    }
	}
	
	if(e.getActionCommand().equals("cancel")){

	    // dispose of the changes and revert to the old ways
	    //
	    this.dispose();
	    parent.setModal(true);
	}
	
	if(e.getActionCommand().equals("default")){
	    defaultSettings();
	}

	if(e.getActionCommand().equals("revert")){
	    revertSettings();
	}	
	
	if(e.getActionCommand().equals("help")){
		
	    // display a help message: "under construction"
	    //
	    JFrame frame = new JFrame("Help");
	    JOptionPane.showMessageDialog(frame, 
					  "The help message is under construction");
	}

	// create config window if dealing with a nested class for config
	//
	if(e.getActionCommand().equals("class")){
	    Vertex temp = (Vertex)e.getSource();
	    if(isModal()) {
		setModal(false);
		SubConfigBox class_config_panel = 
		    new SubConfigBox(this, data, temp, cfgVertexFocus);
		class_config_panel.pack();
		class_config_panel.setVisible(true);
	    }
	}

	// create config window if dealing with a nested param for config
	//
	if(e.getActionCommand().equals("param")){

	    // if the block we've configured is a subparam
	    //
	    if(validation()) {	

		//Vertex temp = (Vertex)e.getSource();

		Vertex temp = (Vertex)subVertex.subparam.get(subVertex.subparam.size()-1);
		if(isModal()) {
		    setModal(false);
		    SubConfigBoxParam class_config_panel = 
			new SubConfigBoxParam(this, data, temp, subVertex, subparamInfo);
		    class_config_panel.pack();
		    class_config_panel.setVisible(true);
		}
	    }
	}

    }

    // method: defaultSettings
    //
    // arguments:  none
    //
    // return:  none
    //
    //  resets all configuartion items to the default values as given in 
    //  the gui configuration file
    //
    public void defaultSettings() {
	
	// get the name of the class we're working on
	//
	String association = subVertex.association;

	// get the beginning and end of my search for default data
	//
	int begin = data.association.indexOf(association);
	int end = data.association.lastIndexOf(association);
	
	// change all values back to the default
	//
	for(int i= begin; i <= end; i++) {
	    
	    // set enum type back to default value
	    //
	    if(data.type.get(i).equals("enum")) {
		Vector enum_values = (Vector)data.values.get(i);
		
		// actually change the enum to the default setting
		//
		
		JComboBox select = (JComboBox)enteredData.get(i - begin);
		select.setSelectedItem((String)enum_values.get(0));
	    }
	    
	    // make the check box revert to its previous state
	    //
	    else if (data.type.get(i).equals("boolean")){
		// get the value for the check box
		//
		String value = (String)(data.values.get(i));
	
		boolean value2;
		if (value.equals("true"))
		    value2 = true;
		else
		    value2 = false;

		// actually make the change to the check box
		//

		JCheckBox checkBox = (JCheckBox)enteredData.get(i - begin); 
		checkBox.setSelected(value2);
	    }

	    // do nothing if the type is image
	    //
	    else if (data.type.get(i).equals("image")) {
	    }
	    
	    // set all text field back to defaults
	    //
	    else {

		JTextField text_box = (JTextField)enteredData.get(i - begin);
		text_box.setText((String)data.values.get(i));	
	    }
	}
    }

    // method: revertSettings
    //
    // arguments:  none
    //
    // return:  none
    //
    //  resets all configuartion items to the values that were stored in the 
    //  referring vertex before the configuration began 
    //    
    public void revertSettings() {
		
	// run through these and add labels and input fields as appropriate
	//
	for(int i=0; i < subVertex.values.size(); i++) {
	    
	    // make the selected option revert to its previous state
	    //
	    if(subVertex.types.get(i).equals("enum")){
		
		JComboBox select = (JComboBox)enteredData.get(i);
		select.setSelectedItem(subVertex.values.get(i));
	    }

	    // make the check box revert to its previous state
	    //
	    else if (subVertex.types.get(i).equals("boolean")){
		
		// get the value for the check box
		//
		String value = (String)(subVertex.values.get(i));
		JCheckBox checkBox = (JCheckBox)enteredData.get(i); 

		boolean value2;
		if (value.equals("true"))
		    value2 = true;
		else
		    value2 = false;
		checkBox.setSelected(value2);
	    }

	    // do nothing if the type is image
	    //
	    else if (subVertex.types.get(i).equals("image")) {
	    }
	    
	    // take care of anything of type text
	    //
	    else if (subVertex.types.get(i).equals("text")) {
		
		JTextField text_box = (JTextField)enteredData.get(i);
		String text = (String)subVertex.values.get(i);
		text_box.setText(text);
		
	    }
	    
	    // creation of input box for unsigned int
	    //
	    else if (subVertex.types.get(i).equals("unsigned-integer")) {
		
		JTextField text_box = (JTextField)enteredData.get(i);
		String text = (String)subVertex.values.get(i);
		text_box.setText(text);	    
	    }

	    // creation of input box for float
	    //
	    else if (subVertex.types.get(i).equals("float")) {
		
		JTextField text_box = (JTextField)enteredData.get(i);
		String text = (String)subVertex.values.get(i);
		text_box.setText(text);
	    }

	    // creation of input box for double
	    //
	    else if (subVertex.types.get(i).equals("double")) {
		
		JTextField text_box = (JTextField)enteredData.get(i);
		String text = (String)subVertex.values.get(i);
		text_box.setText(text);
	    }

	    // creation of input box for int
	    //
	    else if (subVertex.types.get(i).equals("integer")) {

		JTextField text_box = (JTextField)enteredData.get(i);
		String text = (String)subVertex.values.get(i);
		text_box.setText(text);	    
	    }
	}
    }
}

//
// end of file
















































