Class ResourceBundleUtil
- java.lang.Object
-
- org.jhotdraw.util.ResourceBundleUtil
-
- All Implemented Interfaces:
- java.io.Serializable
public class ResourceBundleUtil extends java.lang.Object implements java.io.SerializableThis is a convenience wrapper for accessing resources stored in a ResourceBundle.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 topreferences.text.win, and - if no property with this name exists - it is evaluated topreferences.text.mac, and then topreferences.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:
stringThis is the default format.acceleratorThis format replaces all occurences of the keywords shift, control, ctrl, meta, alt, altGraph by properties which start withaccelerator.. For example, shift is replaced byaccelerator.shift.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description ResourceBundleUtil(java.lang.String baseName, java.util.Locale locale)Creates a new ResouceBundleUtil which wraps the provided resource bundle.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidconfigureAction(javax.swing.Action action, java.lang.String argument)voidconfigureAction(javax.swing.Action action, java.lang.String argument, java.lang.Class baseClass)voidconfigureButton(javax.swing.AbstractButton button, java.lang.String argument)voidconfigureButton(javax.swing.AbstractButton button, java.lang.String argument, java.lang.Class baseClass)voidconfigureMenu(javax.swing.JMenuItem menu, java.lang.String argument)voidconfigureToolBarButton(javax.swing.AbstractButton button, java.lang.String argument)voidconfigureToolBarButton(javax.swing.AbstractButton button, java.lang.String argument, java.lang.Class baseClass)javax.swing.JMenuItemcreateMenuItem(javax.swing.Action a, java.lang.String baseName)java.lang.Stringformat(java.lang.String key, java.lang.Object... arguments)Returns a formatted string using java.util.Formatter().javax.swing.KeyStrokegetAcceleratorProperty(java.lang.String key)Gets a KeyStroke for a JavaBeans "accelerator" property from the ResourceBundle.java.lang.ClassgetBaseClass()static ResourceBundleUtilgetBundle(java.lang.String baseName)Get the appropriate ResourceBundle subclass.static ResourceBundleUtilgetBundle(java.lang.String baseName, java.util.Locale locale)Get the appropriate ResourceBundle subclass.java.lang.StringgetFormatted(java.lang.String key, java.lang.Object... arguments)Returns a formatted string using javax.text.MessageFormat.javax.swing.ImageIcongetIconProperty(java.lang.String key, java.lang.Class baseClass)Get an image icon from the ResourceBundle.java.lang.IntegergetInteger(java.lang.String key)Get an Integer from the ResourceBundle.javax.swing.KeyStrokegetKeyStroke(java.lang.String key)Get a KeyStroke from the ResourceBundle.chargetMnemonic(java.lang.String key)Get a Mnemonic from the ResourceBundle.chargetMnemonicProperty(java.lang.String key)Gets a char for a JavaBeans "mnemonic" property from the ResourceBundle.java.lang.StringgetString(java.lang.String key)Get a String from the ResourceBundle.java.lang.StringgetTextProperty(java.lang.String key)Get a String for a JavaBeans "text" property from the ResourceBundle.java.lang.StringgetToolTipTextProperty(java.lang.String key)Get a String for a JavaBeans "toolTipText" property from the ResourceBundle.java.util.ResourceBundlegetWrappedBundle()Returns the wrapped resource bundle.static booleanisVerbose()static voidputPropertyNameModifier(java.lang.String name, java.lang.String... fallbackChain)Puts a property name modifier along with a fallback chain.static voidremovePropertyNameModifier(java.lang.String name)Removes a property name modifier.voidsetBaseClass(java.lang.Class baseClass)static voidsetVerbose(boolean newValue)java.lang.StringtoString()
-
-
-
Constructor Detail
-
ResourceBundleUtil
public ResourceBundleUtil(java.lang.String baseName, java.util.Locale locale)Creates a new ResouceBundleUtil which wraps the provided resource bundle.
-
-
Method Detail
-
getWrappedBundle
public java.util.ResourceBundle getWrappedBundle()
Returns the wrapped resource bundle.- Returns:
- The wrapped resource bundle.
-
getString
public java.lang.String getString(java.lang.String key)
Get a String from the ResourceBundle.
Convenience method to save casting.- Parameters:
key- The key of the property.- Returns:
- The value of the property. Returns the key if the property is missing.
-
getFormatted
public java.lang.String getFormatted(java.lang.String key, java.lang.Object... arguments)Returns a formatted string using javax.text.MessageFormat.- Parameters:
key-arguments-- Returns:
- formatted String
-
format
public java.lang.String format(java.lang.String key, java.lang.Object... arguments)Returns a formatted string using java.util.Formatter().- Parameters:
key-arguments-- Returns:
- formatted String
-
getInteger
public java.lang.Integer getInteger(java.lang.String key)
Get an Integer from the ResourceBundle.
Convenience method to save casting.- Parameters:
key- The key of the property.- Returns:
- The value of the property. Returns -1 if the property is missing.
-
getIconProperty
@Nullable public javax.swing.ImageIcon getIconProperty(java.lang.String key, java.lang.Class baseClass)
Get an image icon from the ResourceBundle.
Convenience method .- Parameters:
key- The key of the property. This method appends ".icon" to the key.- Returns:
- The value of the property. Returns null if the property is missing.
-
getMnemonic
public char getMnemonic(java.lang.String key)
Get a Mnemonic from the ResourceBundle.
Convenience method.- Parameters:
key- The key of the property.- Returns:
- The first char of the value of the property. Returns '\0' if the property is missing.
-
getMnemonicProperty
public char getMnemonicProperty(java.lang.String key)
Gets a char for a JavaBeans "mnemonic" property from the ResourceBundle.
Convenience method.- Parameters:
key- The key of the property. This method appends ".mnemonic" to the key.- Returns:
- The first char of the value of the property. Returns '\0' if the property is missing.
-
getToolTipTextProperty
@Nullable public java.lang.String getToolTipTextProperty(java.lang.String key)
Get a String for a JavaBeans "toolTipText" property from the ResourceBundle.
Convenience method.- Parameters:
key- The key of the property. This method appends ".toolTipText" to the key.- Returns:
- The ToolTip. Returns null if no tooltip is defined.
-
getTextProperty
@Nullable public java.lang.String getTextProperty(java.lang.String key)
Get a String for a JavaBeans "text" property from the ResourceBundle.
Convenience method.- Parameters:
key- The key of the property. This method appends ".text" to the key.- Returns:
- The ToolTip. Returns null if no tooltip is defined.
-
getKeyStroke
@Nullable public javax.swing.KeyStroke getKeyStroke(java.lang.String key)
Get a KeyStroke from the ResourceBundle.
Convenience method.- Parameters:
key- The key of the property.- Returns:
javax.swing.KeyStroke.getKeyStroke(value). Returns null if the property is missing.
-
getAcceleratorProperty
@Nullable public javax.swing.KeyStroke getAcceleratorProperty(java.lang.String key)
Gets a KeyStroke for a JavaBeans "accelerator" property from the ResourceBundle.
Convenience method.- Parameters:
key- The key of the property. This method adds ".accelerator" to the key.- Returns:
javax.swing.KeyStroke.getKeyStroke(value). Returns null if the property is missing.
-
getBundle
public static ResourceBundleUtil getBundle(java.lang.String baseName) throws java.util.MissingResourceException
Get the appropriate ResourceBundle subclass.- Throws:
java.util.MissingResourceException- See Also:
ResourceBundle
-
setBaseClass
public void setBaseClass(java.lang.Class baseClass)
-
getBaseClass
public java.lang.Class getBaseClass()
-
configureAction
public void configureAction(javax.swing.Action action, java.lang.String argument)
-
configureAction
public void configureAction(javax.swing.Action action, java.lang.String argument, java.lang.Class baseClass)
-
configureButton
public void configureButton(javax.swing.AbstractButton button, java.lang.String argument)
-
configureButton
public void configureButton(javax.swing.AbstractButton button, java.lang.String argument, java.lang.Class baseClass)
-
configureToolBarButton
public void configureToolBarButton(javax.swing.AbstractButton button, java.lang.String argument)
-
configureToolBarButton
public void configureToolBarButton(javax.swing.AbstractButton button, java.lang.String argument, java.lang.Class baseClass)
-
configureMenu
public void configureMenu(javax.swing.JMenuItem menu, java.lang.String argument)
-
createMenuItem
public javax.swing.JMenuItem createMenuItem(javax.swing.Action a, java.lang.String baseName)
-
getBundle
public static ResourceBundleUtil getBundle(java.lang.String baseName, java.util.Locale locale) throws java.util.MissingResourceException
Get the appropriate ResourceBundle subclass.- Throws:
java.util.MissingResourceException- See Also:
ResourceBundle
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
setVerbose
public static void setVerbose(boolean newValue)
-
isVerbose
public static boolean isVerbose()
-
putPropertyNameModifier
public static void putPropertyNameModifier(java.lang.String name, java.lang.String... fallbackChain)Puts a property name modifier along with a fallback chain.- Parameters:
name- The name of the modifier.fallbackChain- The fallback chain of the modifier.
-
removePropertyNameModifier
public static void removePropertyNameModifier(java.lang.String name)
Removes a property name modifier.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG