The undo/redo history is represented by a CommandHistory instance. That instance is created by the UndoManager and can be accessed from its getHistory method.
The undo manager adds commands to the history after executing them. If the history queue is full, the oldest command records are removed when new ones are added. Use the setCapacity method of CommandHistory to specify how many action records to keep in the queue.
The history has a current-command pointer indicating which are the next commands to undo or redo. If a command is undone, the current pointer in the history queue is moved back and allows undoing even older actions. If the current pointer is not at the last record, any newer commands can be redone again.
To query which are the next commands to be undone or redone, use the getNextUndo and getNextRedo methods. They return the Command instances contained in the queue, which are referred by the current position pointer. If no further undo or redo is possible, these methods return null. You might use them to indicate to end-users, which are the next commands to undo/redo, for example
Java
![]() |
---|
if (diagram.getUndoManager().getHistory().getNextUndo() == null) |
To ban end-users from undoing last commands, clear the command history by invoking the clear method.