Package qupath.lib.gui.tools
Class GuiTools
java.lang.Object
qupath.lib.gui.tools.GuiTools
Assorted static methods to help with JavaFX and QuPath GUI-related tasks.
- Author:
- Pete Bankhead
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumKinds of snapshot image that can be created for QuPath. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanbrowseDirectory(File file) Open the directory containing a file for browsing.static booleanTry to open a URI in a web browser.static <T> org.controlsfx.control.ListSelectionView<T>Create a newListSelectionView.static ButtoncreateMoreButton(ContextMenu menu, Side side) Create aButtonwith a standardized icon and tooltip text to indicate 'More', which triggers aContextMenuwhen clicked.static MenucreateRecentItemsMenu(String menuTitle, ObservableList<URI> recentItems, Consumer<URI> consumer) Create a menu that displays recent items, stored in the form of URIs, using default text to show for the menu item.static MenucreateRecentItemsMenu(String menuTitle, ObservableList<URI> recentItems, Consumer<URI> consumer, Function<URI, String> menuitemText) Create a menu that displays recent items, stored in the form of URIs, customizing the text displayed for the menu items.static org.controlsfx.glyphfont.GlyphensureDuplicatableGlyph(org.controlsfx.glyphfont.Glyph glyph) Ensure that aGlyphis 'duplicatable', without losing its key properties.static org.controlsfx.glyphfont.GlyphensureDuplicatableGlyph(org.controlsfx.glyphfont.Glyph glyph, boolean useFill) Ensure that aGlyphis 'duplicatable', optionally retaining any fill.static ImageData.ImageTypeestimateImageType(ImageServer<BufferedImage> server, BufferedImage imgThumbnail) Make a semi-educated guess at the image type of a PathImageServer.static StringgetMagnificationString(QuPathViewer viewer) Get an appropriate String to represent the magnification of the image currently in the viewer.static WritableImagegetScaledRGBInstance(BufferedImage img, int targetWidth, int targetHeight) Get a scaled (RGB or ARGB) image, achieving reasonable quality even when scaling down by a considerably amount.static voidinstallRangePrompt(Slider slider) Install a mouse click listener to prompt the user to input min/max values for a slider.static BufferedImageMake a BufferedImage snapshot of the full screen.static BufferedImageMake a BufferedImage snapshot of the current GUI.static BufferedImagemakeSnapshot(QuPathGUI qupath, GuiTools.SnapshotType type) Make a snapshot (image) showing what is currently displayed in a QuPath window or the active viewer within QuPath, as determined by the SnapshotType.static BufferedImagemakeSnapshot(QuPathGUI qupath, QuPathViewer viewer, GuiTools.SnapshotType type) Make a snapshot (image) showing what is currently displayed in a QuPath window or the specified viewer, as determined by the SnapshotType.static WritableImagemakeSnapshotFX(QuPathGUI qupath, GuiTools.SnapshotType type) Make a snapshot as a JavaFXImage, using the current viewer if a viewer is required.static WritableImagemakeSnapshotFX(QuPathGUI qupath, QuPathViewer viewer, GuiTools.SnapshotType type) Make a snapshot as a JavaFXImage.static BufferedImageMake a BufferedImage snapshot of the current viewer.static BufferedImagemakeViewerSnapshot(QuPathViewer viewer) Make a BufferedImage snapshot of the specified viewer.static booleanTry to open a file in the native application.static voidpaintImage(Canvas canvas, Image image) Paint an image centered within a canvas, scaled to be as large as possible while maintaining its aspect ratio.static voidpaintImage(Canvas canvas, Image image, double scale) Paint an image centered within a canvas, scaled by the specified scale factor.static ContextMenupopulateAnnotationsMenu(QuPathGUI qupath, ContextMenu menu) Populate aContextMenuwith standard options to operate on selected annotation objects.static MenupopulateAnnotationsMenu(QuPathGUI qupath, Menu menu) Populate aMenuwith standard options to operate on selected annotation objects.static booleanpromptForParentObjects(String name, ImageData<?> imageData, boolean includeSelected, Collection<Class<? extends PathObject>> supportedParents) Get the parent objects to use when running the plugin, or null if no suitable parent objects are found.static booleanpromptForSliderRange(Slider slider) Prompt the user to input min/max values for a slider.static booleanpromptToClearAllSelectedObjects(ImageData<?> imageData) Prompt user to select all currently-selected objects (except TMA core objects).static booleanpromptToRemoveSelectedObject(PathObject pathObjectSelected, PathObjectHierarchy hierarchy) Prompt to remove a single, specified selected object.static booleanPrompt the user to set properties for the currently-selected annotation(s).static <T> voidrefreshList(ListView<T> listView) Refresh aListViewin the Application thread.static voidshowNoImageError(String title) Show an error message that no image is available.static voidshowNoProjectError(String title) Show an error message that no project is available.static booleanshowParameterDialog(String title, ParameterList params) Show a (modal) dialog for a specified ParameterList.static voidshowWithScreenSizeConstraints(Stage stage, double proportion) Show a stage, while ensuring that it cannot be larger than the screen size.static voidshowWithSizeConstraints(Stage stage, double maxWidth, double maxHeight) Show a stage, while ensuring that it cannot be larger the maximum dimensions provided This effectively sets the maximum dimensions of the stage, shows it, and then restores the previous maximum dimensions.
-
Constructor Details
-
GuiTools
public GuiTools()
-
-
Method Details
-
createMoreButton
Create aButtonwith a standardized icon and tooltip text to indicate 'More', which triggers aContextMenuwhen clicked.- Parameters:
menu- context menu to display on clickside- preferred side at which the context menu should be displayed- Returns:
- an initialized button with icon, tooltip and onAction event to trigger the context menu.
-
showParameterDialog
Show a (modal) dialog for a specified ParameterList.- Parameters:
title-params-- Returns:
- False if the user pressed 'cancel', true otherwise
-
showNoImageError
Show an error message that no image is available. This is included to help standardize the message throughout the software.- Parameters:
title-
-
showNoProjectError
Show an error message that no project is available. This is included to help standardize the message throughout the software.- Parameters:
title-
-
browseDirectory
Open the directory containing a file for browsing.- Parameters:
file-- Returns:
-
createListSelectionView
public static <T> org.controlsfx.control.ListSelectionView<T> createListSelectionView()Create a newListSelectionView. This should be used instead of simply calling the constructor whenever theListSelectionViewis expected to respond well to styles, since ControlsFX's default will stubbornly use black arrows to move between source and target lists.- Type Parameters:
T-- Returns:
- Since:
- v0.4.0
- See Also:
-
ensureDuplicatableGlyph
public static org.controlsfx.glyphfont.Glyph ensureDuplicatableGlyph(org.controlsfx.glyphfont.Glyph glyph) Ensure that aGlyphis 'duplicatable', without losing its key properties. This is needed to have glyphs that behave well with css styles. ControlsFX's default implementation tends to lose the fill color otherwise.- Parameters:
glyph-- Returns:
- Since:
- v0.4.0
-
ensureDuplicatableGlyph
public static org.controlsfx.glyphfont.Glyph ensureDuplicatableGlyph(org.controlsfx.glyphfont.Glyph glyph, boolean useFill) Ensure that aGlyphis 'duplicatable', optionally retaining any fill. This is needed to have glyphs that behave well with css styles. ControlsFX's default implementation tends to lose the fill color otherwise.- Parameters:
glyph- the original glyphuseFill- if true, use any text fill value for the glyph- Returns:
- Since:
- v0.4.1
-
browseURI
Try to open a URI in a web browser.- Parameters:
uri-- Returns:
- True if the request succeeded, false otherwise.
-
estimateImageType
public static ImageData.ImageType estimateImageType(ImageServer<BufferedImage> server, BufferedImage imgThumbnail) Make a semi-educated guess at the image type of a PathImageServer.- Parameters:
server-imgThumbnail- Thumbnail for the image. This is now a required parameter (previously <= 0.1.2 it was optional).- Returns:
-
makeSnapshotFX
Make a snapshot as a JavaFXImage, using the current viewer if a viewer is required.- Parameters:
qupath-type-- Returns:
-
makeSnapshotFX
public static WritableImage makeSnapshotFX(QuPathGUI qupath, QuPathViewer viewer, GuiTools.SnapshotType type) Make a snapshot as a JavaFXImage.- Parameters:
qupath-viewer- the viewer to use (or null to use the current viewer)type-- Returns:
-
makeSnapshot
Make a snapshot (image) showing what is currently displayed in a QuPath window or the active viewer within QuPath, as determined by the SnapshotType.- Parameters:
qupath-type-- Returns:
-
makeSnapshot
public static BufferedImage makeSnapshot(QuPathGUI qupath, QuPathViewer viewer, GuiTools.SnapshotType type) Make a snapshot (image) showing what is currently displayed in a QuPath window or the specified viewer, as determined by the SnapshotType.- Parameters:
qupath-viewer-type-- Returns:
-
makeViewerSnapshot
Make a BufferedImage snapshot of the specified viewer.- Parameters:
viewer-- Returns:
-
makeSnapshot
Make a BufferedImage snapshot of the current GUI.- Returns:
-
makeViewerSnapshot
Make a BufferedImage snapshot of the current viewer.- Returns:
-
makeFullScreenshot
Make a BufferedImage snapshot of the full screen.- Returns:
-
getMagnificationString
Get an appropriate String to represent the magnification of the image currently in the viewer.- Parameters:
viewer-- Returns:
-
promptToClearAllSelectedObjects
Prompt user to select all currently-selected objects (except TMA core objects).- Parameters:
imageData-- Returns:
-
promptToRemoveSelectedObject
public static boolean promptToRemoveSelectedObject(PathObject pathObjectSelected, PathObjectHierarchy hierarchy) Prompt to remove a single, specified selected object.- Parameters:
pathObjectSelected-hierarchy-- Returns:
-
openFile
Try to open a file in the native application. This can be used to open a directory in Finder (Mac OSX) or Windows Explorer etc. This can however fail on Linux, so an effort is made to query Desktop support and offer to copy the path instead of opening the file, if necessary.- Parameters:
file-- Returns:
-
paintImage
Paint an image centered within a canvas, scaled to be as large as possible while maintaining its aspect ratio. Background is transparent.- Parameters:
canvas-image-
-
paintImage
Paint an image centered within a canvas, scaled by the specified scale factor. If the scale factor is ≤ 0, the image will be scaled to be as large as possible while maintaining its aspect ratio. Background is transparent.- Parameters:
canvas-image-scale-
-
refreshList
Refresh aListViewin the Application thread.- Type Parameters:
T-- Parameters:
listView-
-
promptToSetActiveAnnotationProperties
Prompt the user to set properties for the currently-selected annotation(s).- Parameters:
hierarchy- current hierarchy- Returns:
- true if changes to annotation properties were made, false otherwise.
-
populateAnnotationsMenu
Populate aMenuwith standard options to operate on selected annotation objects.- Parameters:
qupath-menu-- Returns:
-
populateAnnotationsMenu
Populate aContextMenuwith standard options to operate on selected annotation objects.- Parameters:
qupath-menu-- Returns:
-
installRangePrompt
Install a mouse click listener to prompt the user to input min/max values for a slider.- Parameters:
slider-- See Also:
-
promptForSliderRange
Prompt the user to input min/max values for a slider.- Parameters:
slider-- Returns:
- true if the user may have made changes, false if they cancelled the dialog
-
getScaledRGBInstance
public static WritableImage getScaledRGBInstance(BufferedImage img, int targetWidth, int targetHeight) Get a scaled (RGB or ARGB) image, achieving reasonable quality even when scaling down by a considerably amount. Code is based on https://today.java.net/article/2007/03/30/perils-imagegetscaledinstance- Parameters:
img-targetWidth-targetHeight-- Returns:
-
createRecentItemsMenu
public static Menu createRecentItemsMenu(String menuTitle, ObservableList<URI> recentItems, Consumer<URI> consumer) Create a menu that displays recent items, stored in the form of URIs, using default text to show for the menu item.- Parameters:
menuTitle-recentItems-consumer-- Returns:
-
createRecentItemsMenu
public static Menu createRecentItemsMenu(String menuTitle, ObservableList<URI> recentItems, Consumer<URI> consumer, Function<URI, String> menuitemText) Create a menu that displays recent items, stored in the form of URIs, customizing the text displayed for the menu items.- Parameters:
menuTitle-recentItems-consumer-menuitemText-- Returns:
-
promptForParentObjects
public static boolean promptForParentObjects(String name, ImageData<?> imageData, boolean includeSelected, Collection<Class<? extends PathObject>> supportedParents) Get the parent objects to use when running the plugin, or null if no suitable parent objects are found. This involves prompting the user if multiple options are possible, and logging an appropriate command in the workflow history of theImageDataif possible.- Parameters:
name- command name, to include in dialog messagesimageData- imageData containing potential parent objectsincludeSelected- if true, provide 'selected objects' as an optionsupportedParents- collection of valid parent objects- Returns:
-
showWithScreenSizeConstraints
Show a stage, while ensuring that it cannot be larger than the screen size. The screen is determined from the stage itself, its owner, or is the primary screen.This method is useful when there is a risk that an initial stage size is too big for the screen, but we do not want to prevent the user from resizing freely afterwards.
- Parameters:
stage-proportion-- See Also:
-
showWithSizeConstraints
Show a stage, while ensuring that it cannot be larger the maximum dimensions provided This effectively sets the maximum dimensions of the stage, shows it, and then restores the previous maximum dimensions.- Parameters:
stage-maxWidth-maxHeight-- See Also:
-