Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1.4.0)

E13403-05

oracle.javatools.util
Class ResourcePicker

java.lang.Object
  extended by java.util.ResourceBundle
      extended by oracle.javatools.util.ResourcePicker

public class ResourcePicker
extends java.util.ResourceBundle

This package does some very cunning things in order to traverse a given object and find all the objects inside it that are of type JComponent. This allows it to use a ResourceBundle in order to label the components as needed. For example setting textual names, tool-tip values, accelerator keys and images.

The table show here contains all of the commonly used extension.

Component Extension relavent
javax.swing.JComponent
.tooltip The NLS text of a tooltip for this component.
.bordertitle The NLS text name of a titled border around this component
.help The string ID of a help topic to be related to this component.
javax.swing.AbstractButton
.text The NLS text to be displayed on the button, if this is not specified and there is not icon then an error text starting with !NLS will be set instead.
.mnemonic The fast key to a particular item, has to be in the NLS text otherwise an error will occur.
.key The NLS keyboard memonic. For example CTRL-S
javax.swing.text.JTextComponent
.text Same as for AbstractButton
javax.swing.text.JLabel
.text Same as for AbstractButton
.mnemonic Same as for AbstractButton
.image An image to place on the label. The value is a relative path to an image resource that must exist in the CLASSPATH. the image can be relative to the resource bundle class, or the default resource bundle class. Note that back directories (..\) are not permitted.
javax.swing.JComboBox,
javax.swing.JList
Looks for properties .0, .1, .2 etc to construct a simple list model. It is not recommended that people use this code.
javax.swing.JTable Same as above but for the TableHeaders. Safer to use as not part of the actual selection.
javax.swing.JMenuBar,
javax.swing.JPopupMenu
No properties, just fills the properties of contained menus.
javax.swing.JFrame,
javax.swing.JInternalFrame,
javax.swing.JDialog
.title Sets the NLS title for the frame.
.menubar In theory this is done then passed onto the rest of the resource picker, commented out for all but dialog, not sure why.

Bonus feature is that if it finds a string that starts with @> then it will perform an indirection and look up the resource by this string. Note the code will fail safe if there is a networks but with a severe performance hit.


Nested Class Summary
static interface ResourcePicker.ResourceBase
          A label interface that says to restart the lable tree from here.
static interface ResourcePicker.ResourceFree
          A label interface that implies that whilst the panel is named it doesn't have any interesting properties to be set so it can be ignored.
 
Nested classes/interfaces inherited from class java.util.ResourceBundle
java.util.ResourceBundle.Control
 
Field Summary
protected  java.util.ResourceBundle[] m_defaultRes
          The default resource bundles expanded parent hierarchy.
protected  java.text.MessageFormat m_formatter
           
protected  java.util.Vector m_keyList
          Combined list of keys used by the resource bundles for use in enumerating keys.
protected  java.util.ResourceBundle[] m_resource
          The main resource bundles expanded parent hierarchy.
static java.lang.String s_INDIRECTION
          This prefix is used for resource indirection, this can be usefull in some cases where we need to reuse strings, but want to save on translation costs.
 
Fields inherited from class java.util.ResourceBundle
parent
 
Constructor Summary
ResourcePicker(java.lang.Class clazz)
          This constructor looks for a .res.Resource relative to the class provided.
ResourcePicker(java.lang.Class clazz, java.lang.String resource)
          This constructor looks for a .res.Resource relative to the class provided.
ResourcePicker(java.util.ResourceBundle resource)
          This constructor uses the resource passed and the default resource oracle.bm.util.res.DefaultResource
ResourcePicker(java.util.ResourceBundle resource, java.util.ResourceBundle defaultRes)
          Allow the specification of the default resource rather than oracle.bm.util.res.DefaultResource.
ResourcePicker(java.lang.String kjpackage, java.lang.String resource)
          Look for specifica resource in the specific package.
 
Method Summary
protected  void dealWithObject(java.awt.Component current, java.lang.StringBuffer resourcePath, int leafNamePos)
          Overriden method to deal with Components.
protected  void dealWithObject(javax.swing.JComponent current, java.lang.StringBuffer resourcePath, int leafNamePos)
          Overriden method to deal with JComponents.
protected  void dealWithObject(java.lang.Object current, java.lang.StringBuffer resourcePath, int leafNamePos)
          For each different type of Object we fill in the appropriate resources.
 void fillComponent(java.awt.Component c)
          Fill in the resources for the given Component and for any subcomponents if it is a Container.
protected  void fillSubComponents(java.awt.Container current, java.lang.StringBuffer resourcePath)
          Fill in the resources for all the sub Components of the given Container.
 java.lang.String formatString(java.lang.String pattern, java.lang.Object[] arguments)
          Format a pattern using the given arguments.
static ResourcePicker get()
           
protected  javax.swing.table.TableColumnModel getHeaders(java.lang.StringBuffer resourcePath, int leafNamePos)
          Gets a TableColumnModel for the table to use, initialised with column headings from the resource named ???.0, ???.1, etc.
 javax.swing.Icon getImage(java.lang.String key)
          Get an image resource identified by name.
 javax.swing.ImageIcon getImageResource(java.lang.String iconName)
          This gets an image using it's leafname, eg 'WizardImage.gif'.
 java.util.Enumeration getKeys()
          Required method from ResourceBundle.
static ResourcePicker getPicker(java.lang.Class c)
          Gets the cached ResourcePicker for the given class.
static ResourcePicker getPicker(java.lang.Object o)
          Gets the cached ResourcePicker for the given object.
 java.lang.String getString(java.lang.String key, java.lang.Object singleReplace)
          Convenience method for making a single substitution into an NLS string.
 java.lang.String getString(java.lang.String key, java.lang.Object[] replace)
          Get a string that has variables substituted into it
 java.lang.String getStringResource(java.lang.String name)
          Create a getStringResource that does the redirection but without adding in any extra objects onto the end.
 java.lang.String getStringResource(java.lang.StringBuffer resourcePath, java.lang.String type, int leafNamePos)
          This get a string resource based on a resourcePath, a type and an abbreviated (from end) pathname.
 java.lang.String getStringResource(java.lang.String name, java.lang.String type)
          This get a string resource based on a name and a type.
 java.lang.String getStringResource(java.lang.String name, java.lang.StringBuffer longName, java.lang.String type)
          Deprecated. You should use getStringResource(StringBuffer,String,int) instead. Note that the side-effects and contents of the StringBuffer are different for this method.
 java.lang.String getStringResource(java.lang.String name, java.lang.String type, java.lang.Object[] subst)
          Gets a string resource based on a name and a type, substituting the given object array into the string, replacing any replacement parameters (e.g.
protected  java.lang.Object handleGetObject(java.lang.String name)
          Required process method for ResourceBundle, had to make it public here otherwise it gets inlines by the VM rather strangely.
 void start(java.awt.Container current)
          Start from the given Container object and try to find resource strings for all of sub Components.
 
Methods inherited from class java.util.ResourceBundle
clearCache, clearCache, containsKey, getBundle, getBundle, getBundle, getBundle, getBundle, getBundle, getLocale, getObject, getString, getStringArray, handleKeySet, keySet, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

s_INDIRECTION

public static final java.lang.String s_INDIRECTION
This prefix is used for resource indirection, this can be usefull in some cases where we need to reuse strings, but want to save on translation costs. The value of this constant is "@>".

See Also:
Constant Field Values

m_resource

protected java.util.ResourceBundle[] m_resource
The main resource bundles expanded parent hierarchy. Children first.


m_defaultRes

protected java.util.ResourceBundle[] m_defaultRes
The default resource bundles expanded parent hierarchy. Children first.


m_formatter

protected java.text.MessageFormat m_formatter

m_keyList

protected java.util.Vector m_keyList
Combined list of keys used by the resource bundles for use in enumerating keys. It is initialised lazily.

Constructor Detail

ResourcePicker

public ResourcePicker(java.util.ResourceBundle resource,
                      java.util.ResourceBundle defaultRes)
Allow the specification of the default resource rather than oracle.bm.util.res.DefaultResource. This give the sort of parent-hood that ResourceBundle doesn't support properly. And of course using this the resource bundles can be chained.

Parameters:
resource - Resource to check first
defaultRes - Resource to fall back to

ResourcePicker

public ResourcePicker(java.util.ResourceBundle resource)
This constructor uses the resource passed and the default resource oracle.bm.util.res.DefaultResource

Parameters:
resource - Key resource to base picker on.

ResourcePicker

public ResourcePicker(java.lang.String kjpackage,
                      java.lang.String resource)
               throws java.util.MissingResourceException
Look for specifica resource in the specific package.

Parameters:
kjpackage - The package to look for resources in
resource - The name of the bundle
Throws:
java.util.MissingResourceException

ResourcePicker

public ResourcePicker(java.lang.Class clazz)
               throws java.util.MissingResourceException
This constructor looks for a .res.Resource relative to the class provided.

Parameters:
resource - Key resource to base picker on.
Throws:
java.util.MissingResourceException

ResourcePicker

public ResourcePicker(java.lang.Class clazz,
                      java.lang.String resource)
               throws java.util.MissingResourceException
This constructor looks for a .res.Resource relative to the class provided.

Parameters:
resource - Key resource to base picker on.
Throws:
java.util.MissingResourceException
Method Detail

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.Object[] replace)
Get a string that has variables substituted into it


getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.Object singleReplace)
Convenience method for making a single substitution into an NLS string. This is just the same as getString(key, new Object[] { singleReplace } );

Parameters:
key - the key of the string
singleReplace - {0} in the string will be replaced by the toString() of this object.

formatString

public java.lang.String formatString(java.lang.String pattern,
                                     java.lang.Object[] arguments)
Format a pattern using the given arguments. Essentially calls MessageFormat.format, but on a single instance of MessageFormat.

Parameters:
pattern - A string pattern to use. Numbers enclosed in curly brackets indicate replacement parameters (e.g. {0})
arguments - an array of arguments to replace in the pattern.
Returns:
the substituted string

start

public void start(java.awt.Container current)
Start from the given Container object and try to find resource strings for all of sub Components.

This method ignores the name of the top level container.

Parameters:
current - Container to be filled in

fillComponent

public void fillComponent(java.awt.Component c)
Fill in the resources for the given Component and for any subcomponents if it is a Container.

If the name of this top level Component is null then it is taken to be an empty String.

Parameters:
c - Component to be filled in

fillSubComponents

protected void fillSubComponents(java.awt.Container current,
                                 java.lang.StringBuffer resourcePath)
Fill in the resources for all the sub Components of the given Container. The path is used as a prefix when searching for the resources. Note that no seperating characters are appended to this prefix, ie paths should be dot terminated, and any unnamed (null name) sub Components will be ignored.

Parameters:
current - Container for which we want to fill the sub Components.
resourcePath - Dot terminated prefix to be used to search for resources.

dealWithObject

protected void dealWithObject(java.lang.Object current,
                              java.lang.StringBuffer resourcePath,
                              int leafNamePos)
For each different type of Object we fill in the appropriate resources. We may then need to call further routines to deal with any subclasses of the Object. To extend the functionality to more types this method should be overridden and the appropriate behaviour entered into the method which deals with the type's closest supertype.

Parameters:
current - Object under examination
resourcePath - Dot terminated prefix to be used to search for resources (should include name of the Object)
leafNamePos - Position in prefix for a shortened version of the prefix

dealWithObject

protected void dealWithObject(java.awt.Component current,
                              java.lang.StringBuffer resourcePath,
                              int leafNamePos)
Overriden method to deal with Components.

Parameters:
current - Component under examination
resourcePath - Dot terminated prefix to be used to search for resources (should included name of the JComponent)
leafNamePos - Position in prefix for a shortened version of the prefix

dealWithObject

protected void dealWithObject(javax.swing.JComponent current,
                              java.lang.StringBuffer resourcePath,
                              int leafNamePos)
Overriden method to deal with JComponents.

Parameters:
current - JComponent under examination
resourcePath - Dot terminated prefix to be used to search for resources (should included name of the JComponent)
leafNamePos - Position in prefix for a shortened version of the prefix

