Class AttributeKey<T>
- java.lang.Object
-
- org.jhotdraw.draw.AttributeKey<T>
-
- All Implemented Interfaces:
- java.io.Serializable
public class AttributeKey<T> extends java.lang.Object implements java.io.SerializableAn attribute key provides typesafe access to an attribute of aFigure.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
AttributeKeysfor a list of useful attribute keys.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleanequals(java.lang.Object that)Tget(Figure f)Gets the value of the attribute denoted by this AttributeKey from a Figure.Tget(java.util.Map<AttributeKey,java.lang.Object> a)Gets the value of the attribute denoted by this AttributeKey from a Map.TgetClone(Figure f)Gets a clone of the value from the Figure.TgetDefaultValue()Returns the default value of the attribute.java.lang.StringgetKey()Returns the key string.java.lang.StringgetPresentationName()Returns a localized human friendly presentation of the key.inthashCode()booleanisAssignable(java.lang.Object value)Returns true if the specified value is assignable with this key.booleanisNullValueAllowed()Returns true if null values are allowed.Tput(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.voidputClone(java.util.Map<AttributeKey,java.lang.Object> a, T value)Convenience method for putting a clone of a value on a map.voidset(Figure f, T value)Convenience method for setting a value on a Figure.voidsetClone(Figure f, T value)Convenience method for setting a clone of a value on a figure.javax.swing.undo.UndoableEditsetUndoable(Figure f, T value)Sets the attribute and returns an UndoableEditEvent which can be used to undo it.java.lang.StringtoString()Returns the key string.
-
-
-
Constructor Detail
-
AttributeKey
public 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
public AttributeKey(java.lang.String key, java.lang.Class<T> clazz, @Nullable T defaultValue)Creates a new instance with the specified attribute key, type token class, and default value, and allowing null values.
-
AttributeKey
public AttributeKey(java.lang.String key, java.lang.Class<T> clazz, @Nullable 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
public AttributeKey(java.lang.String key, java.lang.Class<T> clazz, @Nullable T defaultValue, boolean isNullValueAllowed, @Nullable ResourceBundleUtil labels)Creates a new instance with the specified attribute key, type token class, default value, and allowing or disallowing null values.- Parameters:
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
-
getKey
public java.lang.String getKey()
Returns the key string.- Returns:
- key string.
-
getPresentationName
public java.lang.String getPresentationName()
Returns a localized human friendly presentation of the key.- Returns:
- the presentation name of the key.
-
getDefaultValue
@Nullable public T getDefaultValue()
Returns the default value of the attribute.- Returns:
- the default value.
-
get
@Nullable public T get(Figure f)
Gets the value of the attribute denoted by this AttributeKey from a Figure.- Parameters:
f- A figure.- Returns:
- The value of the attribute.
-
get
@Nullable public T get(java.util.Map<AttributeKey,java.lang.Object> a)
Gets the value of the attribute denoted by this AttributeKey from a Map.- Parameters:
a- A Map.- Returns:
- The value of the attribute.
-
set
public void set(Figure f, @Nullable T value)
Convenience method for setting a value on a Figure.Note: Unlike in previous versions of JHotDraw 7, this method does not call
f.willChange()before setting the value, andf.changed()afterwards.- Parameters:
f- the Figurevalue- the attribute value
-
setUndoable
public javax.swing.undo.UndoableEdit setUndoable(Figure f, @Nullable T value)
Sets the attribute and returns an UndoableEditEvent which can be used to undo it.Note: Unlike in previous versions of JHotDraw 7, this method does not call
f.willChange()before setting the value, andf.changed()afterwards.
-
setClone
public void setClone(Figure f, @Nullable T value)
Convenience method for setting a clone of a value on a figure.Note: Unlike in previous versions of JHotDraw 7, this method does not call
f.willChange()before setting the value, andf.changed()afterwards.- Parameters:
f- the Figurevalue- the attribute value
-
putClone
public void putClone(java.util.Map<AttributeKey,java.lang.Object> a, @Nullable T value)
Convenience method for putting a clone of a value on a map.- Parameters:
a- the mapvalue- the attribute value
-
put
@Nullable public T put(java.util.Map<AttributeKey,java.lang.Object> a, @Nullable T value)
Use this method to perform a type-safe put operation of an attribute into a Map.- Parameters:
a- An attribute map.value- The new value.- Returns:
- The old value.
-
isNullValueAllowed
public boolean isNullValueAllowed()
Returns true if null values are allowed.- Returns:
- true if null values are allowed.
-
isAssignable
public boolean isAssignable(@Nullable java.lang.Object value)
Returns true if the specified value is assignable with this key.- Parameters:
value-- Returns:
- True if assignable.
-
toString
public java.lang.String toString()
Returns the key string.- Overrides:
toStringin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object that)
- Overrides:
equalsin classjava.lang.Object
-
-
DataMelt 3.0 © DataMelt by jWork.ORG