com.brunchboy.util.swing.relativelayout
Class AxisConstraint

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

public class AxisConstraint
extends Object
implements Constraint

A Constraint that represents a fractional position along an axis of another component. In other words, for a vertical attribute, it can range from the top of the component (0.0) to the bottom (1.0). For horizontal attributes, the range spans from the left to the right edges. It is possible to use values outside this range, to represent points outside the anchor component, but there aren't yet any envisioned uses for such constraints.

This is an immutable class, and so it can be freely copied and shared in a multithreaded environment.

Version:
$Id: AxisConstraint.java,v 1.1.1.1 2002/05/13 20:51:44 jim Exp $
Author:
James Elliott, jim@brunchboy.com

Field Summary
protected  String anchorName
          Tracks the component relative to which this constraint will be computed.
static String VERSION
          Provides access to the CVS version of this class.
 
Constructor Summary
AxisConstraint(String anchorName, AttributeAxis axis, double position)
          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

anchorName

protected final String anchorName
Tracks the component relative to which this constraint will be computed.

Constructor Detail

AxisConstraint

public AxisConstraint(String anchorName,
                      AttributeAxis axis,
                      double position)
Constructor sets the immutable fields.

Parameters:
anchorName - the component relative to which this constraint is computed.
axis - the axis along which we'll compute a fractional position.
position - the fraction to be used to position ourselves within the anchor component.
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.