/**
 * A simple example of the Command pattern
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class Driver
{
    /**
     * The entry point
     *
     * @param args   The command-line arguments
     */
    public static void main(String[] args)
    {
	int              i;
	TextDocument     document;
	Replace[]        replace;


	document = new TextDocument();
	document.setText("George is a little monkey, "+
                         "and all monkeys are curious. "+
                         "But no monkey is as curious "+
                         "as George.");

	System.out.println("\n"+document.getText()+"\n");


	replace = new Replace[3];
	replace[0] = new Replace(document,"curious","power hungry");
	replace[1] = new Replace(document,"monkey", "President");
	replace[2] = new Replace(document,"little", "U.S.");


	for (i=0; i < replace.length; i++) {
	    
	    replace[i].apply();
	    System.out.println("\n"+document.getText()+"\n");
	}

	for (i=replace.length-1; i >= 0; i--) {
	    
	    replace[i].undo();
	    System.out.println("\n"+document.getText()+"\n");
	}


    }
}
