Package sc.fiji.snt.gui
Class GuiUtils
java.lang.Object
sc.fiji.snt.gui.GuiUtils
Misc. utilities for SNT's GUI.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classUtility methods forJTableconfiguration and creation.static classstatic classstatic class -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddClearButton(JTextField textField) static voidaddCloseShortcut(JFrame frame) static voidaddPlaceholder(JTextField textField, String placeholder) static voidaddSeparator(JComponent component, String heading, boolean vgap, GridBagConstraints c) static voidaddSeparator(JComponent component, JLabel label, boolean vgap, GridBagConstraints c) static voidaddSeparator(JMenu menu, String header) static voidaddSeparator(JPopupMenu menu, String header) static voidaddTooltip(JComponent c, String text) voidadjustComponentThroughPrompt(Component container) static voidapplyRoundCorners(JComponent component) static String[]voidblinkingError(JComponent blinkingComponent, String msg) voidcenteredMsg(String msg, String title) voidcenteredMsg(String msg, String title, String buttonLabel) static voidcenterOnParent(Component parent, Window dialog) static voidcenterOnParent(Rectangle parentBounds, Window dialog) static voidcenterWindow(Window dialogToCenter, Window... windows) static voidstatic JColorChoosercolorChooser(Color defaultValue) voidstatic StringctrlKey()static GridBagConstraintsdialog(String msg, JComponent component, String title) static voiddisplayBanner(String msg, Color background, Component parent) static JSpinnerdoubleSpinner(double value, double min, double max, double step, int nDecimals) static voiddrawDragAndDropPlaceHolder(Component component, Graphics2D g) static voidenableComponents(Container container, boolean enable) static voidenhanceTableDisplay(SNTTable table, String windowTitle) Enhances a SciJava-managed table display with conveniences (close shortcut, save menu).voidvoidvoidstatic Colorstatic voiderrorPrompt(String msg) static doubleextractDouble(JTextField textfield) static JFileChooserfileChooser(String title, File file, int type, int selectionMode) floatingMsg(String msg, boolean autodismiss) getChoice(String message, String title, String[] choices, String[] descriptions, String defaultChoice) Object[]getChoiceAndDouble(String message, String title, String[] choices, String defaultChoice, Double defaultValue) String[]getChoiceWithInput(String message, String title, String[] choices, String defaultChoice, String defaultInput) 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.Simplified color chooser.org.scijava.util.ColorRGBgetColorRGB(String title, org.scijava.util.ColorRGB defaultValue, String... panes) Simplified color chooser for ColorRGB.booleangetConfirmation(String msg, String title) booleangetConfirmation(String msg, String title, String yesLabel, String noLabel) getConfirmation2(String msg, String title, String yesLabel, String noLabel) boolean[]getConfirmationAndOption(String msg, String title, String checkboxLabel, boolean checkboxDefault) boolean[]getConfirmationAndOption(String msg, String title, String checkboxLabel, boolean checkboxDefault, String[] yesNoButtonLabels) static WindowgetCoordinates(String promptMsg, String promptTitle, SNTPoint defaultValue, int decimalPlaces) getCoordinatesInternal(String promptMsg, String promptTitle, SNTPoint defaultValue, String[] labels, int decimalPlaces) static Colorstatic JFileChoosergetDouble(String promptMsg, String promptTitle, double defaultValue, double min, double max, String unit) getImageFile(File file) getMultipleChoices(String title, String[] choices, String defaultChoice) Object[]getMultipleChoicesAndChoice(String title, String[] choices1, String defaultChoice1, boolean multipleSelectionAllowed1, String[] choices2, String defaultChoice2) getOpenFile(String title, File file, String... allowedExtensions) getPercentage(String promptMsg, String promptTitle, int defaultValue) boolean[]getPersistentConfirmation(String msg, String title) getPersistentWarning(String msg, String title) float[]getReconstructionFile(File file, String extension) File[]getReconstructionFiles(File selectedFile) getSaveFile(String title, File file, String... allowedExtensions) static ColorString[]getStrings(String promptTitle, String[] labels, String[] defaultValues) String[]getStringSet(String promptMsg, String promptTitle, Collection<String> defaultValues) static JTabbedPaneNumber[]getThreeNumbers(String promptMsg, String promptTitle, Number[] defaultValues, String[] labels, int decimalPlaces) String[]getTwoChoices(String title, String choice1Label, String[] choices1, String defaultChoice1, String choice2Label, String[] choices2, String defaultChoice2) Number[]getTwoNumbers(String promptMsg, String promptTitle, Number[] defaultValues, String[] labels, int decimalPlaces) static voidstatic JSpinnerintegerSpinner(int value, int min, int max, int step, boolean allowEditing) static booleanstatic JLabelleftAlignedLabel(String text, boolean enabled) static JLabelleftAlignedLabel(String text, String uri, boolean enabled) static Colorstatic JTextArealongSmallMsg(String msg, Component parent) static Stringstatic voidDisplays a floating notification in the upper corner of the active screenvoidnotifyIfNewVersion(int msDelayBeforeShow) voidnotifyIfOldVersion(int msDelayBeforeCheck) Checks for available SNT updates in the background by querying the Neuroanatomy update site.static voidstatic voidrecolorTracks(JScrollPane scrollPane, Color color, boolean updateUI) static voidremoveIcon(Object rootPaneContainerOrWindow) static intrenderedWidth(String text) static voidstatic StringscaledMicrometer(double umLength, int digits) Returns a more human-readable representation of a length in micrometers.voidsearchForum(String query) static voidsetAutoDismiss(JDialog dialog) static voidstatic booleansetLookAndFeel(String lookAndFeelName, boolean persistentChoice) static booleansetLookAndFeel(String lookAndFeelName, boolean persistentChoice, Component... componentsToUpdate) voidvoidstatic voidstatic JLabelshortSmallMsg(String msg) static JLabelshortSmallMsg(String msg, boolean enabled) static JDialogvoidshowDirectory(File file) voidstatic voidshowHTMLDialog(String msg, String title) showHTMLDialog(String msg, String title, boolean modal) voidshowKeyboardShortcuts(InputMap[] inputMaps, ActionMap... actionMaps) Displays a sorted HTML table of all registered keyboard shortcuts in the specified inputMaps.voidvoidstatic voidstatic <T> Stringstatic Stringstatic floatstatic doubleuiScale()Returns the effective UI scale factor for the current display environment, accounting for HiDPI displays and user-configured scaling.static ColorintyesNoDialog(String msg, String title) intyesNoDialog(String msg, String title, String yesButtonLabel, String noButtonLabel) booleanyesNoHTMLDialog(String htmlMsg, String title, String yesLabel, String noLabel) org.scijava.ui.DialogPrompt.ResultyesNoPrompt(String message, String title)
-
Field Details
-
LAF_LIGHT
- See Also:
-
LAF_LIGHT_INTJ
- See Also:
-
LAF_DARK
- See Also:
-
LAF_DARCULA
- See Also:
-
LAF_DEFAULT
- See Also:
-
-
Constructor Details
-
GuiUtils
-
GuiUtils
public GuiUtils()Create a new GuiUtils instance using active (focused) window as parent.
-
-
Method Details
-
setParentToActiveWindow
public void setParentToActiveWindow() -
setParent
-
error
-
error
-
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
-
loadHints
-
applyRoundCorners
-
floatingMsg
-
tempMsg
-
tempMsg
-
isLegacy3DViewerAvailable
public static boolean isLegacy3DViewerAvailable() -
notify
Displays a floating notification in the upper corner of the active screen- Parameters:
msg- The message to be displayedmsDelayBeforeShow- the amount (in ms) of time before notification shouls be displayed
-
yesNoDialog
-
yesNoDialog
-
yesNoPrompt
-
getConfirmation
-
error
-
getConfirmation
-
getConfirmation2
-
getChoice
-
getTwoChoices
-
getChoiceWithInput
-
getChoiceAndDouble
-
getChoice
-
getMultipleChoices
-
getMultipleChoicesAndChoice
-
getPersistentConfirmation
-
getConfirmationAndOption
-
getConfirmationAndOption
-
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 titlemessage- the message/prompt shown at the top (can be HTML)choices- array of choices to display as radio buttonsdefaultChoice- 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
-
getString
-
getStrings
-
getStrings
-
getStringSet
-
getColorRGB
public org.scijava.util.ColorRGB getColorRGB(String title, org.scijava.util.ColorRGB defaultValue, String... panes) Simplified color chooser for ColorRGB.- See Also:
-
getColor
Simplified color chooser.- Parameters:
title- the title of the chooser dialogdefaultValue- the initial color set in the chooserpanes- 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
-
getPercentage
-
getDouble
-
getInt
-
getTwoNumbers
-
getThreeNumbers
-
getCoordinates
-
getCoordinatesInternal
-
getRange
-
adjustComponentThroughPrompt
-
getOpenFile
-
getSaveFile
-
getReconstructionFiles
-
getFile
-
getImageFile
-
getReconstructionFile
-
fileChooser
-
centeredMsg
-
centeredMsg
-
dialog
-
centerOnParent
-
centerOnParent
-
displayBanner
-
addTooltip
-
blinkingError
-
errorColor
-
warningColor
-
linkColor
-
shortSmallMsg
-
shortSmallMsg
-
longSmallMsg
-
showAboutDialog
-
showDirectory
-
toString
-
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:
- FlatLaf's
UIScale.getUserScaleFactor()the most reliable source when FlatLaf is active, as it combines OS-level DPI with any user overrides - AWT's
GraphicsConfiguration.getDefaultTransform().getScaleX(), the platform-level fallback ij.Prefs.getGuiScale(): last resort
- Returns:
- the scale factor (1.0 = no scaling, 2.0 = 200%, etc.)
- FlatLaf's
-
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
-
addSeparator
-
renderedWidth
-
leftAlignedLabel
-
leftAlignedLabel
-
searchForum
-
openURL
-
showKeyboardShortcuts
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 listedactionMaps- If null, all key binding are listed, including those with no corresponding action (e.g. disabled or inherited Swing defaults) will be listed
-
ctrlKey
-
getConsole
-
colorChooser
-
setRenderingHints
-
defaultGbc
-
recolorTracks
-
addClearButton
-
addPlaceholder
-
removeIcon
-
getSelectionColor
-
getDisabledComponentColor
-
integerSpinner
-
doubleSpinner
public static JSpinner doubleSpinner(double value, double min, double max, double step, int nDecimals) -
extractDouble
-
enableComponents
-
micrometer
-
scaledMicrometer
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 micrometersdigits- the number of output decimals- Returns:
- the scaled unit
-
errorPrompt
-
availableLookAndFeels
-
setLookAndFeel
public static void setLookAndFeel() -
getDnDFileChooser
-
restoreLookAndFeel
public static void restoreLookAndFeel() -
setLookAndFeel
-
setLookAndFeel
-
setAutoDismiss
-
truncate
-
tile
-
showHTMLDialog
-
showHTMLDialog
-
yesNoHTMLDialog
-
combineSNTChartPrompt
public void combineSNTChartPrompt() -
drawDragAndDropPlaceHolder
-
getTabbedPane
-
centerWindow
-
addCloseShortcut
-
enhanceTableDisplay
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 displayedwindowTitle- the title of the display window to find
-