com.lightdev.app.shtm
Class DynamicResource

java.lang.Object
  extended by com.lightdev.app.shtm.DynamicResource

public class DynamicResource
extends java.lang.Object

Provides methods to dynamically combine components and resource bundles.

The actions, menus and menuitems created by this object are stored privately inside this object. This allows for later access to one of the stored items through the action command name.

IMPORTANT: Action command names must be unique, if actions or menus are added to an instance of this class and if the actions or menus are defined in different ResourceBundles, the action names must be unique over all ResourceBundles involved, because the action names are used as identifiers for connection of actions to compnents such as menus and menu items.

Component creation methods such as createMenu or createMenuItem expect definitions coming from a ResourceBundle, typically a text file ending with '.properties'.

Inside the .properties file, a menu definition is looking similar to

   # plugin menu definition
   plugin=test1 test2 test3
   pluginLabel=Test Plug-In

   # plugin menu items
   test1Label=Test 1
   test1Image=images/test1.gif
   test1Tip=test menu item 1
   test2Label=Test 2
   test3Label=Test 3
 

The calling class has to define actions named accordingly, e.g.

    DynamicResource dynRes = new DynamicResource("com.foo.bar.myPlugin");
    dynRes.addAction("test1", new MyAction("test1");
    dynRes.addAction("test2", new MyAction("test2");
    dynRes.addAction("test3", new MyAction("test3");
 


Field Summary
static java.lang.String IMAGE_EMPTY
           
static java.lang.String imageSuffix
          name constant for indicating image resources in the resource file
static java.lang.String menuSeparatorKey
          indicator for menu separators
static java.lang.String selectedIconSuffix
          name constant for selected icon names in the resource file
static java.lang.String toolTipSuffix
          name constant for tool tip strings in the resource file
 
Constructor Summary
DynamicResource()
          construct a new DynamicResource.
 
Method Summary
 void addAction(java.lang.String cmd, javax.swing.Action action)
          add an action to this DynamicResource
 javax.swing.JMenu createMenu(java.util.ResourceBundle resources, java.lang.String key)
          Create a menu for the app.
 javax.swing.JMenuBar createMenubar(java.util.ResourceBundle resources, java.lang.String name)
          Create a menu bar.
 javax.swing.JMenuItem createMenuItem(java.util.ResourceBundle resources, java.lang.String cmd)
          create a menu item
 javax.swing.JToolBar createToolBar(java.util.ResourceBundle resources, java.lang.String nm)
          Create a tool bar.
 javax.swing.Action getAction(java.lang.String cmd)
          get an action from the commands table
 java.util.Enumeration getActions()
          get all actions registered in this DynamicResource
 javax.swing.Icon getIconForCommand(java.util.ResourceBundle resources, java.lang.String cmd)
          get the icon for a given command.
 javax.swing.Icon getIconForName(java.util.ResourceBundle resources, java.lang.String name)
           
 javax.swing.JMenu getMenu(java.lang.String cmd)
           
 javax.swing.JMenuItem getMenuItem(java.lang.String cmd)
          get the menu item that was created for the given command.
 java.net.URL getResource(java.util.ResourceBundle resources, java.lang.String key)
          get the location of a resource.
 java.lang.String getResourceString(java.util.ResourceBundle resources, java.lang.String nm)
          get a string from the resources file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

imageSuffix

public static final java.lang.String imageSuffix
name constant for indicating image resources in the resource file

See Also:
Constant Field Values

toolTipSuffix

public static final java.lang.String toolTipSuffix
name constant for tool tip strings in the resource file

See Also:
Constant Field Values

selectedIconSuffix

public static final java.lang.String selectedIconSuffix
name constant for selected icon names in the resource file

See Also:
Constant Field Values

menuSeparatorKey

public static final java.lang.String menuSeparatorKey
indicator for menu separators

See Also:
Constant Field Values

IMAGE_EMPTY

public static final java.lang.String IMAGE_EMPTY
See Also:
Constant Field Values
Constructor Detail

DynamicResource

public DynamicResource()
construct a new DynamicResource.

Method Detail

addAction

public void addAction(java.lang.String cmd,
                      javax.swing.Action action)
add an action to this DynamicResource

Parameters:
cmd - the internal identifier for the action
action - the action to associate with actionCommand

createMenubar

public javax.swing.JMenuBar createMenubar(java.util.ResourceBundle resources,
                                          java.lang.String name)
Create a menu bar. This reads the definition of the menu from the associated resource file.

Parameters:
resources - the ResourceBundle to get the menu definition from
name - name of the menu bar definition
Returns:
the created menu bar

createMenu

public javax.swing.JMenu createMenu(java.util.ResourceBundle resources,
                                    java.lang.String key)
Create a menu for the app. This reads the definition of the menu from the associated resource file.

Parameters:
resources - the ResourceBundle to get the menu definition from
key - the key of the menu definition in the resource file
Returns:
the created menu

getMenu

public javax.swing.JMenu getMenu(java.lang.String cmd)

createMenuItem

public javax.swing.JMenuItem createMenuItem(java.util.ResourceBundle resources,
                                            java.lang.String cmd)
create a menu item

Parameters:
resources - the ResourceBundle to get the item definition from
cmd - the action command to be associated with the new menu item
Returns:
the created menu item

getResourceString

public java.lang.String getResourceString(java.util.ResourceBundle resources,
                                          java.lang.String nm)
get a string from the resources file

Parameters:
resources - the ResourceBundle to get the string from
nm - the key of the string
Returns:
the string for the given key or null if not found

getAction

public javax.swing.Action getAction(java.lang.String cmd)
get an action from the commands table

Parameters:
cmd - the name of the action the get
Returns:
the action found for the given name

getActions

public java.util.Enumeration getActions()
get all actions registered in this DynamicResource

Returns:
all actions

getMenuItem

public javax.swing.JMenuItem getMenuItem(java.lang.String cmd)
get the menu item that was created for the given command.

Parameters:
cmd - name of the action.
Returns:
item created for the given command or null if one wasn't created.

getIconForCommand

public javax.swing.Icon getIconForCommand(java.util.ResourceBundle resources,
                                          java.lang.String cmd)
get the icon for a given command.

If the resource bundle has a reference to an icon for the given commamd, an icon is created for the respective image resource. otherwise, null is returned.

Parameters:
resources - the ResourceBundle to get the icon from
cmd - the command an icon is requested for
Returns:
the icon for that command or null, if none is present for this command

getIconForName

public javax.swing.Icon getIconForName(java.util.ResourceBundle resources,
                                       java.lang.String name)

getResource

public java.net.URL getResource(java.util.ResourceBundle resources,
                                java.lang.String key)
get the location of a resource.

Resources such as images are delivered with the application in the path containing the application's classes. The resources file coming with SimplyHTML has a key for every resource pointing to the subdirectory relative to the class path.

Parameters:
resources - the ResourceBundle to get the resource from
key - the key of the resource in the resource file
Returns:
the resource location as a URL

createToolBar

public javax.swing.JToolBar createToolBar(java.util.ResourceBundle resources,
                                          java.lang.String nm)
Create a tool bar. This reads the definition of a tool bar from the associated resource file.

Parameters:
resources - the ResourceBundle to get the tool bar definition from
nm - the name of the tool bar definition in the resource file
Returns:
the created tool bar