java.lang.Object
qupath.fx.utils.FXUtils
Static utility methods to help when working with JavaFX.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
addCloseWindowShortcuts
(javafx.stage.Stage stage) Add shortcuts to close a window using the standard shortcuts (Shortcut+W, Esc).static void
addCloseWindowShortcuts
(javafx.stage.Stage stage, Collection<? extends javafx.scene.input.KeyCombination> keyCombinations) Add shortcuts to close a window using the specified key combinations.static javafx.beans.property.DoubleProperty
bindSliderAndTextField
(javafx.scene.control.Slider slider, javafx.scene.control.TextField tf, boolean expandLimits) Bind the value of a slider and contents of a text field with a default number of decimal places, so that both may be used to set a numeric (double) value.static javafx.beans.property.DoubleProperty
bindSliderAndTextField
(javafx.scene.control.Slider slider, javafx.scene.control.TextField tf, boolean expandLimits, int ndp) Bind the value of a slider and contents of a text field, so that both may be used to set a numeric (double) value.static <T> T
callOnApplicationThread
(Callable<T> callable) Return a result after executing a Callable on the JavaFX Platform thread.static <T> javafx.scene.control.ListCell<T>
createCustomListCell
(Function<T, String> stringFun) Create aListCell
with custom methods to derive text for a specific object.static <T> javafx.scene.control.ListCell<T>
createCustomListCell
(Function<T, String> stringFun, Function<T, javafx.scene.Node> graphicFun) Create aListCell
with custom methods to derive text and a graphic for a specific object.static javafx.scene.control.Spinner<Double>
createDynamicStepSpinner
(double minValue, double maxValue, double defaultValue, double minStepValue, int scale) Create a newSpinner
for double values with a step size that adapts according to the absolute value of the current spinner value.static javafx.beans.binding.DoubleBinding
createStepBinding
(javafx.beans.value.ObservableValue<Double> value, double minStep, int scale) Create a binding that may be used with aSpinner
to adjust the step size dynamically based upon the absolute value of the input.static Collection<javafx.scene.Node>
getContents
(javafx.scene.Parent parent, Collection<javafx.scene.Node> collection, boolean doRecursive) Get the nodes that are included within aParent
, optionally adding other nodes recursively.static <T extends javafx.scene.Node>
Collection<T>getContentsOfType
(javafx.scene.Parent parent, Class<T> cls, boolean doRecursive) Get the nodes of type T that are contained within aParent
, optionally adding other nodes recursively.static javafx.stage.Screen
getMaxOverlapScreen
(double x, double y, double width, double height) Get the screen that contains the largest overlap with the specified bounding rectangle, or null if no screen overlaps with the rectangle.static javafx.stage.Screen
getMaxOverlapScreen
(javafx.geometry.Rectangle2D bounds) Get the screen that contains the largest overlap with the specified bounding rectangle, or null if no screen overlaps with the rectangle.static javafx.stage.Screen
getScreen
(javafx.scene.Node node) Get the screen that contains a node, or null if no screen contains the node.static javafx.stage.Screen
getScreen
(javafx.stage.Window window) Get the screen that contains a window, or null if no screen contains the window.static javafx.stage.Window
getWindow
(javafx.scene.Node node) Get theWindow
containing a specificNode
.static void
installSelectAllOrNoneMenu
(org.controlsfx.control.CheckComboBox<?> combo) Add a context menu to a CheckComboBox to quickly select all items, or clear selection.static void
makeDraggableStage
(javafx.stage.Stage stage) Make a stage moveable by click and drag on the scene.static void
makeTabUndockable
(javafx.scene.control.Tab tab) Make a tab undockable, via a context menu available on right-click.static void
Call .refresh() on all the ListView, TreeView, TableView and TreeTableViews found throughout the application.static void
refreshAllListsAndTables
(javafx.scene.Parent parent) Call .refresh() on all the ListView, TreeView, TableView and TreeTableViews found under a parent component, searching recursively.static <T> void
resetSpinnerNullToPrevious
(javafx.scene.control.Spinner<T> spinner) Add a listener to the value of a spinner, resetting it to its previous value if it becomes null.static void
restrictTextFieldInputToNumber
(javafx.scene.control.TextField textField, boolean allowDecimals) Restrict theTextField
input to positive/negative integer (or double) format (including scientific notation).static void
retainWindowPosition
(javafx.stage.Window window) Request that a window retains its position and size even when hidden.static void
runOnApplicationThread
(Runnable runnable) Run on the application thread and wait until this is complete.static void
simplifyTitledPane
(javafx.scene.control.TitledPane pane, boolean boldTitle) Simplify the appearance of aTitledPane
using CSS.
-
Constructor Details
-
FXUtils
public FXUtils()
-
-
Method Details
-
callOnApplicationThread
Return a result after executing a Callable on the JavaFX Platform thread.- Parameters:
callable
-- Returns:
-
runOnApplicationThread
Run on the application thread and wait until this is complete.- Parameters:
runnable
-
-
getWindow
public static javafx.stage.Window getWindow(javafx.scene.Node node) Get theWindow
containing a specificNode
.- Parameters:
node
-- Returns:
-
getScreen
public static javafx.stage.Screen getScreen(javafx.scene.Node node) Get the screen that contains a node, or null if no screen contains the node. If the node spans across multiple screens, then the one with the largest overlap will be returned.- Parameters:
node
-- Returns:
-
getScreen
public static javafx.stage.Screen getScreen(javafx.stage.Window window) Get the screen that contains a window, or null if no screen contains the window. If the window spans across multiple screens, then the one with the largest overlap will be returned.- Parameters:
window
-- Returns:
-
getMaxOverlapScreen
public static javafx.stage.Screen getMaxOverlapScreen(double x, double y, double width, double height) Get the screen that contains the largest overlap with the specified bounding rectangle, or null if no screen overlaps with the rectangle.- Parameters:
x
-y
-width
-height
-- Returns:
-
getMaxOverlapScreen
public static javafx.stage.Screen getMaxOverlapScreen(javafx.geometry.Rectangle2D bounds) Get the screen that contains the largest overlap with the specified bounding rectangle, or null if no screen overlaps with the rectangle.- Parameters:
bounds
-- Returns:
-
makeDraggableStage
public static void makeDraggableStage(javafx.stage.Stage stage) Make a stage moveable by click and drag on the scene. This is useful for undecorated stages.- Parameters:
stage
-
-
retainWindowPosition
public static void retainWindowPosition(javafx.stage.Window window) Request that a window retains its position and size even when hidden.- Parameters:
window
-
-
makeTabUndockable
public static void makeTabUndockable(javafx.scene.control.Tab tab) Make a tab undockable, via a context menu available on right-click. When undocked, the tab will become a floating window. If the window is closed, it will be added back to its original tab pane.- Parameters:
tab
-- Since:
- v0.4.0
-
restrictTextFieldInputToNumber
public static void restrictTextFieldInputToNumber(javafx.scene.control.TextField textField, boolean allowDecimals) Restrict theTextField
input to positive/negative integer (or double) format (including scientific notation).N.B: the
TextArea
might still finds itself in an invalid state at any moment, as:- character deletion is always permitted (e.g. -1.5e5 -> -1.5e; deletion of last character).
- users are allowed to input a minus sign, in order to permit manual typing, which then needs to accept intermediate (invalid) states.
- users are allowed to input an 'E'/'e' character, in order to permit manual typing as well, which then needs to accept intermediate (invalid) states.
- copy-pasting is not as strictly restricted (e.g. -1.6e--5 and 1.6e4e9 are accepted, but won't be parsed).
Some invalid states are accepted and should therefore be caught after this method returns.
P.S: 'copy-pasting' an entire value (e.g.
'' -> '1.2E-6'
) is regarded as the opposite of 'manual typing' (e.g.'' -> '-', '-' -> '-1', ...
).- Parameters:
textField
-allowDecimals
-
-
resetSpinnerNullToPrevious
public static <T> void resetSpinnerNullToPrevious(javafx.scene.control.Spinner<T> spinner) Add a listener to the value of a spinner, resetting it to its previous value if it becomes null.- Type Parameters:
T
-- Parameters:
spinner
-
-
bindSliderAndTextField
public static javafx.beans.property.DoubleProperty bindSliderAndTextField(javafx.scene.control.Slider slider, javafx.scene.control.TextField tf, boolean expandLimits) Bind the value of a slider and contents of a text field with a default number of decimal places, so that both may be used to set a numeric (double) value.This aims to overcome the challenge of keeping both synchronized, while also quietly handling parsing errors that may occur whenever the text field is being edited.
- Parameters:
slider
- slider that may be used to adjust the valuetf
- text field that may also be used to adjust the value and show it visuallyexpandLimits
- optionally expand slider min/max range to suppose the text field input; if this is false, the text field may contain a different value that is unsupported by the slider- Returns:
- a property representing the value represented by the slider and text field
-
bindSliderAndTextField
public static javafx.beans.property.DoubleProperty bindSliderAndTextField(javafx.scene.control.Slider slider, javafx.scene.control.TextField tf, boolean expandLimits, int ndp) Bind the value of a slider and contents of a text field, so that both may be used to set a numeric (double) value.This aims to overcome the challenge of keeping both synchronized, while also quietly handling parsing errors that may occur whenever the text field is being edited.
- Parameters:
slider
- slider that may be used to adjust the valuetf
- text field that may also be used to adjust the value and show it visuallyexpandLimits
- optionally expand slider min/max range to suppose the text field input; if this is false, the text field may contain a different value that is unsupported by the sliderndp
- if ≥ 0, this will be used to define the number of decimal places shown in the text field- Returns:
- a property representing the value represented by the slider and text field
-
installSelectAllOrNoneMenu
public static void installSelectAllOrNoneMenu(org.controlsfx.control.CheckComboBox<?> combo) Add a context menu to a CheckComboBox to quickly select all items, or clear selection.- Parameters:
combo
-
-
createCustomListCell
public static <T> javafx.scene.control.ListCell<T> createCustomListCell(Function<T, String> stringFun, Function<T, javafx.scene.Node> graphicFun) Create aListCell
with custom methods to derive text and a graphic for a specific object.- Type Parameters:
T
-- Parameters:
stringFun
- function to extract a stringgraphicFun
- function to extract a graphic- Returns:
- a new list cell
-
createCustomListCell
public static <T> javafx.scene.control.ListCell<T> createCustomListCell(Function<T, String> stringFun) Create aListCell
with custom methods to derive text for a specific object.- Type Parameters:
T
-- Parameters:
stringFun
- function to extract a string- Returns:
- a new list cell
-
createDynamicStepSpinner
public static javafx.scene.control.Spinner<Double> createDynamicStepSpinner(double minValue, double maxValue, double defaultValue, double minStepValue, int scale) Create a newSpinner
for double values with a step size that adapts according to the absolute value of the current spinner value. This is useful for cases where the possible values cover a wide range (e.g. potential brightness/contrast values).- Parameters:
minValue
-maxValue
-defaultValue
-minStepValue
-scale
- number of decimal places to shift the step size relative to the log10 of the value (suggested default = 1)- Returns:
-
createStepBinding
public static javafx.beans.binding.DoubleBinding createStepBinding(javafx.beans.value.ObservableValue<Double> value, double minStep, int scale) Create a binding that may be used with aSpinner
to adjust the step size dynamically based upon the absolute value of the input.- Parameters:
value
- current value for theSpinner
minStep
- minimum step size (should be > 0)scale
- number of decimal places to shift the step size relative to the log10 of the value (suggested default = 1)- Returns:
- a binding that may be attached to a
SpinnerValueFactory.DoubleSpinnerValueFactory.amountToStepByProperty()
-
refreshAllListsAndTables
public static void refreshAllListsAndTables()Call .refresh() on all the ListView, TreeView, TableView and TreeTableViews found throughout the application. This is particularly useful after a locale change. -
refreshAllListsAndTables
public static void refreshAllListsAndTables(javafx.scene.Parent parent) Call .refresh() on all the ListView, TreeView, TableView and TreeTableViews found under a parent component, searching recursively. This is particularly useful after a locale change.- Parameters:
parent
-
-
getContents
public static Collection<javafx.scene.Node> getContents(javafx.scene.Parent parent, Collection<javafx.scene.Node> collection, boolean doRecursive) Get the nodes that are included within aParent
, optionally adding other nodes recursively. Without the recursive search, this is similar toParent.getChildrenUnmodifiable()
in most cases, except that a separate collection is used. However in some casesgetItems()
must be used instead. Currently this applies only toSplitPane
but this may be used elsewhere if appropriate.- Parameters:
parent
-collection
-doRecursive
-- Returns:
-
getContentsOfType
public static <T extends javafx.scene.Node> Collection<T> getContentsOfType(javafx.scene.Parent parent, Class<T> cls, boolean doRecursive) Get the nodes of type T that are contained within aParent
, optionally adding other nodes recursively. This can be helpful, for example, to extract all the Buttons or Regions within a pane in order to set some property of all of them.- Type Parameters:
T
-- Parameters:
parent
-cls
-doRecursive
-- Returns:
- See Also:
-
simplifyTitledPane
public static void simplifyTitledPane(javafx.scene.control.TitledPane pane, boolean boldTitle) Simplify the appearance of aTitledPane
using CSS. This is useful if using aTitledPane
to define expanded options, which should be displayed unobtrusively.- Parameters:
pane
- the pane to simplifyboldTitle
- if true, the title should be displayed in bold
-
addCloseWindowShortcuts
public static void addCloseWindowShortcuts(javafx.stage.Stage stage) Add shortcuts to close a window using the standard shortcuts (Shortcut+W, Esc).- Parameters:
stage
-- See Also:
-
addCloseWindowShortcuts
public static void addCloseWindowShortcuts(javafx.stage.Stage stage, Collection<? extends javafx.scene.input.KeyCombination> keyCombinations) Add shortcuts to close a window using the specified key combinations. These are applied as key released events, so they will not interfere with text input.- Parameters:
stage
-keyCombinations
-- See Also:
-