Undo manager into the chart customizer
The chart customizer provides no undo manager by itself. Usually, an application has already a central undo manager. The chart customizer can be easily integrated into a standard Swing undo manager ( javax.swing.undo.UndoManager ).
UndoManager undoManager = new UndoManager();
The chart customizer fires a javax.swing.event.UndoableEditEvent whenever a change that cannot be undone occurs in the chart customizer. You can listen to these events in the following way:
customizer.addUndoableEditListener(undoListener);
When the undo listener receives an event, it adds the corresponding undo edit to the undo manager and updates the undoManager:
private UndoableEditListener undoListener = new UndoableEditListener() {
public void undoableEditHappened(UndoableEditEvent e) {
undoManager.addEdit(e.getEdit());
... code that updates the buttons and menu items that trigger an undo/redo,
for example, enable the undo button to indicate undo is now possible, or
update the tooltip of the undo button ...
}
};
To trigger an undo, you can use the standard Swing mechanism, that is, implement a menu item or button that calls the method undoManager.undo() when an action is performed.
Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.