getHeaders

protected javax.swing.table.TableColumnModel getHeaders(java.lang.StringBuffer resourcePath,
                                                        int leafNamePos)
Gets a TableColumnModel for the table to use, initialised with column headings from the resource named ???.0, ???.1, etc.

Parameters:
resourcePath - Dot terminated prefix to be used to search for list entries
leafNamePos - Position in prefix for a shortened version of the prefix

handleGetObject

protected java.lang.Object handleGetObject(java.lang.String name)
Required process method for ResourceBundle, had to make it public here otherwise it gets inlines by the VM rather strangely.

Specified by:
handleGetObject in class java.util.ResourceBundle

getKeys

public java.util.Enumeration getKeys()
Required method from ResourceBundle.

TODO implement with innner class.

Specified by:
getKeys in class java.util.ResourceBundle

getStringResource

public java.lang.String getStringResource(java.lang.String name,
                                          java.lang.String type,
                                          java.lang.Object[] subst)
Gets a string resource based on a name and a type, substituting the given object array into the string, replacing any replacement parameters (e.g. {0}, {1})

Parameters:
name - A resource to look up
type - sub-type to look up
subst - The set of substitutions

getStringResource

public java.lang.String getStringResource(java.lang.String name,
                                          java.lang.String type)
This get a string resource based on a name and a type.

These are concatinated thus: name + "." + type

Parameters:
name - A resource to look up
type - sub-type to look up

getStringResource

public java.lang.String getStringResource(java.lang.String name,
                                          java.lang.StringBuffer longName,
                                          java.lang.String type)
Deprecated. You should use getStringResource(StringBuffer,String,int) instead. Note that the side-effects and contents of the StringBuffer are different for this method.

This get a string resource based on a longName and a type.

These are concatinated thus: longName + "." + type but it will test in the following order:

  1. resource -> longName.type
  2. default -> name.type
  3. resource -> name.type
  4. default -> longName.type

Parameters:
name - A resource to look up
longName - The longname for the resource
type - sub-type to look up

getStringResource

public java.lang.String getStringResource(java.lang.StringBuffer resourcePath,
                                          java.lang.String type,
                                          int leafNamePos)
This get a string resource based on a resourcePath, a type and an abbreviated (from end) pathname.

These are concatinated thus: resourcePath + type and then a search is done in the following order:

  1. resource -> longName.type
  2. default -> name.type
  3. resource -> name.type
  4. default -> longName.type

Parameters:
resourcePath - Dot terminated prefix to be used to search for resources
type - Sub-type to look up
leafNamePos - Offset of abbreviated name

getStringResource

public java.lang.String getStringResource(java.lang.String name)
Create a getStringResource that does the redirection but without adding in any extra objects onto the end. This ensure that any redirection also occures.


getImage

public javax.swing.Icon getImage(java.lang.String key)
Get an image resource identified by name. The key will be looked up to retrieve a resource name, then getImageResource() will be called on the resource name


getImageResource

public javax.swing.ImageIcon getImageResource(java.lang.String iconName)
This gets an image using it's leafname, eg 'WizardImage.gif'. An ordered search is made for the image in the following areas:
  1. Same part of class hierarchy as m_resource
  2. Same part of class hierarchy as s_defaultRes
If the default resource is an instance of ResourcePicker then we actually just use its getImageResource stuff. ImageIcon instances are cached in the resource picker.

Parameters:
iconName - The name of the image to be searched for.

getPicker

public static final ResourcePicker getPicker(java.lang.Object o)
Gets the cached ResourcePicker for the given object.

Parameters:
o - the object whose ResourcePicker should be returned.
Returns:
a ResourcePicker for the object.

getPicker

public static final ResourcePicker getPicker(java.lang.Class c)
Gets the cached ResourcePicker for the given class.

Parameters:
c - the class whose ResourcePicker should be returned.
Returns:
a ResourcePicker for the class.

get

public static final ResourcePicker get()

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1.4.0)

E13403-05

Copyright © 1997, 2011, Oracle. All rights reserved.