com.brunchboy.util.swing.relativelayout
Class AttributeType

java.lang.Object
  |
  +--com.brunchboy.util.swing.relativelayout.AttributeType

public abstract class AttributeType
extends Object

A typesafe enumeration of the types of attributes that can be associated with components within a RelativeLayout. This class is immutable, and thus may be safely shared without concern for threading behavior.

This is an abstract class; there is a concrete subclass for each defined attribute type. The concrete subclasses know how to derive their own value from other available attributes. This refinement is an illustration of how typesafe enumerations can grow into full-fledged, polymorphic tools.

Version:
$Id: AttributeType.java,v 1.2 2002/08/16 05:13:04 jim Exp $
Author:
James Elliott, jim@brunchboy.com

Field Summary
static AttributeType BOTTOM
          Attribute type representing the bottom edge of a component.
static AttributeType HEIGHT
          Attribute type representing the height of a component.
static AttributeType HORIZONTAL_CENTER
          Attribute type representing the horizontal center of a component.
static AttributeType LEFT
          Attribute type representing the left edge of a component.
static AttributeType RIGHT
          Attribute type representing the right edge of a component.
static AttributeType TOP
          Attribute type representing the top edge of a component.
static String VERSION
          Provides access to the CVS version of this class.
static AttributeType VERTICAL_CENTER
          Attribute type representing the vertical center of a component.
static AttributeType WIDTH
          Attribute type representing the width of a component.
 
Constructor Summary
protected AttributeType(String name, AttributeAxis axis)
          Protected constructor prevents instantiation of this class.
 
Method Summary
abstract  int deriveValue(ComponentSpecifications specs, boolean minimumSize)
          Compute the value of this attribute given other attributes from which it can be derived.
static Set getAllTypes()
          Return the set of all known attribute types.
 AttributeAxis getAxis()
          Return the axis on which this attribute type is defined.
static Set getAxisTypes(AttributeAxis axis)
          Return the set of attribute types associated with an axis.
static AttributeType getInstance(String name)
          Static factory that looks up an attribute type by name.
 String getName()
          Return name of this attribute type.
 String toString()
          Provide a textual representation of the attribute type for debugging purposes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VERSION

public static final String VERSION
Provides access to the CVS version of this class.

See Also:
Constant Field Values

LEFT

public static final AttributeType LEFT
Attribute type representing the left edge of a component.


RIGHT

public static final AttributeType RIGHT
Attribute type representing the right edge of a component.


HORIZONTAL_CENTER

public static final AttributeType HORIZONTAL_CENTER
Attribute type representing the horizontal center of a component.


WIDTH

public static final AttributeType WIDTH
Attribute type representing the width of a component.


TOP

public static final AttributeType TOP
Attribute type representing the top edge of a component.


BOTTOM

public static final AttributeType BOTTOM
Attribute type representing the bottom edge of a component.


VERTICAL_CENTER

public static final AttributeType VERTICAL_CENTER
Attribute type representing the vertical center of a component.


HEIGHT

public static final AttributeType HEIGHT
Attribute type representing the height of a component.

Constructor Detail

AttributeType

protected AttributeType(String name,
                        AttributeAxis axis)
Protected constructor prevents instantiation of this class. Also builds the sets per-Axis attributes at class-load time.

Parameters:
name - the name of the attribute type to create.
axis - the axis on which this attribute type is defined.
Throws:
NullPointerException - if either parameter is null.
Method Detail

getName

public String getName()
Return name of this attribute type.

Returns:
the name by which this type is known.

getAxis

public AttributeAxis getAxis()
Return the axis on which this attribute type is defined.

Returns:
the axis affected by this attribute type.

getInstance

public static AttributeType getInstance(String name)
Static factory that looks up an attribute type by name.

Parameters:
name - the name of the desired attribute type.
Returns:
the corresponding instance.
Throws:
NoSuchElementException - if the desired instance doesn't exist.

deriveValue

public abstract int deriveValue(ComponentSpecifications specs,
                                boolean minimumSize)
Compute the value of this attribute given other attributes from which it can be derived. Concrete subclasses must implement this method.

Parameters:
specs - source of other attributes for deriving this value.
minimumSize - indicates whether, should we need to query the component itself for sizing information, we should ask for the minimum size as opposed to the preferred size.
Returns:
the derived value, if possible.
Throws:
IllegalStateException - if there are not enough values from which to derive ours.

getAllTypes

public static Set getAllTypes()
Return the set of all known attribute types.

Returns:
the attributes which exist; these are the only instances of this class which will ever exist. Cannot be modified.

getAxisTypes

public static Set getAxisTypes(AttributeAxis axis)
Return the set of attribute types associated with an axis.

Parameters:
axis - the axis of interest.
Returns:
the attribute types which are defined on that axis. May be empty, but will never be null. Cannot be modified.

toString

public String toString()
Provide a textual representation of the attribute type for debugging purposes.

Overrides:
toString in class Object
Returns:
the description of this attribute type.