Class UndoManagerImpl<C>

java.lang.Object
org.fxmisc.undo.impl.UndoManagerImpl<C>
Type Parameters:
C - the type of change to undo/redo
All Implemented Interfaces:
UndoManager<C>
Direct Known Subclasses:
MultiChangeUndoManagerImpl

public class UndoManagerImpl<C> extends Object implements UndoManager<C>
Implementation for UndoManager for single changes. For multiple changes, see MultiChangeUndoManagerImpl.
  • Property Details

  • Field Details

    • queue

      private final ChangeQueue<C> queue
    • invert

      private final Function<? super C,? extends C> invert
    • apply

      private final Consumer<C> apply
    • merge

      private final BiFunction<C,C,Optional<C>> merge
    • isIdentity

      private final Predicate<C> isIdentity
    • subscription

      private final org.reactfx.Subscription subscription
    • performingAction

      private final org.reactfx.SuspendableNo performingAction
    • invalidationRequests

      private final org.reactfx.EventSource<Void> invalidationRequests
    • nextUndo

      private final org.reactfx.value.Val<C> nextUndo
    • nextRedo

      private final org.reactfx.value.Val<C> nextRedo
    • atMarkedPosition

      private final javafx.beans.binding.BooleanBinding atMarkedPosition
    • canMerge

      private boolean canMerge
    • mark

    • expectedChange

      private C expectedChange
  • Constructor Details

  • Method Details

    • close

      public void close()
      Description copied from interface: UndoManager
      Stops observing change events.
      Specified by:
      close in interface UndoManager<C>
    • undo

      public boolean undo()
      Description copied from interface: UndoManager
      Undo the most recent change, if there is any change to undo.
      Specified by:
      undo in interface UndoManager<C>
      Returns:
      true if a change was undone, false otherwise.
    • redo

      public boolean redo()
      Description copied from interface: UndoManager
      Redo previously undone change, if there is any change to redo.
      Specified by:
      redo in interface UndoManager<C>
      Returns:
      true if a change was redone, false otherwise.
    • nextUndoProperty

      public org.reactfx.value.Val<C> nextUndoProperty()
      Description copied from interface: UndoManager
      Gives a peek at the change that will be undone by UndoManager.undo().
      Specified by:
      nextUndoProperty in interface UndoManager<C>
      Returns:
      the nextUndo property
      See Also:
    • nextRedoProperty

      public org.reactfx.value.Val<C> nextRedoProperty()
      Description copied from interface: UndoManager
      Gives a peek at the change that will be redone by UndoManager.redo().
      Specified by:
      nextRedoProperty in interface UndoManager<C>
      Returns:
      the nextRedo property
      See Also:
    • isUndoAvailable

      public boolean isUndoAvailable()
      Specified by:
      isUndoAvailable in interface UndoManager<C>
    • undoAvailableProperty

      public org.reactfx.value.Val<Boolean> undoAvailableProperty()
      Description copied from interface: UndoManager
      Indicates whether there is a change that can be undone.
      Specified by:
      undoAvailableProperty in interface UndoManager<C>
      Returns:
      the undoAvailable property
    • isRedoAvailable

      public boolean isRedoAvailable()
      Specified by:
      isRedoAvailable in interface UndoManager<C>
    • redoAvailableProperty

      public org.reactfx.value.Val<Boolean> redoAvailableProperty()
      Description copied from interface: UndoManager
      Indicates whether there is a change that can be redone.
      Specified by:
      redoAvailableProperty in interface UndoManager<C>
      Returns:
      the redoAvailable property
    • isPerformingAction

      public boolean isPerformingAction()
      Specified by:
      isPerformingAction in interface UndoManager<C>
    • performingActionProperty

      public javafx.beans.value.ObservableBooleanValue performingActionProperty()
      Description copied from interface: UndoManager
      Indicates whether this undo manager is currently performing undo or redo action.
      Specified by:
      performingActionProperty in interface UndoManager<C>
      Returns:
      the performingAction property
    • isAtMarkedPosition

      public boolean isAtMarkedPosition()
      Specified by:
      isAtMarkedPosition in interface UndoManager<C>
    • atMarkedPositionProperty

      public javafx.beans.value.ObservableBooleanValue atMarkedPositionProperty()
      Description copied from interface: UndoManager
      Indicates whether this UndoManager's current position within its history is the same as the last marked position.
      Specified by:
      atMarkedPositionProperty in interface UndoManager<C>
      Returns:
      the atMarkedPosition property
    • getCurrentPosition

      public UndoManager.UndoPosition getCurrentPosition()
      Description copied from interface: UndoManager
      Returns the current position within this UndoManager's history.
      Specified by:
      getCurrentPosition in interface UndoManager<C>
    • preventMerge

      public void preventMerge()
      Description copied from interface: UndoManager
      Prevents the next change from being merged with the latest one.
      Specified by:
      preventMerge in interface UndoManager<C>
    • forgetHistory

      public void forgetHistory()
      Description copied from interface: UndoManager
      Forgets all changes prior to the current position in the history.
      Specified by:
      forgetHistory in interface UndoManager<C>
    • applyChange

      private boolean applyChange(boolean isChangeAvailable, Supplier<C> changeToApply)
      Helper method for reducing code duplication
      Parameters:
      isChangeAvailable - same as `isUndoAvailable()` [Undo] or `isRedoAvailable()` [Redo]
      changeToApply - same as `invert.apply(queue.prev())` [Undo] or `queue.next()` [Redo]
    • changeObserved

      private void changeObserved(C change)
    • addChange

      private void addChange(C change)
    • invalidateProperties

      private void invalidateProperties()