public final class UndoRedoHandler extends java.lang.Object
DataSets.
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 class |
UndoRedoHandler.CommandAddedEvent
Event fired after a command has been added to the command queue.
|
static class |
UndoRedoHandler.CommandQueueCleanedEvent
Event fired after the command queue has been cleaned.
|
(package private) static class |
UndoRedoHandler.CommandQueueEvent |
static interface |
UndoRedoHandler.CommandQueueListener
A simple listener that gets notified of command queue (undo/redo) size changes.
|
static interface |
UndoRedoHandler.CommandQueuePreciseListener
A listener that gets notified of command queue (undo/redo) operations individually.
|
static class |
UndoRedoHandler.CommandRedoneEvent
Event fired after a command has been redone.
|
static class |
UndoRedoHandler.CommandUndoneEvent
Event fired after a command has been undone.
|
private static class |
UndoRedoHandler.InstanceHolder |
| 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 |
private java.util.LinkedList<UndoRedoHandler.CommandQueuePreciseListener> |
preciseListenerCommands |
java.util.LinkedList<Command> |
redoCommands
The stack for redoing commands
|
| Modifier | Constructor and Description |
|---|---|
private |
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.
|
void |
add(Command c,
boolean execute)
Executes the command only if wanted and add it to the intern command queue.
|
boolean |
addCommandQueueListener(UndoRedoHandler.CommandQueueListener l)
Adds a command queue listener.
|
boolean |
addCommandQueuePreciseListener(UndoRedoHandler.CommandQueuePreciseListener l)
Adds a precise command queue listener.
|
void |
addNoRedraw(Command c)
Executes the command and add it to the intern command queue.
|
void |
addNoRedraw(Command c,
boolean execute)
Executes the command and add it to the intern command queue.
|
void |
afterAdd(Command cmd)
Fires a commands change event after adding a command.
|
void |
afterAdd(java.util.List<? extends Command> cmds)
Fires a commands change event after adding a list of commands.
|
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.
|
private void |
fireEvent(UndoRedoHandler.CommandQueueEvent e) |
static UndoRedoHandler |
getInstance()
Returns the unique instance.
|
Command |
getLastCommand()
Gets the last command that was executed on the command stack.
|
java.util.LinkedList<Command> |
getRedoCommands()
Returns all commands that were made and undone on the dataset, that can be redone.
|
java.util.LinkedList<Command> |
getUndoCommands()
Returns all commands that were made on the dataset, that can be undone.
|
boolean |
hasRedoCommands()
Determines if commands can be redone.
|
boolean |
hasUndoCommands()
Determines if commands can be undone.
|
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 |
removeCommandQueuePreciseListener(UndoRedoHandler.CommandQueuePreciseListener l)
Removes a precise 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(),
getUndoCommands()public final java.util.LinkedList<Command> redoCommands
getRedoCommands()private final java.util.LinkedList<UndoRedoHandler.CommandQueueListener> listenerCommands
private final java.util.LinkedList<UndoRedoHandler.CommandQueuePreciseListener> preciseListenerCommands
private UndoRedoHandler()
UndoRedoHandler.public static UndoRedoHandler getInstance()
public java.util.LinkedList<Command> getUndoCommands()
public java.util.LinkedList<Command> getRedoCommands()
public Command getLastCommand()
null if there is no such command.public boolean hasUndoCommands()
true if at least a command can be undonepublic boolean hasRedoCommands()
true if at least a command can be redonepublic void addNoRedraw(Command c)
c - The command to execute. Must not be null.public void addNoRedraw(Command c, boolean execute)
c - The command to execute. Must not be null.execute - true: Execute, else it is assumed that the command was already executedpublic void afterAdd(Command cmd)
cmd - command addedpublic void afterAdd(java.util.List<? extends Command> cmds)
cmds - commands addedpublic void add(Command c, boolean execute)
c - The command to execute. Must not be null.execute - true: Execute, else it is assumed that the command was already executedpublic 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()
private void fireEvent(UndoRedoHandler.CommandQueueEvent e)
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 command queue listener to addtrue if the listener has been added, false otherwisepublic void removeCommandQueuePreciseListener(UndoRedoHandler.CommandQueuePreciseListener l)
l - The precise command queue listener to removepublic boolean addCommandQueuePreciseListener(UndoRedoHandler.CommandQueuePreciseListener l)
l - The precise command queue listener to addtrue if the listener has been added, false otherwise