Class GuiTools

java.lang.Object
qupath.lib.gui.tools.GuiTools

public class GuiTools extends Object
Assorted static methods to help with JavaFX and QuPath GUI-related tasks.
Author:
Pete Bankhead
  • Constructor Details

    • GuiTools

      public GuiTools()
  • Method Details

    • createMoreButton

      public static Button createMoreButton(ContextMenu menu, Side side)
      Create a Button with a standardized icon and tooltip text to indicate 'More', which triggers a ContextMenu when clicked.
      Parameters:
      menu - context menu to display on click
      side - 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

      public static boolean showParameterDialog(String title, ParameterList params)
      Show a (modal) dialog for a specified ParameterList.
      Parameters:
      title -
      params -
      Returns:
      False if the user pressed 'cancel', true otherwise
    • showNoImageError

      public static void showNoImageError(String title)
      Show an error message that no image is available. This is included to help standardize the message throughout the software.
      Parameters:
      title -
    • showNoProjectError

      public static void showNoProjectError(String title)
      Show an error message that no project is available. This is included to help standardize the message throughout the software.
      Parameters:
      title -
    • browseDirectory

      public static boolean browseDirectory(File file)
      Open the directory containing a file for browsing.
      Parameters:
      file -
      Returns:
    • createListSelectionView

      public static <T> org.controlsfx.control.ListSelectionView<T> createListSelectionView()
      Create a new ListSelectionView. This should be used instead of simply calling the constructor whenever the ListSelectionView 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 a Glyph 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 a Glyph 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 glyph
      useFill - if true, use any text fill value for the glyph
      Returns:
      Since:
      v0.4.1
    • browseURI

      public static boolean browseURI(URI uri)
      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

      public static WritableImage makeSnapshotFX(QuPathGUI qupath, GuiTools.SnapshotType type)
      Make a snapshot as a JavaFX Image, 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 JavaFX Image.
      Parameters:
      qupath -
      viewer - the viewer to use (or null to use the current viewer)
      type -
      Returns:
    • makeSnapshot

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

      public static BufferedImage makeViewerSnapshot(QuPathViewer viewer)
      Make a BufferedImage snapshot of the specified viewer.
      Parameters:
      viewer -
      Returns:
    • makeSnapshot

      public static BufferedImage makeSnapshot()
      Make a BufferedImage snapshot of the current GUI.
      Returns:
    • makeViewerSnapshot

      public static BufferedImage makeViewerSnapshot()
      Make a BufferedImage snapshot of the current viewer.
      Returns:
    • makeFullScreenshot

      public static BufferedImage makeFullScreenshot()
      Make a BufferedImage snapshot of the full screen.
      Returns:
    • getMagnificationString

      public static String getMagnificationString(QuPathViewer viewer)
      Get an appropriate String to represent the magnification of the image currently in the viewer.
      Parameters:
      viewer -
      Returns:
    • promptToClearAllSelectedObjects

      public static boolean promptToClearAllSelectedObjects(ImageData<?> imageData)
      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

      public static boolean openFile(File file)
      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

      public 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. Background is transparent.
      Parameters:
      canvas -
      image -
    • paintImage

      public static void paintImage(Canvas canvas, Image image, double scale)
      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

      public static <T> void refreshList(ListView<T> listView)
      Refresh a ListView in the Application thread.
      Type Parameters:
      T -
      Parameters:
      listView -
    • promptToSetActiveAnnotationProperties

      public static boolean promptToSetActiveAnnotationProperties(PathObjectHierarchy hierarchy)
      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

      public static Menu populateAnnotationsMenu(QuPathGUI qupath, Menu menu)
      Populate a Menu with standard options to operate on selected annotation objects.
      Parameters:
      qupath -
      menu -
      Returns:
    • populateAnnotationsMenu

      public static ContextMenu populateAnnotationsMenu(QuPathGUI qupath, ContextMenu menu)
      Populate a ContextMenu with standard options to operate on selected annotation objects.
      Parameters:
      qupath -
      menu -
      Returns:
    • installRangePrompt

      public static void installRangePrompt(Slider slider)
      Install a mouse click listener to prompt the user to input min/max values for a slider.
      Parameters:
      slider -
      See Also:
    • promptForSliderRange

      public static boolean promptForSliderRange(Slider slider)
      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 the ImageData if possible.
      Parameters:
      name - command name, to include in dialog messages
      imageData - imageData containing potential parent objects
      includeSelected - if true, provide 'selected objects' as an option
      supportedParents - collection of valid parent objects
      Returns:
    • showWithScreenSizeConstraints

      public static void showWithScreenSizeConstraints(Stage stage, double proportion)
      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

      public 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.
      Parameters:
      stage -
      maxWidth -
      maxHeight -
      See Also: