// file: Vertex.java
//

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

/**
 * class that handles the vertices as buttons
 */
public class Vertex extends JButton implements Serializable, Constants {

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

    // the relevant information about the vertex
    //
    public String vertexName = null;
    public String iconName = null;
    public int vertexType = NONE;
    public int vertexImpl = NONE;
    public ImageIcon vertexIcon = null;
    public Point vertexLocation = null;
    
    // the parents and children of the vertex
    //
    public Vector<Vertex> vertexParents = null;
    public Vector<Vertex> vertexChildren = null;

    // the dimensions of the vertex
    //
    public int vertexWidth = -1;
    public int vertexHeight = -1;

    // container related data types
    //
    public Vector<Vertex> vertexContainer = null;

    // parameters used by the algorithm vertex
    //
    public Vector<Object> values =new Vector<Object>(5,5);
    public Vector<Object> names = new Vector<Object>(5,5);
    public Vector<Object> types = new Vector<Object>(5,5);
    public String association = null;
    public Vector<Object> subclass =new Vector<Object>(5,5); 
    public int max_subclass = 0;
    public Vector<Object> subparam =new Vector<Object>(5,5); 
    public int max_subparam = 0;
    public Vector<Object> identify = new Vector<Object>(5,5);

    public boolean actionAdded = false;
    public static boolean isAdd = false;

    // ---------------------------------------------------
    //
    // class constructors
    //
    // ---------------------------------------------------

    /**
     * default class constructor
     */
    public Vertex() {
	
	// invoke the parent constructor
	//
	super();

	// set the font of the vertex
	//
	setFont(newFont);

	// disable the focus from being painted
	//
	setFocusPainted(false);

	// disable the content area from being painted
	//
	setContentAreaFilled(false); 

	// set the horizontal text position
	//
	setHorizontalTextPosition(SwingConstants.CENTER);

	// initialize class vector data types
	//
	vertexParents = new Vector<Vertex>(10, 10);
	vertexChildren = new Vector<Vertex>(10, 10);

	// set the default dimensions of the vertex
	//
	setBackground(Color.white);
	setSize(VERTEX_WIDTH, VERTEX_HEIGHT);
	setPreferredSize(new Dimension(VERTEX_WIDTH, VERTEX_HEIGHT));
	setMinimumSize(new Dimension(VERTEX_WIDTH, VERTEX_HEIGHT));
	setVertexWidth(VERTEX_WIDTH);
	setVertexHeight(VERTEX_HEIGHT);
    }

    /**
     * class constructor with name
     *
     * @param name String name of vertex
     */
    public Vertex(String name) {
	
	// invoke the parent constructor
	//
	super(name);	
	//setBorder(LineBorder.createGrayLineBorder());
	//setBorder(new EtchedBorder());
	//setBorderPainted(true);
	// set the font of the vertex
	//
	setFont(newFont);

	// disable the focus from being painted
	//
	//setFocusPainted(true);

	// disable the content area from being painted
	//
	//setContentAreaFilled(true); 

	// set the horizontal text position
	//
	//setHorizontalTextPosition(SwingConstants.CENTER);	
    }

