Class GuiUtils

java.lang.Object
sc.fiji.snt.gui.GuiUtils

public class GuiUtils extends Object
Misc. utilities for SNT's GUI.
  • Field Details

  • Constructor Details

    • GuiUtils

      public GuiUtils(Component parent)
    • GuiUtils

      public GuiUtils()
      Create a new GuiUtils instance using active (focused) window as parent.
  • Method Details

    • setParentToActiveWindow

      public void setParentToActiveWindow()
    • setParent

      public void setParent(Component parent)
    • error

      public void error(String msg)
    • error

      public void error(String msg, String title)
    • notifyIfNewVersion

      public void notifyIfNewVersion(int msDelayBeforeShow)
    • notifyIfOldVersion

      public void notifyIfOldVersion(int msDelayBeforeCheck)
      Checks for available SNT updates in the background by querying the Neuroanatomy update site. If the site's content is newer than the local installation, a notification is displayed suggesting the user run the Fiji updater. Respects the Fiji updater's own preferences (e.g., "never remind me", "remind me later") and fails silently on any error (network, missing updater, etc.).
      Parameters:
      msDelayBeforeCheck - delay in ms before the background check starts
    • showHint

      public void showHint(String tip)
    • loadHints

      public List<String> loadHints()
    • applyRoundCorners

      public static void applyRoundCorners(JComponent component)
    • floatingMsg

      public JDialog floatingMsg(String msg, boolean autodismiss)
    • tempMsg

      public void tempMsg(String msg)
    • tempMsg

      public void tempMsg(String msg, int location)
    • isLegacy3DViewerAvailable

      public static boolean isLegacy3DViewerAvailable()
    • notify

      public static void notify(String msg, int msDelayBeforeShow)
      Displays a floating notification in the upper corner of the active screen
      Parameters:
      msg - The message to be displayed
      msDelayBeforeShow - the amount (in ms) of time before notification shouls be displayed
    • yesNoDialog

      public int yesNoDialog(String msg, String title, String yesButtonLabel, String noButtonLabel)
    • yesNoDialog

      public int yesNoDialog(String msg, String title)
    • yesNoPrompt

      public org.scijava.ui.DialogPrompt.Result yesNoPrompt(String message, String title)
    • getConfirmation

      public boolean getConfirmation(String msg, String title)
    • error

      public void error(String msg, String title, String helpURI)
    • getConfirmation

      public boolean getConfirmation(String msg, String title, String yesLabel, String noLabel)
    • getConfirmation2

      public Boolean getConfirmation2(String msg, String title, String yesLabel, String noLabel)
    • getChoice

      public String getChoice(String message, String title, String[] choices, String defaultChoice)
    • getTwoChoices

      public String[] getTwoChoices(String title, String choice1Label, String[] choices1, String defaultChoice1, String choice2Label, String[] choices2, String defaultChoice2)
    • getChoiceWithInput

      public String[] getChoiceWithInput(String message, String title, String[] choices, String defaultChoice, String defaultInput)
    • getChoiceAndDouble

      public Object[] getChoiceAndDouble(String message, String title, String[] choices, String defaultChoice, Double defaultValue)
    • getChoice

      public String getChoice(String message, String title, String[] choices, String[] descriptions, String defaultChoice)
    • getMultipleChoices

      public List<String> getMultipleChoices(String title, String[] choices, String defaultChoice)
    • getMultipleChoicesAndChoice

      public Object[] getMultipleChoicesAndChoice(String title, String[] choices1, String defaultChoice1, boolean multipleSelectionAllowed1, String[] choices2, String defaultChoice2)
    • getPersistentConfirmation

      public boolean[] getPersistentConfirmation(String msg, String title)
    • getConfirmationAndOption

      public boolean[] getConfirmationAndOption(String msg, String title, String checkboxLabel, boolean checkboxDefault, String[] yesNoButtonLabels)
    • getConfirmationAndOption

      public boolean[] getConfirmationAndOption(String msg, String title, String checkboxLabel, boolean checkboxDefault)
    • getChoiceWithOptionAndInfo

      public Object[] getChoiceWithOptionAndInfo(String title, String message, String[] choices, String defaultChoice, String infoText, String checkboxLabel, boolean checkboxDefault)
      Displays a dialog with radio button choices, optional info text, and an optional checkbox. Useful for operations that require a selection with additional context and options.
      Parameters:
      title - the dialog title
      message - the message/prompt shown at the top (can be HTML)
      choices - array of choices to display as radio buttons
      defaultChoice - the initially selected choice (must be in choices array)
      infoText - optional informational text shown below the choices (null to hide)
      checkboxLabel - optional checkbox label (null to hide checkbox)
      checkboxDefault - default state of checkbox (ignored if checkboxLabel is null)
      Returns:
      Object array: {selectedChoice (String), checkboxSelected (Boolean)}, or null if canceled. checkboxSelected is false if checkbox was hidden.
    • getPersistentWarning

      public Boolean getPersistentWarning(String msg, String title)
    • getString

      public String getString(String promptMsg, String promptTitle, String defaultValue)
    • getStrings

      public String[] getStrings(String promptTitle, String[] labels, String[] defaultValues)
    • getStrings

      public String[] getStrings(String promptTitle, Map<String,List<String>> choicesMap, String... defaultChoices)
    • getStringSet

      public Set<String> getStringSet(String promptMsg, String promptTitle, Collection<String> defaultValues)
    • getColorRGB

      public org.scijava.util.ColorRGB getColorRGB(String title, org.scijava.util.ColorRGB defaultValue, String... panes)
      Simplified color chooser for ColorRGB.
      See Also:
    • getColor

      public Color getColor(String title, Color defaultValue, String... panes)
      Simplified color chooser.
      Parameters:
      title - the title of the chooser dialog
      defaultValue - the initial color set in the chooser
      panes - the panes a list of strings specifying which tabs should be displayed. In most platforms this includes: "Swatches", "HSB" and "RGB". Note that e.g., the GTK L&F may only include the default GtkColorChooser pane. Set to null to include all available panes.
      Returns:
      the color
    • getDouble

      public Double getDouble(String promptMsg, String promptTitle, Number defaultValue)
    • getPercentage

      public Integer getPercentage(String promptMsg, String promptTitle, int defaultValue)
    • getDouble

      public Double getDouble(String promptMsg, String promptTitle, double defaultValue, double min, double max, String unit)
    • getInt

      public Integer getInt(String promptMsg, String promptTitle, int defaultValue, int min, int max)
    • getTwoNumbers

      public Number[] getTwoNumbers(String promptMsg, String promptTitle, Number[] defaultValues, String[] labels, int decimalPlaces)
    • getThreeNumbers

      public Number[] getThreeNumbers(String promptMsg, String promptTitle, Number[] defaultValues, String[] labels, int decimalPlaces)
    • getCoordinates

      public SNTPoint getCoordinates(String promptMsg, String promptTitle, SNTPoint defaultValue, int decimalPlaces)
    • getCoordinatesInternal

      public SNTPoint getCoordinatesInternal(String promptMsg, String promptTitle, SNTPoint defaultValue, String[] labels, int decimalPlaces)
    • getRange

      public float[] getRange(String promptMsg, String promptTitle, float[] defaultRange)
    • adjustComponentThroughPrompt

      public void adjustComponentThroughPrompt(Component container)
    • getOpenFile

      public File getOpenFile(String title, File file, String... allowedExtensions)
    • getSaveFile

      public File getSaveFile(String title, File file, String... allowedExtensions)
    • getReconstructionFiles

      public File[] getReconstructionFiles(File selectedFile)
    • getFile

      public File getFile(File file, String extensionWithoutPeriod)
    • getImageFile

      public File getImageFile(File file)
    • getReconstructionFile

      public File getReconstructionFile(File file, String extension)
    • fileChooser

      public static JFileChooser fileChooser(String title, File file, int type, int selectionMode)
    • centeredMsg

      public void centeredMsg(String msg, String title)
    • centeredMsg

      public void centeredMsg(String msg, String title, String buttonLabel)
    • dialog

      public JDialog dialog(String msg, JComponent component, String title)
    • centerOnParent

      public static void centerOnParent(Component parent, Window dialog)
    • centerOnParent

      public static void centerOnParent(Rectangle parentBounds, Window dialog)
    • displayBanner

      public static void displayBanner(String msg, Color background, Component parent)
    • addTooltip

      public static void addTooltip(JComponent c, String text)
    • blinkingError

      public void blinkingError(JComponent blinkingComponent, String msg)
    • errorColor

      public static Color errorColor()
    • warningColor

      public static Color warningColor()
    • linkColor

      public static Color linkColor()
    • shortSmallMsg

      public static JLabel shortSmallMsg(String msg, boolean enabled)
    • shortSmallMsg

      public static JLabel shortSmallMsg(String msg)
    • longSmallMsg

      public static JTextArea longSmallMsg(String msg, Component parent)
    • showAboutDialog

      public static JDialog showAboutDialog()
    • showDirectory

      public void showDirectory(File file)
    • toString

      public static <T> String toString(Iterable<T> iterable)
    • uiFontSize

      public static float uiFontSize()
    • uiScale

      public static double uiScale()
      Returns the effective UI scale factor for the current display environment, accounting for HiDPI displays and user-configured scaling.

      The detection strategy is:

      1. FlatLaf's UIScale.getUserScaleFactor()the most reliable source when FlatLaf is active, as it combines OS-level DPI with any user overrides
      2. AWT's GraphicsConfiguration.getDefaultTransform().getScaleX(), the platform-level fallback
      3. ij.Prefs.getGuiScale(): last resort
      Returns:
      the scale factor (1.0 = no scaling, 2.0 = 200%, etc.)
    • initSplashScreen

      public static void initSplashScreen()
    • closeSplashScreen

      public static void closeSplashScreen()
    • addSeparator

      public static void addSeparator(JComponent component, String heading, boolean vgap, GridBagConstraints c)
    • addSeparator

      public static void addSeparator(JComponent component, JLabel label, boolean vgap, GridBagConstraints c)
    • addSeparator

      public static void addSeparator(JPopupMenu menu, String header)
    • addSeparator

      public static void addSeparator(JMenu menu, String header)
    • renderedWidth

      public static int renderedWidth(String text)
    • leftAlignedLabel

      public static JLabel leftAlignedLabel(String text, boolean enabled)
    • leftAlignedLabel

      public static JLabel leftAlignedLabel(String text, String uri, boolean enabled)
    • searchForum

      public void searchForum(String query)
    • openURL

      public static void openURL(String uri)
    • showKeyboardShortcuts

      public void showKeyboardShortcuts(InputMap[] inputMaps, ActionMap... actionMaps)
      Displays a sorted HTML table of all registered keyboard shortcuts in the specified inputMaps. Action names are title-cased for readability.
      Parameters:
      inputMaps - The InputMap(s) to be listed
      actionMaps - If null, all key binding are listed, including those with no corresponding action (e.g. disabled or inherited Swing defaults) will be listed
    • ctrlKey

      public static String ctrlKey()
    • getConsole

      public static Window getConsole()
    • colorChooser

      public static JColorChooser colorChooser(Color defaultValue)
    • setRenderingHints

      public static void setRenderingHints(Graphics2D g2)
    • defaultGbc

      public static GridBagConstraints defaultGbc()
    • recolorTracks

      public static void recolorTracks(JScrollPane scrollPane, Color color, boolean updateUI)
    • addClearButton

      public static void addClearButton(JTextField textField)
    • addPlaceholder

      public static void addPlaceholder(JTextField textField, String placeholder)
    • removeIcon

      public static void removeIcon(Object rootPaneContainerOrWindow)
    • getSelectionColor

      public static Color getSelectionColor()
    • getDisabledComponentColor

      public static Color getDisabledComponentColor()
    • integerSpinner

      public static JSpinner integerSpinner(int value, int min, int max, int step, boolean allowEditing)
    • doubleSpinner

      public static JSpinner doubleSpinner(double value, double min, double max, double step, int nDecimals)
    • extractDouble

      public static double extractDouble(JTextField textfield)
    • enableComponents

      public static void enableComponents(Container container, boolean enable)
    • micrometer

      public static String micrometer()
    • scaledMicrometer

      public static String scaledMicrometer(double umLength, int digits)
      Returns a more human-readable representation of a length in micrometers.

      E.g., scaledMicrometer(0.01,1) returns "1.0nm"

      Parameters:
      umLength - the length in micrometers
      digits - the number of output decimals
      Returns:
      the scaled unit
    • errorPrompt

      public static void errorPrompt(String msg)
    • availableLookAndFeels

      public static String[] availableLookAndFeels()
    • setLookAndFeel

      public static void setLookAndFeel()
    • getDnDFileChooser

      public static JFileChooser getDnDFileChooser()
    • restoreLookAndFeel

      public static void restoreLookAndFeel()
    • setLookAndFeel

      public static boolean setLookAndFeel(String lookAndFeelName, boolean persistentChoice)
    • setLookAndFeel

      public static boolean setLookAndFeel(String lookAndFeelName, boolean persistentChoice, Component... componentsToUpdate)
    • setAutoDismiss

      public static void setAutoDismiss(JDialog dialog)
    • truncate

      public static String truncate(String label, int maxLength)
    • tile

      public static void tile(List<? extends Window> windowList)
    • showHTMLDialog

      public static void showHTMLDialog(String msg, String title)
    • showHTMLDialog

      public JDialog showHTMLDialog(String msg, String title, boolean modal)
    • yesNoHTMLDialog

      public boolean yesNoHTMLDialog(String htmlMsg, String title, String yesLabel, String noLabel)
    • combineSNTChartPrompt

      public void combineSNTChartPrompt()
    • drawDragAndDropPlaceHolder

      public static void drawDragAndDropPlaceHolder(Component component, Graphics2D g)
    • getTabbedPane

      public static JTabbedPane getTabbedPane()
    • centerWindow

      public static void centerWindow(Window dialogToCenter, Window... windows)
    • addCloseShortcut

      public static void addCloseShortcut(JFrame frame)
    • enhanceTableDisplay

      public static void enhanceTableDisplay(SNTTable table, String windowTitle)
      Enhances a SciJava-managed table display with conveniences (close shortcut, save menu). Fails silently if the display cannot be found or enhanced.
      Parameters:
      table - the SNTTable being displayed
      windowTitle - the title of the display window to find