Package org.openstreetmap.josm.data
Class UndoRedoHandler
- java.lang.Object
-
- org.openstreetmap.josm.data.UndoRedoHandler
-
public final class UndoRedoHandler extends java.lang.Object
This is the global undo/redo handler for allDataSet
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class 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
-
Field Summary
Fields Modifier and Type Field Description private java.util.LinkedList<Command>
commands
All commands that were made on the datasetprivate java.util.LinkedList<UndoRedoHandler.CommandQueueListener>
listenerCommands
private java.util.LinkedList<UndoRedoHandler.CommandQueuePreciseListener>
preciseListenerCommands
private java.util.LinkedList<Command>
redoCommands
The stack for redoing commands
-
Constructor Summary
Constructors Modifier Constructor Description private
UndoRedoHandler()
Constructs a newUndoRedoHandler
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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(java.util.List<? extends Command> cmds)
Fires a commands change event after adding a list of commands.void
afterAdd(Command cmd)
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.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.List<Command>
getRedoCommands()
Returns all commands that were made and undone on the dataset, that can be redone.java.util.List<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.
-
-
-
Field Detail
-
commands
private final java.util.LinkedList<Command> commands
All commands that were made on the dataset- See Also:
getLastCommand()
,getUndoCommands()
-
redoCommands
private final java.util.LinkedList<Command> redoCommands
The stack for redoing commands- See Also:
getRedoCommands()
-
listenerCommands
private final java.util.LinkedList<UndoRedoHandler.CommandQueueListener> listenerCommands
-
preciseListenerCommands
private final java.util.LinkedList<UndoRedoHandler.CommandQueuePreciseListener> preciseListenerCommands
-
-
Constructor Detail
-
UndoRedoHandler
private UndoRedoHandler()
Constructs a newUndoRedoHandler
.
-
-
Method Detail
-
getInstance
public static UndoRedoHandler getInstance()
Returns the unique instance.- Returns:
- the unique instance
- Since:
- 14134
-
getUndoCommands
public java.util.List<Command> 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
public java.util.List<Command> 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
public Command getLastCommand()
Gets the last command that was executed on the command stack.- Returns:
- That command or
null
if there is no such command. - Since:
- #12316
-
hasUndoCommands
public boolean hasUndoCommands()
Determines if commands can be undone.- Returns:
true
if at least a command can be undone- Since:
- 14281
-
hasRedoCommands
public boolean hasRedoCommands()
Determines if commands can be redone.- Returns:
true
if at least a command can be redone- Since:
- 14281
-
addNoRedraw
public void addNoRedraw(Command c)
Executes the command and add it to the intern command queue.- Parameters:
c
- The command to execute. Must not benull
.
-
addNoRedraw
public void addNoRedraw(Command c, boolean execute)
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
public void afterAdd(Command cmd)
Fires a commands change event after adding a command.- Parameters:
cmd
- command added- Since:
- 13729
-
afterAdd
public void afterAdd(java.util.List<? extends Command> cmds)
Fires a commands change event after adding a list of commands.- Parameters:
cmds
- commands added- Since:
- 14381
-
add
public void add(Command c, boolean execute)
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
public void add(Command c)
Executes the command and add it to the intern command queue.- Parameters:
c
- The command to execute. Must not benull
.
-
undo
public void undo()
Undoes the last added command.
-
undo
public void undo(int num)
Undoes multiple commands.- Parameters:
num
- The number of commands to undo
-
redo
public void redo()
Redoes the last undoed command.
-
redo
public void redo(int num)
Redoes multiple commands.- Parameters:
num
- The number of commands to redo
-
fireCommandsChanged
private void fireCommandsChanged()
Fires a command change to all listeners.
-
fireEvent
private void fireEvent(UndoRedoHandler.CommandQueueEvent e)
-
clean
public void clean()
Resets the undo/redo list.
-
clean
public void clean(DataSet dataSet)
Resets all commands that affect the given dataset.- Parameters:
dataSet
- The data set that was affected.- Since:
- 12718
-
removeCommandQueueListener
public void removeCommandQueueListener(UndoRedoHandler.CommandQueueListener l)
Removes a command queue listener.- Parameters:
l
- The command queue listener to remove
-
addCommandQueueListener
public boolean addCommandQueueListener(UndoRedoHandler.CommandQueueListener l)
Adds a command queue listener.- Parameters:
l
- The command queue listener to add- Returns:
true
if the listener has been added,false
otherwise
-
removeCommandQueuePreciseListener
public void removeCommandQueuePreciseListener(UndoRedoHandler.CommandQueuePreciseListener l)
Removes a precise command queue listener.- Parameters:
l
- The precise command queue listener to remove- Since:
- 13729
-
addCommandQueuePreciseListener
public boolean addCommandQueuePreciseListener(UndoRedoHandler.CommandQueuePreciseListener l)
Adds a precise command queue listener.- Parameters:
l
- The precise command queue listener to add- Returns:
true
if the listener has been added,false
otherwise- Since:
- 13729
-
-