    /**
     * class constructor with name, type, and impl
     *
     * @param name vertex name
     * @param type vertex type
     * @param impl vertex implementation type
     */
    public Vertex(String name, int type, int impl) {

	// invoke the parent constructor
	//
	super(name);

	// set the format and name of the vertex
	//
	vertexName = name;
	vertexType = type;
	vertexImpl = impl;

	// set the name of the vertex
	//
	if (name.length() > 3) {
	    setText(name.substring(0, 3));
	}
	else {
	    setText(name);
	}

	// set the font of the vertex
	//
	setFont(newFont);

	// disable the focus from being painted
	//
	setFocusPainted(false);

	// disable the content area from being painted
	//
	setContentAreaFilled(false); 

	// set the horizontal text position
	//
	setHorizontalTextPosition(SwingConstants.CENTER);

	// initialize class vector data types
	//
	switch (vertexType) {

	case CONTAINER:
	    vertexParents = new Vector<Vertex>(10, 10);
	    vertexChildren = new Vector<Vertex>(10, 10);
	    vertexContainer = new Vector<Vertex>(50, 10);
	    break;	    
	default:
	    vertexParents = new Vector<Vertex>(10, 10);
	    vertexChildren = new Vector<Vertex>(10, 10);
	    break;
	}

	// set the default dimensions of the vertex
	//
	switch (vertexType) {

	case ALGORITHM:
	    setBackground(Color.white);
	    setSize(ALGORITHM_WIDTH, ALGORITHM_HEIGHT);
	    setPreferredSize(new Dimension(ALGORITHM_WIDTH, ALGORITHM_HEIGHT));
	    setMinimumSize(new Dimension(ALGORITHM_WIDTH, ALGORITHM_HEIGHT));
	    setVertexWidth(ALGORITHM_WIDTH);
	    setVertexHeight(ALGORITHM_HEIGHT);
	    break;
	case CONTAINER:
	    setBackground(Color.white);
	    setSize(CONT_WIDTH, CONT_HEIGHT);
	    setPreferredSize(new Dimension(CONT_WIDTH, CONT_HEIGHT));
	    setMinimumSize(new Dimension(CONT_WIDTH, CONT_HEIGHT));
	    setVertexWidth(CONT_WIDTH);
	    setVertexHeight(CONT_HEIGHT);
	    break;	    
	default:
	    setBackground(Color.cyan);
	    setSize(VERTEX_WIDTH, VERTEX_HEIGHT);
	    setPreferredSize(new Dimension(VERTEX_WIDTH, VERTEX_HEIGHT));
	    setMinimumSize(new Dimension(VERTEX_WIDTH, VERTEX_HEIGHT));
	    setVertexWidth(VERTEX_WIDTH);
	    setVertexHeight(VERTEX_HEIGHT);
	    break;
	}
    }

    /**
     * class constructor with icon and type
     *
     * @param icon  vertex icon
     * @param type  vertex type
     */
    public Vertex(ImageIcon icon, int type) {

	// invoke the parent constructor
	//
	super(icon);

	// set the format for the vertex
	//
	vertexName = new String("Algorithm");
	vertexIcon = icon;
	vertexType = type;
	vertexImpl = NONE;

	// set the font of the vertex
	//
	setFont(newFont);

	// disable the focus from being painted
	//
	setFocusPainted(false);

	// disable the content area from being painted
	//
	setContentAreaFilled(false); 

	// set the horizontal text position
	//
	setHorizontalTextPosition(SwingConstants.CENTER);

	// initialize class vector data types
	//
	switch (vertexType) {

	case CONTAINER:
	    vertexParents = new Vector<Vertex>(10, 10);
	    vertexChildren = new Vector<Vertex>(10, 10);
	    vertexContainer = new Vector<Vertex>(50, 10);
	    break;	    
	default:
	    vertexParents = new Vector<Vertex>(10, 10);
	    vertexChildren = new Vector<Vertex>(10, 10);
	    break;
	}

	// set the default dimensions of the vertex
	//
	switch (vertexType) {

	case ALGORITHM:
	    setBackground(Color.white);
	    setSize(ALGORITHM_WIDTH, ALGORITHM_HEIGHT);
	    setPreferredSize(new Dimension(ALGORITHM_WIDTH, ALGORITHM_HEIGHT));
	    setMinimumSize(new Dimension(ALGORITHM_WIDTH, ALGORITHM_HEIGHT));
	    setVertexWidth(ALGORITHM_WIDTH);
	    setVertexHeight(ALGORITHM_HEIGHT);
	    break;
	case CONTAINER:
	    setBackground(Color.white);
	    setSize(CONT_WIDTH, CONT_HEIGHT);
	    setPreferredSize(new Dimension(CONT_WIDTH, CONT_HEIGHT));
	    setMinimumSize(new Dimension(CONT_WIDTH, CONT_HEIGHT));
	    setVertexWidth(CONT_WIDTH);
	    setVertexHeight(CONT_HEIGHT);
	    break;	    
	default:
	    setBackground(Color.cyan);
	    setSize(VERTEX_WIDTH, VERTEX_HEIGHT);
	    setPreferredSize(new Dimension(VERTEX_WIDTH, VERTEX_HEIGHT));
	    setMinimumSize(new Dimension(VERTEX_WIDTH, VERTEX_HEIGHT));
	    setVertexWidth(VERTEX_WIDTH);
	    setVertexHeight(VERTEX_HEIGHT);
	    break;
	}
    }

