public class AtomicUndoManager extends UndoManager
UndoManager providing nested atomic (or scoped) undo/redo
operations. Note undo/redo operations are captured in StateEditable implementations.
A generic application of this class follows:
...
_undoMgr = new AtomicUndoManager( 1000 );
...
//
// This method decorates a typical change operation with undo/redo capability.
// Notice the XXXOperationUndoItem class. You'll need to create one of these
// for each undo operation. Basically these UndoItem classes are extensions
// of StateEditable. They are responsible for capturing the state
// before and after an operation and also for restoring the state as directed
// by this undo manager.
//
void performUndoableXXXOperation( ... )
{
XXXOperationUndoItem undoItem = new XXXOperationUndoItem( ... );
StateEdit transaction = new StateEdit( undoItem, "XXX Operation" );
performXXXOperation( ... );
transaction.end();
_undoMgr.addEdit( transaction );
}
// Your typical change operation.
void performXXXOperation( ... )
{
// do whatever it is you do...
}
//
// This method exercises the atomic and nested features of AtomicUndoManager.
// The atomic boundaries should be enforced with the try/finally idiom so
// a failed atomic operation can be safely (and optionally) "rolled back".
//
void performUndoableZZZOperation
{
try
{
_undoMgr.beginUndoAtom( "ZZZ Operation" );
performUndoableXXXOperation( ... );
performUndoableYYYOperation( ... );
...
}
finally
{
_undoMgr.endUndoAtom();
}
}
//
// Create ui components using Actions such as these:
//
class UndoAction extends AbstractAction
{
UndoAction( String strName, Icon icon )
{
super( strName, icon );
}
public void actionPerformed( ActionEvent e )
{
_undoMgr.undo();
}
public boolean isEnabled()
{
return _undoMgr.canUndo();
}
}
class RedoAction extends AbstractAction
{
RedoAction( String strName, Icon icon )
{
super( strName, icon );
}
public void actionPerformed( ActionEvent e )
{
_undoMgr.redo();
}
public boolean isEnabled()
{
return _undoMgr.canRedo();
}
}editsRedoName, UndoName| Constructor and Description |
|---|
AtomicUndoManager()
An
AtomicUndoManager with a default limit of 1000 edits. |
AtomicUndoManager(int iUndoLimit) |
| Modifier and Type | Method and Description |
|---|---|
void |
addChangeListener(ChangeListener listener) |
boolean |
addEdit(UndoableEdit edit) |
void |
beginUndoAtom()
Begin an atomic undo boundary.
|
CompoundEdit |
beginUndoAtom(String strDisplayName)
Begin an atomic undo boundary.
|
void |
discardAllEdits() |
void |
endUndoAtom()
Ends the active atomic undo boundary.
|
void |
endUndoAtom(CompoundEdit undoAtom) |
long |
getLastUndoTime() |
editor.undo.AtomicUndoManager.DisplayableCompoundEdit |
getUndoAtom() |
boolean |
isPaused() |
void |
recordChange(StateEditable change)
Utility method that records a change that can be undone/redone.
|
void |
redo() |
protected void |
redoTo(UndoableEdit edit) |
void |
removeChangeListener(ChangeListener listener) |
void |
removeEdit(UndoableEdit edit) |
void |
setPaused(boolean bPaused)
Sets the paused state of the undo manager.
|
void |
undo() |
void |
undoOrRedo() |
protected void |
undoTo(UndoableEdit edit) |
canRedo, canUndo, canUndoOrRedo, editToBeRedone, editToBeUndone, end, getLimit, getRedoPresentationName, getUndoOrRedoPresentationName, getUndoPresentationName, setLimit, toString, trimEdits, trimForLimit, undoableEditHappeneddie, getPresentationName, isInProgress, isSignificant, lastEditreplaceEditpublic AtomicUndoManager()
AtomicUndoManager with a default limit of 1000 edits.public AtomicUndoManager(int iUndoLimit)
iUndoLimit - The maximum number of edits this undo manager will hold.public boolean isPaused()
public void setPaused(boolean bPaused)
bPaused - The paused state.public boolean addEdit(UndoableEdit edit)
addEdit in interface UndoableEditaddEdit in class UndoManageredit - The edit to be added. Note nested edits are supported.public void removeEdit(UndoableEdit edit)
edit - The edit to be removed.public void discardAllEdits()
discardAllEdits in class UndoManagerpublic void beginUndoAtom()
endUndoAtom().
Note undo atoms can contain other undo atoms allowing for unlimited nesting of atomic
undo operations.public CompoundEdit beginUndoAtom(String strDisplayName)
endUndoAtom().
Note undo atoms can contain other undo atoms allowing for unlimited nesting of atomic
undo operations.strDisplayName - The name associated with the undo atom. A user interface typically
displays this name in Undo/Redo menu items or toolbar button text.UndoManager.getUndoPresentationName()public void endUndoAtom()
beginUndoAtom()public void endUndoAtom(CompoundEdit undoAtom)
public editor.undo.AtomicUndoManager.DisplayableCompoundEdit getUndoAtom()
public void redo()
throws CannotRedoException
redo in interface UndoableEditredo in class UndoManagerCannotRedoExceptionpublic void undo()
throws CannotUndoException
undo in interface UndoableEditundo in class UndoManagerCannotUndoExceptionpublic long getLastUndoTime()
public void undoOrRedo()
throws CannotRedoException,
CannotUndoException
undoOrRedo in class UndoManagerCannotRedoExceptionCannotUndoExceptionprotected void undoTo(UndoableEdit edit) throws CannotUndoException
undoTo in class UndoManagerCannotUndoExceptionprotected void redoTo(UndoableEdit edit) throws CannotRedoException
redoTo in class UndoManagerCannotRedoExceptionpublic void addChangeListener(ChangeListener listener)
public void removeChangeListener(ChangeListener listener)
public void recordChange(StateEditable change)
Copyright © 2020. All rights reserved.