|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.lightdev.app.shtm.DynamicResource
public class DynamicResource
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 |
---|
public static final java.lang.String imageSuffix
public static final java.lang.String toolTipSuffix
public static final java.lang.String selectedIconSuffix
public static final java.lang.String menuSeparatorKey
public static final java.lang.String IMAGE_EMPTY
Constructor Detail |
---|
public DynamicResource()
Method Detail |
---|
public void addAction(java.lang.String cmd, javax.swing.Action action)
DynamicResource
cmd
- the internal identifier for the actionaction
- the action to associate with actionCommandpublic javax.swing.JMenuBar createMenubar(java.util.ResourceBundle resources, java.lang.String name)
resources
- the ResourceBundle to get the menu definition fromname
- name of the menu bar definition
public javax.swing.JMenu createMenu(java.util.ResourceBundle resources, java.lang.String key)
resources
- the ResourceBundle to get the menu definition fromkey
- the key of the menu definition in the resource file
public javax.swing.JMenu getMenu(java.lang.String cmd)
public javax.swing.JMenuItem createMenuItem(java.util.ResourceBundle resources, java.lang.String cmd)
resources
- the ResourceBundle to get the item definition fromcmd
- the action command to be associated
with the new menu item
public java.lang.String getResourceString(java.util.ResourceBundle resources, java.lang.String nm)
resources
- the ResourceBundle to get the string fromnm
- the key of the string
public javax.swing.Action getAction(java.lang.String cmd)
cmd
- the name of the action the get
public java.util.Enumeration getActions()
DynamicResource
public javax.swing.JMenuItem getMenuItem(java.lang.String cmd)
cmd
- name of the action.
public javax.swing.Icon getIconForCommand(java.util.ResourceBundle resources, java.lang.String cmd)
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.
resources
- the ResourceBundle to get the icon fromcmd
- the command an icon is requested for
public javax.swing.Icon getIconForName(java.util.ResourceBundle resources, java.lang.String name)
public java.net.URL getResource(java.util.ResourceBundle resources, java.lang.String key)
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.
resources
- the ResourceBundle to get the resource fromkey
- the key of the resource in the resource file
public javax.swing.JToolBar createToolBar(java.util.ResourceBundle resources, java.lang.String nm)
resources
- the ResourceBundle to get the tool bar definition fromnm
- the name of the tool bar definition in the resource file
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |