org.writersforge.catalan.layout
Class AbstractLayoutEngine

java.lang.Object
  |
  +--org.writersforge.catalan.layout.AbstractLayoutEngine
All Implemented Interfaces:
LayoutEngine
Direct Known Subclasses:
AsciiLayout, SimpleFlowLayout

public abstract class AbstractLayoutEngine
extends java.lang.Object
implements LayoutEngine

Author:
jsheets

Constructor Summary
AbstractLayoutEngine()
           
 
Method Summary
 void acceptArea(LayoutArea area)
          Adds the area to the layout queue.
 LayoutArea[] clearQueue()
          Empties out the layout queue.
 boolean fitsInRegion(LayoutArea area)
          Checks to see if the given area will fit anywhere in the current layout region.
 java.awt.Shape getFreeSpace()
          Returns the free space in the current layout region.
 int getQueueSize()
          Returns the number of areas currently in the layout queue.
 java.awt.Dimension guessSize(LayoutArea area)
          Estimates the size that the area "wants" to be.
 java.util.List layoutAreas(java.util.List areas)
          Attempts to lay out all the areas in the supplied List.
 void setCurrentRegion(java.awt.Shape region)
          Assigns a clipping region for the current rendering context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.writersforge.catalan.layout.LayoutEngine
fitsInRegion, layoutRegion
 

Constructor Detail

AbstractLayoutEngine

public AbstractLayoutEngine()
Method Detail

setCurrentRegion

public void setCurrentRegion(java.awt.Shape region)
Assigns a clipping region for the current rendering context. All layout operations will limit themselves to the current region, either clipping or rejecting areas as necessary to make them fit. As areas are accepted to a region, they accumulate in the layout queue, and must be flushed out with clearQueue() before setting a new current region.

Specified by:
setCurrentRegion in interface LayoutEngine
Parameters:
region - the new clipping region
Throws:
java.lang.IllegalStateException - if called with areas in the queue

getQueueSize

public int getQueueSize()
Returns the number of areas currently in the layout queue.

Specified by:
getQueueSize in interface LayoutEngine
Returns:
the number of areas currently in the layout queue

clearQueue

public LayoutArea[] clearQueue()
Empties out the layout queue. This must be called before assigning a new clipping region with setCurrentRegion().

Specified by:
clearQueue in interface LayoutEngine
Returns:
an array of areas that were in the layout queue

layoutAreas

public java.util.List layoutAreas(java.util.List areas)
Attempts to lay out all the areas in the supplied List. Areas that fit are added to the layout queue. Areas that don't fit are returned. When this method returns, it typically means the current region is full, and the queue needs to be cleared for the next layout pass.

Specified by:
layoutAreas in interface LayoutEngine
Parameters:
areas - the list of areas to add to the current region
Returns:
the areas that did not fit in the current region
Throws:
java.lang.IllegalStateException - if called without a valid current region

acceptArea

public void acceptArea(LayoutArea area)
Adds the area to the layout queue. This method should initialize the area's extents to match its new position in the layout, and because it's in the queue, the area should reduce the free space in the current layout.

Specified by:
acceptArea in interface LayoutEngine
Parameters:
area - the area to add to the layout queue
Throws:
java.lang.IllegalStateException - if called without a valid current region

getFreeSpace

public java.awt.Shape getFreeSpace()
Returns the free space in the current layout region. Areas accepted into the layout queue reduce the free space. The returned Shape can be any closed shape, but is typically a Rectangle.

Specified by:
getFreeSpace in interface LayoutEngine
Returns:
the space in the current region unclaimed by the layout queue
Throws:
java.lang.IllegalStateException - if called without a valid current region

guessSize

public java.awt.Dimension guessSize(LayoutArea area)
Estimates the size that the area "wants" to be. The default implementation simply returns the value of 'preferred'. If the preferred width or height is DefaultStyle.NOT_FOUND, that extent is autosized. In the case of a LayoutText area, the size the text needs will determine the autosized extent. A LayoutGroup extent will become the sum of its children in that direction.

Specified by:
guessSize in interface LayoutEngine
Parameters:
area - the area to examine
Returns:
the size the area should be

fitsInRegion

public boolean fitsInRegion(LayoutArea area)
Checks to see if the given area will fit anywhere in the current layout region.

Specified by:
fitsInRegion in interface LayoutEngine
Parameters:
area - the area to check
Returns:
true if the area fits in the current region, or false if it does not fit
Throws:
java.lang.IllegalStateException - if called without a valid current region