Class Commands

java.lang.Object
qupath.lib.gui.commands.Commands

public class Commands extends Object
Helper class implementing simple 'single-method' commands for easy inclusion in the GUI.
Author:
Pete Bankhead
  • Constructor Details

    • Commands

      public Commands()
  • Method Details

    • insertSelectedObjectsInHierarchy

      public static void insertSelectedObjectsInHierarchy(ImageData<?> imageData)
      Insert the selected objects in the hierarchy, resolving positions accordingly.

      This causes smaller 'completely-contained' annotations to be positioned below larger containing annotations, and detections to be assigned to other annotations based on centroid location.

      Parameters:
      imageData - the image data containing the hierarchy
    • promptToResolveHierarchy

      public static void promptToResolveHierarchy(ImageData<?> imageData)
      Resolve parent-child relationships within the object hierarchy. This means that objects will be arranged hierarchically, rather than as a flat list.
      Parameters:
      imageData - the image data to process
    • createFullImageAnnotation

      public static void createFullImageAnnotation(QuPathViewer viewer)
      Create a full image annotation for the image in the specified viewer. The z and t positions of the viewer will be used.
      Parameters:
      viewer - the viewer containing the image to be processed
    • editSelectedAnnotation

      public static void editSelectedAnnotation(QuPathGUI qupath)
      Prompt to edit the selected annotation by translation and rotation.

      Note that this method may change in future versions to be tied to a specified image data, rather than a specific QuPath instance.

      Parameters:
      qupath - the QuPath instance for which the object should be edited
    • showAnnotationGridView

      public static void showAnnotationGridView(QuPathGUI qupath)
      Show a grid view for annotation objects.
      Parameters:
      qupath - the QuPath instance
    • showTMACoreGridView

      public static void showTMACoreGridView(QuPathGUI qupath)
      Show a grid view for TMA core objects.
      Parameters:
      qupath - the QuPath instance
    • showDetectionMeasurementTable

      public static void showDetectionMeasurementTable(QuPathGUI qupath, ImageData<BufferedImage> imageData)
      Show a measurement table for all detection objects.
      Parameters:
      qupath - the QuPath instance
      imageData - the image data for which to show measurements
    • showCellMeasurementTable

      public static void showCellMeasurementTable(QuPathGUI qupath, ImageData<BufferedImage> imageData)
      Show a measurement table for all cell objects.
      Parameters:
      qupath - the QuPath instance
      imageData - the image data for which to show measurements
    • showAnnotationMeasurementTable

      public static void showAnnotationMeasurementTable(QuPathGUI qupath, ImageData<BufferedImage> imageData)
      Show a measurement table for all annotation objects.
      Parameters:
      qupath - the QuPath instance
      imageData - the image data for which to show measurements
    • showTMAMeasurementTable

      public static void showTMAMeasurementTable(QuPathGUI qupath, ImageData<BufferedImage> imageData)
      Show a measurement table for all TMA core objects.
      Parameters:
      qupath - the QuPath instance
      imageData - the image data for which to show measurements
    • promptToEstimateStainVectors

      public static void promptToEstimateStainVectors(ImageData<BufferedImage> imageData)
      Prompt to estimate stain vectors for the specified image, using any current region of interest.
      Parameters:
      imageData - the image data for which stain vectors should be estimated
    • promptToExportImageRegion

      public static void promptToExportImageRegion(QuPathViewer viewer, boolean renderedImage)
      Prompt to export the current image region selected in the viewer.
      Parameters:
      viewer - the viewer containing the image to export
      renderedImage - if true, export the rendered (RGB) image rather than original pixel values
    • showInstalledExtensions

      public static void showInstalledExtensions(QuPathGUI qupath)
      Show a dialog displaying the extensions installed for a specified QuPath instance.
      Parameters:
      qupath - the QuPath instance
    • showDetectionMeasurementManager

      public static void showDetectionMeasurementManager(QuPathGUI qupath, ImageData<?> imageData)
      Show a simple dialog for viewing (and optionally removing) detection measurements.
      Parameters:
      qupath -
      imageData -
    • resetTMAMetadata

      public static boolean resetTMAMetadata(ImageData<?> imageData)
      Reset TMA metadata, if available.
      Parameters:
      imageData -
      Returns:
      true if changes were made, false otherwise
    • createSingleStageAction

      public static org.controlsfx.control.action.Action createSingleStageAction(Supplier<Stage> supplier)
      Create a command that generates a persistent single dialog on demand. A reference to the dialog can be retained, so that if the command is called again either the original dialog is shown and/or brought to the front.
      Parameters:
      supplier - supplier function to generate the dialog on demand
      Returns:
      the action
    • createSingleStageAction

      public static org.controlsfx.control.action.Action createSingleStageAction(Supplier<Stage> supplier, String name)
      Create a named command that generates a persistent single dialog on demand. A reference to the dialog can be retained, so that if the command is called again either the original dialog is shown and/or brought to the front.
      Parameters:
      supplier - supplier function to generate the dialog on demand
      name -
      Returns:
      the action
    • createMeasurementMapDialog

      public static Stage createMeasurementMapDialog(QuPathGUI qupath)
      Create a dialog for displaying measurement maps.
      Parameters:
      qupath - the QuPathGUI instance to which the maps refer
      Returns:
      a measurement map dialog
    • showScriptInterpreter

      public static void showScriptInterpreter(QuPathGUI qupath)
      Show a script interpreter window for a Qupath instance.
      Parameters:
      qupath - the QuPath instance
    • createLicensesWindow

      public static Stage createLicensesWindow(QuPathGUI qupath)
      Create a window summarizing license information for QuPath and its third party dependencies.
      Parameters:
      qupath - the current QuPath instance
      Returns:
      a window to display license information
    • createShowSystemInfoDialog

      public static Stage createShowSystemInfoDialog(QuPathGUI qupath)
      Create a window summarizing key system information relevant for QuPath.
      Parameters:
      qupath - the current QuPath instance
      Returns:
      a window to display license information
    • createPreferencesDialog

      public static Stage createPreferencesDialog(QuPathGUI qupath)
      Show a dialog to adjust QuPath preferences.
      Parameters:
      qupath - the QuPath instance
      Returns:
      window to use to display preferences
    • createRotateImageDialog

      public static void createRotateImageDialog(QuPathGUI qupath)
      Create a dialog for rotating the image in the current viewer (for display only).
      Parameters:
      qupath - the QuPathGUI instance
    • createZoomCommand

      public static org.controlsfx.control.action.Action createZoomCommand(QuPathGUI qupath, int zoomAmount)
      Create a zoom in/out command action.
      Parameters:
      qupath - QuPath instance
      zoomAmount - relative amount to zoom in (positive) or out (negative). Suggested value is +/-10.
      Returns:
    • createSpecifyAnnotationDialog

      public static Stage createSpecifyAnnotationDialog(QuPathGUI qupath)
      Create a stage to prompt the user to specify an annotation to add.
      Parameters:
      qupath -
      Returns:
    • createObjectDescriptionsDialog

      public static Stage createObjectDescriptionsDialog(QuPathGUI qupath)
      Create a stage to display object descriptions.
      Parameters:
      qupath -
      Returns:
    • promptToSaveImageData

      public static boolean promptToSaveImageData(QuPathGUI qupath, ImageData<BufferedImage> imageData, boolean overwriteExisting)
      Prompt to save the specified ImageData.
      Parameters:
      qupath -
      imageData -
      overwriteExisting -
      Returns:
    • saveSnapshot

      public static boolean saveSnapshot(QuPathGUI qupath, GuiTools.SnapshotType type)
      Save an image snapshot, prompting the user to select the output file.
      Parameters:
      qupath - the QuPathGUI instance to snapshot
      type - the snapshot type
      Returns:
      true if a snapshot was saved, false otherwise
    • mergeSelectedAnnotations

      public static void mergeSelectedAnnotations(ImageData<?> imageData)
      Merge the currently-selected annotations for an image, replacing them with a single new annotation.
      Parameters:
      imageData -
    • duplicateSelectedAnnotations

      public static void duplicateSelectedAnnotations(ImageData<?> imageData)
      Duplicate the selected annotations.
      Parameters:
      imageData -
    • copySelectedAnnotationsToCurrentPlane

      public static void copySelectedAnnotationsToCurrentPlane(QuPathViewer viewer)
      Copy the selected objects and add them to the plane currently active in the viewer.
      Parameters:
      viewer - the viewer that determines the current image and plane
    • makeInverseAnnotation

      public static void makeInverseAnnotation(ImageData<?> imageData)
      Make an inverse annotation for the selected objects, storing the command in the history workflow.
      Parameters:
      imageData -
      See Also:
    • showViewTracker

      public static void showViewTracker(QuPathGUI qupath)
      Show a dialog to track the viewed region of an image.
      Parameters:
      qupath -
    • combineSelectedAnnotations

      public static boolean combineSelectedAnnotations(ImageData<?> imageData, RoiTools.CombineOp op)
      Combine the selected annotations for the specified hierarchy.
      Parameters:
      imageData - the image data to process
      op - the RoiTools.CombineOp operation to apply
      Returns:
      true if changes were made, false otherwise
    • promptToSelectObjectsByClassification

      public static void promptToSelectObjectsByClassification(QuPathGUI qupath, ImageData<?> imageData)
      Prompt to select objects according to their classifications.
      Parameters:
      qupath -
      imageData -
    • promptToEditClass

      public static boolean promptToEditClass(PathClass pathClass)
      Prompt to edit the name/color of a class.
      Parameters:
      pathClass -
      Returns:
    • selectObjectsByClassification

      public static boolean selectObjectsByClassification(ImageData<?> imageData, PathClass... pathClasses)
      Select objects by classification, logging the step (if performed) in the history workflow.
      Parameters:
      imageData - the ImageData containing objects to be selected
      pathClasses - classifications that will result in an object being selected
      Returns:
      true if a selection command was run, false otherwise (e.g. if no pathClasses were specified)
    • promptToDeleteObjects

      public static void promptToDeleteObjects(ImageData<?> imageData, Class<? extends PathObject> cls)
      Prompt to delete objects of a specified type, or all objects.
      Parameters:
      imageData -
      cls -
    • promptToResetPreferences

      public static boolean promptToResetPreferences()
      Reset QuPath's preferences, after confirming with the user. QuPath needs to be restarted for this to take effect.
      Returns:
      true if the preferences were reset, false otherwise
    • setViewerDownsample

      public static void setViewerDownsample(QuPathViewer viewer, double downsample)
      Set the downsample factor for the specified viewer.
      Parameters:
      viewer -
      downsample -
    • closeProject

      public static void closeProject(QuPathGUI qupath)
      Close the current project open in the QuPathGUI.
      Parameters:
      qupath -
    • promptToCreateProject

      public static boolean promptToCreateProject(QuPathGUI qupath)
      Prompt the user to select an empty directory, and use this to create a new project and set it as active.
      Parameters:
      qupath - the QuPathGUI instance for which the project should be created.
      Returns:
      true if a project was created, false otherwise (e.g. the user cancelled).
    • promptToOpenProject

      public static boolean promptToOpenProject(QuPathGUI qupath)
      Prompt the user to open an existing project and set it as active.
      Parameters:
      qupath - the QuPathGUI instance for which the project should be opened.
      Returns:
      true if a project was opened, false otherwise (e.g. the user cancelled).
    • launchTMADataViewer

      public static void launchTMADataViewer(QuPathGUI qupath)
      Open new window with the TMA data viewer.
      Parameters:
      qupath - current QuPathGUI instance (may be null).
    • distanceToAnnotations2D

      public static void distanceToAnnotations2D(ImageData<?> imageData, boolean signedDistances)
      Compute the distance between all detections and the closest annotation, for all annotation classifications.
      Parameters:
      imageData - the image data to process
      signedDistances - if true, use signed distances
    • detectionCentroidDistances2D

      public static void detectionCentroidDistances2D(ImageData<?> imageData)
      Compute the distance between the centroids of all detections, for all available classifications.
      Parameters:
      imageData - the image data to process
    • promptToSetGridLineSpacing

      public static void promptToSetGridLineSpacing(OverlayOptions options)
      Prompt to input the spacing for the grid lines optionally displayed on viewers.
      Parameters:
      options - the OverlayOptions that manage the grid lines.
    • requestUserDirectory

      public static File requestUserDirectory(boolean promptIfMissing)
      Request the current user directory, optionally prompting the user to request a directory if none is available.
      Parameters:
      promptIfMissing -
      Returns:
      the user directory, or null if none exists and the user did not create one
    • reloadImageData

      public static void reloadImageData(QuPathGUI qupath, ImageData<BufferedImage> imageData)
      Reload the specified image data from a previously saved version,if available.
      Parameters:
      qupath -
      imageData -
    • promptToAddShapeFeatures

      public static void promptToAddShapeFeatures(QuPathGUI qupath)
      Prompt to add shape features for selected objects.
      Parameters:
      qupath - current QuPath instance
    • convertDetectionsToPoints

      public static void convertDetectionsToPoints(ImageData<?> imageData, boolean preferNucleus)
      Convert detection objects to point annotations based upon their ROI centroids.
      Parameters:
      imageData - the image data to process
      preferNucleus - if true, use a nucleus ROI for cell objects (if available
    • promptToSimplifySelectedAnnotations

      public static void promptToSimplifySelectedAnnotations(ImageData<?> imageData, double altitudeThreshold)
      Show a prompt to selected annotations in a hierarchy.
      Parameters:
      imageData - the current image data
      altitudeThreshold - default altitude value for simplification
    • selectObjectsOnCurrentPlane

      public static void selectObjectsOnCurrentPlane(QuPathViewer viewer)
      Select all the objects on the current plane of the viewer.
      Parameters:
      viewer -
    • selectAllObjects

      public static void selectAllObjects(ImageData<?> imageData)
      Select all objects (excluding the root object) in the imageData.
      Parameters:
      imageData -
    • selectObjectsByClass

      public static void selectObjectsByClass(ImageData<?> imageData, Class<? extends PathObject> cls)
      Select objects that are instances of a specified class, logging an appropriate method in the workflow.
      Parameters:
      imageData -
      cls -
    • resetSelection

      public static void resetSelection(ImageData<?> imageData)
      Reset the selection for an image.
      Parameters:
      imageData -
    • resetClassifications

      public static void resetClassifications(ImageData<?> imageData, Class<? extends PathObject> cls)
      Select objects that are instances of a specified class, logging an appropriate method in the workflow.
      Parameters:
      imageData -
      cls -
    • createWorkflowDisplayDialog

      public static Stage createWorkflowDisplayDialog(QuPathGUI qupath)
      Create a dialog to show the workflow history for the current image data.
      Parameters:
      qupath - the QuPath instance
      Returns:
      a workflow display dialog
    • showWorkflowScript

      public static void showWorkflowScript(QuPathGUI qupath, ImageData<?> imageData)
      Show the QuPath script editor with a script corresponding to the command history of a specified image.
      Parameters:
      qupath -
      imageData -
    • showScriptEditor

      public static void showScriptEditor(QuPathGUI qupath)
      Show the script editor, or bring the window to the front if it is already open.
      Parameters:
      qupath -
    • createMemoryMonitorDialog

      public static Stage createMemoryMonitorDialog(QuPathGUI qupath)
      Create a dialog to monitor memory usage.
      Parameters:
      qupath -
      Returns:
    • showMiniViewer

      public static void showMiniViewer(QuPathViewer viewer)
      Show a mini viewer window associated with a specific viewer.
      Parameters:
      viewer - the viewer with which to associate this window
    • showChannelViewer

      public static void showChannelViewer(QuPathViewer viewer)
      Show a channel viewer window associated with a specific viewer.
      Parameters:
      viewer - the viewer with which to associate this window
    • refreshObjectIDs

      public static void refreshObjectIDs(ImageData<?> imageData, boolean duplicatesOnly)
      Refresh object IDs to ensure uniqueness.
      Parameters:
      imageData -
      duplicatesOnly - only refresh IDs that are duplicates of other IDs
    • runObjectImport

      public static void runObjectImport(QuPathGUI qupath, ImageData<BufferedImage> imageData)
      Show a dialog to import object(s) from a file.
      Parameters:
      qupath -
      imageData -
    • copySelectedObjectsToClipboard

      public static void copySelectedObjectsToClipboard(ImageData<BufferedImage> imageData)
      Attempt to copy selected objects to the system clipboard, if available
      Parameters:
      imageData -
    • copyAnnotationsToClipboard

      public static void copyAnnotationsToClipboard(ImageData<BufferedImage> imageData)
      Attempt to annotation objects to the system clipboard, if available
      Parameters:
      imageData -
    • pasteFromClipboard

      public static void pasteFromClipboard(QuPathGUI qupath, boolean addToCurrentPlane)
      Attempt to paste objects from the system clipboard to the current image, if available; otherwise, check for text on the clipboard and paste it into a new script editor tab
      Parameters:
      qupath -
      addToCurrentPlane - if true, add the objects to the plane currently visible in the viewer (and don't show any text if objects can't be found)
    • runGeoJsonObjectExport

      public static void runGeoJsonObjectExport(QuPathGUI qupath, ImageData<BufferedImage> imageData)
      Show a dialog to export object(s) to a GeoJSON file.
      Parameters:
      qupath -
      imageData -