public abstract class ALcdUndoable extends Object implements ILcdUndoable
Abstract implementation that implements all methods of ILcdUndoable
, except ILcdUndoable.undo()
and ILcdUndoable.redo()
. It keeps track of whether or
not the undoable is already undone or not and whether it is still alive (see die()
).
The implementations of undo()
and redo()
check these properties and throw a
TLcdCannotUndoRedoException when they are invoked at the wrong moment. If they are invoked at the
right moment, they call undoImpl()
and redoImpl()
respectively.
Modifier | Constructor and Description |
---|---|
protected |
ALcdUndoable(String aDisplayName)
Creates a new undoable where
aDisplayName will be used to construct all respective
display names. |
protected |
ALcdUndoable(String aDisplayName,
Format aUndoFormat,
Format aRedoFormat)
Creates a new undoable with
aDisplayName as display name. |
protected |
ALcdUndoable(String aDisplayName,
ILcdStringTranslator aStringTranslator)
Creates a new undoable where
aDisplayName will be used to construct all respective
display names. |
Modifier and Type | Method and Description |
---|---|
void |
addPropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
Registers the given
PropertyChangeListener to be notified when this object's
properties change. |
boolean |
addUndoable(ILcdUndoable aUndoable)
This default implementation does nothing with
aUndoable and returns
false . |
boolean |
canRedo()
This default implementation looks if it has been redone already.
|
protected boolean |
canRedoImpl()
Override this method if you have additional conditions that need to be met before an event
can be redone.
|
boolean |
canUndo()
This default implementation looks if it has been undone already.
|
protected boolean |
canUndoImpl()
Override this method if you have additional conditions that need to be met before an event
can be undone.
|
void |
die()
Method that might be invoked to allow for cleanup tasks.
|
protected void |
dieImpl()
Override this method with the actual die behavior.
|
String |
getDisplayName()
Returns the display name of this
ILcdUndoable . |
String |
getRedoDisplayName()
Takes the display name as defined in the constructor
ALcdUndoable(String) and formats
it with the appropriate format. |
String |
getUndoDisplayName()
Takes the display name as defined in the constructor
ALcdUndoable(String) and formats
it with the appropriate format. |
boolean |
isSignificant()
Returns false if this
ILcdUndoable is insignificant--for example one that
maintains the user's selection, but does not change any model state. |
void |
redo()
This
final implementation checks if it can be redone and if the undoable is still
alive, and if so, calls redoImpl() . |
protected abstract void |
redoImpl()
Implement this method with the actual redo behavior.
|
void |
removePropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
De-registers the given
PropertyChangeListener from receiving property change events
for this object. |
void |
undo()
This
final implementation checks if it can be undone and if the undoable is still
alive, and if so, calls undoImpl() . |
protected abstract void |
undoImpl()
Implement this method with the actual undo behavior.
|
protected ALcdUndoable(String aDisplayName)
aDisplayName
will be used to construct all respective
display names. Equivalent to ALcdUndoable( aDisplayName, new MessageFormat( "Undo {0}" ),
new MessageFormat( "Redo {0}" ) )
aDisplayName
- Used to construct the display names for undo and redo. See getUndoDisplayName()
and getRedoDisplayName()
.protected ALcdUndoable(String aDisplayName, ILcdStringTranslator aStringTranslator)
aDisplayName
will be used to construct all respective
display names. All display names will be translated with aStringTranslator
.aDisplayName
- Used to construct the display names for undo and redo. See getUndoDisplayName()
and getRedoDisplayName()
.
The constructor will translate aDisplayName
, do not pass its translation to this constructor.aStringTranslator
- Used to translate the display name + undo/redo formats.protected ALcdUndoable(String aDisplayName, Format aUndoFormat, Format aRedoFormat)
aDisplayName
as display name. The specified
Format
objects will be used to create the respective display names.aDisplayName
- The default display name for this ILcdUndoable
aUndoFormat
- The format that will be used to create the undo display name. This
Format
will be asked to format an array which contains the display name as single
element.aRedoFormat
- The format that will be used to create the redo display name. This
Format
will be asked to format an array which contains the display name as single
element.public void addPropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
ILcdPropertyChangeSource
Registers the given PropertyChangeListener
to be notified when this object's
properties change.
In case you need to register a listener which keeps a reference to an object with a shorter life-time than this change source,
you can use a ALcdWeakPropertyChangeListener
instance as property change listener.
addPropertyChangeListener
in interface ILcdPropertyChangeSource
aPropertyChangeListener
- The listener to be notifiedALcdWeakPropertyChangeListener
,
ILcdPropertyChangeSource.removePropertyChangeListener(java.beans.PropertyChangeListener)
public void removePropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
ILcdPropertyChangeSource
De-registers the given PropertyChangeListener
from receiving property change events
for this object.
If the listener was added more than once, it will be notified one less time after being
removed.
If the listener is null
, or was never added, no exception is thrown and no action is taken.
removePropertyChangeListener
in interface ILcdPropertyChangeSource
aPropertyChangeListener
- the listener that should no longer be notified of changes of
this object's propertiesILcdPropertyChangeSource.addPropertyChangeListener(java.beans.PropertyChangeListener)
public String getDisplayName()
ILcdUndoable
ILcdUndoable
. It can for example be used for
logging purposes.getDisplayName
in interface ILcdUndoable
public String getRedoDisplayName()
ALcdUndoable(String)
and formats
it with the appropriate format.getRedoDisplayName
in interface ILcdUndoable
public String getUndoDisplayName()
ALcdUndoable(String)
and formats
it with the appropriate format.getUndoDisplayName
in interface ILcdUndoable
ALcdUndoable(String, java.text.Format, java.text.Format)
public final boolean canUndo()
canUndoImpl()
is returned, otherwise false.
Alive means the die
method was not invoked yet.canUndo
in interface ILcdUndoable
false
if already undone or died, the return value of canUndoImpl
otherwise.public final boolean canRedo()
canRedoImpl()
is returned, otherwise false.
Alive means the die
method was not invoked yet.canRedo
in interface ILcdUndoable
false
if already undone or died, the return value of canRedoImpl
otherwise.public final void undo() throws TLcdCannotUndoRedoException
final
implementation checks if it can be undone and if the undoable is still
alive, and if so, calls undoImpl()
.undo
in interface ILcdUndoable
TLcdCannotUndoRedoException
- if the undoable cannot be undone, either because
canUndo
returned false or because the undoable
is no longer alivepublic final void redo() throws TLcdCannotUndoRedoException
final
implementation checks if it can be redone and if the undoable is still
alive, and if so, calls redoImpl()
.redo
in interface ILcdUndoable
TLcdCannotUndoRedoException
- if the undoable cannot be redone, either because
canRedo
returned false or because the undoable
is no longer alivepublic final void die()
ILcdUndoable
die
in interface ILcdUndoable
protected boolean canUndoImpl()
Override this method if you have additional conditions that need to be met before an event can be undone. The default implementation returns true.
protected boolean canRedoImpl()
Override this method if you have additional conditions that need to be met before an event can be redone. The default implementation returns true.
protected abstract void undoImpl() throws TLcdCannotUndoRedoException
undo()
when it is allowed to do so.TLcdCannotUndoRedoException
protected abstract void redoImpl() throws TLcdCannotUndoRedoException
redo()
when it is allowed to do so.TLcdCannotUndoRedoException
protected void dieImpl()
die()
when it is allowed to do so. The default implementation is an empty implementation.public boolean isSignificant()
ILcdUndoable
is insignificant--for example one that
maintains the user's selection, but does not change any model state. This status can be used by
an ILcdUndoableListener
(like TLcdUndoManager) when deciding which
ILcdUndoable
s to present to the user as Undo/Redo options, and which to perform as
side effects of undoing or redoing other events. This default implementation always returns true.
isSignificant
in interface ILcdUndoable
ILcdUndoable
is significant.public boolean addUndoable(ILcdUndoable aUndoable)
aUndoable
and returns
false
.addUndoable
in interface ILcdUndoable
aUndoable
- The undoable to add to this ILcdUndoable
.aUndoable
was accepted by this ILcdUndoable
.