public class ResourcePicker
extends java.util.ResourceBundle
The table show here contains all of the commonly used extension.
Component | Extension relavent | ||||||
---|---|---|---|---|---|---|---|
javax.swing.JComponent |
|
||||||
javax.swing.AbstractButton |
|
||||||
javax.swing.text.JTextComponent |
|
||||||
javax.swing.text.JLabel |
|
||||||
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 |
|
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.
Modifier and Type | Class and Description |
---|---|
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.
|
Modifier and Type | Field and Description |
---|---|
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.
|
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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.
|
public static final java.lang.String s_INDIRECTION
protected java.util.ResourceBundle[] m_resource
protected java.util.ResourceBundle[] m_defaultRes
protected java.text.MessageFormat m_formatter
protected java.util.Vector m_keyList
public ResourcePicker(java.util.ResourceBundle resource, java.util.ResourceBundle defaultRes)
resource
- Resource to check firstdefaultRes
- Resource to fall back topublic ResourcePicker(java.util.ResourceBundle resource)
resource
- Key resource to base picker on.public ResourcePicker(java.lang.Class clazz) throws java.util.MissingResourceException
resource
- Key resource to base picker on.java.util.MissingResourceException
public ResourcePicker(java.lang.Class clazz, java.lang.String resource) throws java.util.MissingResourceException
resource
- Key resource to base picker on.java.util.MissingResourceException
public java.lang.String getString(java.lang.String key, java.lang.Object[] replace)
public java.lang.String getString(java.lang.String key, java.lang.Object singleReplace)
key
- the key of the stringsingleReplace
- {0} in the string will be replaced by the toString()
of this object.public java.lang.String formatString(java.lang.String pattern, java.lang.Object[] arguments)
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.public void start(java.awt.Container current)
This method ignores the name of the top level container.
current
- Container to be filled inpublic void fillComponent(java.awt.Component c)
If the name of this top level Component is null then it is taken to be an empty String.
c
- Component to be filled inprotected void fillSubComponents(java.awt.Container current, java.lang.StringBuffer resourcePath)
current
- Container for which we want to fill the sub Components.resourcePath
- Dot terminated prefix to be used to search for resources.protected void dealWithObject(java.lang.Object current, java.lang.StringBuffer resourcePath, int leafNamePos)
current
- Object under examinationresourcePath
- 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 prefixprotected void dealWithObject(java.awt.Component current, java.lang.StringBuffer resourcePath, int leafNamePos)
current
- Component under examinationresourcePath
- 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 prefixprotected void dealWithObject(javax.swing.JComponent current, java.lang.StringBuffer resourcePath, int leafNamePos)
current
- JComponent under examinationresourcePath
- 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 prefixprotected javax.swing.table.TableColumnModel getHeaders(java.lang.StringBuffer resourcePath, int leafNamePos)
resourcePath
- Dot terminated prefix to be used to search for list entriesleafNamePos
- Position in prefix for a shortened version of the prefixprotected java.lang.Object handleGetObject(java.lang.String name)
handleGetObject
in class java.util.ResourceBundle
public java.util.Enumeration getKeys()
TODO implement with innner class.
getKeys
in class java.util.ResourceBundle
public java.lang.String getStringResource(java.lang.String name, java.lang.String type, java.lang.Object[] subst)
name
- A resource to look uptype
- sub-type to look upsubst
- The set of substitutionspublic java.lang.String getStringResource(java.lang.String name, java.lang.String type)
These are concatinated thus: name + "." + type
name
- A resource to look uptype
- sub-type to look uppublic java.lang.String getStringResource(java.lang.String name, java.lang.StringBuffer longName, java.lang.String type)
These are concatinated thus: longName + "." + type but it will test in the following order:
name
- A resource to look uplongName
- The longname for the resourcetype
- sub-type to look uppublic java.lang.String getStringResource(java.lang.StringBuffer resourcePath, java.lang.String type, int leafNamePos)
These are concatinated thus: resourcePath + type and then a search is done in the following order:
resourcePath
- Dot terminated prefix to be used to search for resourcestype
- Sub-type to look upleafNamePos
- Offset of abbreviated namepublic java.lang.String getStringResource(java.lang.String name)
public javax.swing.Icon getImage(java.lang.String key)
public javax.swing.ImageIcon getImageResource(java.lang.String iconName)
iconName
- The name of the image to be searched for.public static final ResourcePicker getPicker(java.lang.Object o)
o
- the object whose ResourcePicker should be returned.public static final ResourcePicker getPicker(java.lang.Class c)
c
- the class whose ResourcePicker should be returned.public static final ResourcePicker get()