Package qupath.lib.gui.commands
Class Commands
java.lang.Object
qupath.lib.gui.commands.Commands
Helper class implementing simple 'single-method' commands for easy inclusion in the GUI.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
closeProject
(QuPathGUI qupath) Close the current project open in theQuPathGUI
.static boolean
combineSelectedAnnotations
(ImageData<?> imageData, RoiTools.CombineOp op) Combine the selected annotations for the specified hierarchy.static void
convertDetectionsToPoints
(ImageData<?> imageData, boolean preferNucleus) Convert detection objects to point annotations based upon their ROI centroids.static void
copyAnnotationsToClipboard
(ImageData<BufferedImage> imageData) Attempt to annotation objects to the system clipboard, if availablestatic void
Copy the selected objects and add them to the plane currently active in the viewer.static void
copySelectedObjectsToClipboard
(ImageData<BufferedImage> imageData) Attempt to copy selected objects to the system clipboard, if availablestatic void
Create a full image annotation for the image in the specified viewer.static Stage
createLicensesWindow
(QuPathGUI qupath) Create a window summarizing license information for QuPath and its third party dependencies.static Stage
createMeasurementMapDialog
(QuPathGUI qupath) Create a dialog for displaying measurement maps.static Stage
createMemoryMonitorDialog
(QuPathGUI qupath) Create a dialog to monitor memory usage.static Stage
Create a stage to display object descriptions.static Stage
createPreferencesDialog
(QuPathGUI qupath) Show a dialog to adjust QuPath preferences.static void
createRotateImageDialog
(QuPathGUI qupath) Create a dialog for rotating the image in the current viewer (for display only).static Stage
createShowSystemInfoDialog
(QuPathGUI qupath) Create a window summarizing key system information relevant for QuPath.static org.controlsfx.control.action.Action
createSingleStageAction
(Supplier<Stage> supplier) Create a command that generates a persistent single dialog on demand.static org.controlsfx.control.action.Action
createSingleStageAction
(Supplier<Stage> supplier, String name) Create a named command that generates a persistent single dialog on demand.static Stage
Create a stage to prompt the user to specify an annotation to add.static Stage
createWorkflowDisplayDialog
(QuPathGUI qupath) Create a dialog to show the workflow history for the current image data.static org.controlsfx.control.action.Action
createZoomCommand
(QuPathGUI qupath, int zoomAmount) Create a zoom in/out command action.static void
detectionCentroidDistances2D
(ImageData<?> imageData) Compute the distance between the centroids of all detections, for all available classifications.static void
distanceToAnnotations2D
(ImageData<?> imageData, boolean signedDistances) Compute the distance between all detections and the closest annotation, for all annotation classifications.static void
duplicateSelectedAnnotations
(ImageData<?> imageData) Duplicate the selected annotations.static void
editSelectedAnnotation
(QuPathGUI qupath) Prompt to edit the selected annotation by translation and rotation.static void
insertSelectedObjectsInHierarchy
(ImageData<?> imageData) Insert the selected objects in the hierarchy, resolving positions accordingly.static void
launchTMADataViewer
(QuPathGUI qupath) Open new window with the TMA data viewer.static void
makeInverseAnnotation
(ImageData<?> imageData) Make an inverse annotation for the selected objects, storing the command in the history workflow.static void
mergeSelectedAnnotations
(ImageData<?> imageData) Merge the currently-selected annotations for an image, replacing them with a single new annotation.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 tabstatic void
promptToAddShapeFeatures
(QuPathGUI qupath) Prompt to add shape features for selected objects.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.static void
promptToDeleteObjects
(ImageData<?> imageData, Class<? extends PathObject> cls) Prompt to delete objects of a specified type, or all objects.static boolean
promptToEditClass
(PathClass pathClass) Prompt to edit the name/color of a class.static void
promptToEstimateStainVectors
(ImageData<BufferedImage> imageData) Prompt to estimate stain vectors for the specified image, using any current region of interest.static void
promptToExportImageRegion
(QuPathViewer viewer, boolean renderedImage) Prompt to export the current image region selected in the viewer.static boolean
promptToOpenProject
(QuPathGUI qupath) Prompt the user to open an existing project and set it as active.static boolean
Reset QuPath's preferences, after confirming with the user.static void
promptToResolveHierarchy
(ImageData<?> imageData) Resolve parent-child relationships within the object hierarchy.static boolean
promptToSaveImageData
(QuPathGUI qupath, ImageData<BufferedImage> imageData, boolean overwriteExisting) Prompt to save the specifiedImageData
.static void
promptToSelectObjectsByClassification
(QuPathGUI qupath, ImageData<?> imageData) Prompt to select objects according to their classifications.static void
promptToSetGridLineSpacing
(OverlayOptions options) Prompt to input the spacing for the grid lines optionally displayed on viewers.static void
promptToSimplifySelectedAnnotations
(ImageData<?> imageData, double altitudeThreshold) Show a prompt to selected annotations in a hierarchy.static void
refreshObjectIDs
(ImageData<?> imageData, boolean duplicatesOnly) Refresh object IDs to ensure uniqueness.static void
reloadImageData
(QuPathGUI qupath, ImageData<BufferedImage> imageData) Reload the specified image data from a previously saved version,if available.static void
removeOnImageBounds
(ImageData<?> imageData) Delete all objects touching the image boundary.static File
requestUserDirectory
(boolean promptIfMissing) Request the current user directory, optionally prompting the user to request a directory if none is available.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.static void
resetSelection
(ImageData<?> imageData) Reset the selection for an image.static boolean
resetTMAMetadata
(ImageData<?> imageData) Reset TMA metadata, if available.static void
runGeoJsonObjectExport
(QuPathGUI qupath, ImageData<BufferedImage> imageData) Show a dialog to export object(s) to a GeoJSON file.static void
runObjectImport
(QuPathGUI qupath, ImageData<BufferedImage> imageData) Show a dialog to import object(s) from a file.static boolean
saveSnapshot
(QuPathGUI qupath, GuiTools.SnapshotType type) Save an image snapshot, prompting the user to select the output file.static void
saveSnapshotWithDelay
(QuPathGUI qupath, GuiTools.SnapshotType type, long delayMillis) Save an image snapshot after a specified delay, prompting the user to select the output file.static void
selectAllObjects
(ImageData<?> imageData) Select all objects (excluding the root object) in the imageData.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.static boolean
selectObjectsByClassification
(ImageData<?> imageData, PathClass... pathClasses) Select objects by classification, logging the step (if performed) in the history workflow.static void
Select all the objects on the current plane of the viewer.static void
setViewerDownsample
(QuPathViewer viewer, double downsample) Set the downsample factor for the specified viewer.static void
showAnnotationGridView
(QuPathGUI qupath) Show a grid view for annotation objects.static void
showAnnotationMeasurementTable
(QuPathGUI qupath, ImageData<BufferedImage> imageData) Show a measurement table for all annotation objects.static void
showCellMeasurementTable
(QuPathGUI qupath, ImageData<BufferedImage> imageData) Show a measurement table for all cell objects.static void
showChannelViewer
(QuPathViewer viewer) Show a channel viewer window associated with a specific viewer.static void
showDetectionMeasurementManager
(QuPathGUI qupath, ImageData<?> imageData) Show a simple dialog for viewing (and optionally removing) detection measurements.static void
showDetectionMeasurementTable
(QuPathGUI qupath, ImageData<BufferedImage> imageData) Show a measurement table for all detection objects.static void
showInstalledExtensions
(QuPathGUI qupath) Show a dialog displaying the extensions installed for a specified QuPath instance.static void
showMiniViewer
(QuPathViewer viewer) Show a mini viewer window associated with a specific viewer.static void
showScriptEditor
(QuPathGUI qupath) Show the script editor, or bring the window to the front if it is already open.static void
showScriptInterpreter
(QuPathGUI qupath) Show a script interpreter window for a Qupath instance.static void
showTMACoreGridView
(QuPathGUI qupath) Show a grid view for TMA core objects.static void
showTMAMeasurementTable
(QuPathGUI qupath, ImageData<BufferedImage> imageData) Show a measurement table for all TMA core objects.static void
showViewTracker
(QuPathGUI qupath) Show a dialog to track the viewed region of an image.static void
showWorkflowScript
(QuPathGUI qupath, ImageData<?> imageData) Show the QuPath script editor with a script corresponding to the command history of a specified image.
-
Constructor Details
-
Commands
public Commands()
-
-
Method Details
-
insertSelectedObjectsInHierarchy
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
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
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
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
Show a grid view for annotation objects.- Parameters:
qupath
- the QuPath instance
-
showTMACoreGridView
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 instanceimageData
- the image data for which to show measurements
-
showCellMeasurementTable
Show a measurement table for all cell objects.- Parameters:
qupath
- the QuPath instanceimageData
- 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 instanceimageData
- the image data for which to show measurements
-
showTMAMeasurementTable
Show a measurement table for all TMA core objects.- Parameters:
qupath
- the QuPath instanceimageData
- the image data for which to show measurements
-
promptToEstimateStainVectors
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
Prompt to export the current image region selected in the viewer.- Parameters:
viewer
- the viewer containing the image to exportrenderedImage
- if true, export the rendered (RGB) image rather than original pixel values
-
showInstalledExtensions
Show a dialog displaying the extensions installed for a specified QuPath instance.- Parameters:
qupath
- the QuPath instance
-
showDetectionMeasurementManager
Show a simple dialog for viewing (and optionally removing) detection measurements.- Parameters:
qupath
- the qupath GUIimageData
- the image data
-
resetTMAMetadata
Reset TMA metadata, if available.- Parameters:
imageData
- the image data- 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 demandname
- the command name (for the Action)- Returns:
- the action
-
createMeasurementMapDialog
Create a dialog for displaying measurement maps.- Parameters:
qupath
- theQuPathGUI
instance to which the maps refer- Returns:
- a measurement map dialog
-
showScriptInterpreter
Show a script interpreter window for a Qupath instance.- Parameters:
qupath
- the QuPath instance
-
createLicensesWindow
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
Create a window summarizing key system information relevant for QuPath.- Parameters:
qupath
- the current QuPath instance- Returns:
- a window to display license information
-
createPreferencesDialog
Show a dialog to adjust QuPath preferences.- Parameters:
qupath
- the QuPath instance- Returns:
- window to use to display preferences
-
createRotateImageDialog
Create a dialog for rotating the image in the current viewer (for display only).- Parameters:
qupath
- theQuPathGUI
instance
-
createZoomCommand
public static org.controlsfx.control.action.Action createZoomCommand(QuPathGUI qupath, int zoomAmount) Create a zoom in/out command action.- Parameters:
qupath
- QuPath instancezoomAmount
- relative amount to zoom in (positive) or out (negative). Suggested value is +/-10.- Returns:
- an action
-
createSpecifyAnnotationDialog
Create a stage to prompt the user to specify an annotation to add.- Parameters:
qupath
- the qupath GUI- Returns:
- a stage
-
createObjectDescriptionsDialog
Create a stage to display object descriptions.- Parameters:
qupath
- the qupath GUI- Returns:
- a stage
-
promptToSaveImageData
public static boolean promptToSaveImageData(QuPathGUI qupath, ImageData<BufferedImage> imageData, boolean overwriteExisting) Prompt to save the specifiedImageData
.- Parameters:
qupath
- the QuPath GUIimageData
- the image dataoverwriteExisting
- whether to overwrite existing image data- Returns:
- whether the save succeeded
-
saveSnapshotWithDelay
public static void saveSnapshotWithDelay(QuPathGUI qupath, GuiTools.SnapshotType type, long delayMillis) Save an image snapshot after a specified delay, prompting the user to select the output file.
The delay is used to work around the fact that making a snapshot immediately can sometimes result in undesirable UI elements still being visible, e.g. the menu item used to trigger the snapshot.
See https://github.com/qupath/qupath/issues/1854- Parameters:
qupath
- theQuPathGUI
instance to snapshottype
- the snapshot typedelayMillis
- the delay in milliseconds
-
saveSnapshot
Save an image snapshot, prompting the user to select the output file.- Parameters:
qupath
- theQuPathGUI
instance to snapshottype
- the snapshot type- Returns:
- true if a snapshot was saved, false otherwise
-
mergeSelectedAnnotations
Merge the currently-selected annotations for an image, replacing them with a single new annotation.- Parameters:
imageData
- the image data
-
duplicateSelectedAnnotations
Duplicate the selected annotations.- Parameters:
imageData
- the image data
-
copySelectedAnnotationsToCurrentPlane
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- Implementation Note
- this command is scriptable, but will store the plane in the script (since there is not necessarily a 'current plane' when running a script without a viewer)
-
makeInverseAnnotation
Make an inverse annotation for the selected objects, storing the command in the history workflow.- Parameters:
imageData
- the image data- See Also:
-
showViewTracker
Show a dialog to track the viewed region of an image.- Parameters:
qupath
- the QuPath GUI
-
combineSelectedAnnotations
Combine the selected annotations for the specified hierarchy.- Parameters:
imageData
- the image data to processop
- theRoiTools.CombineOp
operation to apply- Returns:
- true if changes were made, false otherwise
-
promptToSelectObjectsByClassification
Prompt to select objects according to their classifications.- Parameters:
qupath
- the QuPath GUIimageData
- the image data
-
promptToEditClass
Prompt to edit the name/color of a class.- Parameters:
pathClass
- the path class- Returns:
- whether the edit succeeds.
-
selectObjectsByClassification
public static boolean selectObjectsByClassification(ImageData<?> imageData, PathClass... pathClasses) Select objects by classification, logging the step (if performed) in the history workflow.- Parameters:
imageData
- theImageData
containing objects to be selectedpathClasses
- 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
Prompt to delete objects of a specified type, or all objects.- Parameters:
imageData
- the image datacls
- the type of object (if null, all)
-
removeOnImageBounds
Delete all objects touching the image boundary.- Parameters:
imageData
- the image data
-
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
Set the downsample factor for the specified viewer.- Parameters:
viewer
- the QuPath viewerdownsample
- the new downsample
-
closeProject
Close the current project open in theQuPathGUI
.- Parameters:
qupath
- The QuPath GUI
-
promptToCreateProject
Prompt the user to select an empty directory, and use this to create a new project and set it as active.- Parameters:
qupath
- theQuPathGUI
instance for which the project should be created.- Returns:
- true if a project was created, false otherwise (e.g. the user cancelled).
-
promptToOpenProject
Prompt the user to open an existing project and set it as active.- Parameters:
qupath
- theQuPathGUI
instance for which the project should be opened.- Returns:
- true if a project was opened, false otherwise (e.g. the user cancelled).
-
launchTMADataViewer
Open new window with the TMA data viewer.- Parameters:
qupath
- currentQuPathGUI
instance (may be null).
-
distanceToAnnotations2D
Compute the distance between all detections and the closest annotation, for all annotation classifications.- Parameters:
imageData
- the image data to processsignedDistances
- if true, use signed distances
-
detectionCentroidDistances2D
Compute the distance between the centroids of all detections, for all available classifications.- Parameters:
imageData
- the image data to process
-
promptToSetGridLineSpacing
Prompt to input the spacing for the grid lines optionally displayed on viewers.- Parameters:
options
- theOverlayOptions
that manage the grid lines.
-
requestUserDirectory
Request the current user directory, optionally prompting the user to request a directory if none is available.- Parameters:
promptIfMissing
- whether to prompt the user if the directory is not set yet- Returns:
- the user directory, or null if none exists and the user did not create one
-
reloadImageData
Reload the specified image data from a previously saved version,if available.- Parameters:
qupath
- the QuPath GUIimageData
- the image data
-
promptToAddShapeFeatures
Prompt to add shape features for selected objects.- Parameters:
qupath
- current QuPath instance
-
convertDetectionsToPoints
Convert detection objects to point annotations based upon their ROI centroids.- Parameters:
imageData
- the image data to processpreferNucleus
- 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 dataaltitudeThreshold
- default altitude value for simplification
-
selectObjectsOnCurrentPlane
Select all the objects on the current plane of the viewer.- Parameters:
viewer
- the QuPath GUI
-
selectAllObjects
Select all objects (excluding the root object) in the imageData.- Parameters:
imageData
- the image data
-
selectObjectsByClass
Select objects that are instances of a specified class, logging an appropriate method in the workflow.- Parameters:
imageData
- the image datacls
- the type of object
-
resetSelection
Reset the selection for an image.- Parameters:
imageData
- the image data
-
resetClassifications
Select objects that are instances of a specified class, logging an appropriate method in the workflow.- Parameters:
imageData
- the image datacls
- the type of object
-
createWorkflowDisplayDialog
Create a dialog to show the workflow history for the current image data.- Parameters:
qupath
- the QuPath instance- Returns:
- a workflow display dialog
-
showWorkflowScript
Show the QuPath script editor with a script corresponding to the command history of a specified image.- Parameters:
qupath
- the QuPath GUIimageData
- the image data
-
showScriptEditor
Show the script editor, or bring the window to the front if it is already open.- Parameters:
qupath
- the QuPath GUI
-
createMemoryMonitorDialog
Create a dialog to monitor memory usage.- Parameters:
qupath
- the QuPath GUI- Returns:
- the dialog stage
-
showMiniViewer
Show a mini viewer window associated with a specific viewer.- Parameters:
viewer
- the viewer with which to associate this window
-
showChannelViewer
Show a channel viewer window associated with a specific viewer.- Parameters:
viewer
- the viewer with which to associate this window
-
refreshObjectIDs
Refresh object IDs to ensure uniqueness.- Parameters:
imageData
- the image dataduplicatesOnly
- only refresh IDs that are duplicates of other IDs
-
runObjectImport
Show a dialog to import object(s) from a file.- Parameters:
qupath
- the qupath GUIimageData
- the image data
-
copySelectedObjectsToClipboard
Attempt to copy selected objects to the system clipboard, if available- Parameters:
imageData
- the image data
-
copyAnnotationsToClipboard
Attempt to annotation objects to the system clipboard, if available- Parameters:
imageData
- the image data
-
pasteFromClipboard
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
- the qupath GUIaddToCurrentPlane
- 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
Show a dialog to export object(s) to a GeoJSON file.- Parameters:
qupath
- the QuPath GUIimageData
- the image data
-