Class Action

  • All Implemented Interfaces:
    EventListener, javafx.event.EventHandler<javafx.event.ActionEvent>
    Direct Known Subclasses:
    ActionGroup, AnnotatedAction, ColumnFixAction, ListActionView.ListAction, ListSelectionView.ListSelectionAction, RowFixAction

    public class Action
    extends Object
    implements javafx.event.EventHandler<javafx.event.ActionEvent>
    A base class for Action API.

    What is an Action?

    An action in JavaFX can be used to separate functionality and state from a control. For example, if you have two or more controls that perform the same function (e.g. one in a Menu and another on a toolbar), consider using an Action object to implement the function. An Action object provides centralized handling of the state of action-event-firing components such as buttons, menu items, etc. The state that an action can handle includes text, graphic, long text (i.e. tooltip text), and disabled.
    • Constructor Summary

      Constructors 
      Constructor Description
      Action​(String text)
      Constructors
      Action​(String text, Consumer<javafx.event.ActionEvent> eventHandler)
      Creates a new AbstractAction instance with the given String set as the text value, as well as the Consumer<ActionEvent> set to be called when the action event is fired.
      Action​(Consumer<javafx.event.ActionEvent> eventHandler)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      javafx.beans.property.ObjectProperty<javafx.scene.input.KeyCombination> acceleratorProperty()
      The accelerator KeyCombination that should be used for this action, if it is used in an applicable UI control (most notably MenuItem).
      javafx.beans.property.BooleanProperty disabledProperty()
      This represents whether the action should be available to the end user, or whether it should appeared 'grayed out'.
      javafx.scene.input.KeyCombination getAccelerator()  
      protected Consumer<javafx.event.ActionEvent> getEventHandler()  
      javafx.scene.Node getGraphic()  
      String getLongText()  
      javafx.collections.ObservableMap<Object,​Object> getProperties()
      Returns an observable map of properties on this Action for use primarily by application developers.
      String getStyle()  
      javafx.collections.ObservableList<String> getStyleClass()
      A list of String identifiers which can be used to logically group Nodes, specifically for an external style engine.
      String getText()  
      javafx.beans.property.ObjectProperty<javafx.scene.Node> graphicProperty()
      The graphic that should be shown to the user in relation to this action.
      void handle​(javafx.event.ActionEvent event)
      Defers to the Consumer<ActionEvent> passed in to the Action constructor.
      boolean isDisabled()  
      boolean isSelected()
      Selected state of the Action.
      protected void lock()  
      javafx.beans.property.StringProperty longTextProperty()
      The longer form of the text to show to the user (e.g. on a Button, it is usually a tooltip that should be shown to the user if their mouse hovers over this action).
      javafx.beans.property.BooleanProperty selectedProperty()
      Represents action's selected state.
      void setAccelerator​(javafx.scene.input.KeyCombination value)
      Sets the accelerator KeyCombination that should be used for this action, if it is used in an applicable UI control
      void setDisabled​(boolean value)
      Sets whether the action should be available to the end user, or whether it should appeared 'grayed out'.
      protected void setEventHandler​(Consumer<javafx.event.ActionEvent> eventHandler)  
      void setGraphic​(javafx.scene.Node value)
      Sets the graphic that should be shown to the user in relation to this action.
      void setLongText​(String value)
      Sets the longer form of the text to show to the user
      void setSelected​(boolean selected)
      Sets selected state of the Action
      void setStyle​(String value)  
      void setText​(String value)
      Sets the text of the Action.
      javafx.beans.property.StringProperty styleProperty()  
      javafx.beans.property.StringProperty textProperty()
      The text to show to the user.
    • Constructor Detail

      • Action

        public Action​(String text)
        Constructors
      • Action

        public Action​(Consumer<javafx.event.ActionEvent> eventHandler)
      • Action

        public Action​(String text,
                      Consumer<javafx.event.ActionEvent> eventHandler)
        Creates a new AbstractAction instance with the given String set as the text value, as well as the Consumer<ActionEvent> set to be called when the action event is fired.
        Parameters:
        text - The string to display in the text property of controls such as Button.
        eventHandler - This will be called when the ActionEvent is fired.
    • Method Detail

      • lock

        protected void lock()
      • setStyle

        public final void setStyle​(String value)
      • getStyle

        public final String getStyle()
      • styleProperty

        public final javafx.beans.property.StringProperty styleProperty()
      • getStyleClass

        public javafx.collections.ObservableList<String> getStyleClass()
        A list of String identifiers which can be used to logically group Nodes, specifically for an external style engine. This variable is analogous to the "class" attribute on an HTML element and, as such, each element of the list is a style class to which this Node belongs.
        See Also:
        CSS3 class selectors
      • selectedProperty

        public final javafx.beans.property.BooleanProperty selectedProperty()
        Represents action's selected state. Usually bound to selected state of components such as Toggle Buttons, CheckBOxes etc
        Returns:
        An observable BooleanProperty that represents the current selected state, and which can be observed for changes.
      • isSelected

        public final boolean isSelected()
        Selected state of the Action.
        Returns:
        The selected state of this action.
      • setSelected

        public final void setSelected​(boolean selected)
        Sets selected state of the Action
        Parameters:
        selected -
      • textProperty

        public final javafx.beans.property.StringProperty textProperty()
        The text to show to the user.
        Returns:
        An observable StringProperty that represents the current text for this property, and which can be observed for changes.
      • getText

        public final String getText()
        Returns:
        the text of the Action.
      • setText

        public final void setText​(String value)
        Sets the text of the Action.
        Parameters:
        value -
      • disabledProperty

        public final javafx.beans.property.BooleanProperty disabledProperty()
        This represents whether the action should be available to the end user, or whether it should appeared 'grayed out'.
        Returns:
        An observable BooleanProperty that represents the current disabled state for this property, and which can be observed for changes.
      • isDisabled

        public final boolean isDisabled()
        Returns:
        whether the action is available to the end user, or whether it should appeared 'grayed out'.
      • setDisabled

        public final void setDisabled​(boolean value)
        Sets whether the action should be available to the end user, or whether it should appeared 'grayed out'.
        Parameters:
        value -
      • longTextProperty

        public final javafx.beans.property.StringProperty longTextProperty()
        The longer form of the text to show to the user (e.g. on a Button, it is usually a tooltip that should be shown to the user if their mouse hovers over this action).
        Returns:
        An observable StringProperty that represents the current long text for this property, and which can be observed for changes.
      • getLongText

        public final String getLongText()
        Returns:
        The longer form of the text to show to the user
        See Also:
        longTextProperty()
      • setLongText

        public final void setLongText​(String value)
        Sets the longer form of the text to show to the user
        Parameters:
        value -
        See Also:
        longTextProperty()
      • graphicProperty

        public final javafx.beans.property.ObjectProperty<javafx.scene.Node> graphicProperty()
        The graphic that should be shown to the user in relation to this action.
        Returns:
        An observable ObjectProperty that represents the current graphic for this property, and which can be observed for changes.
      • getGraphic

        public final javafx.scene.Node getGraphic()
        Returns:
        The graphic that should be shown to the user in relation to this action.
      • setGraphic

        public final void setGraphic​(javafx.scene.Node value)
        Sets the graphic that should be shown to the user in relation to this action.
        Parameters:
        value -
      • acceleratorProperty

        public final javafx.beans.property.ObjectProperty<javafx.scene.input.KeyCombination> acceleratorProperty()
        The accelerator KeyCombination that should be used for this action, if it is used in an applicable UI control (most notably MenuItem).
        Returns:
        An observable ObjectProperty that represents the current accelerator for this property, and which can be observed for changes.
      • getAccelerator

        public final javafx.scene.input.KeyCombination getAccelerator()
        Returns:
        The accelerator KeyCombination that should be used for this action, if it is used in an applicable UI control
      • setAccelerator

        public final void setAccelerator​(javafx.scene.input.KeyCombination value)
        Sets the accelerator KeyCombination that should be used for this action, if it is used in an applicable UI control
        Parameters:
        value -
      • getProperties

        public final javafx.collections.ObservableMap<Object,​Object> getProperties()
        Returns an observable map of properties on this Action for use primarily by application developers.
        Returns:
        An observable map of properties on this Action for use primarily by application developers
      • getEventHandler

        protected Consumer<javafx.event.ActionEvent> getEventHandler()
      • setEventHandler

        protected void setEventHandler​(Consumer<javafx.event.ActionEvent> eventHandler)
      • handle

        public final void handle​(javafx.event.ActionEvent event)
        Defers to the Consumer<ActionEvent> passed in to the Action constructor.
        Specified by:
        handle in interface javafx.event.EventHandler<javafx.event.ActionEvent>