com.brunchboy.util.swing.relativelayout
Class ComponentSpecifications

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

public class ComponentSpecifications
extends Object

Keeps track of the specifications that have been provided for a particular component, and is able to determine how to derive the rest from these constraints.

Version:
$Id: ComponentSpecifications.java,v 1.2 2002/05/20 23:17:13 jim Exp $
Author:
James Elliott, jim@brunchboy.com

Field Summary
static String VERSION
          Provides access to the CVS version of this class.
 
Constructor Summary
ComponentSpecifications(String componentName)
          Create a new set of specifications for the named component.
ComponentSpecifications(String componentName, Component component)
          Create a new set of specifications for the supplied component.
 
Method Summary
 void addConstraint(AttributeType type, Constraint constraint)
          Add a constraint for this component.
 void clearAttributeValues()
          Clear out any existing attribute values in preparation for a new layout operation.
 void computeAttribute(AttributeType attribute, AttributeSource allAttrs, boolean minimumSize, int parentWidth, int parentHeight)
          Compute the specified attribute, either from a supplied constraint, or by deriving it from other attributes of this component if it was not constrained.
 int getAttributeValue(AttributeType type)
          Return an attribute value, assuming it has been resolved.
 Component getComponent()
          Return the component being controlled by these specifications.
 int getComponentHeight(boolean minimumSize)
          Look up the natural height of the component being managed, if there is one.
 String getComponentName()
          Return the logical name of the component to which these specifications apply.
 int getComponentWidth(boolean minimumSize)
          Look up the natural width of the component being managed, if there is one.
 boolean hasConstraint(AttributeType type)
          Tests whether the specified attribute value has been defined explicitly (i.e. not through derivation).
 void layoutComponent(int xOffset, int yOffset)
          Sets the bounds of the component being managed by these specifications.
 void reportDependencies(DependencyManager dependencies)
          Called the first time layout is being performed after components or constraints have been changed, to build up the master list of dependencies to be sorted.
 void setAttributeValue(AttributeType type, int value)
          Set an attribute value, which should not yet exist.
 void setComponent(Component component)
          Set the component being controlled by these specifications, once we learn about it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, 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
Constructor Detail

ComponentSpecifications

public ComponentSpecifications(String componentName)
Create a new set of specifications for the named component. We don't currently have an actual AWT Component associated with the constraints; that will be set later.

Parameters:
componentName - the logical name by which the RelativeLayout knows the component.

ComponentSpecifications

public ComponentSpecifications(String componentName,
                               Component component)
Create a new set of specifications for the supplied component.

Parameters:
componentName - the logical name by which the RelativeLayout knows the component.
component - the graphical component that will be controlled by these specifications.
Method Detail

getComponentName

public String getComponentName()
Return the logical name of the component to which these specifications apply.

Returns:
name by which component is known to the RelativeLayout.

setComponent

public void setComponent(Component component)
Set the component being controlled by these specifications, once we learn about it.

Parameters:
component - the component to constrain.
Throws:
IllegalStateException - if the component has already been set.

getComponent

public Component getComponent()
Return the component being controlled by these specifications.

Returns:
the component being constrained, or null if we don't yet have one.

getAttributeValue

public int getAttributeValue(AttributeType type)
Return an attribute value, assuming it has been resolved.

Parameters:
type - the type of attribute desired.
Returns:
the computed value of that attribute.
Throws:
IllegalStateException - if this method is called before the specified attribute has been resolved.

hasConstraint

public boolean hasConstraint(AttributeType type)
Tests whether the specified attribute value has been defined explicitly (i.e. not through derivation).

Parameters:
type - the type of attribute desired.
Returns:
true iff the attribute has been given a constraint.

getComponentWidth

public int getComponentWidth(boolean minimumSize)
Look up the natural width of the component being managed, if there is one.

Parameters:
minimumSize - indicates whether we should ask the component for its minimum size rather than its preferred size.
Returns:
the reported width if there is a component, or 0.

getComponentHeight

public int getComponentHeight(boolean minimumSize)
Look up the natural height of the component being managed, if there is one.

Parameters:
minimumSize - indicates whether we should ask the component for its minimum size rather than its preferred size.
Returns:
the reported height if there is a component, or 0.

setAttributeValue

public void setAttributeValue(AttributeType type,
                              int value)
Set an attribute value, which should not yet exist.

Parameters:
type - the type of attribute desired.
value - the desired value of that attribute.
Throws:
IllegalStateException - if this method is called to set an attribute whose value has already been resolved.

clearAttributeValues

public void clearAttributeValues()
Clear out any existing attribute values in preparation for a new layout operation.


addConstraint

public void addConstraint(AttributeType type,
                          Constraint constraint)
Add a constraint for this component.

Parameters:
type - the attribute which is to be constrained.
constraint - the place from which the attribute's value can be calculated.
Throws:
IllegalStateException - if this would cause the component to become overconstrained.
NullPointerException - if any argument is null.

reportDependencies

public void reportDependencies(DependencyManager dependencies)
Called the first time layout is being performed after components or constraints have been changed, to build up the master list of dependencies to be sorted. Reports both the explicit constraints that have been registered for this component, and the dependencies needed to compute the derived attributes.

Parameters:
dependencies - the dependency analyzer to which dependencies need to be reported.
Throws:
IllegalStateException - if this leads to a bad dependency graph.

computeAttribute

public void computeAttribute(AttributeType attribute,
                             AttributeSource allAttrs,
                             boolean minimumSize,
                             int parentWidth,
                             int parentHeight)
Compute the specified attribute, either from a supplied constraint, or by deriving it from other attributes of this component if it was not constrained. Any attributes on which we depend must have been computed prior to calling this.

Parameters:
attribute - the type of attribute that should now be computed.
allAttrs - provides read access to all existing component attributes, for use in evaluating constraints
minimumSize - if true the minimum sizes of components should be used in order to compute a minimum size for the overall layout. If false, the preferred sizes are used.
parentWidth - the width of the parent container, in case we have any container-based constraints.
parentHeight - the height of the parent container, in case we have any container-based constraints.
Throws:
IllegalStateException - if called before a required attribute has been computed, or if the component is underconstrained.

layoutComponent

public void layoutComponent(int xOffset,
                            int yOffset)
Sets the bounds of the component being managed by these specifications. Called when the container is laid out. All attributes must be computed before calling this method.

Parameters:
xOffset - offset to be added to horizontal coordinates (for example to account for container insets).
yOffset - offset to be added to vertical coordinates (for example to account for container insets).
Throws:
IllegalStateException - if any required attributes have not been computed.