org.umber.crucible.old.layout
Class SimpleFlowLayout

java.lang.Object
  extended byorg.umber.crucible.old.layout.AbstractLayoutEngine
      extended byorg.umber.crucible.old.layout.SimpleFlowLayout
All Implemented Interfaces:
LayoutEngine

public class SimpleFlowLayout
extends AbstractLayoutEngine

Very simple layout engine which flows all LayoutArea objects down and to the right. Half-heartedly attempts to keep adjacent areas together, but does not bother with more complex relationships. This is a very low-tech layout engine intended for simple, small objects with few formatting constraints. It's good for simple ASCII to PDF conversion.

Author:
jsheets

Constructor Summary
SimpleFlowLayout()
           
 
Method Summary
protected  void acceptArea(LayoutArea area, LayoutContext context, java.util.List oldAreas)
          Accept the entire contents of this area; if this is a group area, accept all child elements.
protected  java.awt.Rectangle calculateFinalExtents(LayoutArea area, LayoutContext context)
          Creates an extent for placing the area in its final position in the layout.
 boolean fitsInRegion(LayoutArea area, java.awt.Rectangle region, java.util.List areasInRegion)
          Checks to see if the area will fit in the given region.
 java.awt.Dimension guessSize(LayoutArea area)
          Estimates the size that the area "wants" to be.
protected  boolean layoutArea(LayoutArea area, LayoutContext context, java.util.List oldAreas)
          Lay out an area; unlike layoutRegion(), it can be called recursively.
 void layoutRegion(LayoutContext context, java.awt.Rectangle region)
          Attempts to lay out as many of the pending areas in the context as it can, into the provided region's bounding box.
 
Methods inherited from class org.umber.crucible.old.layout.AbstractLayoutEngine
acceptArea, clearQueue, fitsInRegion, getFreeSpace, getQueueSize, layoutAreas, setCurrentRegion
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleFlowLayout

public SimpleFlowLayout()
Method Detail

guessSize

public java.awt.Dimension guessSize(LayoutArea area)
Estimates the size that the area "wants" to be.

This 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
Overrides:
guessSize in class AbstractLayoutEngine
Parameters:
area - the area to examine
Returns:
the size the area should be

fitsInRegion

public boolean fitsInRegion(LayoutArea area,
                            java.awt.Rectangle region,
                            java.util.List areasInRegion)
Checks to see if the area will fit in the given region. The areasInRegion parameter may contain an optional array of LayoutArea objects that the engine has already fitted into the region. This method should take these pre-existing areas into account. If no areas are currently in the region, areasInRegion can be null or an empty array.

The SimpleFlowLayout engine uses a very simple algorithm for fit-testing. It ignores smallest and largest constraints, using only preferred constraints, to get a better performance and keep the code leaner. For a more "respectful" layout engine, try the FlowLayout engine. SimpleFlowLayout does allow area breaking.

Parameters:
area - the LayoutArea object to try to fit
region - the bounding area of the region
areasInRegion - optional list of areas already in the region
Returns:
true if the area fits in the region, or false if not

layoutRegion

public void layoutRegion(LayoutContext context,
                         java.awt.Rectangle region)
Attempts to lay out as many of the pending areas in the context as it can, into the provided region's bounding box. This implementation calls layoutArea() on all top-level areas until one is rejected.

Parameters:
context - the running context for this rendering pass
region - the bounding area to render areas into

layoutArea

protected boolean layoutArea(LayoutArea area,
                             LayoutContext context,
                             java.util.List oldAreas)
Lay out an area; unlike layoutRegion(), it can be called recursively. This method should only accept areas, and should never reject areas. If a rejection occurs, the current area will probably be altered, according to the rules below.

Criteria:

  1. If the area fits, accept it immediately, regardless of whether it's a group or leaf area. Return true.
  2. If the area does not fit, and is not breakable, do not accept anything. Return false.
  3. If this is a breakable group area, accept as many of its individual children as possible (setting those array elements to null), and leave the rest untouched, for later rejection. Return false.
  4. If the area is a breakable leaf area, create a new area for the accepted portion, and modify the existing area to only contain the rejected portion. Return false.

Parameters:
area - the area to render
context - the running context for this rendering pass
oldAreas - areas already accepted in this region
Returns:
true if entire area was accepted, otherwise false if any portion is rejected

calculateFinalExtents

protected java.awt.Rectangle calculateFinalExtents(LayoutArea area,
                                                   LayoutContext context)
Creates an extent for placing the area in its final position in the layout.

Parameters:
area - the LayoutArea object to calculate extents for
context - context for the region
Returns:
the final extents

acceptArea

protected void acceptArea(LayoutArea area,
                          LayoutContext context,
                          java.util.List oldAreas)
Accept the entire contents of this area; if this is a group area, accept all child elements. Do not accept any LayoutGroup areas. If any LayoutGroup areas have a border, create and accept a new LayoutShape area for it. This implementation sets the extents of the area and all its children to the exact value of its preferred extents. Text alignment should take place in the Renderer.

Parameters:
area - the LayoutArea to accept into the LayoutContext
context - the running context for this rendering pass
oldAreas - areas already accepted in this region