Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.crosswire.common.swing
Class ActionFactory

    java.lang.Object
      org.crosswire.common.swing.ActionFactory

All Implemented Interfaces:
  ActionListener, EventListener, Actionable

    public class ActionFactory

extends Object
implements ActionListener, Actionable

The ActionFactory is responsible for creating CWActions and making them available to the program. Each Action is constructed from resources of the form: simplename.field=value where simplename is the ACTION_COMMAND_KEY value and field is one of the CWAction constants, e.g. LargeIcon. The values for the icons are a path which can be found as a resource.

Author:
  DM Smith [dmsmith555 at yahoo dot com], Joe Walker [joe at eireneh dot com]
See Also:
  `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 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
`private CWAction` | `createAction(String acronymn, String name, String short_desc, String long_desc, Integer mnemonic, KeyStroke accel, Icon small_icon, Icon large_icon, boolean enabled)` Create a new CWAction
`JButton` | `createJButton(String key)` Build a button from an action that consist solely of the icon.
`JLabel` | `createJLabel(String key)` Construct a JLabel from the Action.
`private KeyStroke` | `getAccelerator(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.
`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 resources, String actionName)` Convert the string to a mnemonic
`private int` | `getModifier(String[] modifiers)`
`private String` | `getOptionalActionString(ResourceBundle resources, String actionName, String field)` Lookup an action/field combination, returning null for missing resoruces.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### MISSING_RESOURCE

    private static final 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.

  See Also:
    Constant Field Values

### METHOD_PREFIX

    private static final String METHOD_PREFIX

  The prefix to methods that we call

  See Also:
    Constant Field Values

### SEPARATOR

    private static final String SEPARATOR

  What we lookup

  See Also:
    Constant Field Values

### TEST

    private static final String TEST

  The test string to find actions

  See Also:
    Constant Field Values

### bean

    private Object bean

  The object to which we forward events

### log

    private static final Logger log

  The log stream

### actions

    private Map actions

  The map of known CWActions

Constructor Detail

### ActionFactory

    public ActionFactory(Class type,
                         Object bean)

  Constructor that distinguishes between the object to call and the type to look up resources against. This is useful for when you are writing a class with subclasses but wish to keep the resources registered in the name of the superclass.

Method Detail

### actionPerformed

    public void actionPerformed(String action)

  Specified by:
    `actionPerformed` in interface `Actionable`

### actionPerformed

    public void actionPerformed(ActionEvent ev)

  Specified by:
    `actionPerformed` in interface `ActionListener`

### getAction

    public Action getAction(String key)

  Get the Action for the given actionName.

  Parameters:
    `key` - the internal name of the CWAction
  Returns:
    CWAction null if it does not exist

### createJLabel

    public JLabel createJLabel(String key)

  Construct a JLabel from the Action. Only Action.NAME and Action.MNEMONIC_KEY are used.

  Parameters:
    `key` - the internal name of the CWAction
  Returns:
    A label, asserting if missing resources or with default values otherwise

### createJButton

    public JButton createJButton(String key)

  Build a button from an action that consist solely of the icon.

  Parameters:
    `key` - the action to use
  Returns:
    the button

### buildActionMap

    private void buildActionMap(Class basis)

  Build the map of actions from resources

### getActionString

    private String getActionString(ResourceBundle resources,
                                   String actionName,
                                   String field)

  Lookup an action/field combination, warning about missing resources rather than excepting.

### getOptionalActionString

    private String getOptionalActionString(ResourceBundle resources,
                                           String actionName,
                                           String field)

  Lookup an action/field combination, returning null for missing resoruces.

### getIcon

    private Icon getIcon(ResourceBundle resources,
                         String actionName,
                         String iconName)

  Get an icon for the string

### getMnemonic

    private Integer getMnemonic(ResourceBundle resources,
                                String actionName)

  Convert the string to a mnemonic

### getAccelerator

    private KeyStroke getAccelerator(ResourceBundle resources,
                                     String actionName)

  Convert the string to a valid Accelerator (ie a KeyStroke)

### getInteger

    private int getInteger(String str)
                    throws NumberFormatException

  Convert the string to an integer. The string is either a single character or it is hex number.

  Returns:
    the integer value of the accelerator
  Throws:
    `NumberFormatException`

### getModifier

    private int getModifier(String[] modifiers)

### createAction

    private CWAction createAction(String acronymn,
                                  String name,
                                  String short_desc,
                                  String long_desc,
                                  Integer mnemonic,
                                  KeyStroke accel,
                                  Icon small_icon,
                                  Icon large_icon,
                                  boolean enabled)

  Create a new CWAction

  Parameters:
    `acronymn` - The internal name for this action. Must not be null.
    `name` - The label for buttons, menu items, ...
    `small_icon` - The icon used in labelling
    `large_icon` - The icon to use if large icons are needed
    `short_desc` - Tooltip text
    `long_desc` - Context sensitive help
    `mnemonic` - The java.awt.event.EventKey value for the mnemonic
    `accel` - The accelerator key
    `enabled` - Whether the CWAction is enabled initially
  Returns:
    CWAction

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Copyright ¨ 2003-2007
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD