- java.lang.Object
-
- org.controlsfx.control.action.ActionMap
-
public class ActionMap extends Object
Action Map provides an ability to create an action map of any object. Attempts to convert methods annotated withActionProxy
toAction
.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:
ActionProxy
,Action
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Action
action(String id)
Returns action by its id.static Collection<Action>
actions(String... ids)
Returns collection of actions by ids.static AnnotatedActionFactory
getActionFactory()
Returns the action factory used by ActionMap to construct AnnotatedAction instances.static void
register(Object target)
Attempts to convert target's methods annotated withActionProxy
toAction
s.static void
setActionFactory(AnnotatedActionFactory factory)
Sets the action factory used by ActionMap to construct AnnotatedAction instances.static void
unregister(Object target)
Removes all the actions associated with target object from the action map.
-
-
-
Method Detail
-
getActionFactory
public static AnnotatedActionFactory getActionFactory()
Returns the action factory used by ActionMap to construct AnnotatedAction instances. By default, this is an instance ofDefaultActionFactory
.
-
setActionFactory
public static void setActionFactory(AnnotatedActionFactory factory)
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
public static void register(Object target)
Attempts to convert target's methods annotated withActionProxy
toAction
s. 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
public static void unregister(Object target)
Removes all the actions associated with target object from the action map.- Parameters:
target
- object to work on
-
action
public static Action action(String id)
Returns action by its id.- Parameters:
id
- action id- Returns:
- action or null if id was not found
-
actions
public static Collection<Action> actions(String... ids)
Returns collection of actions by ids. Useful to createActionGroup
s. Ids starting with "---" are converted toActionUtils.ACTION_SEPARATOR
. Incorrect ids are ignored.- Parameters:
ids
- action ids- Returns:
- collection of actions
-
-