|
|||||||||
| Home >> All >> org >> dinopolis >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.dinopolis.util
Interface Resources

- public interface Resources
This Interface is used to access any Resources. Resources may be given in a file, database, memory or wherever. Resources may also be locale-specific. (see java.util.ResourceBundle for further details.)
Stored resources can not only be requested as Strings,
but also in many different other types, like integers,
StringArrays, booleans, Colors,
Icons and others.
When your program needs a specific object, it loads the
ResourceManager class using one of the
getResources methods:
If a lookup fails,Resources my_resources = ResourceManager.getResources(this, "MyResources");
getBundle() throws a
MissingResourceException.Resource files contain key/value pairs. The keys uniquely identify a locale-specific object in the bundle. Here's an example resource file that contains two key/value pairs:
Keys are alwaysmy_app.dimension.width=300 my_app.dimension.height=200
Strings.
In this example, the keys are my_app.dimension.width
and my_app.dimension.height.
In the above example, the values
are also Strings--200 and 300--but
they may also be interpreted as integer values using the method
getInt(java.lang.String) 55 .
The single argumented getter methods all require the key as an
argument and return the object if found. If the object is not
found, the getter method throws a
MissingResourceException. To avoid this behavior, it
is also possible to use the corresponding methods that take two
arguments, the key and the default value. If no property was bound
under the given key, the default value will be returned instead of
throwing a MissingResourceException.
- Version:
- $Revision: 1.7 $
| Field Summary | |
static java.lang.String |
GROUPS
the key of the 'resource.groups' property |
static java.lang.String |
KEY_DELIMITER
the delimiter used in resources for string arrays |
static java.lang.String |
RESOURCE_STRING_ARRAY_DELIMITER
the delimiter used in resources for string arrays |
static java.lang.String |
SWALLOW_IDENTIFIER
the delimiter used for swallow replacs. |
static int |
SWALLOW_LENGTH
the length of SWALLOW_IDENTIFIER |
static java.lang.String |
VAR_IDENTIFIER
the delimiter used for variable replacement. |
static int |
VAR_LENGTH
the length of VAR_IDENTIFIER |
| Method Summary | |
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a PropertyChangeListener to the listener list. |
void |
addPropertyChangeListener(java.lang.String property_name,
java.beans.PropertyChangeListener listener)
Add a PropertyChangeListener for a specific property. |
void |
attachResources(Resources resources)
Attach another set of resources. |
void |
detachResources(Resources resources)
Detach previously attached resources. |
java.lang.Object |
get(java.lang.String key)
Returns the native value loaded from the resource bundle. |
boolean |
getBoolean(java.lang.String key)
Returns the boolean loaded from the resource bundle. |
boolean |
getBoolean(java.lang.String key,
boolean default_value)
Returns the boolean loaded from the resource bundle. |
java.awt.Color |
getColor(java.lang.String key)
Returns the color loaded from the resource bundle. |
java.awt.Color |
getColor(java.lang.String key,
java.awt.Color default_value)
Returns the color loaded from the resource bundle. |
java.lang.String |
getDescription(java.lang.String key)
Returns a string that describes the key and its possible values. |
double |
getDouble(java.lang.String key)
Returns the double loaded from the resource bundle. |
double |
getDouble(java.lang.String key,
double default_value)
Returns the double loaded from the resource bundle. |
double[] |
getDoubleArray(java.lang.String key)
Returns the double array loaded from the resource bundle. |
double[] |
getDoubleArray(java.lang.String key,
double[] default_values)
Returns the double array loaded from the resource bundle. |
java.io.File |
getFile(java.lang.String key)
Returns the file loaded from the resource bundle. |
java.io.File |
getFile(java.lang.String key,
java.io.File default_value)
Returns the file loaded from the resource bundle. |
javax.swing.Icon |
getIcon(java.lang.String key)
Returns the icon loaded from the resource bundle. |
javax.swing.Icon |
getIcon(java.lang.String key,
javax.swing.Icon default_value)
Returns the icon loaded from the resource bundle. |
int |
getInt(java.lang.String key)
Returns the int loaded from the resource bundle. |
int |
getInt(java.lang.String key,
int default_value)
Returns the int loaded from the resource bundle. |
int[] |
getIntArray(java.lang.String key)
Returns the int array loaded from the resource bundle. |
int[] |
getIntArray(java.lang.String key,
int[] default_values)
Returns the int array loaded from the resource bundle. |
java.util.Enumeration |
getKeys()
Returns an Enumeration containing all keys of all resources. |
java.lang.String[] |
getPossibleValues(java.lang.String key)
Returns an array of all values that are valid. |
java.lang.String |
getString(java.lang.String key)
Returns the string loaded from the resource bundle. |
java.lang.String |
getString(java.lang.String key,
java.lang.String default_value)
Returns the string loaded from the resource bundle. |
java.lang.String[] |
getStringArray(java.lang.String key)
Returns the string array, loaded from the resource bundle. |
java.lang.String[] |
getStringArray(java.lang.String key,
java.lang.String delimiter)
Returns the string array, loaded from the resource bundle. |
java.lang.String[] |
getStringArray(java.lang.String key,
java.lang.String[] default_values)
Returns the string array loaded from the resource bundle. |
java.lang.String |
getTitle(java.lang.String key)
Returns the title for the given key. |
java.lang.Class |
getType(java.lang.String key)
Returns the type of the value bound under the given key. |
java.net.URL |
getURL(java.lang.String key)
Returns the Url loaded from the resource bundle. |
java.net.URL |
getURL(java.lang.String key,
java.net.URL default_value)
Returns the Url loaded from the resource bundle. |
boolean |
isModificationSupported()
Returns true, if this resources is capable of storing and deleting resources, false otherwise. |
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a PropertyChangeListener from the listener list. |
void |
removePropertyChangeListener(java.lang.String property_name,
java.beans.PropertyChangeListener listener)
Remove a PropertyChangeListener for a specific property. |
void |
reset(java.lang.String key)
Resets the bound value to its default value (if supported). |
void |
setBoolean(java.lang.String key,
boolean value)
Registers the given value under the given key. |
void |
setColor(java.lang.String key,
java.awt.Color value)
Registers the given value under the given key. |
void |
setDescription(java.lang.String key,
java.lang.String description)
Sets the description for the given key. |
void |
setDouble(java.lang.String key,
double value)
Registers the given value under the given key. |
void |
setDoubleArray(java.lang.String key,
double[] values)
Registers the given values under the given key. |
void |
setInt(java.lang.String key,
int value)
Registers the given value under the given key. |
void |
setIntArray(java.lang.String key,
int[] values)
Registers the given values under the given key. |
void |
setPossibleValues(java.lang.String key,
java.lang.String[] possible_values)
Sets the possible Values for the given key. |
void |
setString(java.lang.String key,
java.lang.String value)
Registers the given value under the given key. |
void |
setStringArray(java.lang.String key,
java.lang.String[] values)
Registers the given values under the given key. |
void |
setStringArray(java.lang.String key,
java.lang.String[] values,
java.lang.String delimiter)
Registers the given values under the given key. |
void |
setTitle(java.lang.String key,
java.lang.String title)
Sets the title for the given key. |
void |
setType(java.lang.String key,
java.lang.Class type)
Sets the type for the given key. |
void |
store()
Call this method to make all changes performed by unset and setter methods persistent. |
void |
unset(java.lang.String key)
Removes the bound value for the given key, if no value was bound under the given key, this method does nothing. |
| Field Detail |
KEY_DELIMITER
public static final java.lang.String KEY_DELIMITER
- the delimiter used in resources for string arrays
- See Also:
- Constant Field Values
RESOURCE_STRING_ARRAY_DELIMITER
public static final java.lang.String RESOURCE_STRING_ARRAY_DELIMITER
- the delimiter used in resources for string arrays
- See Also:
- Constant Field Values
VAR_IDENTIFIER
public static final java.lang.String VAR_IDENTIFIER
- the delimiter used for variable replacement. So '$key$' will be
replace by the value of 'key'
- See Also:
- Constant Field Values
VAR_LENGTH
public static final int VAR_LENGTH
- the length of VAR_IDENTIFIER
SWALLOW_IDENTIFIER
public static final java.lang.String SWALLOW_IDENTIFIER
- the delimiter used for swallow replacs. eg.: '$%key%$' is
equivalent to 'key', but '$%k*%$' will be expanded to all keys of
the resource that start with the letter 'k'. '$k$' will be
expanded to all values of keys that start with the letter 'k'.
- See Also:
- Constant Field Values
SWALLOW_LENGTH
public static final int SWALLOW_LENGTH
- the length of SWALLOW_IDENTIFIER
GROUPS
public static final java.lang.String GROUPS
- the key of the 'resource.groups' property
- See Also:
- Constant Field Values
| Method Detail |
unset
public void unset(java.lang.String key) throws java.lang.UnsupportedOperationException
- Removes the bound value for the given key, if no value was bound
under the given key, this method does nothing.
reset
public void reset(java.lang.String key) throws java.lang.UnsupportedOperationException
- Resets the bound value to its default value (if supported).
isModificationSupported
public boolean isModificationSupported()
- Returns true, if this resources is capable of storing and
deleting resources, false otherwise.
store
public void store()
throws java.io.IOException,
java.lang.UnsupportedOperationException
- Call this method to make all changes performed by unset and
setter methods persistent.
attachResources
public void attachResources(Resources resources) throws java.lang.UnsupportedOperationException
- Attach another set of resources. After they are attached, all
getXXX() operations are able to read the values from the
resources as well as the attached resources. To set any values
(add new or change old values), the methods of the original
resources must be used or otherwise the keys/values are contained
in this resources (new value) and in the attached resources (old
values).
As soon as additional resources are attached, the getXXX() methods read from them. If there are duplicate keys in the resources and in the attached resources, the original resources have priority (take care!!).
The
store()55 method callsstore()on all attached resources as well.Attaching resources has the advantage that read access to resources is easy for different resources (e.g. in the resource editor), but the place where the resources are stored can still be held separated.
detachResources
public void detachResources(Resources resources) throws java.lang.UnsupportedOperationException
- Detach previously attached resources.
getTitle
public java.lang.String getTitle(java.lang.String key)
- Returns the title for the given key. If no title for this key is
available,
nullis returned.
setTitle
public void setTitle(java.lang.String key, java.lang.String title) throws java.lang.UnsupportedOperationException
- Sets the title for the given key.
Deleted the title if title is 'null'.
getDescription
public java.lang.String getDescription(java.lang.String key)
- Returns a string that describes the key and its possible values.
If no description for this key is available,
nullis returned.
setDescription
public void setDescription(java.lang.String key, java.lang.String description) throws java.lang.UnsupportedOperationException
- Sets the description for the given key.
Deleted the description if description is 'null'.
getType
public java.lang.Class getType(java.lang.String key)
- Returns the type of the value bound under the given key. Note
that the returned "Class" object may describe a built-in Java
type such as "int" (Integer.TYPE). For arrays, this may be e.g.:
int[].class. If no type for this key is available,nullis returned.
setType
public void setType(java.lang.String key, java.lang.Class type) throws java.lang.UnsupportedOperationException
- Sets the type for the given key.
Deleted the kype if type is 'null'.
getPossibleValues
public java.lang.String[] getPossibleValues(java.lang.String key)
- Returns an array of all values that are valid. This is usefull if
a value may be choosen out of a predifined set of possible
values.
If no set of valid values exists
nullis returned.
setPossibleValues
public void setPossibleValues(java.lang.String key, java.lang.String[] possible_values) throws java.lang.UnsupportedOperationException
- Sets the possible Values for the given key.
Deleted the possible Values if possible_values are 'null'.
get
public java.lang.Object get(java.lang.String key) throws java.util.MissingResourceException, java.lang.IllegalArgumentException
- Returns the native value loaded from the resource bundle. If variables
are given in the value, they will be replaced
recursively. Variables are Strings that start and end with a
'$'. To escape the $-sign use $$. In case of a deadlock (a
contains variable b, and b contains variable a), the variable
will not be replaced. Variables that are not given within the
resources are also not replaced. The return value will be of type
String, if the Resources are not type save, which means, that the
getType() call with the given key returns
null. If the resource is invalid to its type (e.g.: "x" as Integer), an IllegalArgumentException will be thrown.
getString
public java.lang.String getString(java.lang.String key) throws java.util.MissingResourceException
- Returns the string loaded from the resource bundle. If variables
are given in the value, they will be replaced
recursively. Variables are Strings that start and end with a
'$'. To escape the $-sign use $$. In case of a deadlock (a
contains variable b, and b contains variable a), the variable
will not be replaced. Variables that are not given within the
resources are also not replaced.
getString
public java.lang.String getString(java.lang.String key, java.lang.String default_value)
- Returns the string loaded from the resource bundle. If the key
was not found within the resources,
default_valuewill be returned. Any variables found within the properties value will be replaced.
setString
public void setString(java.lang.String key, java.lang.String value) throws java.lang.UnsupportedOperationException
- Registers the given value under the given key.
getStringArray
public java.lang.String[] getStringArray(java.lang.String key) throws java.util.MissingResourceException
- Returns the string array, loaded from the resource
bundle. Returns an empty array instead of
null. Any variables found within the properties value will be replaced.
getStringArray
public java.lang.String[] getStringArray(java.lang.String key, java.lang.String delimiter) throws java.util.MissingResourceException
- Returns the string array, loaded from the resource
bundle. Returns an empty array instead of
null. Any variables found within the properties value will be replaced.
getStringArray
public java.lang.String[] getStringArray(java.lang.String key, java.lang.String[] default_values)
- Returns the string array loaded from the resource bundle. If the
key was not found within the resources,
default_valueswill be returned. Any variables found within the properties value will be replaced.
setStringArray
public void setStringArray(java.lang.String key, java.lang.String[] values) throws java.lang.UnsupportedOperationException
- Registers the given values under the given key.
setStringArray
public void setStringArray(java.lang.String key, java.lang.String[] values, java.lang.String delimiter) throws java.lang.UnsupportedOperationException
- Registers the given values under the given key.
getInt
public int getInt(java.lang.String key) throws java.util.MissingResourceException, java.lang.NumberFormatException
- Returns the int loaded from the resource bundle. Any variables
found within the properties value will be replaced.
getInt
public int getInt(java.lang.String key, int default_value)
- Returns the int loaded from the resource bundle. If the key was
not found within the resources,
default_valuewill be returned. Any variables found within the properties value will be replaced.
setInt
public void setInt(java.lang.String key, int value) throws java.lang.UnsupportedOperationException
- Registers the given value under the given key.
getIntArray
public int[] getIntArray(java.lang.String key) throws java.util.MissingResourceException, java.lang.NumberFormatException
- Returns the int array loaded from the resource bundle. Any
variables found within the properties value will be replaced.
getIntArray
public int[] getIntArray(java.lang.String key, int[] default_values)
- Returns the int array loaded from the resource bundle. If the key
was not found within the resources,
default_valueswill be returned. Any variables found within the properties value will be replaced.
setIntArray
public void setIntArray(java.lang.String key, int[] values) throws java.lang.UnsupportedOperationException
- Registers the given values under the given key.
getDouble
public double getDouble(java.lang.String key) throws java.util.MissingResourceException, java.lang.NumberFormatException
- Returns the double loaded from the resource bundle. Any variables
found within the properties value will be replaced.
getDouble
public double getDouble(java.lang.String key, double default_value)
- Returns the double loaded from the resource bundle. If the key was
not found within the resources,
default_valuewill be returned. Any variables found within the properties value will be replaced.
setDouble
public void setDouble(java.lang.String key, double value) throws java.lang.UnsupportedOperationException
- Registers the given value under the given key.
getDoubleArray
public double[] getDoubleArray(java.lang.String key) throws java.util.MissingResourceException, java.lang.NumberFormatException
- Returns the double array loaded from the resource bundle. Any
variables found within the properties value will be replaced.
getDoubleArray
public double[] getDoubleArray(java.lang.String key, double[] default_values)
- Returns the double array loaded from the resource bundle. If the key
was not found within the resources,
default_valueswill be returned. Any variables found within the properties value will be replaced.
setDoubleArray
public void setDoubleArray(java.lang.String key, double[] values) throws java.lang.UnsupportedOperationException
- Registers the given values under the given key.
getBoolean
public boolean getBoolean(java.lang.String key) throws java.util.MissingResourceException
- Returns the boolean loaded from the resource bundle. Boolean value
that are interpreted as
truewithin the resource file are: "true", "True", "yes", "Yes" and "1". All other values will be interpreted to befalse. Any variables found within the properties value will be replaced.
getBoolean
public boolean getBoolean(java.lang.String key, boolean default_value)
- Returns the boolean loaded from the resource bundle. Boolean
value that are interpreted as
truewithin the resource file are: "true", "True", "yes", "Yes" and "1". All other values will be interpreted to befalse. If the key was not found within the resources,default_valuewill be returned. Any variables found within the properties value will be replaced.
setBoolean
public void setBoolean(java.lang.String key, boolean value) throws java.lang.UnsupportedOperationException
- Registers the given value under the given key.
getIcon
public javax.swing.Icon getIcon(java.lang.String key) throws java.util.MissingResourceException
- Returns the icon loaded from the resource bundle. The filename of
the icon in the resource file has to be relative to the resource
file. Any variables found within the properties value will be
replaced.
getIcon
public javax.swing.Icon getIcon(java.lang.String key, javax.swing.Icon default_value)
- Returns the icon loaded from the resource bundle. Icon value
that are interpreted as
truewithin the resource file are: "true", "True", "yes", "Yes" and "1". All other values will be interpreted to befalse. If the key was not found within the resources,default_valuewill be returned. Any variables found within the properties value will be replaced.
getColor
public java.awt.Color getColor(java.lang.String key) throws java.util.MissingResourceException
- Returns the color loaded from the resource bundle. Any variables
found within the properties value will be replaced. Possible
values for colors are: "white", "blue",... and "r,g,b" values
like "255,96,96".
getColor
public java.awt.Color getColor(java.lang.String key, java.awt.Color default_value)
- Returns the color loaded from the resource bundle. Any variables
found within the properties value will be replaced. Possible
values for colors are: "white", "blue",... and "r,g,b" values
like 255,96,96. If the key was not found within the resources,
default_valuewill be returned.
setColor
public void setColor(java.lang.String key, java.awt.Color value) throws java.lang.UnsupportedOperationException
- Registers the given value under the given key.
getFile
public java.io.File getFile(java.lang.String key)
- Returns the file loaded from the resource bundle. Any variables
found within the properties value will be replaced.
getFile
public java.io.File getFile(java.lang.String key, java.io.File default_value)
- Returns the file loaded from the resource bundle. Any variables
found within the properties value will be replaced. If the key
was not found within the resources,
default_valuewill be returned.
getURL
public java.net.URL getURL(java.lang.String key) throws java.util.MissingResourceException
- Returns the Url loaded from the resource bundle. Any variables
found within the properties value will be replaced.
getURL
public java.net.URL getURL(java.lang.String key, java.net.URL default_value)
- Returns the Url loaded from the resource bundle. Any variables
found within the properties value will be replaced. If the key
was not found within the resources,
default_valuewill be returned.
getKeys
public java.util.Enumeration getKeys()
- Returns an Enumeration containing all keys of all resources.
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
- Add a PropertyChangeListener to the listener list.
The listener is registered for all properties.
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
- Remove a PropertyChangeListener from the listener list.
This removes a PropertyChangeListener that was registered
for all properties.
addPropertyChangeListener
public void addPropertyChangeListener(java.lang.String property_name, java.beans.PropertyChangeListener listener)
- Add a PropertyChangeListener for a specific property. The listener
will be invoked only when a call on firePropertyChange names that
specific property.
removePropertyChangeListener
public void removePropertyChangeListener(java.lang.String property_name, java.beans.PropertyChangeListener listener)
- Remove a PropertyChangeListener for a specific property.
|
|||||||||
| Home >> All >> org >> dinopolis >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC