Package org.fxmisc.undo.impl
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 java.lang.Object implements UndoManager<C>
Implementation forUndoManagerfor single changes. For multiple changes, seeMultiChangeUndoManagerImpl.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classUndoManagerImpl.UndoPositionImpl-
Nested classes/interfaces inherited from interface org.fxmisc.undo.UndoManager
UndoManager.UndoPosition
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.function.Consumer<C>applyprivate javafx.beans.binding.BooleanBindingatMarkedPositionprivate booleancanMergeprivate CexpectedChangeprivate org.reactfx.EventSource<java.lang.Void>invalidationRequestsprivate java.util.function.Function<? super C,? extends C>invertprivate java.util.function.Predicate<C>isIdentityprivate ChangeQueue.QueuePositionmarkprivate java.util.function.BiFunction<C,C,java.util.Optional<C>>mergeprivate org.reactfx.value.Val<C>nextRedoprivate org.reactfx.value.Val<C>nextUndoprivate org.reactfx.SuspendableNoperformingActionprivate ChangeQueue<C>queueprivate org.reactfx.Subscriptionsubscription
-
Constructor Summary
Constructors Constructor Description UndoManagerImpl(ChangeQueue<C> queue, java.util.function.Function<? super C,? extends C> invert, java.util.function.Consumer<C> apply, java.util.function.BiFunction<C,C,java.util.Optional<C>> merge, java.util.function.Predicate<C> isIdentity, org.reactfx.EventStream<C> changeSource)UndoManagerImpl(ChangeQueue<C> queue, java.util.function.Function<? super C,? extends C> invert, java.util.function.Consumer<C> apply, java.util.function.BiFunction<C,C,java.util.Optional<C>> merge, java.util.function.Predicate<C> isIdentity, org.reactfx.EventStream<C> changeSource, java.time.Duration preventMergeDelay)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddChange(C change)private booleanapplyChange(boolean isChangeAvailable, java.util.function.Supplier<C> changeToApply)Helper method for reducing code duplicationjavafx.beans.value.ObservableBooleanValueatMarkedPositionProperty()Indicates whether this UndoManager's current position within its history is the same as the last marked position.private voidchangeObserved(C change)voidclose()Stops observing change events.voidforgetHistory()Forgets all changes prior to the current position in the history.UndoManager.UndoPositiongetCurrentPosition()Returns the current position within this UndoManager's history.private voidinvalidateProperties()booleanisAtMarkedPosition()booleanisPerformingAction()booleanisRedoAvailable()booleanisUndoAvailable()org.reactfx.value.Val<C>nextRedoProperty()Gives a peek at the change that will be redone byUndoManager.redo().org.reactfx.value.Val<C>nextUndoProperty()Gives a peek at the change that will be undone byUndoManager.undo().javafx.beans.value.ObservableBooleanValueperformingActionProperty()Indicates whether this undo manager is currently performing undo or redo action.voidpreventMerge()Prevents the next change from being merged with the latest one.booleanredo()Redo previously undone change, if there is any change to redo.org.reactfx.value.Val<java.lang.Boolean>redoAvailableProperty()Indicates whether there is a change that can be redone.booleanundo()Undo the most recent change, if there is any change to undo.org.reactfx.value.Val<java.lang.Boolean>undoAvailableProperty()Indicates whether there is a change that can be undone.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.fxmisc.undo.UndoManager
getNextRedo, getNextUndo, mark
-
-
-
-
Field Detail
-
queue
private final ChangeQueue<C> queue
-
apply
private final java.util.function.Consumer<C> apply
-
isIdentity
private final java.util.function.Predicate<C> isIdentity
-
subscription
private final org.reactfx.Subscription subscription
-
performingAction
private final org.reactfx.SuspendableNo performingAction
-
invalidationRequests
private final org.reactfx.EventSource<java.lang.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
private ChangeQueue.QueuePosition mark
-
expectedChange
private C expectedChange
-
-
Constructor Detail
-
UndoManagerImpl
public UndoManagerImpl(ChangeQueue<C> queue, java.util.function.Function<? super C,? extends C> invert, java.util.function.Consumer<C> apply, java.util.function.BiFunction<C,C,java.util.Optional<C>> merge, java.util.function.Predicate<C> isIdentity, org.reactfx.EventStream<C> changeSource)
-
UndoManagerImpl
public UndoManagerImpl(ChangeQueue<C> queue, java.util.function.Function<? super C,? extends C> invert, java.util.function.Consumer<C> apply, java.util.function.BiFunction<C,C,java.util.Optional<C>> merge, java.util.function.Predicate<C> isIdentity, org.reactfx.EventStream<C> changeSource, java.time.Duration preventMergeDelay)
-
-
Method Detail
-
close
public void close()
Description copied from interface:UndoManagerStops observing change events.- Specified by:
closein interfaceUndoManager<C>
-
undo
public boolean undo()
Description copied from interface:UndoManagerUndo the most recent change, if there is any change to undo.- Specified by:
undoin interfaceUndoManager<C>- Returns:
trueif a change was undone,falseotherwise.
-
redo
public boolean redo()
Description copied from interface:UndoManagerRedo previously undone change, if there is any change to redo.- Specified by:
redoin interfaceUndoManager<C>- Returns:
trueif a change was redone,falseotherwise.
-
nextUndoProperty
public org.reactfx.value.Val<C> nextUndoProperty()
Description copied from interface:UndoManagerGives a peek at the change that will be undone byUndoManager.undo().- Specified by:
nextUndoPropertyin interfaceUndoManager<C>
-
nextRedoProperty
public org.reactfx.value.Val<C> nextRedoProperty()
Description copied from interface:UndoManagerGives a peek at the change that will be redone byUndoManager.redo().- Specified by:
nextRedoPropertyin interfaceUndoManager<C>
-
isUndoAvailable
public boolean isUndoAvailable()
- Specified by:
isUndoAvailablein interfaceUndoManager<C>
-
undoAvailableProperty
public org.reactfx.value.Val<java.lang.Boolean> undoAvailableProperty()
Description copied from interface:UndoManagerIndicates whether there is a change that can be undone.- Specified by:
undoAvailablePropertyin interfaceUndoManager<C>
-
isRedoAvailable
public boolean isRedoAvailable()
- Specified by:
isRedoAvailablein interfaceUndoManager<C>
-
redoAvailableProperty
public org.reactfx.value.Val<java.lang.Boolean> redoAvailableProperty()
Description copied from interface:UndoManagerIndicates whether there is a change that can be redone.- Specified by:
redoAvailablePropertyin interfaceUndoManager<C>
-
isPerformingAction
public boolean isPerformingAction()
- Specified by:
isPerformingActionin interfaceUndoManager<C>
-
performingActionProperty
public javafx.beans.value.ObservableBooleanValue performingActionProperty()
Description copied from interface:UndoManagerIndicates whether this undo manager is currently performing undo or redo action.- Specified by:
performingActionPropertyin interfaceUndoManager<C>
-
isAtMarkedPosition
public boolean isAtMarkedPosition()
- Specified by:
isAtMarkedPositionin interfaceUndoManager<C>
-
atMarkedPositionProperty
public javafx.beans.value.ObservableBooleanValue atMarkedPositionProperty()
Description copied from interface:UndoManagerIndicates whether this UndoManager's current position within its history is the same as the last marked position.- Specified by:
atMarkedPositionPropertyin interfaceUndoManager<C>
-
getCurrentPosition
public UndoManager.UndoPosition getCurrentPosition()
Description copied from interface:UndoManagerReturns the current position within this UndoManager's history.- Specified by:
getCurrentPositionin interfaceUndoManager<C>
-
preventMerge
public void preventMerge()
Description copied from interface:UndoManagerPrevents the next change from being merged with the latest one.- Specified by:
preventMergein interfaceUndoManager<C>
-
forgetHistory
public void forgetHistory()
Description copied from interface:UndoManagerForgets all changes prior to the current position in the history.- Specified by:
forgetHistoryin interfaceUndoManager<C>
-
applyChange
private boolean applyChange(boolean isChangeAvailable, java.util.function.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()
-
-