    /**
     * class constructor with icon, name, type, and impl
     *
     * @param icon vertex icon
     * @param name vertex name
     * @param type vertex type
     * @param impl vertex implementation
     */
    public Vertex(ImageIcon icon, String name, int type, int impl) {

	// invoke the parent constructor
	//
	super(icon);

	// set the format for the vertex
	//
	vertexName = name;
	vertexIcon = icon;
	vertexType = type;
	vertexImpl = impl;

	// set the vertex text
	//
	if (name.length() > 3) {
	    setText(name.substring(0, 3));
	}
	else {
	    setText(name);
	}
	
	if(type == GENERATOR_DATA) {
	    setText("");
	} 
	
	// set the font of the vertex
	//
	setFont(newFont);

	// disable the focus from being painted
	//
	setFocusPainted(false);

	// disable the content area from being painted
	//
	setContentAreaFilled(false); 

	// set the horizontal text position
	//
	setHorizontalTextPosition(SwingConstants.CENTER);

	// initialize class vector data types
	//
	switch (vertexType) {

	case CONTAINER:
	    vertexParents = new Vector<Vertex>(10, 10);
	    vertexChildren = new Vector<Vertex>(10, 10);
	    vertexContainer = new Vector<Vertex>(50, 10);
	    break;	    
	default:
	    vertexParents = new Vector<Vertex>(10, 10);
	    vertexChildren = new Vector<Vertex>(10, 10);
	    break;
	}

	// set the default dimensions of the vertex
	//
	switch (vertexType) {

	case ALGORITHM:
	    setBackground(Color.white);
	    setSize(ALGORITHM_WIDTH, ALGORITHM_HEIGHT);
	    setPreferredSize(new Dimension(ALGORITHM_WIDTH, ALGORITHM_HEIGHT));
	    setMinimumSize(new Dimension(ALGORITHM_WIDTH, ALGORITHM_HEIGHT));
	    setVertexWidth(ALGORITHM_WIDTH);
	    setVertexHeight(ALGORITHM_HEIGHT);
	    break;
	case CONTAINER:
	    setBackground(Color.white);
	    setSize(CONT_WIDTH, CONT_HEIGHT);
	    setPreferredSize(new Dimension(CONT_WIDTH, CONT_HEIGHT));
	    setMinimumSize(new Dimension(CONT_WIDTH, CONT_HEIGHT));
	    setVertexWidth(CONT_WIDTH);
	    setVertexHeight(CONT_HEIGHT);
	    break;	    
	default:
	    setBackground(Color.white);
	    setSize(VERTEX_WIDTH, VERTEX_HEIGHT);
	    setPreferredSize(new Dimension(VERTEX_WIDTH, VERTEX_HEIGHT));
	    setMinimumSize(new Dimension(VERTEX_WIDTH, VERTEX_HEIGHT));
	    setVertexWidth(VERTEX_WIDTH);
	    setVertexHeight(VERTEX_HEIGHT);
	    break;
	}
    }

    /**
     * copies a vertex
     *
     * @param copy Vertex to be copied
     */
    public Vertex(Vertex copy) {
		
	super();

	// set the vertex parameters
	//
	vertexType = copy.vertexType;
	vertexImpl = copy.vertexImpl;
	if (copy.vertexName != null) {
	    vertexName = new String(copy.vertexName);	    
	    if (vertexName.length() > 4) {
		setText(vertexName.substring(0, 4));
	    }
	    else {
		setText(vertexName);
	    }
	    if(vertexName.equals("Generator")) {
		setText("");      
	    }

	    if(vertexName.equals("FilterBank")) {
		setText("FilB");      
	    }
	    setVertexName(vertexName);

	    if(copy.iconName != null) {
		 iconName = new String(copy.iconName);
		 setText(iconName);
	    }
	}
	if ((copy.vertexIcon != null)&&(copy.vertexIcon.getImage() != null)) {
	    vertexIcon = new ImageIcon(copy.vertexIcon.getImage());
	    setIcon(vertexIcon);
	}

	// set the vertex arcs parameters
	//
	if (copy.vertexLocation != null) {
	    vertexLocation = new Point(copy.vertexLocation);
	}

	// set the vertex parents, children and container elements
	//
	if (copy.vertexParents != null) {
	    vertexParents = new Vector<Vertex>(copy.vertexParents);
	}
	if (copy.vertexChildren != null) {
	    vertexChildren = new Vector<Vertex>(copy.vertexChildren);
	}
	if (copy.vertexContainer != null) {
	    vertexContainer = new Vector<Vertex>(copy.vertexContainer);
	}

	// set the vertex vertex dimensions
	//
	vertexWidth = copy.vertexWidth;
	vertexHeight = copy.vertexHeight;

	// set the algorithm related parameters
	//
	if (copy.values != null) {
	    values = new Vector<Object>(copy.values);
	}
	if (copy.names != null) {
	    names = new Vector<Object>(copy.names);
	}
	if (copy.types != null) {
	    types = new Vector<Object>(copy.types);
	}
	if ( copy.association != null) {
	    association = new String(copy.association);
	}
	if (copy.subclass != null) {
	    subclass = new Vector<Object>(copy.subclass);
	}
	max_subclass = copy.max_subclass;
	if (copy.subparam != null) {
	    subparam = new Vector<Object>(copy.subparam);
	}
	max_subparam = copy.max_subparam;
	actionAdded = copy.actionAdded;

	// set the font of the vertex
	//
	setFont(newFont);

	// disable the focus from being painted
	//
	setFocusPainted(false);

	// disable the content area from being painted
	//
	setContentAreaFilled(false); 

	// set the horizontal text position
	//
	setHorizontalTextPosition(SwingConstants.CENTER);

	// set the default dimensions of the vertex
	//
	switch (vertexType) {

	case ALGORITHM:
	    setBackground(Color.white);
	    setContentAreaFilled(false); 
	    setHorizontalTextPosition(SwingConstants.CENTER);
	    setSize(ALGORITHM_WIDTH, ALGORITHM_HEIGHT);
	    setPreferredSize(new Dimension(ALGORITHM_WIDTH, ALGORITHM_HEIGHT));
	    setMinimumSize(new Dimension(ALGORITHM_WIDTH, ALGORITHM_HEIGHT));
	    setVertexWidth(ALGORITHM_WIDTH);
	    setVertexHeight(ALGORITHM_HEIGHT);
	    break;
	case CONTAINER:
	    setBackground(Color.white);
	    setContentAreaFilled(false);
	    setHorizontalTextPosition(SwingConstants.CENTER);
	    setSize(CONT_WIDTH, CONT_HEIGHT);
	    setPreferredSize(new Dimension(CONT_WIDTH, CONT_HEIGHT));
	    setMinimumSize(new Dimension(CONT_WIDTH, CONT_HEIGHT));
	    setVertexWidth(CONT_WIDTH);
	    setVertexHeight(CONT_HEIGHT);
	    break;	    
	default:
	    setBackground(Color.cyan);
	    setContentAreaFilled(false);
	    setHorizontalTextPosition(SwingConstants.CENTER);
	    setSize(VERTEX_WIDTH, VERTEX_HEIGHT);
	    setPreferredSize(new Dimension(VERTEX_WIDTH, VERTEX_HEIGHT));
	    setMinimumSize(new Dimension(VERTEX_WIDTH, VERTEX_HEIGHT));
	    setVertexWidth(VERTEX_WIDTH);
	    setVertexHeight(VERTEX_HEIGHT);
	    break;
	}
    }

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

    /**
     * clears all lists associated this the vertex
     */
    public void clear() {
	if (vertexParents != null) {
	    vertexParents.removeAllElements();
	}
	if (vertexChildren != null) {
	    vertexChildren.removeAllElements();
	}
	if (vertexContainer != null) {
	    vertexContainer.removeAllElements();
	}
    }

    /**
     * method changes the order of the connectors for the connector vertex
     *
     * @param destination destination connector
     * @param src  the parent vertex that will be set to the destination
     */
    public void changeConnectors(int dest, Vertex src) {

	// declare local variables
	//
	int stop = 0;
	Vertex vertex = src;

	// reduce to the source and destination to zero based values
	//
	stop = dest - 1;	

	// determine if the source is valid
	//
	if (stop >= vertexParents.size()) {
	    return;
	}
	
	// remove the element at the start location
	//
	vertexParents.set(stop, vertex);
    }

    /**
     * gets the vertex name
     *
     * @return vertex name
     */
    public String getVertexName() {
	return vertexName;
    }

    /**
     * sets the vertex name
     *
     * @param name name to set
     *
     * @return true
     */
    public boolean setVertexName(String name) {
	vertexName = name;
	return true;
    }

    /**
     * gets the vertex icon name
     *
     * @return icons name
     */
    public String getIconName() {
	return iconName;
    }

    /**
     * sets the icon name
     *
     * @param name icon name to be set
     * @return true
     */
    public boolean setIconName(String name) {
	iconName = name;
	return true;
    }

    /**
     * gets the class icon
     *
     * @return class icon
     */
    public ImageIcon getVertexIcon() {
	return vertexIcon;
    }

    /**
     * sets the class icon
     *
     * @param icon class icon
     * @return true
     */
    public boolean setVertexIcon(ImageIcon icon) {
	vertexIcon = icon;
	return true;
    }

    /**
     * get the number of arcs coming into the vertex
     *
     * @return number of incoming arcs
     */
    public int getInDegree() {
	return vertexParents.size();
    }

    /**
     * get the number of arcs coming out of the vertex
     *
     * @return number of outgoing arcs
     */
    public int getOutDegree() {
	return vertexChildren.size();
    }

    /**
     * gets the vertex type
     *
     * @return vertex type
     */
    public int getVertexType() {
	return vertexType;
    }

    /**
     * sets the vertex type
     *
     * @param type vertex type
     * @return true
     */
    public boolean setType(int type) {
	vertexType = type;
	return true;
    }

    /**
     * sets the vertex type
     *
     * @param type vertex type
     * @return true
     */
    public boolean setType(String type) {        
	return true;
    }

    /**
     * gets the vertex type
     *
     * @return method status
     */ 
    public String getType() {

	// return the vertex type
	//
	if (vertexType == SAMPLED_DATA) {
	    return SAMPLED_DATA_STR;
	}
	else if (vertexType == FEATURE_DATA) {
	    return FEATURE_DATA_STR;
	}
	else if (vertexType == GENERATOR_DATA) {
	    return GENERATOR_DATA_STR;
	}
	else if (vertexType == ALGORITHM) {
	    return ALGORITHM_STR;
	}
	else if (vertexType == CONTAINER) {
	    return CONTAINER_STR;
	}
	else if (vertexType == INPUT) {
	    return INPUT_STR;
	}
	else if (vertexType == OUTPUT) {
	    return OUTPUT_STR;
	}
	else if (vertexType == CUSTOM) {
	    return CUSTOM_STR;
	}
	else {
	    return NONE_STR;
	}
    }

    /**
     * gets the class implementation
     *
     * @return class implementation
     */
    public int getVertexImpl() {
	return vertexImpl;
    }

    /**
     * sets the class implementation
     *
     * @param impl class implementation
     * @return true
     */
    public boolean setVertexImpl(int impl) {
	vertexImpl = impl;
	return true;
    }

    /**
     * checks if the input is a child
     *
     * @param child child we intend to find
     * @return method status
     */ 
    public boolean containsChild(Vertex child) {
	return vertexChildren.contains(child);
    }

    /**
     * checks if the input is a parent
     *
     * @param parent parent we intend to find
     * @return method status
     */
    public boolean containsParent(Vertex parent) {
	return vertexParents.contains(parent);
    }

    /**
     * inserts a vertex into the container
     *
     * @param vertex vertex to be inserted
     */
    public void insertContainerElement(Vertex vertex) {
	
	// add the vertex to the required data structures
	//
	vertexContainer.addElement(vertex);
    }

    /**
     * gets the location of the vertex
     *
     * @return point of vertex location
     */
    public Point getVertexLocation() {

	// declare local variables
	//
	Point point = null;

	// get the position of the bean
	//
	point = this.getLocation(point);

	// retrieve the location of the bean
	//
	double xloc = point.getX();
	double yloc = point.getY();

	// return the location of the bean
	//
	return (new Point((int)xloc, (int)yloc));
    }

    /**
     * method returns the name of the bean
     *
     * @param xloc x-coordinate of the bean
     * @param yloc y-coordinate of the bean
     */
    public void updateLocation(int xloc, int yloc) {

	// check to make sure that the memory has been allocated
	//
	if (vertexLocation == null) {
	    vertexLocation = new Point();
	}

	// update the location of the bean
	//
	vertexLocation.x = xloc;
	vertexLocation.y = yloc;
    }

    /**
     * gets the width of the vertex
     *
     * @return vertex width
     */
    public int getVertexWidth() {
	return vertexWidth;
    }

    /**
     * gets the height of the vertex
     *
     * @return vertex height
     */
    public int getVertexHeight() {
	return vertexHeight;
    }

    /**
     * sets the height of the vertex
     *
     * @param height new height of the vertex
     * @return true
     */ 
    public boolean setVertexHeight(int height) {
	vertexHeight = height;
	return true;
    }

    /**
     * sets the width of the vertex
     *
     * @param width new width of the vertex
     * @return true
     */ 
    public boolean setVertexWidth(int width) {
	vertexWidth = width;
	return true;
    }

    /**
     * gets the list of parents associated with the vertex
     *
     * @return list of parents
     */
    public Vector<Vertex> getParents() {
	return vertexParents;
    }

    /**
     * adds the parent to the list
     *
     * @param parent new parent to be added
     * @return true if vertex is not the parent already
     */
    public boolean addParent(Vertex parent) {	
	if (!vertexParents.contains(parent)) {
	    vertexParents.addElement(parent);
	    return true;
	}
	return false;
    }

    /**
     * adds the parent to the list
     *
     * @param parent new parent to be added
     * @param index  index at which the parent is to be added
     * @return true vertex is not the parent already
     */
    public boolean addParent(Vertex parent, int index) {	
	if (!vertexParents.contains(parent)) {
	    if (index >= vertexParents.size()) {
		vertexParents.setSize(index + 1);
	    }
	    vertexParents.setElementAt(parent, index);
	    return true;
	}
	return false;
    }

    /**
     * removes the parent from the list
     *
     * @param parent  parent to be removed
     * return true if removed
     */
  
    public boolean removeParent(Vertex parent) {
	return vertexParents.removeElement(parent);
    }
    /**
     * gets the list of children associated with the vertex
     *
     * @return list of children
     */
    public Vector<Vertex> getChildren() {
	return vertexChildren;
    }

    /**
     * adds the child to the list
     *
     * @param child new child to be added
     * @return true if vertex is not the child already
     */
    public boolean addChild(Vertex child) {
	if (!vertexChildren.contains(child)) {
	    vertexChildren.addElement(child);
	    return true;
	}
	return false;
    }

    /**
     * adds the child to the list
     *
     * @param child new child to be added
     * @param index index at which the child is to be added
     *
     * @return true if vertex is not the child already
     */
    public boolean addChild(Vertex child, int index) {
	if (!vertexChildren.contains(child)) {
	    if (index >= vertexChildren.size()) {
		vertexChildren.setSize(index + 1);
	    }
	    vertexChildren.setElementAt(child, index);
	    return true;
	}
	return false;
    }

