|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.AbstractMap<K,V>
java.util.TreeMap<String,List<String>>
types.GUIAttributes
public final class GUIAttributes
A specialized extension of TreeMap which helps in handling widget attributes. Specifically, a GUIAttributes object holds a map with default values for all attributes; has methods to assist in attribute retrieval and parsing; remembers what widget it is associated with; and automates error handling by generating exceptions that, 90% of the time, should be sufficient such that a widget definition doesn't need any explicit error checking.
| Field Summary | |
|---|---|
static Map<String,Boolean> |
boolStrings
A mapping of acceptible string values for Boolean attributes to their Boolean values. |
static Map<String,String> |
colorEquivs
A mapping of color synonyms to their canonical color names. |
static SortedSet<String> |
colors
The set of acceptable color names (except that colors in colorEquivs are accepted as well). |
Map<String,List<String>> |
defaults
A map of the names of the recognized attributes to their default values. |
static Pattern |
htmlColorPat
The regular expression matching HTML-style color values. |
Map<String,List<String>> |
multisynonyms
A map on multisynonymous attribute names to the names of their component attributes. |
Map<String,String> |
synonyms
A map of synonymous attribute names to their canonical equivalents. |
Widget |
widget
The Widget to which this object belongs. |
| Constructor Summary | |
|---|---|
GUIAttributes(Map<String,List<String>> defaults,
Map<String,String> synonyms,
Map<String,List<String>> multisynonyms,
Widget widget)
Construct a GUIAttributes map, given a map of the defaults, a map describing synonymies of the attributes, and the Widget which is to own the map. |
|
GUIAttributes(Map<String,List<String>> defaults,
Map<String,String> synonyms,
Widget widget)
Construct a GUIAttributes map, given a map of the defaults, a map describing synonymies of the attributes, and the Widget which is to own the map. |
|
GUIAttributes(Map<String,List<String>> defaults,
Widget widget)
Construct a GUIAttributes map, given a map of the defaults and the Widget which is to own it. |
|
| Method Summary | ||
|---|---|---|
List<String> |
get(Object attr)
Deprecated. Use getAll(java.lang.String) instead; it typechecks its argument
and throws suitable exceptions on invalid attribute values. Better
yet, use one of getString(java.lang.String), getStrings(java.lang.String),
getInteger(java.lang.String), etc., as needed. This method is only meant to
allow GUIAttributes objects to be cast to Maps and still work
(somewhat). |
|
List<String> |
getAll(String attr)
Retrieve all values of an attribute by name, as strings. |
|
boolean |
getBoolean(String attr)
Retrieve, as a boolean, the value of an attribute which only allows one value. |
|
List<Boolean> |
getBooleans(String attr)
Retrieve all values of an attribute as booleans. |
|
String |
getColor(String attr)
Retrieve, as a color identifier, the value of an attribute which only allows one value. |
|
List<String> |
getColors(String attr)
Retrieve all values of a color attribute as identifier strings suitable for use in generated code. |
|
double |
getDouble(String attr)
Retrieve, as a double, the value of an attribute which only allows one value. |
|
List<Double> |
getDoubles(String attr)
Retrieve all values of an attribute as doubles. |
|
|
getEnum(String attr,
Class<E> cls)
Retrieve, as an enumeration constant, the value of an attribute which only allows one value. |
|
|
getEnums(String attr,
Class<E> cls)
Retrieve all values of an attribute as enumeration constants. |
|
float |
getFloat(String attr)
Retrieve, as a double, the value of an attribute which only allows one value. |
|
List<Float> |
getFloats(String attr)
Retrieve all values of an attribute as doubles. |
|
int |
getInteger(String attr)
Retrieve, as an integer, the value of an attribute which only allows one value. |
|
Pair<Integer,Integer> |
getIntegerPair(String attr)
Retrieve, as a pair of integers, the value of an attribute which only allows exactly two values. |
|
List<Integer> |
getIntegers(String attr)
Retrieve all values of an attribute as integers. |
|
List<String> |
getMany(String attr,
int quantity)
Retrieve all values of an attribute which allows exactly N values, for some N. |
|
String |
getOne(String attr)
Retrieve the value of an attribute which only allows one value. |
|
String |
getString(String attr)
Retrieve, as a string, the value of an attribute which only allows one value. |
|
List<String> |
getStrings(String attr)
Retrieve all values of an attribute as strings. |
|
boolean |
hasValue(String attr)
Test to see if an attribute has a value (i.e. |
|
boolean |
parseBoolean(String attr,
String value)
Parse a string as a boolean attribute value, as getBoolean(java.lang.String) would. |
|
String |
parseColor(String attr,
String value)
Parse a string as a color value, as getColor(java.lang.String) would. |
|
double |
parseDouble(String attr,
String value)
Parse a string as a double attribute value, as getDouble(java.lang.String) would. |
|
|
parseEnum(String attr,
String value,
Class<E> cls)
Parse a string as an enumeration constaint, as getEnum(java.lang.String, java.lang.Class would. |
|
float |
parseFloat(String attr,
String value)
Parse a string as a float attribute value, as getFloat(java.lang.String) would. |
|
int |
parseInteger(String attr,
String value)
Parse a string as an integer attribute value, as getInteger(java.lang.String)
would. |
|
List<String> |
put(String attr,
List<String> values)
Deprecated. Use putAttribute(String, String[]) when possible,
as it throws the proper checked exception,
BadAttributeNameException, on error. This method is only
provided for compatibility with the base class. |
|
void |
putAllAttributes(Map<String,? extends List<String>> attrs)
|
|
List<String> |
putAttribute(String attr,
List<String> values)
Add an attribute, with arbitrarily many values, to this map. |
|
List<String> |
putAttribute(String attr,
String... values)
Add an attribute, with arbitrarily many values, to this map. |
|
| Methods inherited from class java.util.TreeMap |
|---|
clear, clone, comparator, containsKey, containsValue, entrySet, firstKey, headMap, keySet, lastKey, putAll, remove, size, subMap, tailMap, values |
| Methods inherited from class java.util.AbstractMap |
|---|
equals, hashCode, isEmpty, toString |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Map |
|---|
equals, hashCode, isEmpty |
| Field Detail |
|---|
public final Map<String,List<String>> defaults
public final Map<String,String> synonyms
public final Map<String,List<String>> multisynonyms
public final Widget widget
Widget to which this object belongs.
public static final Map<String,Boolean> boolStrings
public static final SortedSet<String> colors
colorEquivs are accepted as well). Case-insensitive.
public static final Map<String,String> colorEquivs
public static final Pattern htmlColorPat
| Constructor Detail |
|---|
public GUIAttributes(Map<String,List<String>> defaults,
Map<String,String> synonyms,
Map<String,List<String>> multisynonyms,
Widget widget)
defaults - A map of the names of the recognized attributes to their
default values.synonyms - A map, each entry of which has an attribute name as the
key and the real attribute with which it is synonymous as the
value.multisynonyms - A map, each entry of which has an attribute name as
the key and the list of real attributes which it maps to as the
value. For instance, if giving the "size" attribute a value of
two integers is equivalent to giving the "width" and "height"
attributes separately, the map would have an entry with key
"size" and values "width" and "height".widget - The Widget to which this object belongs.
public GUIAttributes(Map<String,List<String>> defaults,
Map<String,String> synonyms,
Widget widget)
defaults - A map of the names of the recognized attributes to their
default values.synonyms - A map, each entry of which has an attribute name as the
key and the real attribute with which it is synonymous as the
value.widget - The Widget to which this object belongs.
public GUIAttributes(Map<String,List<String>> defaults,
Widget widget)
GUIAttributes(Map, Map, Widget) for this).
defaults - A map of the names of the recognized attributes to their
default values.widget - The Widget to which this object belongs.| Method Detail |
|---|
public void putAllAttributes(Map<String,? extends List<String>> attrs)
throws BadAttributeException
attrs - A map of attributes, each of which will be added.
BadAttributeNameException - If any of the given attribute names
are not valid for this widget.
BadAttributeValueException - If a multisynonymous attribute (see
WidgetDef.getMultisynonymousAttributes() has the wrong
number of values.
BadAttributeException
public List<String> putAttribute(String attr,
String... values)
throws BadAttributeException
attr - The name of the attribute.values - Zero or more values for the attribute.
null if it was
at its default setting.
BadAttributeNameException - If the attribute name is not
recognized (see defaults).
BadAttributeValueException - If the attribute is a multisynonym
(see WidgetDef.getMultisynonymousAttributes()) with the
wrong number of values.
BadAttributeException
public List<String> putAttribute(String attr,
List<String> values)
throws BadAttributeException
attr - The name of the attribute.values - A list of values for the attribute.
null if it was
at its default value.
BadAttributeNameException - If the attribute name is not
recognized (see defaults).
BadAttributeException
@Deprecated
public List<String> put(String attr,
List<String> values)
putAttribute(String, String[]) when possible,
as it throws the proper checked exception,
BadAttributeNameException, on error. This method is only
provided for compatibility with the base class.
put in interface Map<String,List<String>>put in class TreeMap<String,List<String>>attr - The name of the attribute.values - A list of its values.
null if it was
at its default setting.
IllegalArgumentException - If the attribute name is not
recognized (see defaults).@Deprecated public List<String> get(Object attr)
getAll(java.lang.String) instead; it typechecks its argument
and throws suitable exceptions on invalid attribute values. Better
yet, use one of getString(java.lang.String), getStrings(java.lang.String),
getInteger(java.lang.String), etc., as needed. This method is only meant to
allow GUIAttributes objects to be cast to Maps and still work
(somewhat).
get in interface Map<String,List<String>>get in class TreeMap<String,List<String>>attr - The name of the attribute.
null if there is
no such attribute.
public List<String> getAll(String attr)
throws BadAttributeException
attr - The name of the attribute.
BadAttributeNameException - If there is no such attribute.
BadAttributeException
public List<String> getMany(String attr,
int quantity)
throws BadAttributeException
attr - The name of the atttribute.quantity - The number of values to require.
BadAttributeNameException - If there is no such attribute.
BadAttributeValueException - If the attribute has more or fewer
values than quantity.
BadAttributeException
public String getOne(String attr)
throws BadAttributeException
attr - The name of the atttribute.
BadAttributeNameException - If there is no such attribute.
BadAttributeValueException - If the attribute has more than one
value.
BadAttributeException
public List<String> getStrings(String attr)
throws BadAttributeException
attr - The name of the attribute.
BadAttributeNameException - If there is no such attribute.
BadAttributeException
public String getString(String attr)
throws BadAttributeException
attr - The name of the attribute.
BadAttributeNameException - If there is no such attribute.
BadAttributeValueException - If the attribute has more than one
value.
BadAttributeException
public List<Integer> getIntegers(String attr)
throws BadAttributeException
attr - The name of the attribute.
BadAttributeNameException - If there is no such attribute.
BadAttributeValueException - If any attribute value fails to
parse as an integer.
BadAttributeException
public int getInteger(String attr)
throws BadAttributeException
attr - The name of the attribute.
BadAttributeNameException - If there is no such attribute.
BadAttributeValueException - If the value fails to parse as an
integer, or the attribute has more than one value.
BadAttributeException
public Pair<Integer,Integer> getIntegerPair(String attr)
throws BadAttributeException
attr - The name of the attribute.
BadAttributeNameException - If there is no such attribute.
BadAttributeValueException - If the value fails to parse as an
integer, or the attribute has more than one value.
BadAttributeException
public int parseInteger(String attr,
String value)
throws BadAttributeValueException
getInteger(java.lang.String)
would.
attr - The name of the attribute, passed to the exception if one is
thrown.value - The value to parse.
BadAttributeValueException - If the value fails to parse as an
integer.
public List<Float> getFloats(String attr)
throws BadAttributeException
attr - The name of the attribute.
BadAttributeNameException - If there is no such attribute.
BadAttributeValueException - If any attribute value fails to
parse as a double.
BadAttributeException
public float getFloat(String attr)
throws BadAttributeException
attr - The name of the attribute.
BadAttributeNameException - If there is no such attribute.
BadAttributeValueException - If the value fails to parse as a
double, or the attribute has more than one value.
BadAttributeException
public float parseFloat(String attr,
String value)
throws BadAttributeValueException
getFloat(java.lang.String) would.
attr - The name of the attribute, passed to the exception if one is
thrown.value - The value to parse.
BadAttributeValueException - If the value fails to parse as a
float.
public List<Double> getDoubles(String attr)
throws BadAttributeException
attr - The name of the attribute.
BadAttributeNameException - If there is no such attribute.
BadAttributeValueException - If any attribute value fails to
parse as a double.
BadAttributeException
public double getDouble(String attr)
throws BadAttributeException
attr - The name of the attribute.
BadAttributeNameException - If there is no such attribute.
BadAttributeValueException - If the value fails to parse as a
double, or the attribute has more than one value.
BadAttributeException
public double parseDouble(String attr,
String value)
throws BadAttributeValueException
getDouble(java.lang.String) would.
attr - The name of the attribute, passed to the exception if one is
thrown.value - The value to parse.
BadAttributeValueException - If the value fails to parse as a
double.
public <E extends Enum> List<E> getEnums(String attr,
Class<E> cls)
throws BadAttributeException
E - The enumeration class.attr - The name of the attribute.cls - The enumeration class.
BadAttributeNameException - If there is no such attribute.
BadAttributeValueException - If any attribute value fails to
parse as a double.
BadAttributeException
public <E extends Enum> E getEnum(String attr,
Class<E> cls)
throws BadAttributeException
E - The enumeration class.attr - The name of the attribute.cls - The enumeration class.
BadAttributeNameException - If there is no such attribute.
BadAttributeValueException - If the value fails to parse as an
integer, or the attribute has more than one value.
BadAttributeException
public <E extends Enum> E parseEnum(String attr,
String value,
Class<E> cls)
throws BadAttributeValueException
getEnum(java.lang.String, java.lang.Class) would.
E - The enumeration class.attr - The name of the attribute, passed to the exception if one is
thrown.value - The value to parse.cls - The enumeration class.
<E>.
BadAttributeValueException - If the value fails to parse as a
constant of the given enumeration.
public List<Boolean> getBooleans(String attr)
throws BadAttributeException
attr - The name of the attribute.
BadAttributeNameException - If there is no such attribute.
BadAttributeException - If any attribute value fails to parse as
a boolean (see getBoolean(java.lang.String)).getBoolean(java.lang.String)
public boolean getBoolean(String attr)
throws BadAttributeException
attr - The name of the attribute.
true for "true", "yes", "1", or "on";
false for "false", "no", "0", or "off". (Case
insensitive.)
BadAttributeNameException - If there is no such attribute.
BadAttributeValueException - If none of the above matches, or
there is more than one value.
BadAttributeException
public boolean parseBoolean(String attr,
String value)
throws BadAttributeValueException
getBoolean(java.lang.String) would.
attr - The name of the attribute, passed to the exception if one is
thrown.value - The value to parse.
BadAttributeValueException - If the value fails to parse as a
boolean.boolStrings
public List<String> getColors(String attr)
throws BadAttributeException
attr - The name of the attribute.
BadAttributeNameException - If there is no such attribute.
BadAttributeValueException - If any attribute value is not
recognized as a color.
BadAttributeException
public String getColor(String attr)
throws BadAttributeException
attr - The name of the attribute.
BadAttributeNameException - If there is no such attribute.
BadAttributeValueException - If the value is not recognized as a
color, or there is more than one value.
BadAttributeException
public String parseColor(String attr,
String value)
throws BadAttributeValueException
getColor(java.lang.String) would.
attr - The name of the attribute, passed to the exception if one is
thrown.value - The value to parse.
BadAttributeValueException - If the value fails to parse as a
color.
public boolean hasValue(String attr)
throws BadAttributeException
null).
attr - The name of the attribute to test.
true if the attribute is not equal to null.
BadAttributeException - If there is no such attribute.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||