Class ActionTools

java.lang.Object
qupath.lib.gui.actions.ActionTools

public class ActionTools extends Object
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
  • Constructor Details

    • ActionTools

      public ActionTools()
  • Method Details

    • getAnnotatedActions

      public static List<org.controlsfx.control.action.Action> getAnnotatedActions(Object obj)
      Actions can be parsed from the accessible (usually public) fields of any object, as well as methods annotated with ActionMethod. 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 update
      element - the annotated element (often a Field).
      baseMenu - prepended to any ActionMenu actions. This makes it easier to insert items in sub-menus without needing to specify the full menu path every time.
    • putActionProperty

      public 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.
      Parameters:
      node - the node for which the action should be added
      action - an action to store as the properties of the node
    • putActionProperty

      public 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.
      Parameters:
      node - the node for which the action should be added
      action - an action to store as the properties of the node
    • getActionProperty

      public 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.
      Parameters:
      node -
      Returns:
    • getActionProperty

      public 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.
      Parameters:
      item -
      Returns:
    • isSelectable

      public static boolean isSelectable(org.controlsfx.control.action.Action action)
      Specify that an Action 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

      public static ActionTools.ActionBuilder actionBuilder(String text, Consumer<ActionEvent> handler)
      Create an ActionTools.ActionBuilder with the specified text and event handler.
      Parameters:
      text -
      handler -
      Returns:
      a new ActionTools.ActionBuilder
    • actionBuilder

      public static ActionTools.ActionBuilder actionBuilder()
      Create an ActionTools.ActionBuilder with no properties set.
      Returns:
      a new ActionTools.ActionBuilder
    • actionBuilder

      public static ActionTools.ActionBuilder actionBuilder(Consumer<ActionEvent> handler)
      Create an ActionTools.ActionBuilder with the specified event handler.
      Parameters:
      handler -
      Returns:
      a new ActionTools.ActionBuilder
    • createMenuItem

      public static MenuItem createMenuItem(org.controlsfx.control.action.Action action)
      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 item
      group - 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

      public static MenuItem createCheckMenuItem(org.controlsfx.control.action.Action action)
      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

      public static CheckBox createCheckBox(org.controlsfx.control.action.Action action)
      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

      public static ToggleButton createToggleButton(org.controlsfx.control.action.Action action)
      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

      public static Button createButton(org.controlsfx.control.action.Action action)
      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

      public static Button createButtonWithGraphicOnly(org.controlsfx.control.action.Action action)
      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 its Action.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 its Action.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 its Action.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

      public static org.controlsfx.control.action.Action createAction(Runnable command, String name)
      Create an action whose event handler calls a runnable, with a specified name.
      Parameters:
      command - the runnable to call
      name - the name of the action, set as the text property
      Returns:
      a new Action
    • createAction

      public static org.controlsfx.control.action.Action createAction(Runnable command)
      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 bound
      name - 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 added
      message - an expression that can return a message; the expression should not be null, but the message can be