org.writersforge.catalan.layout
Class Constraint

java.lang.Object
  extended byorg.writersforge.catalan.layout.Constraint

public class Constraint
extends java.lang.Object

Geometrical constraints for a single LayoutArea object. Describes size and relationships with other areas. The allowable size is defined by the preferred, smallest, and largest properties. With these properties, it's possible to declare an optimal size, but also allow for flexibility. The atomic property declares whether or not the area can be split into smaller sub-areas, for example to flow text from one page to the next. By default, atomic is false, meaning the area cannot be split.

Alignment and positioning are defined by the Relation class, which encapsulates single relationships between two areas, such as edge attraction and distance apart.

Author:
jsheets

Constructor Summary
Constraint()
          Creates a new instance of Constraint.
Constraint(java.awt.Dimension preferred)
          Creates a new instance of Constraint.
Constraint(java.awt.Dimension preferred, boolean atomic)
          Creates a new instance of Constraint.
Constraint(java.awt.Dimension preferred, java.awt.Dimension smallest, java.awt.Dimension largest, boolean atomic)
          Creates a new instance of Constraint.
 
Method Summary
 void addRelations(Relation relations)
          Appends a new Relation object into the Constraint.
 Relation findRelation(java.lang.Class relationClass)
          Searches this Constraint for a Relation object of the given class.
 Relation findRelation(java.lang.Class relationClass, int occurance)
          Searches this Constraint for a Relation object of the given class.
 java.awt.Dimension getLargest()
          Getter for property largest, the maximum size an area can be.
 java.awt.Dimension getPreferred()
          Getter for property preferred, the optimal size an area can be.
 Relation[] getRelations()
          Getter for property relations.
 Relation getRelations(int index)
          Indexed getter for property relations.
 java.awt.Dimension getSmallest()
          Getter for property smallest, the minimum size an area can be.
 boolean isAtomic()
          Getter for property atomic, whether the area can be split or not.
 void setAtomic(boolean atomic)
          Setter for property atomic, whether the area can be split or not.
static void setDefaultSize(java.awt.Dimension size)
          Sets the default size for the preferred property.
 void setRelations(int index, Relation relations)
          Indexed setter for property relations.
 void setRelations(Relation[] relations)
          Setter for property relations.
 java.lang.String toString()
          Creates a String representation of this Constraint
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Constraint

public Constraint()
Creates a new instance of Constraint. Any unspecified size parameters are unbounded. The area is assumed to be atomic, i.e., it cannot be split across pages.


Constraint

public Constraint(java.awt.Dimension preferred)
Creates a new instance of Constraint. Any unspecified size parameters are unbounded. The area is assumed to be atomic, i.e., it cannot be split across pages.

Parameters:
preferred - the best size for this area

Constraint

public Constraint(java.awt.Dimension preferred,
                  boolean atomic)
Creates a new instance of Constraint. Any unspecified size parameters are unbounded.

Parameters:
preferred - the best size for this area
atomic - true if this area cannot be split across pages

Constraint

public Constraint(java.awt.Dimension preferred,
                  java.awt.Dimension smallest,
                  java.awt.Dimension largest,
                  boolean atomic)
Creates a new instance of Constraint. The preferred parameter must be specified, but the smallest and largest parameters may be null if the minimum or maximum size, respectively, are unbounded.

Parameters:
preferred - the best size for this area
smallest - the smallest possible size for this area
largest - the largest possible size for this area
atomic - true if this area cannot be split across pages
Method Detail

setDefaultSize

public static void setDefaultSize(java.awt.Dimension size)
Sets the default size for the preferred property. This default will be used for all Constraint objects created with a null preferred parameter. If this is not called, the default size is 100 by 100.

Parameters:
size - the new default preferred value

getPreferred

public java.awt.Dimension getPreferred()
Getter for property preferred, the optimal size an area can be. Returns a copy of the extents, not the original.

Returns:
Value of property preferred.

getSmallest

public java.awt.Dimension getSmallest()
Getter for property smallest, the minimum size an area can be. Returns a copy of the extents, not the original.

Returns:
Value of property smallest.

getLargest

public java.awt.Dimension getLargest()
Getter for property largest, the maximum size an area can be. Returns a copy of the extents, not the original.

Returns:
Value of property largest.

setAtomic

public void setAtomic(boolean atomic)
Setter for property atomic, whether the area can be split or not.

Parameters:
atomic - New value of property atomic.

isAtomic

public boolean isAtomic()
Getter for property atomic, whether the area can be split or not.

Returns:
Value of property atomic.

getRelations

public Relation getRelations(int index)
Indexed getter for property relations.

Parameters:
index - Index of the property.
Returns:
Value of the property at index.

getRelations

public Relation[] getRelations()
Getter for property relations.

Returns:
Value of property relations.

setRelations

public void setRelations(int index,
                         Relation relations)
Indexed setter for property relations.

Parameters:
index - Index of the property.
relations - New value of the property at index.

setRelations

public void setRelations(Relation[] relations)
Setter for property relations.

Parameters:
relations - New value of property relations.

addRelations

public void addRelations(Relation relations)
Appends a new Relation object into the Constraint.

Parameters:
relations - new Relation object to append

findRelation

public Relation findRelation(java.lang.Class relationClass)
Searches this Constraint for a Relation object of the given class. Returns null if not found.

Parameters:
relationClass - class of the Relation to look for
Returns:
a Relation of the given class, or null if no match

findRelation

public Relation findRelation(java.lang.Class relationClass,
                             int occurance)
Searches this Constraint for a Relation object of the given class. Ignores the first (occurance - 1) matches. Returns null if not found, or if the total number of matches is less than occurance.

Parameters:
relationClass - class of the Relation to look for
occurance - how many matches to look for
Returns:
a Relation of the given class, or null if no match

toString

public java.lang.String toString()
Creates a String representation of this Constraint

Returns:
a String representation of this object