    // method: removeChild
    //
    // arguments:
    //   Vertex child: (input) child to be removed
    // returns: method status
    //
    // removes the child from the list
    // 
    public boolean removeChild(Vertex child) {
	return vertexChildren.removeElement(child);
    }

    // method: updateVertexDimensions
    //
    // arguments: none
    // returns  : none
    //
    // method resets and revalidates the vertex dimension
    //
    public void updateVertexDimensions() {
	
	// declare local variables
	//
	int newWidth = 0;
	int newHeight = 0;

	// check if the parent vector has been initialized
	//
	if (vertexParents == null) {
	    return;
	}

	// determine the width of the vertex
	//
	if (vertexParents.size() == 0) {
	    newWidth =  this.vertexWidth;
	} else {
	    newWidth =  (vertexParents.size() * this.vertexWidth);
	}

	// determine the height of the vertex
	//
	newHeight = this.getVertexHeight();

	// set the new vertex dimensions
	//
	this.setSize(new Dimension(newWidth, newHeight));
	this.setMinimumSize(new Dimension(newWidth, newHeight));
	this.setPreferredSize(new Dimension(newWidth, newHeight));
    }

    /**
     * initializes the configuration parameters of the algorithm vertex
     *
     * @param n vector of algorithm names
     * @param v vector of algorithm values
     * @param t vector of algorithm data types
     * @param s algorithm immage association
     * @param d algorithm data object
     */
    public void initializeConfig(Vector<Object> n, Vector<Object> v, Vector<Object> t, String a, Data d) {
	

	// initialize data members
	//
	names = n;
	types = t;
	association = a;
	Data data = d;

	values = new Vector<Object>(5,5);
	subclass = new Vector<Object>(2,1);

	for(int i=0; i < v.size(); i++) {

	    // if enumerated type, get the first value
	    //	
	    if(types.get(i).equals(ALGORITHM_ENUM)){

		//Vector enum_values = (Vector)v.get(i);
		//values.add(enum_values.get(0));

		values.add(v.get(i));
	    }

	    // add a default subclass with basic parameters here to begin with
	    // this still needs to be worked out properly
	    //
	    else if (types.get(i).equals(ALGORITHM_CLASS)) {
		values.add(v.get(i));
		max_subclass++;
		
		String image_name = null;
		String image_association= null;
		
		// tells the program which ALGORITHM 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(ALGORITHM_ICON_SMALL)) {
			    // 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 = ALGORITHM_DEFAULT;
		}
		else {
		    image_name = ALGORITHM_DEFAULT;
		}

		if(image_association.equals("FourierTransform"))
		    image_name = GUI_PATH +"/lib/images/isip_transform_builder/icons/fourier_01.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 ALGORITHM we're looking at and saved 
		// into these three vectors for use in a bit
		//
		Vector<Object> labels2 = new Vector<Object>(5,5);
		Vector<Object> types2 = new Vector<Object>(5,5);
		Vector<Object> values2 = new Vector<Object>(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 subclass button to the vector
		//
		subclass.add(button);
	
		// attach an action listener to the button
		//
		button.setActionCommand(ALGORITHM_CLASS);
	    }

	    // add sub parameters here to begin with
	    // this still needs to be worked out properly
	    //
	    else if (types.get(i).equals(ALGORITHM_PARAM)) {
		values.add(v.get(i));
		max_subparam++;
		
		String image_name = null;
		String image_association= null;
		
		// tells the program which ALGORITHM 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(ALGORITHM_ICON_SMALL)) {
			    // 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 = ALGORITHM_DEFAULT;
		}
		else {
		    image_name = ALGORITHM_DEFAULT;
		}
		
		if(image_association.equals("FourierTransform"))
		    image_name = GUI_PATH +"/lib/images/isip_transform_builder/icons/fourier_01.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);
		button.association = image_association;

		// to simplify the creation, the data vectors will be trimmed 
		// to only include the ALGORITHM we're looking at and saved 
		// into these three vectors for use in a bit
		//
		Vector<Object> labels2 = new Vector<Object>(5,5);
		Vector<Object> types2 = new Vector<Object>(5,5);
		Vector<Object> values2 = new Vector<Object>(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 subclass button to the vector
		//
		subparam.add(button);
		
		// attach an action listener to the button
		//
		button.setActionCommand(ALGORITHM_PARAM);
	    }

	    // do nothing if the type is image
	    //
	    else if (types.get(i).equals(ALGORITHM_IMAGE)) {
		values.add(v.get(i));
	    }

	    // If there is only one value given, set the default as the value
	    //
	    else {
		
		// add the defaults to the values vector
		//
		values.add(v.get(i));
	    }    
	}
	
    }

