public class ResourceBundleUtil
extends java.lang.Object
implements java.io.Serializable
Placeholders
On top of the functionality provided by ResourceBundle, a property value
can include text from another property, by specifying the desired
property name and format type between "${"
and "}"
.
For example, if there is a "imagedir"
property with the value
"/org/jhotdraw/undo/images"
, then this could be used in an attribute
like this: ${imagedir}/editUndo.png
. This is resolved at run-time
as /org/jhotdraw/undo/images/editUndo.png
.
Property names in placeholders can contain modifiers. Modifiers are written
between @code "[$"} and "]"
. Each modifier has a fallback chain.
For example, if the property name modifier "os"
has the value "win",
and its fallback chain is "mac","default"
, then the property name
${preferences.text.[$os]}
is first evaluted to preferences.text.win
, and - if no property with this name exists -
it is evaluated to preferences.text.mac
, and then to
preferences.text.default
.
The property name modifier "os" is defined by default. It can assume the values "win", "mac" and "other". Its fallback chain is "default".
The format type can be optinally specified after a comma. The following format types are supported:
string
This is the default format.accelerator
This format replaces all occurences of the keywords
shift, control, ctrl, meta, alt, altGraph by properties which start with
accelerator.
. For example, shift is replaced by accelerator.shift
.
Constructor and Description |
---|
ResourceBundleUtil(java.lang.String baseName,
java.util.Locale locale)
Creates a new ResouceBundleUtil which wraps
the provided resource bundle.
|
Modifier and Type | Method and Description |
---|---|
void |
configureAction(javax.swing.Action action,
java.lang.String argument) |
void |
configureAction(javax.swing.Action action,
java.lang.String argument,
java.lang.Class baseClass) |
void |
configureButton(javax.swing.AbstractButton button,
java.lang.String argument) |
void |
configureButton(javax.swing.AbstractButton button,
java.lang.String argument,
java.lang.Class baseClass) |
void |
configureMenu(javax.swing.JMenuItem menu,
java.lang.String argument) |
void |
configureToolBarButton(javax.swing.AbstractButton button,
java.lang.String argument) |
void |
configureToolBarButton(javax.swing.AbstractButton button,
java.lang.String argument,
java.lang.Class baseClass) |
javax.swing.JMenuItem |
createMenuItem(javax.swing.Action a,
java.lang.String baseName) |
java.lang.String |
format(java.lang.String key,
java.lang.Object... arguments)
Returns a formatted string using java.util.Formatter().
|
javax.swing.KeyStroke |
getAcceleratorProperty(java.lang.String key)
Gets a KeyStroke for a JavaBeans "accelerator" property from the ResourceBundle.
|
java.lang.Class |
getBaseClass() |
static ResourceBundleUtil |
getBundle(java.lang.String baseName)
Get the appropriate ResourceBundle subclass.
|
static ResourceBundleUtil |
getBundle(java.lang.String baseName,
java.util.Locale locale)
Get the appropriate ResourceBundle subclass.
|
java.lang.String |
getFormatted(java.lang.String key,
java.lang.Object... arguments)
Returns a formatted string using javax.text.MessageFormat.
|
javax.swing.ImageIcon |
getIconProperty(java.lang.String key,
java.lang.Class baseClass)
Get an image icon from the ResourceBundle.
|
java.lang.Integer |
getInteger(java.lang.String key)
Get an Integer from the ResourceBundle.
|
javax.swing.KeyStroke |
getKeyStroke(java.lang.String key)
Get a KeyStroke from the ResourceBundle.
|
char |
getMnemonic(java.lang.String key)
Get a Mnemonic from the ResourceBundle.
|
char |
getMnemonicProperty(java.lang.String key)
Gets a char for a JavaBeans "mnemonic" property from the ResourceBundle.
|
java.lang.String |
getString(java.lang.String key)
Get a String from the ResourceBundle.
|
java.lang.String |
getTextProperty(java.lang.String key)
Get a String for a JavaBeans "text" property from the ResourceBundle.
|
java.lang.String |
getToolTipTextProperty(java.lang.String key)
Get a String for a JavaBeans "toolTipText" property from the ResourceBundle.
|
java.util.ResourceBundle |
getWrappedBundle()
Returns the wrapped resource bundle.
|
static boolean |
isVerbose() |
static void |
putPropertyNameModifier(java.lang.String name,
java.lang.String... fallbackChain)
Puts a property name modifier along with a fallback chain.
|
static void |
removePropertyNameModifier(java.lang.String name)
Removes a property name modifier.
|
void |
setBaseClass(java.lang.Class baseClass) |
static void |
setVerbose(boolean newValue) |
java.lang.String |
toString() |
public ResourceBundleUtil(java.lang.String baseName, java.util.Locale locale)
public java.util.ResourceBundle getWrappedBundle()
public java.lang.String getString(java.lang.String key)
key
- The key of the property.public java.lang.String getFormatted(java.lang.String key, java.lang.Object... arguments)
key
- arguments
- public java.lang.String format(java.lang.String key, java.lang.Object... arguments)
key
- arguments
- public java.lang.Integer getInteger(java.lang.String key)
key
- The key of the property.public javax.swing.ImageIcon getIconProperty(java.lang.String key, java.lang.Class baseClass)
key
- The key of the property. This method appends ".icon" to the key.public char getMnemonic(java.lang.String key)
key
- The key of the property.public char getMnemonicProperty(java.lang.String key)
key
- The key of the property. This method appends ".mnemonic" to the key.public java.lang.String getToolTipTextProperty(java.lang.String key)
key
- The key of the property. This method appends ".toolTipText" to the key.public java.lang.String getTextProperty(java.lang.String key)
key
- The key of the property. This method appends ".text" to the key.public javax.swing.KeyStroke getKeyStroke(java.lang.String key)
key
- The key of the property.javax.swing.KeyStroke.getKeyStroke(value)
.
Returns null if the property is missing.public javax.swing.KeyStroke getAcceleratorProperty(java.lang.String key)
key
- The key of the property. This method adds ".accelerator" to the key.javax.swing.KeyStroke.getKeyStroke(value)
.
Returns null if the property is missing.public static ResourceBundleUtil getBundle(java.lang.String baseName) throws java.util.MissingResourceException
java.util.MissingResourceException
ResourceBundle
public void setBaseClass(java.lang.Class baseClass)
public java.lang.Class getBaseClass()
public void configureAction(javax.swing.Action action, java.lang.String argument)
public void configureAction(javax.swing.Action action, java.lang.String argument, java.lang.Class baseClass)
public void configureButton(javax.swing.AbstractButton button, java.lang.String argument)
public void configureButton(javax.swing.AbstractButton button, java.lang.String argument, java.lang.Class baseClass)
public void configureToolBarButton(javax.swing.AbstractButton button, java.lang.String argument)
public void configureToolBarButton(javax.swing.AbstractButton button, java.lang.String argument, java.lang.Class baseClass)
public void configureMenu(javax.swing.JMenuItem menu, java.lang.String argument)
public javax.swing.JMenuItem createMenuItem(javax.swing.Action a, java.lang.String baseName)
public static ResourceBundleUtil getBundle(java.lang.String baseName, java.util.Locale locale) throws java.util.MissingResourceException
java.util.MissingResourceException
ResourceBundle
public java.lang.String toString()
toString
in class java.lang.Object
public static void setVerbose(boolean newValue)
public static boolean isVerbose()
public static void putPropertyNameModifier(java.lang.String name, java.lang.String... fallbackChain)
name
- The name of the modifier.fallbackChain
- The fallback chain of the modifier.public static void removePropertyNameModifier(java.lang.String name)