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.
- Author:
- Pete Bankhead
-
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.void
changed
(ObservableValue<? extends QuPathViewer> observable, QuPathViewer oldValue, QuPathViewer newValue) void
clear()
Clear all undo/redo stacks (useful when memory is low).static UndoRedoManager
createForObservableViewer
(ObservableValue<? extends QuPathViewer> viewerProperty) void
Notify listeners of a change in the hierarchy or its objects.void
imageDataChanged
(QuPathViewer viewer, ImageData<BufferedImage> imageDataOld, ImageData<BufferedImage> imageDataNew) Called with the image data within a viewer has changed.boolean
redoOnce()
Request to 'redo' the last 'undone' hierarchy change for the current active viewer.void
selectedObjectChanged
(QuPathViewer viewer, PathObject pathObjectSelected) Called when the primary selected object has changed in a viewer.long
The total number of bytes used for all viewers.boolean
undoOnce()
Request to 'undo' the last observed hierarchy change for the current active viewer.void
viewerClosed
(QuPathViewer viewer) Called when a viewer is closed.void
visibleRegionChanged
(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:
true
if 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:
changed
in interfaceChangeListener<QuPathViewer>
-
imageDataChanged
public void imageDataChanged(QuPathViewer viewer, ImageData<BufferedImage> imageDataOld, ImageData<BufferedImage> imageDataNew) Description copied from interface:QuPathViewerListener
Called with the image data within a viewer has changed.- Specified by:
imageDataChanged
in 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:QuPathViewerListener
Called when the visible region has changed in a viewer.- Specified by:
visibleRegionChanged
in 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:QuPathViewerListener
Called when the primary selected object has changed in a viewer.- Specified by:
selectedObjectChanged
in interfaceQuPathViewerListener
- Parameters:
viewer
- the viewerpathObjectSelected
-
-
viewerClosed
Description copied from interface:QuPathViewerListener
Called when a viewer is closed.- Specified by:
viewerClosed
in interfaceQuPathViewerListener
- Parameters:
viewer
- the viewer that has been closed.
-
hierarchyChanged
Description copied from interface:PathObjectHierarchyListener
Notify listeners of a change in the hierarchy or its objects.- Specified by:
hierarchyChanged
in interfacePathObjectHierarchyListener
- Parameters:
event
-
-