org.writersforge.catalan.templates
Class RenderTemplate

java.lang.Object
  |
  +--org.writersforge.catalan.templates.RenderTemplate
Direct Known Subclasses:
DTDTemplate, GenericTemplate

public abstract class RenderTemplate
extends java.lang.Object

Base class for all rendering templates. The RenderTemplate is a factory for preprocessing data before sending it off to the Renderer. The template decides which input Datum objects should be rendered, and in which order. It creates and initializes the set of LayoutArea objects to pass on to the Renderer, and assigns the layout constraints for each area. It then passes these areas to a LayoutEngine to process within the context of a Page object. After the LayoutEngine has moved and resized the areas, the template adds them into the current Page object. When a Page runs out of available space, the template will create a blank new Page object and continue processing.

Author:
jsheets

Constructor Summary
RenderTemplate()
          Creates a new instance of RenderTemplate using the default LayoutEngine.
RenderTemplate(LayoutEngine layout)
          Creates a new instance of RenderTemplate using the given LayoutEngine.
RenderTemplate(java.lang.String layout)
          Creates a new instance of RenderTemplate using the requested LayoutEngine.
 
Method Summary
protected abstract  LayoutArea[] buildFlowLayout(Section section, java.lang.String regionName, Book book)
          Renders a single flow region in the current section, using the data in the Book as an input source.
protected abstract  LayoutArea[] buildStaticLayout(Section section, java.lang.String regionName, Book book)
          Renders a single static region in the current section, using the data in the Book as an input source.
protected  Page createNewPage(Book book)
          Creates a new Page object, initialized with width, height, and margins appropriate to this template and Book.
protected  int getCurrentPage()
          Retrieves the current page index
abstract  int getDefaultPageHeight()
          Retrieves the default Page height for this template.
abstract  int getDefaultPageWidth()
          Retrieves the default Page width for this template.
protected  LayoutEngine getLayout()
          Retrieves the current LayoutEngine
protected abstract  Section[] getSections()
          Returns an array of all Section objects associated with this template.
static org.writersforge.bellows.Datum[] listToDatumArray(java.util.List list)
          Converts an ArrayList into an array of Datum objects.
static LayoutArea[] listToLayoutAreaArray(java.util.List list)
          Converts an ArrayList into an array of LayoutArea objects.
 void process(Book book)
          Processes all content in the Book's ListDatum container according to the rules in this template, and divides the results into separate Pages.
protected  Page[] renderSection(Section section, Book book)
          Converts a section of the document into Page objects, using the data in the Book as an input source.
protected  void setCurrentPage(int currentPage)
          Sets the current page index
protected  void setLayout(LayoutEngine layout)
          Assigns a LayoutEngine to this template.
protected  LayoutArea[] sortAreas(LayoutArea[] areas)
          Rearranges the LayoutArea objects in a more linear order, gathering keep-with areas together and shuffling to make the layout more efficient.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RenderTemplate

public RenderTemplate()
Creates a new instance of RenderTemplate using the default LayoutEngine.


RenderTemplate

public RenderTemplate(java.lang.String layout)
Creates a new instance of RenderTemplate using the requested LayoutEngine.

Parameters:
layout - the name of the layout engine to render Pages with
Throws:
java.lang.IllegalArgumentException - if the layout engine is invalid

RenderTemplate

public RenderTemplate(LayoutEngine layout)
Creates a new instance of RenderTemplate using the given LayoutEngine.

Parameters:
layout - the layout engine to render Pages with
Method Detail

setLayout

protected void setLayout(LayoutEngine layout)
Assigns a LayoutEngine to this template.

Parameters:
layout - the LayoutEngine for this template

getLayout

protected LayoutEngine getLayout()
Retrieves the current LayoutEngine

Returns:
the current LayoutEngine

setCurrentPage

protected void setCurrentPage(int currentPage)
Sets the current page index

Parameters:
currentPage - the current page index

getCurrentPage

protected int getCurrentPage()
Retrieves the current page index

Returns:
the current page index

getDefaultPageWidth

public abstract int getDefaultPageWidth()
Retrieves the default Page width for this template. The units don't really matter, since the template can just create LayoutAreas to whatever scale it wants.

Returns:
the default Page width, in arbitrary units

getDefaultPageHeight

public abstract int getDefaultPageHeight()
Retrieves the default Page height for this template. The units don't really matter, since the template can just create LayoutAreas to whatever scale it wants.

Returns:
the default Page height, in arbitrary units

getSections

protected abstract Section[] getSections()
Returns an array of all Section objects associated with this template. Each Section represents a series of pages in the document with similar structure.

Returns:
an array of Section objects

buildStaticLayout

protected abstract LayoutArea[] buildStaticLayout(Section section,
                                                  java.lang.String regionName,
                                                  Book book)
Renders a single static region in the current section, using the data in the Book as an input source. The created LayoutArea objects are in a simplified, transitional state, with a single area for each block of text. (Later in the rendering process, these transitional areas will be further decomposed into separate areas per line of text, and perhaps split across two or more pages.) This method should call sortAreas() at some point.

Parameters:
section - the Section object to render
regionName - the name of the region in this section to process
book - the data source
Returns:
an array of partially rendered LayoutArea objects

buildFlowLayout

protected abstract LayoutArea[] buildFlowLayout(Section section,
                                                java.lang.String regionName,
                                                Book book)
Renders a single flow region in the current section, using the data in the Book as an input source. The created LayoutArea objects are in a simplified, transitional state, with a single area for each block of text. (Later in the rendering process, these transitional areas will be further decomposed into separate areas per line of text, and perhaps split across two or more pages.) This method should call sortAreas() at some point.

Parameters:
section - the Section object to render
regionName - the name of the region in this section to process
book - the data source
Returns:
an array of partially rendered LayoutArea objects

createNewPage

protected Page createNewPage(Book book)
Creates a new Page object, initialized with width, height, and margins appropriate to this template and Book.

Parameters:
book - the owning Book object for the new Page
Returns:
a newly created Page object

process

public void process(Book book)
Processes all content in the Book's ListDatum container according to the rules in this template, and divides the results into separate Pages. The Pages are stored inside the Book. Any Book Pages from a previous run are deleted before processing the new content.

Parameters:
book - the data to organize into Pages

renderSection

protected Page[] renderSection(Section section,
                               Book book)
Converts a section of the document into Page objects, using the data in the Book as an input source. The Page objects contain fully rendered LayoutArea objects, ready to be sent to the final output media. If no flow data exists for the regions in this section, the Page array will be empty. This method passes the transitional LayoutArea objects obtained from the various calls to buildRegionLayout() into the template's LayoutEngine for finer processing.

Parameters:
section - the Section object to render
book - the data source
Returns:
an array of fully rendered Page objects

sortAreas

protected LayoutArea[] sortAreas(LayoutArea[] areas)
Rearranges the LayoutArea objects in a more linear order, gathering keep-with areas together and shuffling to make the layout more efficient.

Parameters:
areas - the master list of areas to sort
Returns:
the sorted list of areas

listToDatumArray

public static org.writersforge.bellows.Datum[] listToDatumArray(java.util.List list)
Converts an ArrayList into an array of Datum objects. Ignores any non-Datum objects.

Parameters:
list - list of objects to grab
Returns:
an array of all Datum objects in the list

listToLayoutAreaArray

public static LayoutArea[] listToLayoutAreaArray(java.util.List list)
Converts an ArrayList into an array of LayoutArea objects. Ignores any non-LayoutArea objects.

Parameters:
list - list of objects to grab
Returns:
an array of all LayoutArea objects in the list