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
Modifier and TypeClassDescriptionstatic enum
Kinds of snapshot image that can be created for QuPath. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
browseDirectory
(File file) Open the directory containing a file for browsing.static boolean
Try to open a URI in a web browser.static <T> org.controlsfx.control.ListSelectionView
<T> Create a newListSelectionView
.static Button
createMoreButton
(ContextMenu menu, Side side) Create aButton
with a standardized icon and tooltip text to indicate 'More', which triggers aContextMenu
when clicked.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.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.static org.controlsfx.glyphfont.Glyph
ensureDuplicatableGlyph
(org.controlsfx.glyphfont.Glyph glyph) Ensure that aGlyph
is 'duplicatable', without losing its key properties.static org.controlsfx.glyphfont.Glyph
ensureDuplicatableGlyph
(org.controlsfx.glyphfont.Glyph glyph, boolean useFill) Ensure that aGlyph
is 'duplicatable', optionally retaining any fill.static ImageData.ImageType
estimateImageType
(ImageServer<BufferedImage> server, BufferedImage imgThumbnail) Make a semi-educated guess at the image type of a PathImageServer.static String
getMagnificationString
(QuPathViewer viewer) Get an appropriate String to represent the magnification of the image currently in the viewer.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.static void
installRangePrompt
(Slider slider) Install a mouse click listener to prompt the user to input min/max values for a slider.static BufferedImage
Make a BufferedImage snapshot of the full screen.static BufferedImage
Make a BufferedImage snapshot of the current GUI.static BufferedImage
makeSnapshot
(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 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.static WritableImage
makeSnapshotFX
(QuPathGUI qupath, GuiTools.SnapshotType type) Make a snapshot as a JavaFXImage
, using the current viewer if a viewer is required.static WritableImage
makeSnapshotFX
(QuPathGUI qupath, QuPathViewer viewer, GuiTools.SnapshotType type) Make a snapshot as a JavaFXImage
.static BufferedImage
Make a BufferedImage snapshot of the current viewer.static BufferedImage
makeViewerSnapshot
(QuPathViewer viewer) Make a BufferedImage snapshot of the specified viewer.static boolean
Try to open a file in the native application.static void
paintImage
(Canvas canvas, Image image) Paint an image centered within a canvas, scaled to be as large as possible while maintaining its aspect ratio.static void
paintImage
(Canvas canvas, Image image, double scale) Paint an image centered within a canvas, scaled by the specified scale factor.static ContextMenu
populateAnnotationsMenu
(QuPathGUI qupath, ContextMenu menu) Populate aContextMenu
with standard options to operate on selected annotation objects.static Menu
populateAnnotationsMenu
(QuPathGUI qupath, Menu menu) Populate aMenu
with standard options to operate on selected annotation objects.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.static boolean
promptForSliderRange
(Slider slider) Prompt the user to input min/max values for a slider.static boolean
promptToClearAllSelectedObjects
(ImageData<?> imageData) Prompt user to select all currently-selected objects (except TMA core objects).static boolean
promptToRemoveSelectedObject
(PathObject pathObjectSelected, PathObjectHierarchy hierarchy) Prompt to remove a single, specified selected object.static boolean
Prompt the user to set properties for the currently-selected annotation(s).static <T> void
refreshList
(ListView<T> listView) Refresh aListView
in the Application thread.static void
showNoImageError
(String title) Show an error message that no image is available.static void
showNoProjectError
(String title) Show an error message that no project is available.static boolean
showParameterDialog
(String title, ParameterList params) Show a (modal) dialog for a specified ParameterList.static void
showWithScreenSizeConstraints
(Stage stage, double proportion) Show a stage, while ensuring that it cannot be larger than the screen size.static void
showWithSizeConstraints
(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 aButton
with a standardized icon and tooltip text to indicate 'More', which triggers aContextMenu
when 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 theListSelectionView
is 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 aGlyph
is '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 aGlyph
is '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 aListView
in 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 aMenu
with standard options to operate on selected annotation objects.- Parameters:
qupath
-menu
-- Returns:
-
populateAnnotationsMenu
Populate aContextMenu
with 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 theImageData
if 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:
-