| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jhotdraw.draw.AttributeKey<T>
public class AttributeKey<T>
An attribute key provides typesafe access to an attribute of
 a Figure.
 
An AttributeKey has a name, a type and a default value. The default value is returned by Figure.get, if a Figure does not have an attribute of the specified key.
The following code example shows how to basicSet and get an attribute on a Figure.
Figure aFigure; AttributeKeys.STROKE_COLOR.put(aFigure, Color.blue);
 See AttributeKeys for a list of useful attribute keys.
| Field Summary | |
|---|---|
| private  java.lang.Class<T> | clazzThis variable is used as a "type token" so that we can check for assignability of attribute values at runtime. | 
| private  T | defaultValueHolds the default value. | 
| private  boolean | isNullValueAllowedSpecifies whether null values are allowed. | 
| private  java.lang.String | keyHolds a String representation of the attribute key. | 
| private  ResourceBundleUtil | labelsHolds labels for the localization of the attribute. | 
| Constructor Summary | |
|---|---|
| AttributeKey(java.lang.String key,
             java.lang.Class<T> clazz)Creates a new instance with the specified attribute key, type token class, default value null, and allowing null values. | |
| AttributeKey(java.lang.String key,
             java.lang.Class<T> clazz,
             T defaultValue)Creates a new instance with the specified attribute key, type token class, and default value, and allowing null values. | |
| AttributeKey(java.lang.String key,
             java.lang.Class<T> clazz,
             T defaultValue,
             boolean isNullValueAllowed)Creates a new instance with the specified attribute key, type token class, default value, and allowing or disallowing null values. | |
| AttributeKey(java.lang.String key,
             java.lang.Class<T> clazz,
             T defaultValue,
             boolean isNullValueAllowed,
             ResourceBundleUtil labels)Creates a new instance with the specified attribute key, type token class, default value, and allowing or disallowing null values. | |
| Method Summary | |
|---|---|
|  boolean | equals(java.lang.Object that) | 
|  T | get(Figure f)Gets the value of the attribute denoted by this AttributeKey from a Figure. | 
|  T | get(java.util.Map<AttributeKey,java.lang.Object> a)Gets the value of the attribute denoted by this AttributeKey from a Map. | 
|  T | getClone(Figure f)Gets a clone of the value from the Figure. | 
|  T | getDefaultValue()Returns the default value of the attribute. | 
|  java.lang.String | getKey()Returns the key string. | 
|  java.lang.String | getPresentationName()Returns a localized human friendly presentation of the key. | 
|  int | hashCode() | 
|  boolean | isAssignable(java.lang.Object value)Returns true if the specified value is assignable with this key. | 
|  boolean | isNullValueAllowed()Returns true if null values are allowed. | 
|  T | put(java.util.Map<AttributeKey,java.lang.Object> a,
    T value)Use this method to perform a type-safe put operation of an attribute into a Map. | 
|  void | putClone(java.util.Map<AttributeKey,java.lang.Object> a,
         T value)Convenience method for putting a clone of a value on a map. | 
|  void | set(Figure f,
    T value)Convenience method for setting a value on a Figure. | 
|  void | setClone(Figure f,
         T value)Convenience method for setting a clone of a value on a figure. | 
|  javax.swing.undo.UndoableEdit | setUndoable(Figure f,
            T value)Sets the attribute and returns an UndoableEditEvent which can be used to undo it. | 
|  java.lang.String | toString()Returns the key string. | 
| Methods inherited from class java.lang.Object | 
|---|
| clone, finalize, getClass, notify, notifyAll, wait, wait, wait | 
| Field Detail | 
|---|
private java.lang.String key
private T defaultValue
private boolean isNullValueAllowed
private ResourceBundleUtil labels
private java.lang.Class<T> clazz
| Constructor Detail | 
|---|
public AttributeKey(java.lang.String key,
                    java.lang.Class<T> clazz)
public AttributeKey(java.lang.String key,
                    java.lang.Class<T> clazz,
                    T defaultValue)
public AttributeKey(java.lang.String key,
                    java.lang.Class<T> clazz,
                    T defaultValue,
                    boolean isNullValueAllowed)
public AttributeKey(java.lang.String key,
                    java.lang.Class<T> clazz,
                    T defaultValue,
                    boolean isNullValueAllowed,
                    ResourceBundleUtil labels)
key - The key string.clazz - This is used as a "type token" for assignability checks
 at runtime.isNullValueAllowed - whether null values are allowed.labels - ResourceBundle for human friendly representation of this
 attribute key. The ResourceBundle must have a property named
 "attribute." + key + ".text".| Method Detail | 
|---|
public java.lang.String getKey()
public java.lang.String getPresentationName()
public T getDefaultValue()
public T getClone(Figure f)
public T get(Figure f)
f - A figure.
public T get(java.util.Map<AttributeKey,java.lang.Object> a)
a - A Map.
public void set(Figure f,
                T value)
 Note: Unlike in previous versions of JHotDraw 7, this method does
 not call f.willChange() before setting the value, and
 f.changed() afterwards.
f - the Figurevalue - the attribute value
public javax.swing.undo.UndoableEdit setUndoable(Figure f,
                                                 T value)
 Note: Unlike in previous versions of JHotDraw 7, this method does
 not call f.willChange() before setting the value, and
 f.changed() afterwards.
public void setClone(Figure f,
                     T value)
 Note: Unlike in previous versions of JHotDraw 7, this method does
 not call f.willChange() before setting the value, and
 f.changed() afterwards.
f - the Figurevalue - the attribute value
public void putClone(java.util.Map<AttributeKey,java.lang.Object> a,
                     T value)
a - the mapvalue - the attribute value
public T put(java.util.Map<AttributeKey,java.lang.Object> a,
             T value)
a - An attribute map.value - The new value.
public boolean isNullValueAllowed()
public boolean isAssignable(java.lang.Object value)
value - 
public java.lang.String toString()
toString in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object that)
equals in class java.lang.Object| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||