| # GUI Commands User Guide ## Version 2.1 |
| # Undo/Redo Commands GUI Commands provides basic commands for handling undo and redo. The three core classes are: UndoContext - An extension of Swings UndoManager that provides notifications when the current edit state changes. It can be used as a drop-in replacement for UndoManager. UndoCommand - Undoes the last edit in the UndoContext. RedoCommand - Redoes the last edit in the UndoContext. To use the undo and redo commands you need to: Bind the undo and redo commands to a CommandContainer. Set the UndoContext of the container (or on any parent in the hierarchy).
       CommandContainer container = ...;

       // create and bind our commands
       UndoCommand undoCommand = new UndoCommand("undo");
       UndoCommand redo = new UndoCommand("redo");

       undoCommand.bind(container);
       redoCommand.bind(container);

       // configure the undo context.
       UndoContext undoContext = new UndoContext();
       container.setUndoContext(undoContext);

       // use the context
       JTextPane textPane = ...;
       textPane.addUndoableEditListener(undoContext);
You can change the UndoContext at any time. The commands will be notified of the change and update appropriately. |