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 allDataSets.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 classUndoRedoHandler.CommandAddedEventEvent fired after a command has been added to the command queue.static classUndoRedoHandler.CommandQueueCleanedEventEvent fired after the command queue has been cleaned.(package private) static classUndoRedoHandler.CommandQueueEventstatic interfaceUndoRedoHandler.CommandQueueListenerA simple listener that gets notified of command queue (undo/redo) size changes.static interfaceUndoRedoHandler.CommandQueuePreciseListenerA listener that gets notified of command queue (undo/redo) operations individually.static classUndoRedoHandler.CommandRedoneEventEvent fired after a command has been redone.static classUndoRedoHandler.CommandUndoneEventEvent fired after a command has been undone.private static classUndoRedoHandler.InstanceHolder
-
Field Summary
Fields Modifier and Type Field Description private java.util.LinkedList<Command>commandsAll commands that were made on the datasetprivate java.util.LinkedList<UndoRedoHandler.CommandQueueListener>listenerCommandsprivate java.util.LinkedList<UndoRedoHandler.CommandQueuePreciseListener>preciseListenerCommandsprivate java.util.LinkedList<Command>redoCommandsThe stack for redoing commands
-
Constructor Summary
Constructors Modifier Constructor Description privateUndoRedoHandler()Constructs a newUndoRedoHandler.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Command c)Executes the command and add it to the intern command queue.voidadd(Command c, boolean execute)Executes the command only if wanted and add it to the intern command queue.booleanaddCommandQueueListener(UndoRedoHandler.CommandQueueListener l)Adds a command queue listener.booleanaddCommandQueuePreciseListener(UndoRedoHandler.CommandQueuePreciseListener l)Adds a precise command queue listener.voidaddNoRedraw(Command c)Executes 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.voidafterAdd(java.util.List<? extends Command> cmds)Fires a commands change event after adding a list of commands.voidafterAdd(Command cmd)Fires a commands change event after adding a command.voidclean()Resets the undo/redo list.voidclean(DataSet dataSet)Resets all commands that affect the given dataset.private voidfireCommandsChanged()Fires a command change to all listeners.private voidfireEvent(UndoRedoHandler.CommandQueueEvent e)static UndoRedoHandlergetInstance()Returns the unique instance.CommandgetLastCommand()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.booleanhasRedoCommands()Determines if commands can be redone.booleanhasUndoCommands()Determines if commands can be undone.voidredo()Redoes the last undoed command.voidredo(int num)Redoes multiple commands.voidremoveCommandQueueListener(UndoRedoHandler.CommandQueueListener l)Removes a command queue listener.voidremoveCommandQueuePreciseListener(UndoRedoHandler.CommandQueuePreciseListener l)Removes a precise command queue listener.voidundo()Undoes the last added command.voidundo(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
nullif there is no such command. - Since:
- #12316
-
hasUndoCommands
public boolean hasUndoCommands()
Determines if commands can be undone.- Returns:
trueif at least a command can be undone- Since:
- 14281
-
hasRedoCommands
public boolean hasRedoCommands()
Determines if commands can be redone.- Returns:
trueif 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:
trueif the listener has been added,falseotherwise
-
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:
trueif the listener has been added,falseotherwise- Since:
- 13729
-
-