com.townleyenterprises.swing
Class ResourceUIBuilder

java.lang.Object
  extended bycom.townleyenterprises.swing.AbstractUIBuilder
      extended bycom.townleyenterprises.swing.ResourceUIBuilder
All Implemented Interfaces:
UIBuilder

public class ResourceUIBuilder
extends AbstractUIBuilder

This class provides a concrete implementation of the UIBuilder interface which reads the UI descriptions from a resource bundle. This class is heavily based on the mechanism used in the Java JFC/Swing Notepad demo. This class uses the same approach (and even methods), but abstracts this functionality from a particular application.

It is important to note that this class assumes that the values for each of the labels, etc. are resource keys which will be resolved by the registered resource bundles. String literals should not normally be used for these values.

Since:
2.1
Version:
$Id: ResourceUIBuilder.java,v 1.10 2004/11/28 20:10:52 atownley Exp $
Author:
Andrew S. Townley

Field Summary
static java.lang.String ACCEL_SUFFIX
          this is the suffix used when looking up accelerator/shortcuts
static java.lang.String LABEL_SUFFIX
          this is the suffix used when looking up various labels
static java.lang.String MNEMONIC_SUFFIX
          this is the suffix used when looking up mnemonics
static java.lang.String STATUS_SUFFIX
          this is the suffix used when looking up status text
static java.lang.String STATUSTEXT_PROPERTY
          this is the client property used to hold the status text
 
Fields inherited from class com.townleyenterprises.swing.AbstractUIBuilder
MAINMENU
 
Constructor Summary
ResourceUIBuilder(ResourceProvider loader, java.util.Map actions)
          The constructor takes the initialized ResourceLoader used to read the UI definition.
ResourceUIBuilder(ResourceProvider loader, java.util.Map actions, javax.swing.event.ChangeListener menuStatusListener)
          This version of the constructor takes a ChangeListener which will be notified whenver the menu item or menu changes state.
 
Method Summary
 javax.swing.JMenu buildMenu(java.lang.String key)
          This method builds a menu based on the specified key.
 javax.swing.JMenuBar buildMenuBar(java.lang.String key)
          Menubars are described in terms of a whitespace delimited string representing the top-level menus.
protected  javax.swing.JMenuItem buildMenuItemHelper(java.lang.String key)
          This method builds an individual menu item and associates an action provided in the constructor.
protected  java.lang.String[] tokenize(java.lang.String source)
          This is a utility method which is used to return an array of strings parsed from the source.
 
Methods inherited from class com.townleyenterprises.swing.AbstractUIBuilder
buildMenuBar, buildMenuItem, getAction, getMenuItem
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LABEL_SUFFIX

public static final java.lang.String LABEL_SUFFIX
this is the suffix used when looking up various labels

See Also:
Constant Field Values

MNEMONIC_SUFFIX

public static final java.lang.String MNEMONIC_SUFFIX
this is the suffix used when looking up mnemonics

See Also:
Constant Field Values

ACCEL_SUFFIX

public static final java.lang.String ACCEL_SUFFIX
this is the suffix used when looking up accelerator/shortcuts

See Also:
Constant Field Values

STATUS_SUFFIX

public static final java.lang.String STATUS_SUFFIX
this is the suffix used when looking up status text

See Also:
Constant Field Values

STATUSTEXT_PROPERTY

public static final java.lang.String STATUSTEXT_PROPERTY
this is the client property used to hold the status text

See Also:
Constant Field Values
Constructor Detail

ResourceUIBuilder

public ResourceUIBuilder(ResourceProvider loader,
                         java.util.Map actions)
The constructor takes the initialized ResourceLoader used to read the UI definition. Since the description of the menu structure isn't localized, it allows language-specific strings to be resolved by the normal facilities provided by the Java ResourceBundle class.

Parameters:
loader - the resource loader
actions - the action map

ResourceUIBuilder

public ResourceUIBuilder(ResourceProvider loader,
                         java.util.Map actions,
                         javax.swing.event.ChangeListener menuStatusListener)
This version of the constructor takes a ChangeListener which will be notified whenver the menu item or menu changes state. This is most often used to implement status bar help text.

Parameters:
loader - the resource loader
actions - the action map
menuStatusListener - the change listener
Method Detail

buildMenuBar

public javax.swing.JMenuBar buildMenuBar(java.lang.String key)
Menubars are described in terms of a whitespace delimited string representing the top-level menus. This string is tokenized and each token is used to look up and build the given menu.

The key used for the menu bar is menubar.

Specified by:
buildMenuBar in interface UIBuilder
Specified by:
buildMenuBar in class AbstractUIBuilder
Parameters:
key - the menubar key
Returns:
a JMenuBar instance

buildMenu

public javax.swing.JMenu buildMenu(java.lang.String key)
This method builds a menu based on the specified key. To add separators to the menu, simply insert - characters into the menu definition.

Specified by:
buildMenu in interface UIBuilder
Specified by:
buildMenu in class AbstractUIBuilder
Parameters:
key - the key for the menu
Returns:
a JMenu instance

buildMenuItemHelper

protected javax.swing.JMenuItem buildMenuItemHelper(java.lang.String key)
This method builds an individual menu item and associates an action provided in the constructor. If no action is present, the menu item is disabled.

The original version of this method from the Notepad example deals with menu item images. Currently, images aren't supported by this class. Support will be added to the ResourceLoader shortly, so this class will be able to use it "free" once that happens.

Specified by:
buildMenuItemHelper in class AbstractUIBuilder
Parameters:
key - the menu item key
Returns:
a JMenuItem

tokenize

protected java.lang.String[] tokenize(java.lang.String source)
This is a utility method which is used to return an array of strings parsed from the source. It is assumed that the strings are separated by whitespace.

Parameters:
source - the string to parse
Returns:
the array of parsed strings


Copyright © 2002-2004, Andrew S. Townley and Townley Enterprises. All Rights Reserved.
This project is hosted on http://te-code.sourceforge.net.