Package org.openflexo.pamela.undo
Class UndoManager
- java.lang.Object
-
- javax.swing.undo.AbstractUndoableEdit
-
- javax.swing.undo.CompoundEdit
-
- javax.swing.undo.UndoManager
-
- org.openflexo.pamela.undo.UndoManager
-
- All Implemented Interfaces:
java.io.Serializable
,java.util.EventListener
,javax.swing.event.UndoableEditListener
,javax.swing.undo.UndoableEdit
public class UndoManager extends javax.swing.undo.UndoManager
A PAMELAUndoManager
tracks and record PAMELA atomic edits into aggregates named compound edit.
It provides a way to undo or redo the appropriate edits.
To instantiate and enable anUndoManager
, use thePamelaModelFactory#createUndoManager()
method.
UndoManager
internally manages a list ofCompoundEdit
, which are aggregates of PAMELA atomic events (AtomicEdit
).
You should use {startRecording(String)
and {stopRecording(CompoundEdit)
methods to semantically control undo/redo sequences.
TheUndoManager
is automatically tracking all PAMELA atomic events (seeAtomicEdit
). If anAtomicEdit
is received outside a declared recording edit, then a new edition (aCompoundEdit
) is automatically instantiated. No inconsistency should be raised because of unregistered edits.
UndoManager
maintains an ordered list of edits and the index of the next edit in that list. The index of the next edit is either the size of the current list of edits, or ifundo()
has been invoked it corresponds to the index of the last significant edit that was undone. Whenundo()
is invoked all edits from the index of the next edit to the last significant edit are undone, in reverse order.
Invokingredo()
results in invokingredo()
on all edits between the index of the next edit and the next significant edit (or the end of the list).
Adding an edit to anUndoManager
results in removing all edits from the index of the next edit to the end of the list.
TODO: WARNING: if you are dealing with custom implementation of PAMELA objects with methods involved in setter/adder/remover and declared as final, those calls won't be intercepted by the UndoManager, and thus results will be of undetermined state. Please fix this.
This class is thread safe.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ENABLED
static java.lang.String
REDONE
static java.lang.String
START_RECORDING
static java.lang.String
STOP_RECORDING
static java.lang.String
UNDONE
static java.lang.String
UNIDENTIFIED_RECORDING
-
Constructor Summary
Constructors Constructor Description UndoManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addEdit(javax.swing.undo.UndoableEdit anEdit)
Adds anUndoableEdit
to thisUndoManager
, if it's possible.boolean
canRedo()
Returns true if edits may be redone.boolean
canUndo()
Returns true if edits may be undone.boolean
canUndoIfStoppingCurrentEdition()
Returns true if edits may be undone.
If en edition is in progress, return true if stopping this edition will cause UndoManager to be able to undovoid
debug()
void
disableAnticipatedRecording()
Disable 'anticipated' recording, see aboveCompoundEdit
editToBeRedone()
Returns the the next significant edit to be redone ifredo
is invoked.CompoundEdit
editToBeUndone()
Returns the the next significant edit to be undone ifundo
is invoked.void
enableAnticipatedRecording()
This method should be called whenever some edit might be triggered outside of an official edition action, but if those edits
should be aggregated in the next edition action.
Calling this method enable this scheme.protected void
fireAddEdit(javax.swing.undo.UndoableEdit anEdit)
protected void
fireRedo()
protected void
fireUndo()
CompoundEdit
getCurrentEdition()
Return current editionjava.lang.String
getDeletedProperty()
java.util.List<javax.swing.undo.UndoableEdit>
getEdits()
java.beans.PropertyChangeSupport
getPropertyChangeSupport()
int
getUndoLevel()
java.lang.String
getUndoPresentationName()
Returns a description of the undoable form of this edit.boolean
isAnticipatedRecording()
Return flag indicating ifUndoManager
is currently recording in anticipated modeboolean
isBeeingRecording()
Return flag indicating ifUndoManager
is currently recording.
Return true if start recording has been calledboolean
isEnabled()
boolean
isIgnorable(javax.swing.undo.UndoableEdit edit)
This should be used as a hook to intercept some edit that we dont't want to be caught during capture of UNDO edits
This method should be overriden when required.
Default implementation return falseboolean
isRedoInProgress()
Return boolean indicating if redo is currently being processedboolean
isUndoInProgress()
Return boolean indicating if undo is currently being processedprotected CompoundEdit
makeCompoundEdit(java.lang.String presentationName)
void
redo()
Redoes the appropriate edits.
Invokesredo
on all edits between the index of the next edit and the next significant edit, updating the index of the next edit appropriately.void
setEnabled(boolean enabled)
void
setUndoLevel(int undoLevel)
CompoundEdit
startRecording(java.lang.String presentationName)
Start a new labelled edit tracking
All PAMELA atomic events that will be received from now will be aggregated into newly createdCompoundEdit
CompoundEdit
stopRecording(CompoundEdit edit)
Stops supplied edit tracking
After this method, this edit will be available for undo/redovoid
undo()
Undoes the appropriate edits.
Invokesundo
on all edits between the index of the next edit and the last significant edit, updating the index of the next edit appropriately.-
Methods inherited from class javax.swing.undo.UndoManager
canUndoOrRedo, discardAllEdits, end, getLimit, getRedoPresentationName, getUndoOrRedoPresentationName, redoTo, setLimit, toString, trimEdits, trimForLimit, undoableEditHappened, undoOrRedo, undoTo
-
-
-
-
Field Detail
-
ENABLED
public static final java.lang.String ENABLED
- See Also:
- Constant Field Values
-
START_RECORDING
public static final java.lang.String START_RECORDING
- See Also:
- Constant Field Values
-
STOP_RECORDING
public static final java.lang.String STOP_RECORDING
- See Also:
- Constant Field Values
-
UNDONE
public static final java.lang.String UNDONE
- See Also:
- Constant Field Values
-
REDONE
public static final java.lang.String REDONE
- See Also:
- Constant Field Values
-
UNIDENTIFIED_RECORDING
public static final java.lang.String UNIDENTIFIED_RECORDING
- See Also:
- Constant Field Values
-
-
Method Detail
-
enableAnticipatedRecording
public void enableAnticipatedRecording()
This method should be called whenever some edit might be triggered outside of an official edition action, but if those edits
should be aggregated in the next edition action.
Calling this method enable this scheme. Next received edits will be stored temporarily in this anticipated recording, which will be turned into next official edition action.
-
disableAnticipatedRecording
public void disableAnticipatedRecording()
Disable 'anticipated' recording, see above
-
startRecording
public CompoundEdit startRecording(java.lang.String presentationName)
Start a new labelled edit tracking
All PAMELA atomic events that will be received from now will be aggregated into newly createdCompoundEdit
- Parameters:
presentationName
-- Returns:
- the newly created
CompoundEdit
-
makeCompoundEdit
protected CompoundEdit makeCompoundEdit(java.lang.String presentationName)
-
stopRecording
public CompoundEdit stopRecording(CompoundEdit edit)
Stops supplied edit tracking
After this method, this edit will be available for undo/redo- Parameters:
edit
-- Returns:
-
isBeeingRecording
public boolean isBeeingRecording()
Return flag indicating ifUndoManager
is currently recording.
Return true if start recording has been called- Returns:
-
isAnticipatedRecording
public boolean isAnticipatedRecording()
Return flag indicating ifUndoManager
is currently recording in anticipated mode- Returns:
-
canUndo
public boolean canUndo()
Returns true if edits may be undone.- Specified by:
canUndo
in interfacejavax.swing.undo.UndoableEdit
- Overrides:
canUndo
in classjavax.swing.undo.UndoManager
- Returns:
- true if there are edits to be undone
- See Also:
CompoundEdit.canUndo()
,editToBeUndone()
-
canUndoIfStoppingCurrentEdition
public boolean canUndoIfStoppingCurrentEdition()
Returns true if edits may be undone.
If en edition is in progress, return true if stopping this edition will cause UndoManager to be able to undo- Returns:
- true if there are edits to be undone
- See Also:
CompoundEdit.canUndo()
,editToBeUndone()
-
canRedo
public boolean canRedo()
Returns true if edits may be redone.- Specified by:
canRedo
in interfacejavax.swing.undo.UndoableEdit
- Overrides:
canRedo
in classjavax.swing.undo.UndoManager
- Returns:
- true if there are edits to be redone
- See Also:
CompoundEdit.canRedo()
,editToBeRedone()
-
addEdit
public boolean addEdit(javax.swing.undo.UndoableEdit anEdit)
Adds anUndoableEdit
to thisUndoManager
, if it's possible.- Specified by:
addEdit
in interfacejavax.swing.undo.UndoableEdit
- Overrides:
addEdit
in classjavax.swing.undo.UndoManager
-
fireAddEdit
protected void fireAddEdit(javax.swing.undo.UndoableEdit anEdit)
-
isIgnorable
public boolean isIgnorable(javax.swing.undo.UndoableEdit edit)
This should be used as a hook to intercept some edit that we dont't want to be caught during capture of UNDO edits
This method should be overriden when required.
Default implementation return false- Parameters:
edit
-- Returns:
-
editToBeUndone
public CompoundEdit editToBeUndone()
Returns the the next significant edit to be undone ifundo
is invoked. This returnsnull
if there are no edits to be undone.- Overrides:
editToBeUndone
in classjavax.swing.undo.UndoManager
- Returns:
- the next significant edit to be undone
-
editToBeRedone
public CompoundEdit editToBeRedone()
Returns the the next significant edit to be redone ifredo
is invoked. This returnsnull
if there are no edits to be redone.- Overrides:
editToBeRedone
in classjavax.swing.undo.UndoManager
- Returns:
- the next significant edit to be redone
-
undo
public void undo() throws javax.swing.undo.CannotUndoException
Undoes the appropriate edits.
Invokesundo
on all edits between the index of the next edit and the last significant edit, updating the index of the next edit appropriately.- Specified by:
undo
in interfacejavax.swing.undo.UndoableEdit
- Overrides:
undo
in classjavax.swing.undo.UndoManager
- Throws:
javax.swing.undo.CannotUndoException
- if one of the edits throwsCannotUndoException
or there are no edits to be undone- See Also:
CompoundEdit.end()
,canUndo()
,editToBeUndone()
-
fireUndo
protected void fireUndo()
-
redo
public void redo() throws javax.swing.undo.CannotUndoException
Redoes the appropriate edits.
Invokesredo
on all edits between the index of the next edit and the next significant edit, updating the index of the next edit appropriately.- Specified by:
redo
in interfacejavax.swing.undo.UndoableEdit
- Overrides:
redo
in classjavax.swing.undo.UndoManager
- Throws:
javax.swing.undo.CannotRedoException
- if one of the edits throwsCannotRedoException
or there are no edits to be redonejavax.swing.undo.CannotUndoException
- See Also:
CompoundEdit.end()
,canRedo()
,editToBeRedone()
-
fireRedo
protected void fireRedo()
-
getCurrentEdition
public CompoundEdit getCurrentEdition()
Return current edition
-
getEdits
public java.util.List<javax.swing.undo.UndoableEdit> getEdits()
-
debug
public void debug()
-
getDeletedProperty
public java.lang.String getDeletedProperty()
-
getPropertyChangeSupport
public java.beans.PropertyChangeSupport getPropertyChangeSupport()
-
getUndoPresentationName
public java.lang.String getUndoPresentationName()
Returns a description of the undoable form of this edit.- Specified by:
getUndoPresentationName
in interfacejavax.swing.undo.UndoableEdit
- Overrides:
getUndoPresentationName
in classjavax.swing.undo.UndoManager
- Returns:
- a description of the undoable form of this edit
-
isUndoInProgress
public boolean isUndoInProgress()
Return boolean indicating if undo is currently being processed
-
isRedoInProgress
public boolean isRedoInProgress()
Return boolean indicating if redo is currently being processed
-
getUndoLevel
public int getUndoLevel()
-
setUndoLevel
public void setUndoLevel(int undoLevel)
-
isEnabled
public boolean isEnabled()
-
setEnabled
public void setEnabled(boolean enabled)
-
-