Search
Overview

Interactive actions, carried out by users, and programmatic commands that change the structure of a diagram are recorded in a history queue. While action records are still in that queue, the actions can be undone or redone. The queue has a fixed length - if it gets full, recording a new action makes the oldest one drop from the queue.

Undo is disabled by default. To enable it, call the setUndoEnabled method. To undo or redo an action, call the undo or redo methods of UndoManager. JDiagram does not provide keyboard shortcuts for undo/redo. Your application must have its own menu items and/or keyboard accelerators to provide the necessary user interface, and invoke the respective methods in response to UI events.

JDiagram automatically saves the following types of actions for later undo/redo:

  • adding an item to the diagram
  • removing an item from the diagram
  • moving or resizing items
  • creating a group
  • destroying a group
  • expanding or collapsing trees
  • scrolling table rows
  • adding or removing tables' rows

Changes of item values are not saved automatically in the history. If your application must be able to undo/redo changes, use the ChangeItemCmd command. ChangeItemCmd allows recording several changes as an atomic undoable action.

In some cases, you might need to create your own types of actions or commands. For example, suppose you need undo/redo for changes made to items' tag objects. However, JDiagram is not able to detect such changes, so it cannot undo them. To enable undo/redo, create a subclass of Command and implement the execute, undo and redo methods.