org.jfree.util
Class ResourceBundleSupport
java.lang.Object
org.jfree.util.ResourceBundleSupport
An utility class to ease up using property-file resource bundles.
The class support references within the resource bundle set to minimize the occurence
of duplicate keys. References are given in the format:
a.key.name=@referenced.key
A lookup to a key in an other resource bundle should be written by
a.key.name=@@resourcebundle_name@referenced.key
JMenu | createMenu(String keyPrefix) - Returns a JMenu created from a resource bundle definition.
|
Icon | createTransparentIcon(int width, int height) - Creates a transparent icon.
|
String | formatMessage(String key, Object parameter) - Formats the message stored in the resource bundle (using a MessageFormat).
|
String | formatMessage(String key, Object par1, Object par2) - Formats the message stored in the resource bundle (using a MessageFormat).
|
String | formatMessage(String key, Object[] parameters) - Formats the message stored in the resource bundle (using a MessageFormat).
|
Icon | getIcon(String key) - Returns an unscaled icon.
|
Icon | getIcon(String key, boolean large) - Returns an scaled icon suitable for buttons or menus.
|
KeyStroke | getKeyStroke(String key) - Returns the keystroke stored at the given resourcebundle key.
|
KeyStroke | getKeyStroke(String key, int mask) - Returns the keystroke stored at the given resourcebundle key.
|
Locale | getLocale() - Returns the current locale for this resource bundle.
|
Integer | getMnemonic(String key) - Returns the mnemonic stored at the given resourcebundle key.
|
protected String | getResourceBase() - The base name of the resource bundle.
|
URL | getResourceURL(String key) - Returns a URL pointing to a resource located in the classpath.
|
String | getString(String key) - Gets a string for the given key from this resource bundle or one of its parents.
|
protected String | internalGetString(String key) - Performs the lookup for the given key.
|
ResourceBundleSupport
public ResourceBundleSupport(Locale locale,
ResourceBundle resourceBundle)
Creates a new instance.
locale
- the locale for which the resource bundle is created.resourceBundle
- the resourcebundle
ResourceBundleSupport
protected ResourceBundleSupport(Locale locale,
ResourceBundle resourceBundle,
String baseName)
Creates a new instance.
locale
- the locale for which this resource bundle is created.resourceBundle
- the resourcebundlebaseName
- the base name of the resource bundle, a fully qualified class name
ResourceBundleSupport
public ResourceBundleSupport(Locale locale,
String baseName)
Creates a new instance.
baseName
- the base name of the resource bundle, a fully qualified class name
ResourceBundleSupport
public ResourceBundleSupport(ResourceBundle resourceBundle)
Creates a new instance.
resourceBundle
- the resourcebundle
ResourceBundleSupport
protected ResourceBundleSupport(ResourceBundle resourceBundle,
String baseName)
Creates a new instance.
resourceBundle
- the resourcebundlebaseName
- the base name of the resource bundle, a fully qualified class name
ResourceBundleSupport
public ResourceBundleSupport(String baseName)
Creates a new instance.
baseName
- the base name of the resource bundle, a fully qualified class name
createMenu
public JMenu createMenu(String keyPrefix)
Returns a JMenu created from a resource bundle definition.
The menu definition consists of two keys, the name of the menu and the mnemonic for
that menu. Both keys share a common prefix, which is extended by ".name" for the name
of the menu and ".mnemonic" for the mnemonic.
# define the file menu
menu.file.name=File
menu.file.mnemonic=F
The menu definition above can be used to create the menu by calling
createMenu
("menu.file")
.
keyPrefix
- the common prefix for that menu
createTransparentIcon
public Icon createTransparentIcon(int width,
int height)
Creates a transparent icon. The Icon can be used for aligning menu items.
width
- the width of the new iconheight
- the height of the new icon
- the created transparent icon.
formatMessage
public String formatMessage(String key,
Object parameter)
Formats the message stored in the resource bundle (using a MessageFormat).
key
- the resourcebundle keyparameter
- the parameter for the message
formatMessage
public String formatMessage(String key,
Object par1,
Object par2)
Formats the message stored in the resource bundle (using a MessageFormat).
key
- the resourcebundle keypar1
- the first parameter for the messagepar2
- the second parameter for the message
formatMessage
public String formatMessage(String key,
Object[] parameters)
Formats the message stored in the resource bundle (using a MessageFormat).
key
- the resourcebundle keyparameters
- the parameter collection for the message
getIcon
public Icon getIcon(String key)
Returns an unscaled icon.
key
- the name of the resource bundle key
getIcon
public Icon getIcon(String key,
boolean large)
Returns an scaled icon suitable for buttons or menus.
key
- the name of the resource bundle keylarge
- true, if the image should be scaled to 24x24, or false for 16x16
getKeyStroke
public KeyStroke getKeyStroke(String key)
Returns the keystroke stored at the given resourcebundle key.
The keystroke will be composed of a simple key press and the plattform's
MenuKeyMask.
The keystrokes character key should be either the symbolic name of one of the
KeyEvent.VK_* constants or the character for that key.
For the 'A' key, the resource bundle would therefore either contain "VK_A" or
"a".
a.resourcebundle.key=VK_A
an.other.resourcebundle.key=a
key
- the resourcebundle key
Toolkit.getMenuShortcutKeyMask()
getKeyStroke
public KeyStroke getKeyStroke(String key,
int mask)
Returns the keystroke stored at the given resourcebundle key.
The keystroke will be composed of a simple key press and the given
KeyMask. If the KeyMask is zero, a plain Keystroke is returned.
The keystrokes character key should be either the symbolic name of one of the
KeyEvent.VK_* constants or the character for that key.
For the 'A' key, the resource bundle would therefore either contain "VK_A" or
"a".
a.resourcebundle.key=VK_A
an.other.resourcebundle.key=a
key
- the resourcebundle key
Toolkit.getMenuShortcutKeyMask()
getLocale
public Locale getLocale()
Returns the current locale for this resource bundle.
getMnemonic
public Integer getMnemonic(String key)
Returns the mnemonic stored at the given resourcebundle key. The mnemonic should be
either the symbolic name of one of the KeyEvent.VK_* constants (without the 'VK_') or
the character for that key.
For the enter key, the resource bundle would therefore either contain "ENTER" or
"\n".
a.resourcebundle.key=ENTER
an.other.resourcebundle.key=\n
key
- the resourcebundle key
getResourceBase
protected final String getResourceBase()
The base name of the resource bundle.
- the resource bundle's name.
getResourceURL
public URL getResourceURL(String key)
Returns a URL pointing to a resource located in the classpath. The resource is looked
up using the given key.
Example: The load a file named 'logo.gif' which is stored in a java package named
'org.jfree.resources':
mainmenu.logo=org/jfree/resources/logo.gif
The URL for that file can be queried with:
getResource("mainmenu.logo");
.
key
- the key for the resource
getString
public String getString(String key)
Gets a string for the given key from this resource bundle or one of its parents. If
the key is a link, the link is resolved and the referenced string is returned
instead.
key
- the key for the desired string
- the string for the given key
internalGetString
protected String internalGetString(String key)
Performs the lookup for the given key. If the key points to a link the link is
resolved and that key is looked up instead.
key
- the key for the string
- the string for the given key