|
qflib 0.98.1 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.ResourceBundle | +--de.qfs.lib.util.MapResourceBundle
The MapResourceBundle class extends the standard ResourceBundle to provide a more convenient overall handling of resources and property files.
Instead of using the parent mechanism, all key/value pairs are flattened
into one Hashtable
, with values added later via
addResources
overriding the previous
setting for an identical key.
Additional queries have been added that return a default value for a
non-existing key instead of throwing a MissingResourceException
: getString
, getInteger
and getBoolean
.
There is special support for Icon
s through getIcon
, setIcon
and setResolvingClass
. It adds one level of indirection. Instead of fetching
Icons directly, hardwiring their locations into the program, a property
that maps to a String containing the Icon's location is used. The
MapResourceBundle takes care of fetching and caching the icon itself.
With fetchProperties
resources can be added from a
property file that is bundled with a jar archive, something that doesn't
always work with ResourceBundle.getBundle
, especially in Applets.
Fields inherited from class java.util.ResourceBundle |
parent |
Constructor Summary | |
MapResourceBundle()
Create a new MapResourceBundle. |
|
MapResourceBundle(java.util.ResourceBundle rb)
Create a new MapResourceBundle from a ResourceBundle, copying its key/value pairs. |
Method Summary | |
void |
addResources(java.util.Properties properties)
Add a some Properties to the MapResourceBundle, overriding existing resources with identical keys. |
void |
addResources(java.util.ResourceBundle bundle)
Add a ResourceBundle's resources to the MapResourceBundle, overriding existing resources with identical keys. |
void |
fetchProperties(java.lang.String basename,
java.lang.Class resolve)
This is a replacement for ResourceBundle.getBundle
that can handle resources from jar files. |
void |
fetchProperties(java.lang.String basename,
java.util.Locale locale,
java.lang.Class resolve)
This is a replacement for ResourceBundle.getBundle that can handle resources from jar files.
|
boolean |
getBoolean(java.lang.String key,
boolean def)
Get a boolean from the MapResourceBundle. |
javax.swing.Icon |
getIcon(java.lang.String key,
javax.swing.Icon def)
Get an icon for a resource name. |
int |
getInt(java.lang.String key,
int def)
Get an int value from the MapResourceBundle. |
int |
getInteger(java.lang.String key,
int def)
Deprecated. Replaced in versio 0.98.0 with getInt
for the sake of conformance with OptionSet and ArgsParser . |
java.util.Enumeration |
getKeys()
Return an enumeration of the keys. |
java.lang.String |
getString(java.lang.String key,
java.lang.String def)
Get a String from the MapResourceBundle. |
java.lang.Object |
handleGetObject(java.lang.String key)
Get an object from the MapResourceBundle. |
void |
setIcon(java.lang.String key,
javax.swing.Icon icon)
Set an icon for a resource name. |
void |
setResolvingClass(java.lang.Class clazz)
Set the Class to use for getting Icon resources. |
Methods inherited from class java.util.ResourceBundle |
getBundle, getBundle, getBundle, getLocale, getObject, getString, getStringArray, setParent |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public MapResourceBundle()
public MapResourceBundle(java.util.ResourceBundle rb)
rb
- The resources to start with.Method Detail |
public void addResources(java.util.ResourceBundle bundle)
bundle
- The ResourceBundle to add.public void addResources(java.util.Properties properties)
properties
- The Properties to add.public void fetchProperties(java.lang.String basename, java.util.Locale locale, java.lang.Class resolve) throws java.util.MissingResourceException
ResourceBundle.getBundle
that can handle resources from jar files.
This version searches for .properties
files only. The
properties are then added to the MapResourceBundle.basename
- Basename for resource file.locale
- The locale to use.resolve
- A class from the same jar file as the resource.java.util.MissingResourceException
- If the resource cannot be found.public void fetchProperties(java.lang.String basename, java.lang.Class resolve) throws java.util.MissingResourceException
ResourceBundle.getBundle
that can handle resources from jar files. This version searches for
.properties
files only. The properties are then added to
the MapResourceBundle.basename
- Basename for resource file.resolve
- A class from the same jar file as the resource.java.util.MissingResourceException
- If the resource cannot be found.public java.util.Enumeration getKeys()
getKeys
in class java.util.ResourceBundle
public java.lang.Object handleGetObject(java.lang.String key) throws java.util.MissingResourceException
handleGetObject
in class java.util.ResourceBundle
key
- The key to look for.java.util.MissingResourceException
- If the key is not found.public java.lang.String getString(java.lang.String key, java.lang.String def)
key
- The key to look for.def
- The default value in case key doesn't exist.public int getInteger(java.lang.String key, int def)
getInt
for the sake of conformance with OptionSet
and ArgsParser
.
key
- The key to look for.def
- The default value in case key doesn't exist.public int getInt(java.lang.String key, int def)
key
- The key to look for.def
- The default value in case key doesn't exist.public boolean getBoolean(java.lang.String key, boolean def)
key
- The key to look for.def
- The default value in case key doesn't exist.public void setResolvingClass(java.lang.Class clazz)
clazz
- The Class to use with getResource.public javax.swing.Icon getIcon(java.lang.String key, javax.swing.Icon def)
key
- The resource name.def
- The default value in case key doesn't exist.public void setIcon(java.lang.String key, javax.swing.Icon icon)
key
- The resource name.icon
- The icon to set.
|
qflib 0.98.1 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |