Package qupath.lib.gui.actions
Class ActionTools
java.lang.Object
qupath.lib.gui.actions.ActionTools
Helper methods for generating and configuring Actions and UI elements.
This has some similarities with ActionUtils
, however has QuPath-specific behavior that make it
a better choice when working with actions related to QuPathGUI
.
- Author:
- Pete Bankhead
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Builder class for customAction
objects. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic ActionTools.ActionBuilder
Create anActionTools.ActionBuilder
with no properties set.static ActionTools.ActionBuilder
actionBuilder
(String text, Consumer<ActionEvent> handler) Create anActionTools.ActionBuilder
with the specified text and event handler.static ActionTools.ActionBuilder
actionBuilder
(Consumer<ActionEvent> handler) Create anActionTools.ActionBuilder
with the specified event handler.static org.controlsfx.control.action.Action
createAction
(Runnable command) Create an action whose event handler calls a runnable.static org.controlsfx.control.action.Action
createAction
(Runnable command, String name) Create an action whose event handler calls a runnable, with a specified name.static Button
createButton
(org.controlsfx.control.action.Action action) Create a button from an action, showing both the text and graphic if available.static Button
createButtonWithGraphicOnly
(org.controlsfx.control.action.Action action) Create a button from an action, showing only the graphic and not any text.static CheckBox
createCheckBox
(org.controlsfx.control.action.Action action) Create a checkbox from an action.static MenuItem
createCheckMenuItem
(org.controlsfx.control.action.Action action) Create a menu item from an action that makes use of a selected property.static MenuItem
createCheckMenuItem
(org.controlsfx.control.action.Action action, ToggleGroup group) Create a menu item from an action that makes use of a selected property.static MenuItem
createMenuItem
(org.controlsfx.control.action.Action action) Create a menu item from an action.static org.controlsfx.control.action.Action
createSelectableAction
(ObservableValue<Boolean> property) Create an unnamed action with itsAction.selectedProperty()
bound to a specified property.static org.controlsfx.control.action.Action
createSelectableAction
(ObservableValue<Boolean> property, String name) Create an action with itsAction.selectedProperty()
bound to a specified property.static org.controlsfx.control.action.Action
createSelectableAction
(ObservableValue<Boolean> property, String name, Node icon, KeyCombination accelerator) Create an action with itsAction.selectedProperty()
bound to a specified property, with optional graphic and accelerator.static org.controlsfx.control.action.Action
static <T> org.controlsfx.control.action.Action
createSelectableCommandAction
(SelectableItem<T> command) static <T> org.controlsfx.control.action.Action
createSelectableCommandAction
(SelectableItem<T> command, String name) Create an action from a selectable icon.static <T> org.controlsfx.control.action.Action
createSelectableCommandAction
(SelectableItem<T> command, String name, Node icon, KeyCombination accelerator) static <T> org.controlsfx.control.action.Action
createSelectableCommandAction
(SelectableItem<T> command, ObservableValue<String> name, ObservableValue<Node> icon, KeyCombination accelerator) static org.controlsfx.control.action.Action
Create an action indicating that a separator should be added (e.g.static ToggleButton
createToggleButton
(org.controlsfx.control.action.Action action) Create a toggle button from an action, showing both the text and graphic if available.static ToggleButton
createToggleButtonWithGraphicOnly
(org.controlsfx.control.action.Action action) Create a toggle button from an action, showing only the graphic and not any text.static org.controlsfx.control.action.Action
getActionProperty
(MenuItem item) Retrieve an Action stored within the properties of a menu item, or null if no action is found.static org.controlsfx.control.action.Action
getActionProperty
(Node node) Retrieve an Action stored within the properties of a node, or null if no action is found.static List
<org.controlsfx.control.action.Action> Actions can be parsed from the accessible (usually public) fields of any object, as well as methods annotated withActionMethod
.static void
installInfoMessage
(org.controlsfx.control.action.Action action, ObjectExpression<InfoMessage> message) Install an optional info message to the action.static boolean
isSelectable
(org.controlsfx.control.action.Action action) Specify that anAction
has a meaningful 'selected' status.static void
parseAnnotations
(org.controlsfx.control.action.Action action, AnnotatedElement element) Parse annotations relating to an action, updating the properties of the action.static void
parseAnnotations
(org.controlsfx.control.action.Action action, AnnotatedElement element, String baseMenu) Parse annotations relating to an action, updating the properties of the action with an optional base menu.static void
putActionProperty
(MenuItem node, org.controlsfx.control.action.Action action) Add an Action to the properties of a MenuItem, so that it may be retrieved later.static void
putActionProperty
(Node node, org.controlsfx.control.action.Action action) Add an Action to the properties of a Node, so that it may be retrieved later.static void
setSelectable
(org.controlsfx.control.action.Action action, boolean selectable) Set the selectable property for an action.
-
Constructor Details
-
ActionTools
public ActionTools()
-
-
Method Details
-
getAnnotatedActions
Actions can be parsed from the accessible (usually public) fields of any object, as well as methods annotated withActionMethod
. Any annotations associated with the actions will be parsed.- Parameters:
obj
- the object containing the action fields or methods- Returns:
- a list of parsed and configured actions
-
parseAnnotations
public static void parseAnnotations(org.controlsfx.control.action.Action action, AnnotatedElement element) Parse annotations relating to an action, updating the properties of the action.- Parameters:
action
-element
-
-
parseAnnotations
public static void parseAnnotations(org.controlsfx.control.action.Action action, AnnotatedElement element, String baseMenu) Parse annotations relating to an action, updating the properties of the action with an optional base menu.- Parameters:
action
- the action to updateelement
- the annotated element (often aField
).baseMenu
- prepended to anyActionMenu
actions. This makes it easier to insert items in sub-menus without needing to specify the full menu path every time.
-
putActionProperty
Add an Action to the properties of a Node, so that it may be retrieved later.- Parameters:
node
- the node for which the action should be addedaction
- an action to store as the properties of the node
-
putActionProperty
Add an Action to the properties of a MenuItem, so that it may be retrieved later.- Parameters:
node
- the node for which the action should be addedaction
- an action to store as the properties of the node
-
getActionProperty
Retrieve an Action stored within the properties of a node, or null if no action is found.- Parameters:
node
-- Returns:
-
getActionProperty
Retrieve an Action stored within the properties of a menu item, or null if no action is found.- Parameters:
item
-- Returns:
-
isSelectable
public static boolean isSelectable(org.controlsfx.control.action.Action action) Specify that anAction
has a meaningful 'selected' status. Such actions often relate to properties and lack action event handlers.- Parameters:
action
-- Returns:
- true if the action has been flagged as selectable, false otherwise.
-
setSelectable
public static void setSelectable(org.controlsfx.control.action.Action action, boolean selectable) Set the selectable property for an action.- Parameters:
action
-selectable
-- See Also:
-
createSeparator
public static org.controlsfx.control.action.Action createSeparator()Create an action indicating that a separator should be added (e.g. to a menu or toolbar).- Returns:
-
actionBuilder
Create anActionTools.ActionBuilder
with the specified text and event handler.- Parameters:
text
-handler
-- Returns:
- a new
ActionTools.ActionBuilder
-
actionBuilder
Create anActionTools.ActionBuilder
with no properties set.- Returns:
- a new
ActionTools.ActionBuilder
-
actionBuilder
Create anActionTools.ActionBuilder
with the specified event handler.- Parameters:
handler
-- Returns:
- a new
ActionTools.ActionBuilder
-
createMenuItem
Create a menu item from an action. This stores a reference to the action as a property of the menu item.- Parameters:
action
- the action from which to construct the menu item- Returns:
- a new
MenuItem
configured according to the action.
-
createCheckMenuItem
public static MenuItem createCheckMenuItem(org.controlsfx.control.action.Action action, ToggleGroup group) Create a menu item from an action that makes use of a selected property. This stores a reference to the action as a property of the menu item.- Parameters:
action
- the action from which to construct the menu itemgroup
- a toggle group to associate with the action; if present, a radio menu item will be returned- Returns:
- a new
MenuItem
configured according to the action.
-
createCheckMenuItem
Create a menu item from an action that makes use of a selected property. This stores a reference to the action as a property of the menu item.- Parameters:
action
- the action from which to construct the menu item- Returns:
- a new
MenuItem
configured according to the action.
-
createCheckBox
Create a checkbox from an action. This stores a reference to the action as a property of the checkbox.- Parameters:
action
- the action from which to construct the checkbox- Returns:
- a new
CheckBox
configured according to the action.
-
createToggleButtonWithGraphicOnly
public static ToggleButton createToggleButtonWithGraphicOnly(org.controlsfx.control.action.Action action) Create a toggle button from an action, showing only the graphic and not any text. This stores a reference to the action as a property of the toggle button.- Parameters:
action
-- Returns:
-
createToggleButton
Create a toggle button from an action, showing both the text and graphic if available. This stores a reference to the action as a property of the toggle button.- Parameters:
action
-- Returns:
-
createButton
Create a button from an action, showing both the text and graphic if available. This stores a reference to the action as a property of the button.- Parameters:
action
- the action from which to construct the button- Returns:
- a new
Button
configured according to the action.
-
createButtonWithGraphicOnly
Create a button from an action, showing only the graphic and not any text. This stores a reference to the action as a property of the button.- Parameters:
action
- the action from which to construct the button- Returns:
- a new
Button
configured according to the action.
-
createSelectableAction
public static org.controlsfx.control.action.Action createSelectableAction(ObservableValue<Boolean> property, String name, Node icon, KeyCombination accelerator) Create an action with itsAction.selectedProperty()
bound to a specified property, with optional graphic and accelerator.- Parameters:
property
- the property to which the selected property of the action should be bound. The binding will be bidirectional if possible.name
- the name of the action (set as the text property)icon
- an icon for the icon (set as the graphic property)accelerator
- an accelerator for the action- Returns:
- a new
Action
initialized according to the provided parameters
-
createSelectableAction
public static org.controlsfx.control.action.Action createSelectableAction(ObservableValue<Boolean> property) Create an unnamed action with itsAction.selectedProperty()
bound to a specified property.- Parameters:
property
- the property to which the selected property of the action should be bound. The binding will be bidirectional if possible.- Returns:
- a new
Action
initialized according to the provided parameters
-
createSelectableAction
public static org.controlsfx.control.action.Action createSelectableAction(ObservableValue<Boolean> property, String name) Create an action with itsAction.selectedProperty()
bound to a specified property.- Parameters:
property
- the property to which the selected property of the action should be bound. The binding will be bidirectional if possible.name
- the name of the action (set as the text property)- Returns:
- a new
Action
initialized according to the provided parameters
-
createAction
Create an action whose event handler calls a runnable, with a specified name.- Parameters:
command
- the runnable to callname
- the name of the action, set as the text property- Returns:
- a new
Action
-
createAction
Create an action whose event handler calls a runnable.- Parameters:
command
- the runnable to call- Returns:
- a new
Action
-
createSelectableCommandAction
public static <T> org.controlsfx.control.action.Action createSelectableCommandAction(SelectableItem<T> command, String name, Node icon, KeyCombination accelerator) -
createSelectableCommandAction
public static <T> org.controlsfx.control.action.Action createSelectableCommandAction(SelectableItem<T> command, ObservableValue<String> name, ObservableValue<Node> icon, KeyCombination accelerator) -
createSelectableCommandAction
public static <T> org.controlsfx.control.action.Action createSelectableCommandAction(SelectableItem<T> command, String name) Create an action from a selectable icon.- Type Parameters:
T
-- Parameters:
command
- item to which the action's selected property should be boundname
- text to include in the action- Returns:
-
createSelectableCommandAction
public static <T> org.controlsfx.control.action.Action createSelectableCommandAction(SelectableItem<T> command) -
createSelectableCommandAction
public static org.controlsfx.control.action.Action createSelectableCommandAction(ObservableBooleanValue value) -
installInfoMessage
public static void installInfoMessage(org.controlsfx.control.action.Action action, ObjectExpression<InfoMessage> message) Install an optional info message to the action. If the provided object expression is not empty, a badge will be added to nodes created from the action and display the tooltip provided by the expression.- Parameters:
action
- the action to which the message should be addedmessage
- an expression that can return a message; the expression should not be null, but the message can be
-