Class ALcdUndoable

java.lang.Object
com.luciad.gui.ALcdUndoable
All Implemented Interfaces:
ILcdUndoable, ILcdPropertyChangeSource
Direct Known Subclasses:
TLcdCompositeUndoable

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.

  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    ALcdUndoable(String aDisplayName)
    Creates a new undoable where aDisplayName will be used to construct all respective display names.
    protected
    ALcdUndoable(String aDisplayName, ILcdStringTranslator aStringTranslator)
    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.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Registers the given PropertyChangeListener to be notified when this object's properties change.
    boolean
    This default implementation does nothing with aUndoable and returns false.
    final boolean
    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
    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
    Override this method with the actual die behavior.
    Returns the display name of this ILcdUndoable.
    Takes the display name as defined in the constructor ALcdUndoable(String) and formats it with the appropriate format.
    Takes the display name as defined in the constructor ALcdUndoable(String) and formats it with the appropriate format.
    boolean
    Returns false if this ILcdUndoable is insignificant--for example one that maintains the user's selection, but does not change any model state.
    final void
    This final implementation checks if it can be redone and if the undoable is still alive, and if so, calls redoImpl().
    protected abstract void
    Implement this method with the actual redo behavior.
    void
    De-registers the given PropertyChangeListener from receiving property change events for this object.
    final void
    This final implementation checks if it can be undone and if the undoable is still alive, and if so, calls undoImpl().
    protected abstract void
    Implement this method with the actual undo behavior.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ALcdUndoable

      protected ALcdUndoable(String aDisplayName)
      Creates a new undoable where aDisplayName will be used to construct all respective display names. Equivalent to ALcdUndoable( aDisplayName, new MessageFormat( "Undo {0}" ), new MessageFormat( "Redo {0}" ) )
      Parameters:
      aDisplayName - Used to construct the display names for undo and redo. See getUndoDisplayName() and getRedoDisplayName().
    • ALcdUndoable

      protected ALcdUndoable(String aDisplayName, ILcdStringTranslator aStringTranslator)
      Creates a new undoable where aDisplayName will be used to construct all respective display names. All display names will be translated with aStringTranslator.
      Parameters:
      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.
    • ALcdUndoable

      protected ALcdUndoable(String aDisplayName, Format aUndoFormat, Format aRedoFormat)
      Creates a new undoable with aDisplayName as display name. The specified Format objects will be used to create the respective display names.
      Parameters:
      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.
  • Method Details

    • addPropertyChangeListener

      public void addPropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
      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 interface ILcdPropertyChangeSource
      Parameters:
      aPropertyChangeListener - The listener to be notified
      See Also:
    • removePropertyChangeListener

      public void removePropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
      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 interface ILcdPropertyChangeSource
      Parameters:
      aPropertyChangeListener - the listener that should no longer be notified of changes of this object's properties
      See Also:
    • getDisplayName

      public String getDisplayName()
      Description copied from interface: ILcdUndoable
      Returns the display name of this ILcdUndoable. It can for example be used for logging purposes.
      Specified by:
      getDisplayName in interface ILcdUndoable
    • getRedoDisplayName

      public String getRedoDisplayName()
      Takes the display name as defined in the constructor ALcdUndoable(String) and formats it with the appropriate format.
      Specified by:
      getRedoDisplayName in interface ILcdUndoable
      Returns:
      The redo display name
    • getUndoDisplayName

      public String getUndoDisplayName()
      Takes the display name as defined in the constructor ALcdUndoable(String) and formats it with the appropriate format.
      Specified by:
      getUndoDisplayName in interface ILcdUndoable
      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 method canUndoImpl() is returned, otherwise false. Alive means the die method was not invoked yet.
      Specified by:
      canUndo in interface ILcdUndoable
      Returns:
      false if already undone or died, the return value of canUndoImpl 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 method canRedoImpl() is returned, otherwise false. Alive means the die method was not invoked yet.
      Specified by:
      canRedo in interface ILcdUndoable
      Returns:
      false if already undone or died, the return value of canRedoImpl otherwise.
    • undo

      public final void undo() throws TLcdCannotUndoRedoException
      This final implementation checks if it can be undone and if the undoable is still alive, and if so, calls undoImpl().
      Specified by:
      undo in interface ILcdUndoable
      Throws:
      TLcdCannotUndoRedoException - if the undoable cannot be undone, either because canUndo returned false or because the undoable is no longer alive
    • redo

      public final void redo() throws TLcdCannotUndoRedoException
      This final implementation checks if it can be redone and if the undoable is still alive, and if so, calls redoImpl().
      Specified by:
      redo in interface ILcdUndoable
      Throws:
      TLcdCannotUndoRedoException - if the undoable cannot be redone, either because canRedo 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 interface ILcdUndoable
    • 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

      protected abstract void undoImpl() throws TLcdCannotUndoRedoException
      Implement this method with the actual undo behavior. This method is called by undo() when it is allowed to do so.
      Throws:
      TLcdCannotUndoRedoException
    • redoImpl

      protected abstract void redoImpl() throws TLcdCannotUndoRedoException
      Implement this method with the actual redo behavior. This method is called by redo() 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 by die() when it is allowed to do so. The default implementation is an empty implementation.
    • isSignificant

      public 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. This status can be used by an ILcdUndoableListener (like TLcdUndoManager) when deciding which ILcdUndoables 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 interface ILcdUndoable
      Returns:
      Whether or not this ILcdUndoable is significant.
    • addUndoable

      public boolean addUndoable(ILcdUndoable aUndoable)
      This default implementation does nothing with aUndoable and returns false.
      Specified by:
      addUndoable in interface ILcdUndoable
      Parameters:
      aUndoable - The undoable to add to this ILcdUndoable.
      Returns:
      Whether or not aUndoable was accepted by this ILcdUndoable.