Class UndoRedoHandler

java.lang.Object
org.openstreetmap.josm.data.UndoRedoHandler

public final class UndoRedoHandler extends Object
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.

  • Field Details

  • Constructor Details

    • UndoRedoHandler

      private UndoRedoHandler()
      Constructs a new UndoRedoHandler.
  • Method Details

    • getInstance

      public static UndoRedoHandler 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 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 be null.
    • 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 be null.
      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(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 be null.
      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 be null.
    • 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

    • 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

      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:
      true if the listener has been added, false otherwise
    • 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:
      true if the listener has been added, false otherwise
      Since:
      13729