Package org.opentrafficsim.editor
Class Undo
java.lang.Object
org.opentrafficsim.editor.Undo
- All Implemented Interfaces:
Serializable
,Remote
,EventListener
,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:
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescription(package private) boolean
Boolean to ignore changes during undo/redo, so no new undo/redo is made. -
Constructor Summary
ConstructorDescriptionUndo
(OtsEditor editor, AbstractButton undoItem, AbstractButton redoItem) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionboolean
canRedo()
Returns whether a redo is available.boolean
canUndo()
Returns whether an undo is available.void
clear()
Clears the entire queue, suitable for when a new tree is loaded.void
notify
(org.djutils.event.Event event) void
redo()
Performs a redo.void
setIgnoreChanges
(boolean ignore) Tells the undo unit to ignore all changes.void
Sets the node to show in the tree after the action.void
startAction
(Undo.ActionType type, XsdTreeNode node, String attribute) Starts a new action, which groups all sub-actions until a new action is started.void
undo()
Performs an undo.void
Update the enabled state and text of the undo and redo button.
-
Field Details
-
ignoreChanges
boolean ignoreChangesBoolean to ignore changes during undo/redo, so no new undo/redo is made.
-
-
Constructor Details
-
Undo
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 callingclear()
. Useful during file loading.- Parameters:
ignore
- boolean; ignore changes.
-
startAction
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
- Specified by:
notify
in interfaceorg.djutils.event.EventListener
- Throws:
RemoteException
-
setPostActionShowNode
Sets the node to show in the tree after the action.- Parameters:
node
- XsdTreeNode; node to show in the tree after the action.
-