Package org.openstreetmap.josm.data
Class UndoRedoHandler
java.lang.Object
org.openstreetmap.josm.data.UndoRedoHandler
This is the global undo/redo handler for all
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classEvent fired after a command has been added to the command queue.static final classEvent fired after the command queue has been cleaned.(package private) static classstatic interfaceA simple listener that gets notified of command queue (undo/redo) size changes.static interfaceA listener that gets notified of command queue (undo/redo) operations individually.static final classEvent fired after a command has been redone.static final classEvent fired after a command has been undone.private static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final LinkedList<Command>All commands that were made on the datasetprivate final LinkedList<UndoRedoHandler.CommandQueueListener>private final LinkedList<UndoRedoHandler.CommandQueuePreciseListener>private final LinkedList<Command>The stack for redoing commands -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidExecutes the command and add it to the intern command queue.voidExecutes the command only if wanted and add it to the intern command queue.booleanAdds a command queue listener.booleanAdds a precise command queue listener.voidExecutes the command and add it to the intern command queue.voidaddNoRedraw(Command c, boolean execute) Executes the command and add it to the intern command queue.voidFires a commands change event after adding a list of commands.voidFires a commands change event after adding a command.voidclean()Resets the undo/redo list.voidResets all commands that affect the given dataset.private voidFires a command change to all listeners.private voidstatic UndoRedoHandlerReturns the unique instance.Gets the last command that was executed on the command stack.Returns all commands that were made and undone on the dataset, that can be redone.Returns all commands that were made on the dataset, that can be undone.booleanDetermines if commands can be redone.booleanDetermines if commands can be undone.voidredo()Redoes the last undoed command.voidredo(int num) Redoes multiple commands.voidRemoves a command queue listener.voidRemoves a precise command queue listener.voidundo()Undoes the last added command.voidundo(int num) Undoes multiple commands.
-
Field Details
-
commands
All commands that were made on the dataset- See Also:
-
redoCommands
The stack for redoing commands- See Also:
-
listenerCommands
-
preciseListenerCommands
-
-
Constructor Details
-
UndoRedoHandler
private UndoRedoHandler()Constructs a newUndoRedoHandler.
-
-
Method Details
-
getInstance
Returns the unique instance.- Returns:
- the unique instance
- Since:
- 14134
-
getUndoCommands
Returns all commands that were made on the dataset, that can be undone.- Returns:
- all commands that were made on the dataset, that can be undone
- Since:
- 14281, 16567 (signature)
-
getRedoCommands
Returns all commands that were made and undone on the dataset, that can be redone.- Returns:
- all commands that were made and undone on the dataset, that can be redone.
- Since:
- 14281, 16567 (signature)
-
getLastCommand
Gets the last command that was executed on the command stack.- Returns:
- That command or
nullif there is no such command. - Since:
- #12316
-
hasUndoCommands
Determines if commands can be undone.- Returns:
trueif at least a command can be undone- Since:
- 14281
-
hasRedoCommands
Determines if commands can be redone.- Returns:
trueif at least a command can be redone- Since:
- 14281
-
addNoRedraw
Executes the command and add it to the intern command queue.- Parameters:
c- The command to execute. Must not benull.
-
addNoRedraw
Executes the command and add it to the intern command queue.- Parameters:
c- The command to execute. Must not benull.execute- true: Execute, else it is assumed that the command was already executed- Since:
- 14845
-
afterAdd
Fires a commands change event after adding a command.- Parameters:
cmd- command added- Since:
- 13729
-
afterAdd
Fires a commands change event after adding a list of commands.- Parameters:
cmds- commands added- Since:
- 14381
-
add
Executes the command only if wanted and add it to the intern command queue.- Parameters:
c- The command to execute. Must not benull.execute- true: Execute, else it is assumed that the command was already executed
-
add
Executes the command and add it to the intern command queue.- Parameters:
c- The command to execute. Must not benull.
-
undo
Undoes the last added command. -
undo
Undoes multiple commands.- Parameters:
num- The number of commands to undo
-
redo
Redoes the last undoed command. -
redo
Redoes multiple commands.- Parameters:
num- The number of commands to redo
-
fireCommandsChanged
Fires a command change to all listeners. -
fireEvent
-
clean
Resets the undo/redo list. -
clean
Resets all commands that affect the given dataset.- Parameters:
dataSet- The data set that was affected.- Since:
- 12718
-
removeCommandQueueListener
Removes a command queue listener.- Parameters:
l- The command queue listener to remove
-
addCommandQueueListener
Adds a command queue listener.- Parameters:
l- The command queue listener to add- Returns:
trueif the listener has been added,falseotherwise
-
removeCommandQueuePreciseListener
Removes a precise command queue listener.- Parameters:
l- The precise command queue listener to remove- Since:
- 13729
-
addCommandQueuePreciseListener
Adds a precise command queue listener.- Parameters:
l- The precise command queue listener to add- Returns:
trueif the listener has been added,falseotherwise- Since:
- 13729
-