Class ALcdUndoable
- All Implemented Interfaces:
ILcdUndoable
,ILcdPropertyChangeSource
- Direct Known Subclasses:
TLcdCompositeUndoable
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.
-
Constructor Summary
ModifierConstructorDescriptionprotected
ALcdUndoable
(String aDisplayName) Creates a new undoable whereaDisplayName
will be used to construct all respective display names.protected
ALcdUndoable
(String aDisplayName, ILcdStringTranslator aStringTranslator) Creates a new undoable whereaDisplayName
will be used to construct all respective display names.protected
ALcdUndoable
(String aDisplayName, Format aUndoFormat, Format aRedoFormat) Creates a new undoable withaDisplayName
as display name. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addPropertyChangeListener
(PropertyChangeListener aPropertyChangeListener) Registers the givenPropertyChangeListener
to be notified when this object's properties change.boolean
addUndoable
(ILcdUndoable aUndoable) This default implementation does nothing withaUndoable
and returnsfalse
.final boolean
canRedo()
This default implementation looks if it has been redone already.protected boolean
Override this method if you have additional conditions that need to be met before an event can be redone.final boolean
canUndo()
This default implementation looks if it has been undone already.protected boolean
Override this method if you have additional conditions that need to be met before an event can be undone.final void
die()
Method that might be invoked to allow for cleanup tasks.protected void
dieImpl()
Override this method with the actual die behavior.Returns the display name of thisILcdUndoable
.Takes the display name as defined in the constructorALcdUndoable(String)
and formats it with the appropriate format.Takes the display name as defined in the constructorALcdUndoable(String)
and formats it with the appropriate format.boolean
Returns false if thisILcdUndoable
is insignificant--for example one that maintains the user's selection, but does not change any model state.final void
redo()
Thisfinal
implementation checks if it can be redone and if the undoable is still alive, and if so, callsredoImpl()
.protected abstract void
redoImpl()
Implement this method with the actual redo behavior.void
removePropertyChangeListener
(PropertyChangeListener aPropertyChangeListener) De-registers the givenPropertyChangeListener
from receiving property change events for this object.final void
undo()
Thisfinal
implementation checks if it can be undone and if the undoable is still alive, and if so, callsundoImpl()
.protected abstract void
undoImpl()
Implement this method with the actual undo behavior.
-
Constructor Details
-
ALcdUndoable
Creates a new undoable whereaDisplayName
will be used to construct all respective display names. Equivalent toALcdUndoable( aDisplayName, new MessageFormat( "Undo {0}" ), new MessageFormat( "Redo {0}" ) )
- Parameters:
aDisplayName
- Used to construct the display names for undo and redo. SeegetUndoDisplayName()
andgetRedoDisplayName()
.
-
ALcdUndoable
Creates a new undoable whereaDisplayName
will be used to construct all respective display names. All display names will be translated withaStringTranslator
.- Parameters:
aDisplayName
- Used to construct the display names for undo and redo. SeegetUndoDisplayName()
andgetRedoDisplayName()
. The constructor will translateaDisplayName
, do not pass its translation to this constructor.aStringTranslator
- Used to translate the display name + undo/redo formats.
-
ALcdUndoable
Creates a new undoable withaDisplayName
as display name. The specifiedFormat
objects will be used to create the respective display names.- Parameters:
aDisplayName
- The default display name for thisILcdUndoable
aUndoFormat
- The format that will be used to create the undo display name. ThisFormat
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. ThisFormat
will be asked to format an array which contains the display name as single element.
-
-
Method Details
-
addPropertyChangeListener
Description copied from interface: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.- Specified by:
addPropertyChangeListener
in interfaceILcdPropertyChangeSource
- Parameters:
aPropertyChangeListener
- The listener to be notified- See Also:
-
removePropertyChangeListener
Description copied from interface: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.- Specified by:
removePropertyChangeListener
in interfaceILcdPropertyChangeSource
- Parameters:
aPropertyChangeListener
- the listener that should no longer be notified of changes of this object's properties- See Also:
-
getDisplayName
Description copied from interface:ILcdUndoable
Returns the display name of thisILcdUndoable
. It can for example be used for logging purposes.- Specified by:
getDisplayName
in interfaceILcdUndoable
-
getRedoDisplayName
Takes the display name as defined in the constructorALcdUndoable(String)
and formats it with the appropriate format.- Specified by:
getRedoDisplayName
in interfaceILcdUndoable
- Returns:
- The redo display name
-
getUndoDisplayName
Takes the display name as defined in the constructorALcdUndoable(String)
and formats it with the appropriate format.- Specified by:
getUndoDisplayName
in interfaceILcdUndoable
- See Also:
-
canUndo
public final boolean canUndo()This default implementation looks if it has been undone already. If not yet undone and the undoable is still alive, the return value of the methodcanUndoImpl()
is returned, otherwise false. Alive means thedie
method was not invoked yet.- Specified by:
canUndo
in interfaceILcdUndoable
- Returns:
false
if already undone or died, the return value ofcanUndoImpl
otherwise.
-
canRedo
public final boolean canRedo()This default implementation looks if it has been redone already. If not yet redone and the undoable is still alive, the return value of the methodcanRedoImpl()
is returned, otherwise false. Alive means thedie
method was not invoked yet.- Specified by:
canRedo
in interfaceILcdUndoable
- Returns:
false
if already undone or died, the return value ofcanRedoImpl
otherwise.
-
undo
Thisfinal
implementation checks if it can be undone and if the undoable is still alive, and if so, callsundoImpl()
.- Specified by:
undo
in interfaceILcdUndoable
- Throws:
TLcdCannotUndoRedoException
- if the undoable cannot be undone, either becausecanUndo
returned false or because the undoable is no longer alive
-
redo
Thisfinal
implementation checks if it can be redone and if the undoable is still alive, and if so, callsredoImpl()
.- Specified by:
redo
in interfaceILcdUndoable
- Throws:
TLcdCannotUndoRedoException
- if the undoable cannot be redone, either becausecanRedo
returned false or because the undoable is no longer alive
-
die
public final void die()Description copied from interface:ILcdUndoable
Method that might be invoked to allow for cleanup tasks. For instance I/O streams could be closed here.- Specified by:
die
in interfaceILcdUndoable
-
canUndoImpl
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.
- Returns:
- Whether or not the addition conditions have been met.
-
canRedoImpl
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.
- Returns:
- Whether or not the addition conditions have been met.
-
undoImpl
Implement this method with the actual undo behavior. This method is called byundo()
when it is allowed to do so.- Throws:
TLcdCannotUndoRedoException
-
redoImpl
Implement this method with the actual redo behavior. This method is called byredo()
when it is allowed to do so.- Throws:
TLcdCannotUndoRedoException
-
dieImpl
protected void dieImpl()Override this method with the actual die behavior. This method is called bydie()
when it is allowed to do so. The default implementation is an empty implementation. -
isSignificant
public boolean isSignificant()Returns false if thisILcdUndoable
is insignificant--for example one that maintains the user's selection, but does not change any model state. This status can be used by anILcdUndoableListener
(like TLcdUndoManager) when deciding whichILcdUndoable
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.
- Specified by:
isSignificant
in interfaceILcdUndoable
- Returns:
- Whether or not this
ILcdUndoable
is significant.
-
addUndoable
This default implementation does nothing withaUndoable
and returnsfalse
.- Specified by:
addUndoable
in interfaceILcdUndoable
- Parameters:
aUndoable
- The undoable to add to thisILcdUndoable
.- Returns:
- Whether or not
aUndoable
was accepted by thisILcdUndoable
.
-