org.umber.crucible.old.layout
Class LayoutContext

java.lang.Object
  extended byorg.umber.crucible.old.layout.LayoutContext

public class LayoutContext
extends java.lang.Object

Context for an ongoing iterative layout process. Manages an array of LayoutArea objects as they are split, reformatted, and reflowed onto a series of page regions. The context maintains a running tally of which areas have been used, and allows for a partial area to be carried forward to the next Page, if necessary. Keeps a separate list of finished, accepted areas which are ready to be rendered to a Page.

The context object does not deal directly with Page objects. It merely provides easy access to the "fiddling" actions that are a part of layout generation. Typically, a LayoutEngine will take a LayoutContext object, cram as much into the current region as it can, and return the context for the RenderTemplate to populate a new Page.

Author:
jsheets

Constructor Summary
LayoutContext(LayoutArea[] areas)
          Creates a new instance of LayoutContext
 
Method Summary
 void acceptArea(LayoutArea area)
          Adds an area to the list of renderable areas for the current page.
 void flush()
          Removes all renderable areas from the queue.
 LayoutArea[] getAcceptedAreas()
          Returns an array of areas ready to be rendered onto a Page.
 LayoutArea getCurrentArea()
          Returns the LayoutArea object most recently pulled off the stack.
 java.awt.Rectangle getCurrentRegion()
          Retrieves the cached current rendering region.
 java.awt.Rectangle getOuterRegion()
          Retrieves the the top-level layout region.
 int getStackCount()
          Returns the number of unhandled areas left in the queue.
 LayoutArea nextArea()
          Pulls the next area off the stack.
 void rejectArea(LayoutArea reject)
          Puts the area into the reject pile, to be deferred to the next page.
 void setCurrentRegion(java.awt.Rectangle region)
          Caches the current rendering region in the LayoutContext.
 void setOuterRegion(java.awt.Rectangle region)
          Caches the top-level layout region in the LayoutContext.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LayoutContext

public LayoutContext(LayoutArea[] areas)
Creates a new instance of LayoutContext

Parameters:
areas - an array of areas to initialize the context to
Method Detail

setCurrentRegion

public void setCurrentRegion(java.awt.Rectangle region)
Caches the current rendering region in the LayoutContext. Helps keep parameter lists smaller in the LayoutEngine.

Parameters:
region - the current rendering region

getCurrentRegion

public java.awt.Rectangle getCurrentRegion()
Retrieves the cached current rendering region. If the region has not been previously set, returns a freshly created Rectangle initialized to zeros.

Returns:
the cached region

setOuterRegion

public void setOuterRegion(java.awt.Rectangle region)
Caches the top-level layout region in the LayoutContext. Helps keep parameter lists smaller in the LayoutEngine. .

Parameters:
region - the current outer region

getOuterRegion

public java.awt.Rectangle getOuterRegion()
Retrieves the the top-level layout region. If the region has not been previously set, returns the value of getCurrentRegion().

Returns:
the cached outer region

getStackCount

public int getStackCount()
Returns the number of unhandled areas left in the queue.

Returns:
the number of remaining areas

nextArea

public LayoutArea nextArea()
Pulls the next area off the stack.

Returns:
the next area to be rendered, or null if no areas are left

getCurrentArea

public LayoutArea getCurrentArea()
Returns the LayoutArea object most recently pulled off the stack. If no area has been pulled, this method implicitly calls nextArea() to ensure a valid area is returned.

Returns:
the most recent area returned by nextArea ()

rejectArea

public void rejectArea(LayoutArea reject)
Puts the area into the reject pile, to be deferred to the next page. Call this if the area does not fit on the current page. When flush() is called at the end of a page, the rejects are moved back into the stack in the same order they were rejected.

Parameters:
reject - an area to bump to the next page

acceptArea

public void acceptArea(LayoutArea area)
Adds an area to the list of renderable areas for the current page.

Parameters:
area - a valid renderable area for the current page

getAcceptedAreas

public LayoutArea[] getAcceptedAreas()
Returns an array of areas ready to be rendered onto a Page. Should be called by the RenderTemplate after the LayoutEngine is finished laying out the current page.

Returns:
an array of renderable areas

flush

public void flush()
Removes all renderable areas from the queue. This should be called by the RenderTemplate after it has added the renderable areas to a Page. The template must call this after each Page to ensure that the next Page does not repeat areas from the previous page. This method moves all rejected areas back onto the stack, in the same order they were rejected.