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 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

      public ReadOnlyBooleanProperty canUndo()
      True if it's possible to call undoOnce for the currently-active viewer in QuPath, false otherwise.
      Returns:
    • canRedo

      public ReadOnlyBooleanProperty 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 interface ChangeListener<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 interface QuPathViewerListener
      Parameters:
      viewer - the viewer whose image has changed
      imageDataOld - the image previously open in the viewer
      imageDataNew - the image now open in the viewer
    • visibleRegionChanged

      public void visibleRegionChanged(QuPathViewer viewer, Shape shape)
      Description copied from interface: QuPathViewerListener
      Called when the visible region has changed in a viewer.
      Specified by:
      visibleRegionChanged in interface QuPathViewerListener
      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

      public void selectedObjectChanged(QuPathViewer viewer, PathObject pathObjectSelected)
      Description copied from interface: QuPathViewerListener
      Called when the primary selected object has changed in a viewer.
      Specified by:
      selectedObjectChanged in interface QuPathViewerListener
      Parameters:
      viewer - the viewer
      pathObjectSelected -
    • viewerClosed

      public void viewerClosed(QuPathViewer viewer)
      Description copied from interface: QuPathViewerListener
      Called when a viewer is closed.
      Specified by:
      viewerClosed in interface QuPathViewerListener
      Parameters:
      viewer - the viewer that has been closed.
    • hierarchyChanged

      public void hierarchyChanged(PathObjectHierarchyEvent event)
      Description copied from interface: PathObjectHierarchyListener
      Notify listeners of a change in the hierarchy or its objects.
      Specified by:
      hierarchyChanged in interface PathObjectHierarchyListener
      Parameters:
      event -