Copyright 2012-02-25 Werner Randelshofer

ch.randelshofer.util
Class ResourceBundleUtil

java.lang.Object
  extended by ch.randelshofer.util.ResourceBundleUtil

public class ResourceBundleUtil
extends java.lang.Object

This is a convenience wrapper for accessing resources stored in a ResourceBundle.

Version:
1.4 2005-01-04 Methods configureAction and configureMenu added.
1.3 2001-10-10 The default resource name changed from 'name_Metal' to 'name'.
1.2 2001-07-23 Adaptation to JDK 1.3 in progress.
1.0 2000-06-10 Created.
Author:
Werner Randelshofer, Hausmatt 10, CH-6405 Immensee, Switzerland

Constructor Summary
ResourceBundleUtil(java.util.ResourceBundle r)
          Creates a new ResouceBundleUtil which wraps the provided resource bundle.
 
Method Summary
 void configureAction(javax.swing.Action action, java.lang.String argument)
           
 void configureMenu(javax.swing.JMenuItem menu, java.lang.String argument)
           
 java.lang.String format(java.lang.String key, java.lang.Object... arguments)
          Returns a formatted string using java.util.Formatter().
 javax.swing.KeyStroke getAcc(java.lang.String key)
          Get a KeyStroke from the ResourceBundle.
 java.lang.String getFormatted(java.lang.String key, java.lang.Object... arguments)
          Returns a formatted string using javax.text.MessageFormat.
 javax.swing.ImageIcon getImageIcon(java.lang.String key, java.lang.Class baseClass)
          Get an image icon from the ResourceBundle.
 javax.swing.KeyStroke getKeyStroke(java.lang.String key)
          Get a KeyStroke from the ResourceBundle.
static ResourceBundleUtil getLAFBundle(java.lang.String baseName)
          Get the appropriate ResourceBundle subclass.
 char getMnem(java.lang.String key)
          Get a Mnemonic from the ResourceBundle.
 char getMnemonic(java.lang.String key)
          Get a Mnemonic from the ResourceBundle.
 java.lang.String getString(java.lang.String key)
          Get a String from the ResourceBundle.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceBundleUtil

public ResourceBundleUtil(java.util.ResourceBundle r)
Creates a new ResouceBundleUtil which wraps the provided resource bundle.

Method Detail

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.

getImageIcon

public javax.swing.ImageIcon getImageIcon(java.lang.String key,
                                          java.lang.Class baseClass)
Get an image icon from the ResourceBundle.
Convenience method .

Parameters:
key - The key of the property.
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.

getMnem

public char getMnem(java.lang.String key)
Get a Mnemonic from the ResourceBundle.
Convenience method.

Parameters:
key - The key of the property. This method appends "Mnem" to the key.
Returns:
The first char of the value of the property. Returns '\0' if the property is missing.

getKeyStroke

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.

getAcc

public javax.swing.KeyStroke getAcc(java.lang.String key)
Get a KeyStroke from the ResourceBundle.
Convenience method.

Parameters:
key - The key of the property. This method adds "Acc" to the key.
Returns:
javax.swing.KeyStroke.getKeyStroke(value). Returns null 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

getLAFBundle

public static ResourceBundleUtil getLAFBundle(java.lang.String baseName)
                                       throws java.util.MissingResourceException
Get the appropriate ResourceBundle subclass. The baseName is extended by the Swing Look and Feel ID and by the Locale code. The default Look and Feel ID is Metal.

Throws:
java.util.MissingResourceException
See Also:
ResourceBundle

configureAction

public void configureAction(javax.swing.Action action,
                            java.lang.String argument)

configureMenu

public void configureMenu(javax.swing.JMenuItem menu,
                          java.lang.String argument)

Copyright 2012-02-25 Werner Randelshofer