JHotDraw 7.0.9

org.jhotdraw.draw
Class AttributeKey<T>

java.lang.Object
  extended by org.jhotdraw.draw.AttributeKey<T>

public class AttributeKey<T>
extends java.lang.Object

An AttributeKey has a name, a type and a default value. The default value is returned by Figure.getAttribute, if a Figure does not have an attribute of the specified key.

An AttributeKey provides typesafe getter and setter for a Figure attribute. The following code example shows how to basicSet and get an attribute on a Figure.

 Figure aFigure;
 AttributeKeys.STROKE_COLOR.basicSet(aFigure, Color.blue);
 

See AttributeKeys for a list of useful attribute keys.

FIXME AttributeKey must not override equals and hashCode from Object.

Version:
2.0 2007-05-12 Removed basicSet methods.
1.2 2007-04-10 Convenience methods for getting and setting a clone of an attribute added.
1.1 2006-12-29 Support for getting/setting attribute keys on a Map added.
1.0.1 2006-07-14 Null values are not returned anymore when null values are not allowed.
1.0 7. Juni 2006 Created.
Author:
Werner Randelshofer

Constructor Summary
AttributeKey(java.lang.String key)
          Creates a new instance.
AttributeKey(java.lang.String key, T defaultValue)
           
AttributeKey(java.lang.String key, T defaultValue, boolean isNullValueAllowed)
           
 
Method Summary
 void basicSet(Figure f, T value)
          Sets a value on the specified figure.
 void basicSetClone(Figure f, T value)
          Sets a clone of a value on the specified figure.
 boolean equals(java.lang.Object o)
           
 T get(Figure f)
           
 T get(java.util.Map<AttributeKey,java.lang.Object> a)
           
 T getClone(Figure f)
          Gets a clone of the value from the Figure.
 T getDefaultValue()
           
 java.lang.String getKey()
           
 int hashCode()
           
 boolean isAssignable(java.lang.Object value)
           
 boolean isNullValueAllowed()
           
 void set(Figure f, T value)
          Convenience method for setting a value on the specified figure and calling willChange before and changed after setting the value.
 void set(java.util.Map<AttributeKey,java.lang.Object> a, T value)
           
 void setClone(Figure f, T value)
          Convenience method for seting a clone of a value on the specified figure and calling willChange before and changed after setting the value.
 void setClone(java.util.Map<AttributeKey,java.lang.Object> a, T value)
          Sets a clone of the value to the Figure without firing events.
 javax.swing.undo.UndoableEdit setUndoable(Figure figure, T value, ResourceBundleUtil labels)
          Sets the attribute and returns an UndoableEditEvent which can be used to undo it.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AttributeKey

public AttributeKey(java.lang.String key)
Creates a new instance.


AttributeKey

public AttributeKey(java.lang.String key,
                    T defaultValue)

AttributeKey

public AttributeKey(java.lang.String key,
                    T defaultValue,
                    boolean isNullValueAllowed)
Method Detail

getKey

public java.lang.String getKey()

getDefaultValue

public T getDefaultValue()

getClone

public T getClone(Figure f)
Gets a clone of the value from the Figure.


get

public T get(Figure f)

get

public T get(java.util.Map<AttributeKey,java.lang.Object> a)

set

public void set(Figure f,
                T value)
Convenience method for setting a value on the specified figure and calling willChange before and changed after setting the value.

Parameters:
f - the Figure
value - the attribute value

basicSet

public void basicSet(Figure f,
                     T value)
Sets a value on the specified figure.

Parameters:
f - the Figure
value - the attribute value

setUndoable

public javax.swing.undo.UndoableEdit setUndoable(Figure figure,
                                                 T value,
                                                 ResourceBundleUtil labels)
Sets the attribute and returns an UndoableEditEvent which can be used to undo it.


setClone

public void setClone(Figure f,
                     T value)
Convenience method for seting a clone of a value on the specified figure and calling willChange before and changed after setting the value.

Parameters:
f - the Figure
value - the attribute value

basicSetClone

public void basicSetClone(Figure f,
                          T value)
Sets a clone of a value on the specified figure.

Parameters:
f - the Figure
value - the attribute value

set

public void set(java.util.Map<AttributeKey,java.lang.Object> a,
                T value)

setClone

public void setClone(java.util.Map<AttributeKey,java.lang.Object> a,
                     T value)
Sets a clone of the value to the Figure without firing events.


equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

isNullValueAllowed

public boolean isNullValueAllowed()

isAssignable

public boolean isAssignable(java.lang.Object value)

Copyright 1996-2007 (c) JHotDraw.org.
Some rights reserved.