- java.lang.Object
-
- org.controlsfx.control.action.Action
-
- All Implemented Interfaces:
EventListener
,EventHandler<ActionEvent>
- Direct Known Subclasses:
ActionGroup
,AnnotatedAction
,ListActionView.ListAction
,ListSelectionView.ListSelectionAction
public class Action extends Object implements EventHandler<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 aMenu
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.
-
-
Property Summary
Properties Type Property Description ObjectProperty<KeyCombination>
accelerator
The acceleratorKeyCombination
that should be used for this action, if it is used in an applicable UI control (most notablyMenuItem
).BooleanProperty
disabled
This represents whether the action should be available to the end user, or whether it should appeared 'grayed out'.ObjectProperty<Node>
graphic
The graphic that should be shown to the user in relation to this action.StringProperty
longText
The longer form of the text to show to the user (e.g.BooleanProperty
selected
Represents action's selected state.StringProperty
style
A string representation of the CSS style associated with this Action instance and passed to related UI controls.StringProperty
text
The text to show to the user.
-
Constructor Summary
Constructors Constructor Description Action(String text)
ConstructorsAction(String text, Consumer<ActionEvent> eventHandler)
Creates a new AbstractAction instance with the given String set as thetext
value, as well as theConsumer<ActionEvent>
set to be called when the action event is fired.Action(Consumer<ActionEvent> eventHandler)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ObjectProperty<KeyCombination>
acceleratorProperty()
The acceleratorKeyCombination
that should be used for this action, if it is used in an applicable UI control (most notablyMenuItem
).BooleanProperty
disabledProperty()
This represents whether the action should be available to the end user, or whether it should appeared 'grayed out'.KeyCombination
getAccelerator()
protected Consumer<ActionEvent>
getEventHandler()
Node
getGraphic()
String
getLongText()
ObservableMap<Object,Object>
getProperties()
Returns an observable map of properties on this Action for use primarily by application developers.String
getStyle()
Gets the value of the property style.ObservableList<String>
getStyleClass()
A list of String identifiers which can be used to logically group Nodes, specifically for an external style engine.String
getText()
ObjectProperty<Node>
graphicProperty()
The graphic that should be shown to the user in relation to this action.void
handle(ActionEvent event)
Defers to theConsumer<ActionEvent>
passed in to the Action constructor.boolean
isDisabled()
boolean
isSelected()
Selected state of the Action.protected void
lock()
StringProperty
longTextProperty()
The longer form of the text to show to the user (e.g.BooleanProperty
selectedProperty()
Represents action's selected state.void
setAccelerator(KeyCombination value)
Sets the acceleratorKeyCombination
that should be used for this action, if it is used in an applicable UI controlvoid
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<ActionEvent> eventHandler)
void
setGraphic(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 uservoid
setSelected(boolean selected)
Sets selected state of the Actionvoid
setStyle(String value)
Sets the value of the property style.void
setText(String value)
Sets the text of the Action.StringProperty
styleProperty()
A string representation of the CSS style associated with this Action instance and passed to related UI controls.StringProperty
textProperty()
The text to show to the user.
-
-
-
Property Detail
-
style
public final StringProperty styleProperty
A string representation of the CSS style associated with this Action instance and passed to related UI controls. This is analogous to the "style" attribute of an HTML element. Note that, like the HTML style attribute, this variable contains style properties and values and not the selector portion of a style rule.Parsing this style might not be supported on some limited platforms. It is recommended to use a standalone CSS file instead.
- See Also:
getStyle()
,setStyle(String)
-
selected
public final BooleanProperty selectedProperty
Represents action's selected state. Usually bound to selected state of components such as Toggle Buttons, CheckBOxes etc- See Also:
isSelected()
,setSelected(boolean)
-
text
public final StringProperty textProperty
The text to show to the user.- See Also:
getText()
,setText(String)
-
disabled
public final BooleanProperty disabledProperty
This represents whether the action should be available to the end user, or whether it should appeared 'grayed out'.- See Also:
isDisabled()
,setDisabled(boolean)
-
longText
public final StringProperty longTextProperty
The longer form of the text to show to the user (e.g. on aButton
, it is usually a tooltip that should be shown to the user if their mouse hovers over this action).- See Also:
getLongText()
,setLongText(String)
-
graphic
public final ObjectProperty<Node> graphicProperty
The graphic that should be shown to the user in relation to this action.- See Also:
getGraphic()
,setGraphic(Node)
-
accelerator
public final ObjectProperty<KeyCombination> acceleratorProperty
The acceleratorKeyCombination
that should be used for this action, if it is used in an applicable UI control (most notablyMenuItem
).- See Also:
getAccelerator()
,setAccelerator(KeyCombination)
-
-
Constructor Detail
-
Action
public Action(String text)
Constructors
-
Action
public Action(Consumer<ActionEvent> eventHandler)
-
Action
public Action(String text, Consumer<ActionEvent> eventHandler)
Creates a new AbstractAction instance with the given String set as thetext
value, as well as theConsumer<ActionEvent>
set to be called when the action event is fired.- Parameters:
text
- The string to display in the text property of controls such asButton
.eventHandler
- This will be called when the ActionEvent is fired.
-
-
Method Detail
-
lock
protected void lock()
-
setStyle
public final void setStyle(String value)
Sets the value of the property style.- Property description:
- A string representation of the CSS style associated with this
Action instance and passed to related UI controls.
This is analogous to the "style" attribute of an
HTML element. Note that, like the HTML style attribute, this
variable contains style properties and values and not the
selector portion of a style rule.
Parsing this style might not be supported on some limited platforms. It is recommended to use a standalone CSS file instead.
-
getStyle
public final String getStyle()
Gets the value of the property style.- Property description:
- A string representation of the CSS style associated with this
Action instance and passed to related UI controls.
This is analogous to the "style" attribute of an
HTML element. Note that, like the HTML style attribute, this
variable contains style properties and values and not the
selector portion of a style rule.
Parsing this style might not be supported on some limited platforms. It is recommended to use a standalone CSS file instead.
-
styleProperty
public final StringProperty styleProperty()
A string representation of the CSS style associated with this Action instance and passed to related UI controls. This is analogous to the "style" attribute of an HTML element. Note that, like the HTML style attribute, this variable contains style properties and values and not the selector portion of a style rule.Parsing this style might not be supported on some limited platforms. It is recommended to use a standalone CSS file instead.
- See Also:
getStyle()
,setStyle(String)
-
getStyleClass
public 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 BooleanProperty selectedProperty()
Represents action's selected state. Usually bound to selected state of components such as Toggle Buttons, CheckBOxes etc- See Also:
isSelected()
,setSelected(boolean)
-
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 StringProperty textProperty()
The text to show to the user.- See Also:
getText()
,setText(String)
-
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 BooleanProperty disabledProperty()
This represents whether the action should be available to the end user, or whether it should appeared 'grayed out'.- See Also:
isDisabled()
,setDisabled(boolean)
-
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 StringProperty longTextProperty()
The longer form of the text to show to the user (e.g. on aButton
, it is usually a tooltip that should be shown to the user if their mouse hovers over this action).- See Also:
getLongText()
,setLongText(String)
-
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 ObjectProperty<Node> graphicProperty()
The graphic that should be shown to the user in relation to this action.- See Also:
getGraphic()
,setGraphic(Node)
-
getGraphic
public final Node getGraphic()
- Returns:
- The graphic that should be shown to the user in relation to this action.
-
setGraphic
public final void setGraphic(Node value)
Sets the graphic that should be shown to the user in relation to this action.- Parameters:
value
-
-
acceleratorProperty
public final ObjectProperty<KeyCombination> acceleratorProperty()
The acceleratorKeyCombination
that should be used for this action, if it is used in an applicable UI control (most notablyMenuItem
).- See Also:
getAccelerator()
,setAccelerator(KeyCombination)
-
getAccelerator
public final 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(KeyCombination value)
Sets the acceleratorKeyCombination
that should be used for this action, if it is used in an applicable UI control- Parameters:
value
-
-
getProperties
public final 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<ActionEvent> getEventHandler()
-
setEventHandler
protected void setEventHandler(Consumer<ActionEvent> eventHandler)
-
handle
public final void handle(ActionEvent event)
Defers to theConsumer<ActionEvent>
passed in to the Action constructor.- Specified by:
handle
in interfaceEventHandler<ActionEvent>
-
-