    /**
     * initializes the configuration parameters of the algorithm vertex
     *
     * @param n vector of algorithm names
     * @param v vector of algorithm values
     * @param t vector of algorithm data types
     * @param s algorithm immage association
     * @param d algorithm data object
     */
    public void initializeConfigGen(Vector<Object> n, Vector<Object> v, Vector<Object> t, String a, Data d) {


	// initialize data members
	//
	names = n;
	types = t;
	association = a;
	Data data = d;

	values = new Vector<Object>(5,5);
	//subparam = new Vector<Object>(2,1);

	for(int i=0; i < v.size(); i++) {

	    // if enumerated type, get the first value
	    //	
	    if(types.get(i).equals(ALGORITHM_ENUM)){

		//Vector<Object> enum_values = (Vector<Object>)v.get(i);

		Vector<Object> enum_values = new Vector<Object>();
		enum_values.add(v.get(i));
		values.add(enum_values.get(0));
	    }

	    // add a default object with basic parameters here to begin with
	    // this still needs to be worked out properly
	    //
	    else if (types.get(i).equals(ALGORITHM_PARAM)) {
		values.add(v.get(i));
		max_subparam++;
		
		String image_name = null;
		String image_association= null;
		
		// tells the program which ALGORITHM 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(ALGORITHM_ICON_SMALL)) {
			    // 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 = ALGORITHM_DEFAULT;
		}
		else {
		    image_name = ALGORITHM_DEFAULT;
		}
		
		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
		//
		Vertex button = new Vertex(icon, ALGORITHM);
		button.association = image_association;
		
		// to simplify the creation, the data vectors will be trimmed 
		// to only include the ALGORITHM we're looking at and saved 
		// into these three vectors for use in a bit
		//
		Vector<Object> labels2 = new Vector<Object>(5,5);
		Vector<Object> types2 = new Vector<Object>(5,5);
		Vector<Object> values2 = new Vector<Object>(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 subclass button to the vector
		//
		subparam.add(button);
		
		// attach an action listener to the button
		//
		//xbutton.setActionCommand(ALGORITHM_CLASS);
		button.setActionCommand("param");
		//button.addActionListener(digraph);
	    }

	    // do nothing if the type is image
	    //
	    else if (types.get(i).equals(ALGORITHM_IMAGE)) {
		values.add(v.get(i));
	    }

	    // If there is only one value given, set the default as the value
	    //
	    else {
		
		// add the defaults to the values vector
		//
		values.add(v.get(i));
	    }    
	}


    }

    // ---------------------------------------------------
    //
    // class required methods
    //
    // ---------------------------------------------------

    // method: paintComponent
    //
    // arguments:
    //   Graphics g: (input) graphics object
    //
    // return: none
    //
    protected void paintComponent(Graphics g) {

	// set the background color of the vertex
	//
	switch (vertexType) {

	case ALGORITHM:
	    break;
	case CONTAINER:
	    break;
	default:
	    break;
	}

	// this call will paint the label and the focus
	//
	super.paintComponent(g); 
    }

    // method: paintBorder
    //
    // arguments:
    //    Graphics g: (input) graphics object
    //
    // return: none
    //
    protected void paintBorder(Graphics g) { 
	// not implemented
    }
}

//
// end of file















