public class UndoRedoHandler extends java.lang.Object
DataSet
s.
If you want to change a data set, you can use add(Command)
to execute a command on it and make that command undoable.
Modifier and Type | Class and Description |
---|---|
static interface |
UndoRedoHandler.CommandQueueListener
A listener that gets notified of command queue (undo/redo) size changes.
|
Modifier and Type | Field and Description |
---|---|
java.util.LinkedList<Command> |
commands
All commands that were made on the dataset.
|
private java.util.LinkedList<UndoRedoHandler.CommandQueueListener> |
listenerCommands |
java.util.LinkedList<Command> |
redoCommands
The stack for redoing commands
|
Constructor and Description |
---|
UndoRedoHandler()
Constructs a new
UndoRedoHandler . |
Modifier and Type | Method and Description |
---|---|
void |
add(Command c)
Executes the command and add it to the intern command queue.
|
boolean |
addCommandQueueListener(UndoRedoHandler.CommandQueueListener l)
Adds a command queue listener.
|
void |
addNoRedraw(Command c)
Executes the command and add it to the intern command queue.
|
void |
afterAdd()
Fires a commands change event after adding a command.
|
void |
clean()
Resets the undo/redo list.
|
void |
clean(DataSet dataSet)
Resets all commands that affect the given dataset.
|
private void |
fireCommandsChanged()
Fires a command change to all listeners.
|
Command |
getLastCommand()
Gets the last command that was executed on the command stack.
|
void |
redo()
Redoes the last undoed command.
|
void |
redo(int num)
Redoes multiple commands.
|
void |
removeCommandQueueListener(UndoRedoHandler.CommandQueueListener l)
Removes a command queue listener.
|
void |
undo()
Undoes the last added command.
|
void |
undo(int num)
Undoes multiple commands.
|
public final java.util.LinkedList<Command> commands
getLastCommand()
public final java.util.LinkedList<Command> redoCommands
private final java.util.LinkedList<UndoRedoHandler.CommandQueueListener> listenerCommands
public UndoRedoHandler()
UndoRedoHandler
.public Command getLastCommand()
null
if there is no such command.public void addNoRedraw(Command c)
c
- The command to execute. Must not be null
.public void afterAdd()
public void add(Command c)
c
- The command to execute. Must not be null
.public void undo()
public void undo(int num)
num
- The number of commands to undopublic void redo()
public void redo(int num)
num
- The number of commands to redoprivate void fireCommandsChanged()
public void clean()
public void clean(DataSet dataSet)
dataSet
- The data set that was affected.public void removeCommandQueueListener(UndoRedoHandler.CommandQueueListener l)
l
- The command queue listener to removepublic boolean addCommandQueueListener(UndoRedoHandler.CommandQueueListener l)
l
- The commands queue listener to addtrue
if the listener has been added, false
otherwise