com.brunchboy.util.swing.relativelayout
Class AttributeConstraint

java.lang.Object
  |
  +--com.brunchboy.util.swing.relativelayout.AttributeConstraint
All Implemented Interfaces:
Constraint

public class AttributeConstraint
extends Object
implements Constraint

A Constraint that represents a fixed offset from an attribute of another component (or list of components). In the case of a list, the attribute is treated as coming from the bounding box of all components in the list. This is an immutable class, and so it can be freely copied and shared in a multithreaded environment.

Version:
$Id: AttributeConstraint.java,v 1.2 2002/08/16 03:08:18 jim Exp $
Author:
James Elliott, jim@brunchboy.com

Field Summary
protected  String anchorList
          Tracks the comma-delimited list of components relative to which this constraint will be computed.
static String VERSION
          Provides access to the CVS version of this class.
 
Constructor Summary
AttributeConstraint(String anchorList, AttributeType attribute)
          Simplified constructor usable when offset is zero.
AttributeConstraint(String anchorList, AttributeType attribute, int offset)
          Constructor sets the immutable fields.
 
Method Summary
 List getDependencies()
          Return the attributes on which this constraint depends.
 int getValue(AttributeSource attributes)
          Compute the value of the constraint, given the specifications on on which it is based.
 String toString()
          Provide a textual representation of the constraint 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

anchorList

protected final String anchorList
Tracks the comma-delimited list of components relative to which this constraint will be computed.

Constructor Detail

AttributeConstraint

public AttributeConstraint(String anchorList,
                           AttributeType attribute,
                           int offset)
Constructor sets the immutable fields.

Parameters:
anchorList - a comma-delimited list of the names the component(s) relative to which this constraint is computed.
attribute - the attribute of the anchor component(s) which is the source of this constraint's value. When multiple components are combined, the attribute is treated as coming from their bounding box.
offset - the offset, in pixels, to be added to the anchor attribute value to compute this constraint's value.

AttributeConstraint

public AttributeConstraint(String anchorList,
                           AttributeType attribute)
Simplified constructor usable when offset is zero.

Parameters:
anchorList - a comma-delimited list of the names the component(s) relative to which this constraint is computed.
attribute - the attribute of the anchor component(s) which is the source of this constraint's value. When multiple components are combined, the attribute is treated as coming from their bounding box.
Method Detail

getDependencies

public List getDependencies()
Return the attributes on which this constraint depends.

Specified by:
getDependencies in interface Constraint
Returns:
a list of Attributes which must be resolved before this constraint can be evaluated.

getValue

public int getValue(AttributeSource attributes)
Compute the value of the constraint, given the specifications on on which it is based. Any dependencies must have been resolved prior to calling this method, or the method will fail.

Specified by:
getValue in interface Constraint
Parameters:
attributes - provides read access to all existing component attributes, for use in evaluating this constraint..
Returns:
the value represented by this constraint, assuming any attributes of the anchor component on which it depends have been resolved already.
Throws:
IllegalStateException - if any dependencies are not yet resolved.

toString

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

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