java.lang.Object
org.controlsfx.control.action.ActionMap
Action Map provides an ability to create an action map of any object.
Attempts to convert methods annotated with
ActionProxy to Action.
Code Example
Here's a very simple example of how to use ActionMap to register a class (in this class it is the application class itself), and to then retrieve actions out of the ActionMap (via the staticaction(String) method:
public class ActionMapDemo extends Application {
public ActionMapDemo() {
ActionMap.register(this);
Action action11 = ActionMap.action("action11");
Button actionButton = ActionUtils.createButton(action11);
}
@ActionProxy(text="Action 1.1", graphic="start.png", accelerator="ctrl+shift+T")
private void action11() {
System.out.println( "Action 1.1 is executed");
}
}
If you require more control over the creation of the Action objects, you can either set the
global ActionFactory by calling ActionMap.setActionFactory() and/or you can use the factory
property on individual @ActionProxy declarations to set the factory on a case-by-case basis.- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic ActionReturns action by its id.static Collection<Action>Returns collection of actions by ids.static AnnotatedActionFactoryReturns the action factory used by ActionMap to construct AnnotatedAction instances.static voidAttempts to convert target's methods annotated withActionProxytoActions.static voidsetActionFactory(AnnotatedActionFactory factory) Sets the action factory used by ActionMap to construct AnnotatedAction instances.static voidunregister(Object target) Removes all the actions associated with target object from the action map.
-
Method Details
-
getActionFactory
Returns the action factory used by ActionMap to construct AnnotatedAction instances. By default, this is an instance ofDefaultActionFactory. -
setActionFactory
Sets the action factory used by ActionMap to construct AnnotatedAction instances. This factory can be overridden on a case-by-case basis by specifying a factory class inActionProxy.factory() -
register
Attempts to convert target's methods annotated withActionProxytoActions. Three types of methods are currently converted: parameter-less methods, methods with one parameter of typeActionEvent, and methods with two parameters (ActionEvent,Action). Note that this method supports safe re-registration of a given instance or of another instance of the same class that has already been registered. If another instance of the same class is registered, then those actions will now be associated with the new instance. The first instance is implicitly unregistered. Actions are registered with their id or method name if id is not defined.- Parameters:
target- object to work on- Throws:
IllegalStateException- if a method with unsupported parameters is annotated withActionProxy.
-
unregister
Removes all the actions associated with target object from the action map.- Parameters:
target- object to work on
-
action
Returns action by its id.- Parameters:
id- action id- Returns:
- action or null if id was not found
-
actions
Returns collection of actions by ids. Useful to createActionGroups. Ids starting with "---" are converted toActionUtils.ACTION_SEPARATOR. Incorrect ids are ignored.- Parameters:
ids- action ids- Returns:
- collection of actions
-