GraphicSorter.java
Created with JBuilder |
//package Sorter;
/**
* @author D. X. Nguyen
* @author S. B. Wong
*/
import java.awt.Color;
public class GraphicSorter extends ACompareSorter {
public final static int NapDuration = 1000;
private ACompareSorter _aCSorter; // "DECOREE"
public GraphicSorter (ACompareSorter aCSorter) {
_aCSorter = aCSorter;
}
protected int split (IOrdered[] A, int lo, int hi) {
System.out.println ("Sort from " + lo + " to " + hi);
int s = _aCSorter.split (A,lo, hi); // delegates to decoree
// s > lo
SorterColor color = (SorterColor) ((IColored)A[s]).getColor ();
Color splitColor = color.getLoSplit ();
for (int i = lo; i < s; i++) {
((IColored) A[i]).setColor (splitColor);
}
splitColor = color.getHiSplit ();
for(int i=s;i<=hi;i++) {
((IColored) A[i]).setColor (splitColor);
}
try {
System.out.println ("Split at " + s);
Thread.sleep (NapDuration);
}
catch (Exception e){}
return s;
}
protected void join (IOrdered[] A, int lo, int s, int hi) {
// lo < hi
_aCSorter.join(A,lo,s,hi); // delegates to decoree
SorterColor loColor = (SorterColor)(((IColored) A[lo]).getColor ());
SorterColor hiColor = (SorterColor)(((IColored) A[hi]).getColor ());
SorterColor color = loColor.join(hiColor);
for(int i=lo;i<=hi;i++) {
((IColored) A[i]).setColor (color);
}
try {
System.out.println ("Join at " + s);
Thread.sleep (NapDuration);
System.out.println ("Done sorting from " + lo + " to " + hi);
}
catch(Exception e){}
}
}
GraphicSorter.java
Created with JBuilder |