public class TLcdCompositeUndoable extends ALcdUndoable
ILcdUndoable
that is composed of several other
ILcdUndoable
s. Its undo/redo methods apply to all undoable's at once. All undoables
added to this composite undoable are undone in the reverse order in which they were added, and
redone in the order they were added.
Example:
TLcdCompositeUndoable undoable = new TLcdCompositeUndoable("composite undoable");
//Here add all necessary undoables
undoable.addUndoable(anUndoable);
undoable.addUndoable(anotherUndoable);
// indicate that all undoables have been added
undoable.finish();
Constructor and Description |
---|
TLcdCompositeUndoable(String aDisplayName)
This constructor calls the analogous superclass constructor.
|
TLcdCompositeUndoable(String aDisplayName,
Format aUndoFormat,
Format aRedoFormat)
This constructor calls the analogous superclass constructor.
|
TLcdCompositeUndoable(String aDisplayName,
ILcdStringTranslator aStringTranslator)
This constructor calls the analogous superclass constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addUndoable(ILcdUndoable aUndoable)
Adds the given
ILcdUndoable to this composite undoable. |
ILcdUndoableListener |
asListener()
Returns an
ILcdUndoableListener instance that will add each received
ILcdUndoable to this composite implementation. |
boolean |
canRedoImpl()
Returns whether or not this composite undoable can be redone.
|
boolean |
canUndoImpl()
Returns whether or not this composite undoable can be undone.
|
void |
dieImpl()
Override this method with the actual die behavior.
|
void |
finish()
Finishes this composite undoable so that no other undoables can be added to it.
|
String |
getDisplayName()
Returns the display name of this
ILcdUndoable . |
String |
getRedoDisplayName()
Takes the display name as defined in the constructor
ALcdUndoable.ALcdUndoable(String) and formats
it with the appropriate format. |
String |
getUndoDisplayName()
Takes the display name as defined in the constructor
ALcdUndoable.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. |
boolean |
isUseWrappedDisplayName()
Returns whether the display name of the wrapped undoable is used.
|
protected void |
redoImpl()
Redoes all
ILcdUndoable objects added to this composite in the order they were
added. |
void |
setUseWrappedDisplayName(boolean aUseWrappedDisplayName)
Specifies whether the display name of the contained undoable should be used when only one
undoable is wrapped in this composite undoable.
|
protected void |
undoImpl()
Undoes all added
ILcdUndoable objects added to this composite in the reverse order
they were added. |
addPropertyChangeListener, canRedo, canUndo, die, redo, removePropertyChangeListener, undo
public TLcdCompositeUndoable(String aDisplayName)
ALcdUndoable.ALcdUndoable(String)
public TLcdCompositeUndoable(String aDisplayName, Format aUndoFormat, Format aRedoFormat)
public TLcdCompositeUndoable(String aDisplayName, ILcdStringTranslator aStringTranslator)
public void setUseWrappedDisplayName(boolean aUseWrappedDisplayName)
aUseWrappedDisplayName
- true
if you want the display name of the wrapped
ILcdUndoable
to be used, false
otherwise.isUseWrappedDisplayName()
public boolean isUseWrappedDisplayName()
setUseWrappedDisplayName(boolean)
public String getDisplayName()
ILcdUndoable
ILcdUndoable
. It can for example be used for
logging purposes.getDisplayName
in interface ILcdUndoable
getDisplayName
in class ALcdUndoable
public String getUndoDisplayName()
ALcdUndoable
ALcdUndoable.ALcdUndoable(String)
and formats
it with the appropriate format.getUndoDisplayName
in interface ILcdUndoable
getUndoDisplayName
in class ALcdUndoable
ALcdUndoable.ALcdUndoable(String, java.text.Format, java.text.Format)
public String getRedoDisplayName()
ALcdUndoable
ALcdUndoable.ALcdUndoable(String)
and formats
it with the appropriate format.getRedoDisplayName
in interface ILcdUndoable
getRedoDisplayName
in class ALcdUndoable
protected void undoImpl() throws TLcdCannotUndoRedoException
ILcdUndoable
objects added to this composite in the reverse order
they were added. This means the ILcdUndoable
that was added last will be undone
first.undoImpl
in class ALcdUndoable
TLcdCannotUndoRedoException
protected void redoImpl() throws TLcdCannotUndoRedoException
ILcdUndoable
objects added to this composite in the order they were
added. This means the ILcdUndoable
that was added first will be redone first.redoImpl
in class ALcdUndoable
TLcdCannotUndoRedoException
public boolean addUndoable(ILcdUndoable aUndoable)
ILcdUndoable
to this composite undoable. This undoable will be
undone and redone, along with the other undoables that have been added. All undoables added to
this composite undoable are undone in the order in which they were added, and redone in the
reverse order they were added. Will only succeed if finish()
has not yet been called.addUndoable
in interface ILcdUndoable
addUndoable
in class ALcdUndoable
aUndoable
- The undoable to add.aUndoable
was accepted by this ILcdUndoable
.public void finish()
Finishes this composite undoable so that no other undoables can be added to it.
Do not forget to call this method when you have added all necessary undoables, as TLcdUndoManager
calls addUndoable(ILcdUndoable)
to provide multiple ILcdUndoable
instances with the option of collapsing into a single one if this is desired. For
instance several keystrokes can be combined in one undoable when a user is typing text.
public void dieImpl()
ALcdUndoable
die()
when it is allowed to do so. The default implementation is an empty implementation.dieImpl
in class ALcdUndoable
public boolean isSignificant()
ALcdUndoable
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
isSignificant
in class ALcdUndoable
ILcdUndoable
is significant.public boolean canRedoImpl()
canRedoImpl
in class ALcdUndoable
ILcdUndoable
objects to be redone.public boolean canUndoImpl()
canUndoImpl
in class ALcdUndoable
ILcdUndoable
objects to be undone.public final ILcdUndoableListener asListener()
ILcdUndoableListener
instance that will add each received
ILcdUndoable
to this composite implementation.
Each call of this method will return the same listener instance.
A typical use-case of this method is if you want to combine multiple undoables (from a single or multiple sources) into one composite undoable,
allowing the user to undo/redo multiple operations in one go:
ILcdUndoableSource firstSource = ...;
ILcdUndoableSource secondSource = ...;
TLcdCompositeUndoable undoable = new TLcdCompositeUndoable("Undo changes");
firstSource.addUndoableListener(undoable.asListener());
secondSource.addUndoableListener(undoable.asListener());
makeChanges(firstSource, secondSource);
firstSource.removeUndoableListener(undoable.asListener());
secondSource.removeUndoableListener(undoable.asListener());
undoable.finish();
fireUndoableHappened(undoable);
ILcdUndoableListener
that adds the undoables to this composite implementation