|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectresources.Settings
public class Settings
A collection of keys (names) and associated String values.
Standard component types
use settings to control how cards are laid out and to localize text for the game
language. The main application uses settings to control program behaviour and
store user preferences.
Settings values are scoped. Within a given scope a setting key can have a different value than it would in another scope. If a key is not defined at the current scope, then the value in the parent scope (if any) will be used instead.
The most common place where where a scoping is encountered is in the private settings managed by every game component. When you change the value of a key in a component's private settings, the new value is visible only to that component. This can be used to customize an existing standard component, for example, by changing the images normally used for its card faces.
At the highest level in the scope chain for every Settings object
there is a common global scope. This scope contains the settings made up from the
default values for the application, changes applied because of the game language
setting, and user settings (representing user preferences that persist between
sessions). (Technically, these are actually different scopes, but from the
point of view of users of this class that is rarely significant.) You can obtain
a Settings instance that represents the global scope by calling
Settings.getShared().
| Nested Class Summary | |
|---|---|
static class |
Settings.Colour
A specialized Color that is more easily
converted to or from a setting value. |
static class |
Settings.Region
A specialized Rectangle that is more easily
converted to or from a setting value. |
static class |
Settings.Region2D
A specialized Rectangle that is more easily
converted to or from a setting value. |
| Field Summary | |
|---|---|
static java.beans.PropertyChangeListener |
DEBUG_LISTENER
A PropertyChangeListener that will print diagnostic information
to the script console whenever a key's value changes. |
| Constructor Summary | |
|---|---|
Settings()
Creates a new Settings scope whose parent is the shared
global scope. |
|
Settings(Settings parent)
Create a new settings scope within the scope of parent. |
|
| Method Summary | |
|---|---|
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a property change listener for this scope. |
void |
addSettingsFrom(java.util.Map<java.lang.String,java.lang.String> settings)
Add settings stored in a resource file to this settings object. |
void |
addSettingsFrom(java.lang.String resource)
Add settings stored in a resource file to this settings object. |
boolean |
applyWindowSettings(java.lang.String prefix,
java.awt.Window window)
Restores the position and size of a window from the last time its settings were stored in this settings object. |
static java.awt.Color |
color(java.lang.String value)
Cover method for #colour(value). |
static java.awt.Color |
colour(java.lang.String value)
Parses a Color from a string in the same way that
getColour(java.lang.String) does. |
javax.swing.Icon |
createIcon(java.lang.String key)
Deprecated. |
Settings |
createNamespace(java.lang.String namespace)
Return a view of this Settings instance within a namespace; all keys
accessed through the returned Settings will add the
namespace prefix to their keys. |
static PageShape.CupShape |
cupShape(java.lang.String value)
|
void |
flush()
If this settings object is backed by a persistent store, then this method will immediately write the settings to the store. |
static Settings |
forProperties(java.util.Properties p)
Creates a Settings view of Properties object. |
java.lang.String |
get(java.lang.String key)
Return a setting value, or null if it is not defined. |
java.lang.String |
get(java.lang.String key,
java.lang.String defaultValue)
Returns a setting value, or a default value if it is not defined. |
boolean |
getBoolean(java.lang.String key)
This is a cover for getYesNo(java.lang.String). |
java.awt.Color |
getColor(java.lang.String key)
A cover method for getColour( key ). |
java.awt.Color |
getColour(java.lang.String key)
Parse an RRGGBB colour from key + "-colour". |
PageShape |
getCupShape(java.lang.String key)
Return a CupShape for shaping mark-up text from the value
of key + "-shape". |
double |
getDouble(java.lang.String key)
Return a double based on the value of key. |
java.lang.String |
getExpansionSymbol()
|
int |
getExtraRegionType(java.lang.String key,
int index)
Parse an extra region type from a key + "-extra-" + index "-type". |
float |
getFloat(java.lang.String key)
Return a float based on the value of key. |
java.lang.String |
getFootnoteSymbol(int index)
Return the footnote symbol for the indexth footnote. |
javax.swing.Icon |
getIconResource(java.lang.String key)
Return an Icon from an image resource pointed to
by key. |
java.awt.image.BufferedImage |
getImageResource(java.lang.String key)
Return a BufferedImage from an image resource pointed to
by key. |
int |
getInt(java.lang.String key)
Return an integer value based on the value of key. |
java.util.Set<java.lang.String> |
getKeySet()
Returns an immutable set of all of the keys that have values defined at this scope. |
java.awt.image.BufferedImage |
getNumberedImageResource(java.lang.String base,
int number)
Get an image resource that follows a numbered sequence by replacing "00" in the the file name with the requested number. |
java.lang.String |
getOverride(java.lang.String key)
Return a setting value, or null if it is not defined. |
Settings |
getParent()
Returns the parent scope of this Settings, or null
if this is the shared scope. |
float |
getPointSize(java.lang.String key)
Return a font point size from key + "-pointsize". |
java.awt.Rectangle |
getRegion(java.lang.String key)
Return a Rectangle from the value of key + "-region". |
java.awt.geom.Rectangle2D.Double |
getRegion2D(java.lang.String key)
Return a Rectangle from the value of key + "-region". |
java.net.URL |
getResourceURL(java.lang.String key)
Returns the URL of a resource by looking up the value
of key and treating it as a relative URL in the
applications /resources folder. |
static Settings |
getShared()
Returns the Settings object that represents the
shared global scope. |
java.lang.String |
getText(java.lang.String key)
Returns the value of the setting formed by appending "-text"
to key (key + "text"). |
int |
getTextFittingMethod(java.lang.String key)
Return a text-fitting method stored in key + "-text-fitting". |
java.lang.String |
getTextOrNull(java.lang.String key)
Returns the value of the setting formed by appending "-text"
to key (key + "text"). |
float[] |
getTint(java.lang.String key)
Parse a tint from a comma separated list of three numbers from key + "-tint". |
static Settings |
getUser()
Returns the Settings object that represents
user settings. |
java.util.Set<java.lang.String> |
getVisibleKeySet()
Returns an immutable set of all of the keys that are visible from this scope (including all parent scopes). |
boolean |
getYesNo(java.lang.String key)
Return a boolean value based on the value of key. |
static int |
integer(java.lang.String value)
Parse a string into an integer value. |
static double |
number(java.lang.String value)
Parse a string into a double value. |
static java.awt.Rectangle |
region(java.lang.String value)
Parse a string into an integer region. |
static java.awt.geom.Rectangle2D.Double |
region2D(java.lang.String value)
Parse a string into a double precision region. |
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes a listener that was previously added to this Settings. |
void |
reset(java.lang.String key)
Removes a key from this scope, returning the key to whatever value it has in the parent scope. |
void |
set(java.lang.String key,
java.lang.String value)
Sets the value of a key at this scope. |
void |
setSettings(java.lang.String... keyValuePairs)
Set mulitple key, value pairs in a single call. |
int |
size()
Returns the number of keys that are defined at this scope. |
void |
storeWindowSettings(java.lang.String prefix,
java.awt.Window window)
Saves the position of a window for later recall by writing it as a group of settings. |
static float[] |
tint(java.lang.String value)
Given a string, parse into into a tint value. |
java.lang.String |
toString()
Returns a string that uniquely identifies this scope. |
static void |
traceSetting(Settings scope,
java.lang.String key)
A debugging aid that prints tracing information for a key, relative to the scope defined by a particular Settings object. |
void |
traceSetting(java.lang.String key)
Print tracing information for a key to the script console from the scope of this Settings object. |
static boolean |
yesNo(java.lang.String value)
Convert a string into a boolean value using the same rules
as those used by getYesNo(java.lang.String). |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final java.beans.PropertyChangeListener DEBUG_LISTENER
PropertyChangeListener that will print diagnostic information
to the script console whenever a key's value changes.
| Constructor Detail |
|---|
public Settings()
Settings scope whose parent is the shared
global scope.
public Settings(Settings parent)
parent.
Passing null or Settings.getShared() for the
parent will use the shared global scope.
parent - the parent scope that will be used to look up keys not defined in this scope| Method Detail |
|---|
public static Settings forProperties(java.util.Properties p)
Settings view of Properties object.
The Settings is backed by the Properties instance;
changes to one affect the other.
p -
public Settings getParent()
Settings, or null
if this is the shared scope.
public Settings createNamespace(java.lang.String namespace)
Settings instance within a namespace; all keys
accessed through the returned Settings will add the
namespace prefix to their keys. As long as the name is unique
keys in the returned Settings will be private to it and
not conflict with keys with the same name but a different namespace.
(This may fail to hold if the naming conventions for keys names
are not followed.)
namespace - the space to create a view for
Settings that is confined to the namespacepublic java.util.Set<java.lang.String> getKeySet()
getVisibleKeySet() instead.
Note that the set returned by this is a copy of the keys at the time that
this method was called. It is not updated as this Settings
instance is modified.
public java.util.Set<java.lang.String> getVisibleKeySet()
Note that the set returned by this is a copy of the keys at the time that
this method was called. It is not updated as this Settings
instance is modified. Be aware that
public int size()
this.getVisibleKeySet().size().
public static Settings getShared()
Settings object that represents the
shared global scope.
Currently, attempting to set or reset a setting key in the
shared scope will cause an UnsupportedOperationException
to be thrown, although this may change in the future.
public static Settings getUser()
Settings object that represents
user settings. User settings are used to store data that must persist
between program runs, such as the recent file list and preference choices.
Because user settings take precedence over the standard Strange Eons settings,
it can also be used to permanently modify a layout setting at the global scope.
This is not usually recommended. The preferred way to achieve this is to
write an extension that temporarily changes the setting for the duration
of the program run. This way, the extension can be uninstalled to
eliminate the effect.
Note that user settings can be read through the shared scope. Using the user scope directly is mainly useful for writing settings that will persist.
The user settings scope should not be used to store preference settings
for a plug-in. Instead, use PluginContext#setPluginSetting(java.lang.String, java.lang.String).
Using this method ensures that your setting names will not conflict with
standard SE settings or preferecnes from other plug-ins.
public java.lang.String get(java.lang.String key)
null if it is not defined.
key - the key to fetch the value of
null
public java.lang.String get(java.lang.String key,
java.lang.String defaultValue)
key - the key to fetch the value ofdefaultValue - the default value to return if get(key) == null
public java.lang.String getOverride(java.lang.String key)
null if it is not defined.
This method searches only the local scope without delegating to
parent scopes.
key - the key to fetch the value of
null
public void set(java.lang.String key,
java.lang.String value)
key - the key to whose value at this scope should be changedvalue - the value to set for this scopepublic void reset(java.lang.String key)
key - the key to be removepublic void setSettings(java.lang.String... keyValuePairs)
keyValuePairs -
public void addSettingsFrom(java.lang.String resource)
throws java.io.IOException
resource - a file relative to the resources folder
java.io.IOExceptionpublic void addSettingsFrom(java.util.Map<java.lang.String,java.lang.String> settings)
resource - a file relative to the resources folder
java.io.IOExceptionpublic void flush()
The only standard settings object that is backed by a persistent store
is the user settings object obtained with getUser(). Calling
this method on the user settings object will immediately write user
settings to the user settings file
(typically, ~/.strange-eons-settings). (User settings will
always be flushed during program shutdown.)
public java.lang.String getText(java.lang.String key)
"-text"
to key (key + "text"). If no such setting is defined,
the string "[UNDEFINED: " + key + "]" is returned instead.
key - the name of a text key, less -text
public java.lang.String getTextOrNull(java.lang.String key)
"-text"
to key (key + "text"). If no such setting is defined,
returns null.
key - the name of a text key, less -text
nullpublic java.lang.String getFootnoteSymbol(int index)
indexth footnote.
Footnote symbol settings are stored in a sequence of keys of the form
footnote-symboln-text, where n
is the value of index. Footnote numbers start at 1 and
there are guaranteed to be as many unique symbols as the value of
this.getInt( "footnote-symbol" ). (The global scope
currently provides four unique symbols.) If there is no unique symbol
for the requested index, a unique footnote symbol consisting of multiple copies
of an existing symbol will be generated.
index - the footnote number, starting from 1
indexth footnote, or null if the number of symbols is exceeded
java.lang.IndexOutOfBoundsException - if index < 1#getInt(key)public boolean getYesNo(java.lang.String key)
key.
Any of "yes", "true", or "1" are mapped to true, and all
other values are mapped to false.
- Parameters:
key - the name of the setting key
- Returns:
true if the value of the setting is "yes", "true", or "1"
public final boolean getBoolean(java.lang.String key)
getYesNo(java.lang.String).
key - the name of the setting key
true if the value of the setting is "yes", "true", or "1"public static final boolean yesNo(java.lang.String value)
boolean value using the same rules
as those used by getYesNo(java.lang.String).
value - the value to parse
true if the value is "yes", "true", or "1"public int getInt(java.lang.String key)
key.
The conversion of the value is performed as if by integer(java.lang.String).
key - the name of the setting key
public static int integer(java.lang.String value)
Integer.MIN_VALUE + 1
to Integer.MAX_VALUE, inclusive.
The value is parsed identically to Integer.valueOf(String),
except that it is legal for the value to begin with a plus sign (which
is ignored) or a decimal point (the number is parsed only up to the decimal
point).
If the value cannot be parsed, Integer.MIN_VALUE is returned.
value - the string to convert to an integer
Integer.MIN_VALUEpublic float getFloat(java.lang.String key)
float based on the value of key.
The conversion of the value is performed similarly to number(java.lang.String),
except that float precision is used throughout the conversion.
key - the name of the setting key
Float.NaNpublic double getDouble(java.lang.String key)
double based on the value of key.
The conversion of the value is performed as if by number(java.lang.String).
key - the name of the setting key
Double.NaNpublic static double number(java.lang.String value)
double value.
The value is parsed identically to Double.valueOf(String).
If the value cannot be parsed, Double.NaN is returned.
value - the string to convert to a floating-point number
Double.NaNpublic java.awt.Color getColour(java.lang.String key)
key + "-colour".
Fatal error if key undefined.
the - name of a key, less -colour, that names a colour value
value in either RRGGBB or AARRGGBB formatscolour(java.lang.String)public final java.awt.Color getColor(java.lang.String key)
getColour( key ).
the - name of a key, less -colour that names a colour value
value in either RRGGBB or AARRGGBB formatscolour(java.lang.String)public static final java.awt.Color colour(java.lang.String value)
Color from a string in the same way that
getColour(java.lang.String) does. Returns null
if it is unable to parse the string.
The string is taken to be a hexadecimal number which
consists of the red component in bits 16-23, the green component
in bits 8-15, and the blue component in bits 0-7. Optionally,
bits 24-31 describe an alpha value. If the length of value
if 6 characters or less (RRGGBB) then the alpha value will be
set to FF (that is, 255, or completely opaque).
value - a string of six or eight hex digits to parse
value in either RRGGBB or AARRGGBB formatspublic static final java.awt.Color color(java.lang.String value)
#colour(value).
value - a string of six or eight hex digits to parse
value in either RRGGBB or AARRGGBB formatspublic float[] getTint(java.lang.String key)
key + "-tint". A tint is a relative colour described
in terms of shifts to the hue, saturation, and brightness of a source
colour. Tints can be applied to an image using the filters in
ca.cgjennings.graphics.filters.
the - name of a key, less -tint, that names a tint value
value in either RRGGBB or AARRGGBB formatscolour(java.lang.String)public static final float[] tint(java.lang.String value)
ca.cgjennings.graphics.filters. A tint is described using
a list of comma-separated floating point numbers. The first number is
an angle, in degrees, that describes the shift to apply to the hue.
The second number is a relative saturation factor (normally between 0
and 1). The third number is a relative brightness (normally greater than
or equal to 0). The exact effect of these values depends on the filter
used. The tint is returned as an array of three float values.
The hue is converted to the range -1 to 1. The other two values are unchanged.
This function returns null if it is unable to parse the tint
string.
value - a tint string consisting of three numbers separated by commas: h,s,b
public java.net.URL getResourceURL(java.lang.String key)
URL of a resource by looking up the value
of key and treating it as a relative URL in the
applications /resources folder. This folder consists
of the resources stored in the main application file, as well as
the contents of the /resources folders stored in any
installed plug-in bundles, libraries, or themes. Note that if there
is a naming conflict, resources obtained with this method will prefer
the main application's resources over any add-ons.
key - a key whose value is a resource URL
nullpublic java.awt.Rectangle getRegion(java.lang.String key)
Rectangle from the value of key + "-region".
The returned rectangle is limited to integer precision.
If the requested region is not defined, or its is formatted incorrectly,
this method displays an error and returns a dummy region.
key - the key whose value should be parsed, less <-regionpublic java.awt.geom.Rectangle2D.Double getRegion2D(java.lang.String key)
Rectangle from the value of key + "-region".
If the requested region is not defined, returns null.
If it is formatted incorrectly,
this method logs an error and returns a dummy region.
this method returns null.
key - the key whose value should be parsed, less <-regionpublic PageShape getCupShape(java.lang.String key)
CupShape for shaping mark-up text from the value
of key + "-shape".
If the requested shape is not defined, returns null.
If it is formatted incorrectly,
this method logs an error and returns a dummy shape.
key - the key whose value should be parsed, less <-shapepublic static final java.awt.Rectangle region(java.lang.String value)
Note: Since 2.00.8, the object returned is an instance of
Settings.Region.
value - the comma separated coordinate string to parse
value, or nullpublic static final java.awt.geom.Rectangle2D.Double region2D(java.lang.String value)
double precision region.
The region is described by four comma-separated numbers which give
the x- and y-coordinates of the upper left corner, the width, and the height.
Note: Since 2.00.8, the object returned is an instance of
Settings.Region2D.
value - the comma separated coordinate string to parse
value, or nullpublic static final PageShape.CupShape cupShape(java.lang.String value)
public float getPointSize(java.lang.String key)
key + "-pointsize".
key - the base name of a key whose value is a point sizepublic int getTextFittingMethod(java.lang.String key)
key + "-text-fitting".
The value is mapped to a text-fitting constant as follows:
"none" MarkupRenderer.FIT_NONE "spacing" MarkupRenderer.FIT_TIGHTEN_LINE_SPACING "scaling" MarkupRenderer.FIT_SCALE_TEXT "both" MarkupRenderer.FIT_BOTH
key - the key, less -text-fitting to obtain a fitting value from
MarkupRenderer.
public int getExtraRegionType(java.lang.String key,
int index)
key + "-extra-" + index "-type".
Extra regions are used by some sheets as a way to support a specific
game language. The value is converted to a CharacterSheet
constant as follows:
"left" CharacterSheet.EXTRA_REGION_LEFT "center" CharacterSheet.EXTRA_REGION_CENTER "body" CharacterSheet.EXTRA_REGION_BODY
public java.lang.String getExpansionSymbol()
public java.awt.image.BufferedImage getImageResource(java.lang.String key)
BufferedImage from an image resource pointed to
by key. This will convert the value of key
into a resource URL using getResourceURL(java.lang.String),
then create an image from the resulting resource.
The format of the image is guaranteed to be one of three types. If the image
does not contain alpha data, then it is normalized to
BufferedImage.TYPE_INT_RGB. If it does contain alpha data,
then the type will either be
BufferedImage.TYPE_INT_ARGB or
BufferedImage.TYPE_INT_ARGB_PRE.
The later type is returned only if the global boolean settings key
premultiply-image-alpha is true.
key - a key whose value points to an image file
public java.awt.image.BufferedImage getNumberedImageResource(java.lang.String base,
int number)
number is less than
10, the replacement will use two digits (01 instead of 1).
This method takes the base file name directly, not the key that points to the base file name. As a result, its use normally follows the pattern:
settings.getNumberedImageResource( settings.get( key ), number );
public javax.swing.Icon getIconResource(java.lang.String key)
Icon from an image resource pointed to
by key. This will convert the value of key
into a resource URL using getResourceURL(java.lang.String),
then create an icon from the resulting resource.
key - a key whose value points to an image file
public void storeWindowSettings(java.lang.String prefix,
java.awt.Window window)
prefix is a unique prefix for that window.
To restore the position later, call applyWindowSettings(java.lang.String, java.awt.Window) using
the same prefix. Usually used with the getUser() instance.
prefix - a unique name for the windowwindow - the window whose shape should be written into settings
public boolean applyWindowSettings(java.lang.String prefix,
java.awt.Window window)
prefix - the unique prefix chosen for this window when it was storedwindow - the window to be restored
true if there were settings to restore; otherwise
you should use a default placement algorithm to place the window@Deprecated public javax.swing.Icon createIcon(java.lang.String key)
getIconResource(java.lang.String) and is
provided for backward compatibility.
key - a key whose value points to an image file
public void traceSetting(java.lang.String key)
Settings object.
key - the key to tracetraceSetting(resources.Settings, java.lang.String)
public static void traceSetting(Settings scope,
java.lang.String key)
Settings object.
This will trace the value of key up from scope
through to the shared global scope. The value of the key at each scope
will be printed to the script console.
scope - the scope to start tracing fromkey - the key whose value should be tracedpublic java.lang.String toString()
Settings will return "Settings (Shared)".
Other scopes will return a string specifying "Private" instead
of "Shared", along with a hexadecimal number that uniquely
identifies this instance.
toString in class java.lang.Objectpublic void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
listener - the listener to call when a key's value changespublic void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Settings.
listener - the listener to remove
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||