|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.crosswire.common.swing.ActionFactory
public class ActionFactory
The ActionFactory is responsible for creating CWActions
and making them available to the program. Each Action is
constructed from resources of the form: ActionName.field=value
where ActionName is the ACTION_COMMAND_KEY value and
field is one of the CWAction constants, e.g. LargeIcon.
Field is one of:
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.
for license details.
The copyright to this program is held by it's authors.
Field Summary | |
---|---|
private Map |
actions
The map of known CWActions |
private static String |
ALIAS
|
private static ResourceBundle |
aliases
The aliases known by this system. |
private static String |
ALIASES
|
private Object |
bean
The object to which we forward events |
private static 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. |
private static String |
SEPARATOR
What we lookup |
private static String |
TEST
The test string to find actions |
Constructor Summary | |
---|---|
ActionFactory(Class type,
Object bean)
Constructor that distinguishes between the object to call and the type to look up resources against. |
Method Summary | |
---|---|
void |
actionPerformed(ActionEvent ev)
|
void |
actionPerformed(String action)
|
private void |
buildActionMap(Class basis)
Build the map of actions from resources |
JButton |
createActionIcon(String key)
Build a button from an action that consist solely of the icon. |
JButton |
createActionIcon(String key,
ActionListener listener)
Build a button from an action that consist solely of the icon. |
JButton |
createJButton(String key)
Build a button from an action. |
JButton |
createJButton(String key,
ActionListener listener)
Build a button from an action. |
JLabel |
createJLabel(String key)
Construct a JLabel from the Action. |
private KeyStroke |
getAccelerator(ResourceBundle nicknames,
ResourceBundle resources,
String actionName)
Convert the string to a valid Accelerator (ie a KeyStroke) |
Action |
getAction(String key)
Get the Action for the given actionName. |
Action |
getAction(String key,
ActionListener listener)
Get the Action for the given actionName. |
private String |
getActionString(ResourceBundle resources,
String actionName,
String field)
Lookup an action/field combination, warning about missing resources rather than excepting. |
private Icon |
getIcon(ResourceBundle resources,
String actionName,
String iconName)
Get an icon for the string |
private int |
getInteger(String str)
Convert the string to an integer. |
private Integer |
getMnemonic(ResourceBundle nicknames,
ResourceBundle resources,
String actionName)
Convert the string to a mnemonic |
private int |
getModifier(String[] modifiers)
|
private String |
getOptionalActionString(ResourceBundle nicknames,
ResourceBundle resources,
String actionName,
String field)
Lookup an action/field combination, returning null for missing resources. |
private String |
getOptionalActionString(ResourceBundle resources,
String actionName,
String field)
Lookup an action/field combination, returning null for missing resources. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final String MISSING_RESOURCE
private static final String METHOD_PREFIX
private static final String SEPARATOR
private static final String TEST
private Object bean
private static final String ALIASES
private static final String ALIAS
private static final Logger log
private static ResourceBundle aliases
private Map actions
Constructor Detail |
---|
public ActionFactory(Class type, Object bean)
Method Detail |
---|
public void actionPerformed(String action)
actionPerformed
in interface Actionable
public void actionPerformed(ActionEvent ev)
actionPerformed
in interface ActionListener
public Action getAction(String key)
key
- the internal name of the CWAction
public Action getAction(String key, ActionListener listener)
key
- the internal name of the CWAction
public JLabel createJLabel(String key)
key
- the internal name of the CWAction
public JButton createActionIcon(String key)
key
- the action to use
public JButton createActionIcon(String key, ActionListener listener)
key
- the action to use
public JButton createJButton(String key)
key
- the action to use
public JButton createJButton(String key, ActionListener listener)
key
- the action to use
private void buildActionMap(Class basis)
private String getActionString(ResourceBundle resources, String actionName, String field)
private String getOptionalActionString(ResourceBundle resources, String actionName, String field)
private String getOptionalActionString(ResourceBundle nicknames, ResourceBundle resources, String actionName, String field)
private Icon getIcon(ResourceBundle resources, String actionName, String iconName)
private Integer getMnemonic(ResourceBundle nicknames, ResourceBundle resources, String actionName)
private KeyStroke getAccelerator(ResourceBundle nicknames, ResourceBundle resources, String actionName)
private int getInteger(String str) throws NumberFormatException
NumberFormatException
private int getModifier(String[] modifiers)
|
Copyright ยจ 2003-2007 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |