//---------------------------------
// SortAlgorithm.Java
// Written By: Russell Schwager
//             russells@jhu.edu
// January 29, 1997
//---------------------------------

// Insert Copyright comments

//------------------ BEGIN UI CODE ----------------
import java.awt.Graphics;
//------------------ END UI CODE ------------------

// Generic base class for all sorting algorithms.  It allows
// for any sortable object to be sorted.

public abstract class SortAlgorithm
{
	
	public SortableObject objectToSort;
	public String algorithmName;

	public abstract void sort();

	//---------BEGIN UI CODE---------------
	public abstract void demoSort() throws Exception;
	public abstract void drawMiscInfo(Graphics g);
	//---------END UI CODE-----------------
	
	public SortAlgorithm(SortableObject anObject)
	{ // Constructor

		setSortableObject(anObject);
		algorithmName = "";
	}

	public SortAlgorithm()
	{ // Default Constructor
		algorithmName = "";
	}

	public String getAlgorithmName()
	{ // Returns the name of the sort algorithm

		String aString = new String(this.algorithmName);
		return aString;
	}
	
	public void setSortableObject(SortableObject anObject)
	{ // assign the object to Sort variable
		
		objectToSort = anObject;
		objectToSort.setStatus(false);

	}

	public SortableObject sort(SortableObject anObject)
	{
		if (!anObject.getStatus())
		{ // Sort if the object hasn't been sorted.
			setSortableObject(anObject);
			sort();
			anObject.setStatus(true);
			return anObject;
		}

		return anObject;
	}

	//---------BEGIN UI CODE---------------
	protected void stop()
	{ // Force the sort to stop by changing the status of
	  // object to be sorted.

		objectToSort.setStatus(true);
	}

	protected void init()
	{
		objectToSort.setStatus(false);

	}
	//---------END UI CODE-----------------


}
