Java Magazine, May/June 2018
ORACLE COM JAVAMAGAZINE MAY JUNE 2018 22 design patterns buffer addAll startLnum newLines current newLines size pushUndo add newLines size lines deleteLines startLnum startLnum newLines size The pushUndo method is simply a convenience routine that creates the UndoableCommand and pushes it on the stack private void pushUndo String name Runnable r undoables push new UndoableCommand name r Now the undo implementation becomes trivial error handling is omitted public void undo UndoableCommand undoable undoables pop undoable r run Here is an example of the edj editor in action 1 I run edj telling it to start with the sample three line file included with the source code 2 The p command prints all the lines in memory its short for 1 Np where N is the number of lines in the bufer 3 The 2d command deletes the second line 4 I print the whole thing again to show that the deletion worked 5 I invoke the newly added undo feature using the u command 6 I print the bufer again to show that line 2 was miraculously restored by the u command 7 I use the command q to quit
You must have JavaScript enabled to view digital editions.