/* An instance of this class is for the purpose of carrying out a sequence ** of edit commands upon a document, as well as for managing the history of ** that sequence of commands, for the purpose of implementing undo and redo ** meta-commands. ** ** Authors: Gemini (AI), R. McCloskey, and < STUDENT's NAME > ** Collaborated with: ... ** Known defects: ... */ public class CommandHistoryManager { // instance variables // ------------------ private final Document doc; // the "resident" document (being edited) // Stack holding the edit commands that have been done (i.e., executed) // and that are subject to being undone. private final Stack doneStack; // Stack holding the edit commands that have been undone (since the last // time a "new" command was issued) and are subject to being redone. private final Stack undoneStack; // constructor // ----------- /* Establishes the "resident" document of this command history manager. */ public CommandHistoryManager(Document doc) { this.doc = doc; doneStack = new StackViaArray(); undoneStack = new StackViaArray(); } /* Applies the given edit commmand to the "resident" document ** (and adjusts the two stacks accordingly). */ public void executeCommand(EditCommand cmd) { // STUB // For purposes of debugging, the following statement can be // included at end of method body. // System.out.println("Executed: " + cmd); } /* Undoes the latest (not already-undone) edit command that was applied ** (and adjusts the two stacks accordingly). ** If there is no command subject to being undone, an error message ** should be displayed (indicating that fact), but otherwise no ** changes should occur. */ public void undo() { // STUB // For purposes of debugging, the following statement can be // included at end of method body. //System.out.println("Undid: " + cmd); } /* Redoes the edit command that was most recently undone. ** If there is no command subject to being redone, an error message ** should be displayed (indicating that fact), but otherwise no ** changes should occur. */ public void redo() { // STUB // For purposes of debugging, the following statement can be // included at end of method body. //System.out.println("Redid: " + cmd); } }