Class Undo

java.lang.Object
org.opentrafficsim.editor.Undo
All Implemented Interfaces:
Serializable, Remote, EventListener, org.djutils.event.EventListener

public class Undo extends Object implements org.djutils.event.EventListener
Undo unit for the OTS editor. This class stores an internal queue of actions. Changes to XsdTreeNodes should be grouped per single user input in an action. All actions need to be initiated externally using startAction(). This class will itself listen to all relevant changes in the tree and add incoming sub-actions under the started action.

Copyright (c) 2023-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.

Author:
Wouter Schakel
See Also:
  • Field Details

    • ignoreChanges

      boolean ignoreChanges
      Boolean to ignore changes during undo/redo, so no new undo/redo is made.
  • Constructor Details

    • Undo

      public Undo(OtsEditor editor, AbstractButton undoItem, AbstractButton redoItem)
      Constructor.
      Parameters:
      editor - OtsEditor; editor.
      undoItem - AbstractButton; undo GUI item.
      redoItem - AbstractButton; redo GUI item.
  • Method Details

    • clear

      public void clear()
      Clears the entire queue, suitable for when a new tree is loaded. Also set ignore changes to false.
    • setIgnoreChanges

      public void setIgnoreChanges(boolean ignore)
      Tells the undo unit to ignore all changes. Reset this by calling clear(). Useful during file loading.
      Parameters:
      ignore - boolean; ignore changes.
    • startAction

      public void startAction(Undo.ActionType type, XsdTreeNode node, String attribute)
      Starts a new action, which groups all sub-actions until a new action is started.
      Parameters:
      type - ActionType; action type.
      node - XsdTreeNode; node on which the action is applied, i.e. node that should be selected on undo/redo.
      attribute - String; attribute name, may be null for actions that are not an attribute value change.
    • canUndo

      public boolean canUndo()
      Returns whether an undo is available.
      Returns:
      boolean; whether an undo is available.
    • canRedo

      public boolean canRedo()
      Returns whether a redo is available.
      Returns:
      boolean; whether a redo is available.
    • undo

      public void undo()
      Performs an undo.
    • redo

      public void redo()
      Performs a redo.
    • updateButtons

      public void updateButtons()
      Update the enabled state and text of the undo and redo button.
    • notify

      public void notify(org.djutils.event.Event event) throws RemoteException
      Specified by:
      notify in interface org.djutils.event.EventListener
      Throws:
      RemoteException
    • setPostActionShowNode

      public void setPostActionShowNode(XsdTreeNode node)
      Sets the node to show in the tree after the action.
      Parameters:
      node - XsdTreeNode; node to show in the tree after the action.