public class ActionFactory extends Object implements ActionListener, Actionable
KeyStroke
with
KeyStroke.getKeyStroke(key, modifierMask);
In order to facilitate easier translation, Enabled, SmallIcon and LargeIcon can be specified in a parallel resource, whose name is suffixed with "_control" as in Desktop_control. This is meant to extrapolate the constant behavior of an action into a file that probably does not need to be internationalized. If it does, for example, to suppress the display of icons, then one would create a resource further suffixed with the language and perhaps country, as in Desktop_control_fa.
To add another twist, several actions may have the same name and mnemonic, differing perhaps by tooltip. To facilitate the sharing of these definitions, an Aliases resource is defined to contain common values. If the value of a ActionName.Name is prefixed with "Alias.", as in Go.Name=Alias.Go, then Go will be used as the ActionName to look up values in the Aliases resource.
Aliases defines defaults that can be overridden by the referring resource file. The only value that cannot be overridden is Name.
When an action is fired, this class, as a listener, reflects the action on the class providing the resource. For example, DesktopActions creates an ActionFactory from the Desktop ResourceBundle. When the Exit action is fired, ActionFactory calls DesktopActions.doExit(ActionEvent event) or DesktopActions.doExit(), if the first did not exist.
The GNU General Public License for details.
Modifier and Type | Field and Description |
---|---|
private Map<String,CWAction> |
actions
The map of known CWActions
|
private Object |
bean
The object to which we forward events
|
private static org.slf4j.Logger |
log
The log stream
|
private static String |
METHOD_PREFIX
The prefix to methods that we call
|
private static String |
MISSING_RESOURCE
The tooltip for actions that we generate to paper around missing
resources Normally we would assert, but in live we might want to limp on.
|
Constructor and Description |
---|
ActionFactory()
Creates an ActionFactory that merely holds actions.
|
ActionFactory(Object bean)
Creates an ActionFactory that merely arranges for actions to be called against a bean.
|
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(ActionEvent ev) |
void |
actionPerformed(String action) |
CWAction |
addAction(String key) |
CWAction |
addAction(String key,
String name)
Lookup an existing action for actionName.
|
private CWAction |
buildAction(String key,
String name) |
JButton |
createJButton(CWAction action,
ActionListener listener)
Build a button from an action.
|
Action |
findAction(String key)
Get the Action for the given actionName.
|
private static final String MISSING_RESOURCE
private static final String METHOD_PREFIX
private Object bean
private static final org.slf4j.Logger log
public ActionFactory()
public ActionFactory(Object bean)
bean
- public void actionPerformed(String action)
actionPerformed
in interface Actionable
public void actionPerformed(ActionEvent ev)
actionPerformed
in interface ActionListener
public Action findAction(String key)
key
- the internal name of the CWActionpublic JButton createJButton(CWAction action, ActionListener listener)
action
- the action to usepublic CWAction addAction(String key, String name)
key
- The short name by which this action is known. It is used to
lookup the action for reuse.name
- This is required. The value is used for the text of the
Action.