de.michab.mack
Class ConfigurableAction

java.lang.Object
  extended byjavax.swing.AbstractAction
      extended byde.michab.mack.ConfigurableAction
All Implemented Interfaces:
javax.swing.Action, java.awt.event.ActionListener, java.lang.Cloneable, java.util.EventListener, java.io.Serializable
Direct Known Subclasses:
ActAbout, ActExitApplication

public abstract class ConfigurableAction
extends javax.swing.AbstractAction

A base class that supports configuration and localisation of actions. It adds the concept of a unique key to the action used to read the localised attributes from the resource bundle passed to the setAttributes() method. The table below lists the configurable attributes supported by this class:

Key Comment
NAME The Action's display name.
TOOLTIP Text to be displayed on the Action's tooltip.
DESCRIPTION A textual description of the Action.
POPUP Flag indicating whether the Action should show up in a popup menu.
MENU Flag indicating whether the Action is part of the menu. The value of the flag is the menu group, see ActionManager.
TOOLBAR Flag indicating whether the Action is part of the application's toolbar.
KEYSTROKE A keystroke that results in an Action invocation. Displayed also in the application and context sensitive popup menu.
ICON The icon to be used to represent the Action in menus and on the toolbar. Note that the value for the ICON key is the path name of an image file, e.g. de/michab/apps/lichen/cosexplorer/res/Lumumba.gif

An ActionManager is used to create menus and toolbars from the COnfigurableActions that are available in an application.

Version:
$Revision: 1.8 $
Author:
Michael Binz
See Also:
ActionManager, Serialized Form

Field Summary
 
Fields inherited from class javax.swing.AbstractAction
changeSupport, enabled
 
Fields inherited from interface javax.swing.Action
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SHORT_DESCRIPTION, SMALL_ICON
 
Constructor Summary
ConfigurableAction(java.lang.String key)
          Create an instance for the given key.
ConfigurableAction(java.lang.String key, boolean enabled)
          Create a new action for the given key with the passed enabled setting.
 
Method Summary
 void configureFrom(java.util.ResourceBundle b)
          A template method to be overridden if an action requires addititional information from the resource file.
protected static java.awt.Component getDialogRoot(java.util.EventObject event)
          Computes the default parent component for a dialog displayed by this action.
 java.lang.String getKey()
          Get the Action's key.
 javax.swing.JComponent getToolbarComponent()
          Creates a JComponent that is to be placed on a toolbar.
protected  java.lang.String localize(java.util.ResourceBundle b, java.lang.String key)
          Read the value for the passed key from the resource bundle.
protected  java.lang.String localize(java.util.ResourceBundle b, java.lang.String key, java.lang.String deflt)
          Read the value for the passed key from the resource bundle.
protected  javax.swing.Icon localizeIcon(java.util.ResourceBundle b, java.lang.String key)
          Return an icon for the given key.
 
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.awt.event.ActionListener
actionPerformed
 

Constructor Detail

ConfigurableAction

public ConfigurableAction(java.lang.String key,
                          boolean enabled)
Create a new action for the given key with the passed enabled setting.

Parameters:
key - The new action's key.
enabled - The initial setting for the enabled poperty.

ConfigurableAction

public ConfigurableAction(java.lang.String key)
Create an instance for the given key. The new action is disabled by default.

Parameters:
key - The new action's key.
Method Detail

getDialogRoot

protected static final java.awt.Component getDialogRoot(java.util.EventObject event)
Computes the default parent component for a dialog displayed by this action. The returned result can always directly passed into dialog creation, even in case it is null.

Parameters:
event - The event that triggered the action.
Returns:
Either a reference to a component or null in case no root component could be found.

getToolbarComponent

public javax.swing.JComponent getToolbarComponent()
Creates a JComponent that is to be placed on a toolbar. This default implementation returns a JButton instance. Override if other components need to be placed on the toolbar. Restrict yourself to simple components, since the real estate on a toolbar is rare.

Returns:
A component to be placed on the toolbar.

getKey

public java.lang.String getKey()
Get the Action's key.

Returns:
The Actions key.

configureFrom

public void configureFrom(java.util.ResourceBundle b)
A template method to be overridden if an action requires addititional information from the resource file. It is called after the basic attributes have been initialised. This default implementation is guaranteed to be empty and needs not to be called from the overriding method.

Parameters:
b - The resource bundle to read the configuration from.

localizeIcon

protected final javax.swing.Icon localizeIcon(java.util.ResourceBundle b,
                                              java.lang.String key)
Return an icon for the given key.

Parameters:
b - The resource bundle to use for resource lookup.
key - The resource name to lookup.
Returns:
A reference to the icon or null if the icon was not found.

localize

protected final java.lang.String localize(java.util.ResourceBundle b,
                                          java.lang.String key)
Read the value for the passed key from the resource bundle. If the key is not found, null is returned. Note that the passed key will be extended with the action's key before resolution is tried. E.g. if the actions key is A_KEY and the parameter key's value is name then it is tried to resolve A_KEY.name in the resource bundle.

Parameters:
b - The resource bundle used to resolve the key.
key - The key used for resource resolution.
Returns:
The resolved resource value or null if the key could not be found.
See Also:
Localiser.localise( ResourceBundle, String, String )

localize

protected final java.lang.String localize(java.util.ResourceBundle b,
                                          java.lang.String key,
                                          java.lang.String deflt)
Read the value for the passed key from the resource bundle. If the key is not found, the passed default value is returned.

Parameters:
b - The resource bundle used to resolve the key.
key - The key used for resource resolution.
deflt - The valuje to return in case the key could not be resolved.
Returns:
The resolved resource value or null if the key could not be found.