Package qupath.lib.gui
Class UndoRedoManager
java.lang.Object
qupath.lib.gui.UndoRedoManager
- All Implemented Interfaces:
EventListener,ChangeListener<QuPathViewer>,QuPathViewerListener,PathObjectHierarchyListener
public class UndoRedoManager
extends Object
implements ChangeListener<QuPathViewer>, QuPathViewerListener, PathObjectHierarchyListener
Helper class to add undo/redo support to QuPath.
This is restricted to tracking changes in the PathObjectHierarchy for individual viewers, and is intended mostly for cases where there aren't many objects - but where making mistakes would be especially annoying (e.g. laboriously annotating images).
The reason is because of the (fairly simple) implementation: every time the hierarchy is changed, the entire hierarchy is serialized in case it becomes necessary to revert back.
This is a lot easier than trying to figure out how to computationally revert every conceivable change that the hierarchy might experience, but it is inevitably quite memory hungry and risks having a substantial impact on performance for large object hierarchies.
-
Method Summary
Modifier and TypeMethodDescriptioncanRedo()True if it's possible to call redoOnce for the currently-active viewer in QuPath, false otherwise.canUndo()True if it's possible to call undoOnce for the currently-active viewer in QuPath, false otherwise.voidchanged(ObservableValue<? extends QuPathViewer> observable, QuPathViewer oldValue, QuPathViewer newValue) voidclear()Clear all undo/redo stacks (useful when memory is low).static UndoRedoManagercreateForObservableViewer(ObservableValue<? extends QuPathViewer> viewerProperty) voidNotify listeners of a change in the hierarchy or its objects.voidimageDataChanged(QuPathViewer viewer, ImageData<BufferedImage> imageDataOld, ImageData<BufferedImage> imageDataNew) Called with the image data within a viewer has changed.booleanredoOnce()Request to 'redo' the last 'undone' hierarchy change for the current active viewer.voidselectedObjectChanged(QuPathViewer viewer, PathObject pathObjectSelected) Called when the primary selected object has changed in a viewer.longThe total number of bytes used for all viewers.booleanundoOnce()Request to 'undo' the last observed hierarchy change for the current active viewer.voidviewerClosed(QuPathViewer viewer) Called when a viewer is closed.voidvisibleRegionChanged(QuPathViewer viewer, Shape shape) Called when the visible region has changed in a viewer.
-
Method Details
-
createForObservableViewer
public static UndoRedoManager createForObservableViewer(ObservableValue<? extends QuPathViewer> viewerProperty) -
undoOnce
public boolean undoOnce()Request to 'undo' the last observed hierarchy change for the current active viewer.- Returns:
trueif any changes were made, false otherwise.
-
totalBytes
public long totalBytes()The total number of bytes used for all viewers.- Returns:
-
clear
public void clear()Clear all undo/redo stacks (useful when memory is low). -
redoOnce
public boolean redoOnce()Request to 'redo' the last 'undone' hierarchy change for the current active viewer.- Returns:
- True if any changes were made, false otherwise.
-
canUndo
True if it's possible to call undoOnce for the currently-active viewer in QuPath, false otherwise.- Returns:
-
canRedo
True if it's possible to call redoOnce for the currently-active viewer in QuPath, false otherwise.- Returns:
-
changed
public void changed(ObservableValue<? extends QuPathViewer> observable, QuPathViewer oldValue, QuPathViewer newValue) - Specified by:
changedin interfaceChangeListener<QuPathViewer>
-
imageDataChanged
public void imageDataChanged(QuPathViewer viewer, ImageData<BufferedImage> imageDataOld, ImageData<BufferedImage> imageDataNew) Description copied from interface:QuPathViewerListenerCalled with the image data within a viewer has changed.- Specified by:
imageDataChangedin interfaceQuPathViewerListener- Parameters:
viewer- the viewer whose image has changedimageDataOld- the image previously open in the viewerimageDataNew- the image now open in the viewer
-
visibleRegionChanged
Description copied from interface:QuPathViewerListenerCalled when the visible region has changed in a viewer.- Specified by:
visibleRegionChangedin interfaceQuPathViewerListener- Parameters:
viewer- the viewer whose visible region has changed.shape- shape representing the new visible region (in image pixel coordinates). This is rectangular, but may also be rotated.
-
selectedObjectChanged
Description copied from interface:QuPathViewerListenerCalled when the primary selected object has changed in a viewer.- Specified by:
selectedObjectChangedin interfaceQuPathViewerListener- Parameters:
viewer- the viewerpathObjectSelected-
-
viewerClosed
Description copied from interface:QuPathViewerListenerCalled when a viewer is closed.- Specified by:
viewerClosedin interfaceQuPathViewerListener- Parameters:
viewer- the viewer that has been closed.
-
hierarchyChanged
Description copied from interface:PathObjectHierarchyListenerNotify listeners of a change in the hierarchy or its objects.- Specified by:
hierarchyChangedin interfacePathObjectHierarchyListener- Parameters:
event-
-