jimm.datavision.layout
Class LayoutEngine

java.lang.Object
  extended by jimm.datavision.layout.LayoutEngine
Direct Known Subclasses:
ExcelLE, LaTeXLE, PDFLE, SortedLayoutEngine, SwingLE

public abstract class LayoutEngine
extends java.lang.Object

A layout engine is responsible for formatting and outputting report data. LayoutEngine is an abstract class. The Template design pattern is heavily used to provide a framework for concrete layout engine subclasses.

Author:
Jim Menard, jimm@io.com

Field Summary
protected  Section currentSection
           
protected  boolean newPage
           
protected  java.io.PrintWriter out
           
protected  double pageHeight
           
protected  double pageHeightUsed
           
protected  int pageNumber
           
protected  double pageWidth
           
static int POINTS_PER_INCH
          The number of points per inch.
protected  int previousSectionArea
           
protected  Report report
          Set by report in Report.setLayoutEngine.
protected static int SECT_DETAIL
           
protected static int SECT_GROUP_FOOTER
           
protected static int SECT_GROUP_HEADER
           
protected static int SECT_PAGE_FOOTER
           
protected static int SECT_PAGE_HEADER
           
protected static int SECT_REPORT_FOOTER
           
protected static int SECT_REPORT_HEADER
           
protected  boolean wantsMoreData
           
 
Constructor Summary
LayoutEngine()
          Constructor.
LayoutEngine(java.io.PrintWriter out)
          Constructor.
 
Method Summary
protected  double calcDetailHeight()
          Returns the total height of all detail sections.
protected  double calcPageFooterHeight()
          Returns the total height of all page footer sections.
protected  double calcReportFooterHeight()
          Returns the total height of all report footer sections.
protected  double calcSectionHeights(SectionArea area)
          Returns the total height of all sections in the specified list.
 void cancel()
          Called by someone else running the report to cancel all the hard work this layout engine has performed.
protected  void checkRemainingPageLength(boolean isLastRow, boolean includeDetail)
          Checks remaining page length and outputs a new page if we are at the bottom of the page.
protected  void closeOutput()
          Called by end to let this layout engine clean up a bit.
protected  java.lang.String currentSectionTypeAsString()
          Returns the current section type (header, footer, detail) as a string.
 void detail(boolean isLastRow)
          Called by the report when a single detail row needs to be output.
protected  void doEnd()
          Called by end as a chance to insert behavior when the report ends.
protected  void doEndPage()
          Called by endPage as a chance to insert behavior when a new page ends.
protected abstract  void doOutputField(Field field)
          Called by outputField as a chance to insert behavior when a field is output.
protected abstract  void doOutputImage(ImageField image)
          Called by outputImage as a chance to insert behavior when a image is output.
protected abstract  void doOutputLine(Line line)
          Called by outputLine as a chance to insert behavior when a line is output.
protected  void doOutputSection(Section sect)
          Called by outputSection as a chance to insert behavior when a section is output.
protected  void doStart()
          Called by start as a chance to insert behavior when the report starts.
protected  void doStartPage()
          Called by startPage as a chance to insert behavior when a new page starts.
 void end()
          Called by the report at the end of a report run.
protected  void endPage(boolean isLastPage)
          Ends a new page.
 void groupFooters(boolean isLastRow)
          Called by the report when group footers need to be output.
 void groupHeaders(boolean isLastRow)
          Called by the report when group headers need to be output.
protected  void outputField(Field field)
          Outputs a field.
protected  void outputImage(ImageField image)
          Outputs a image.
protected  void outputLine(Line line)
          Outputs a line.
protected  void outputSection(Section sect, int which)
          Outputs a section.
 double pageHeight()
          Returns the page height in points.
 int pageNumber()
          Returns the current page number.
 double pageWidth()
          Returns the page width in points.
 void setReport(Report r)
           
 void start()
          Called by the report at the beginning of a report run.
protected  void startPage()
          Starts a new page.
 boolean wantsMoreData()
          Called by a report before retrieving each row of data, this method returns true if this layout engine wants more data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

POINTS_PER_INCH

public static final int POINTS_PER_INCH
The number of points per inch.

See Also:
Constant Field Values

SECT_REPORT_HEADER

protected static final int SECT_REPORT_HEADER
See Also:
Constant Field Values

SECT_REPORT_FOOTER

protected static final int SECT_REPORT_FOOTER
See Also:
Constant Field Values

SECT_PAGE_HEADER

protected static final int SECT_PAGE_HEADER
See Also:
Constant Field Values

SECT_PAGE_FOOTER

protected static final int SECT_PAGE_FOOTER
See Also:
Constant Field Values

SECT_GROUP_HEADER

protected static final int SECT_GROUP_HEADER
See Also:
Constant Field Values

SECT_GROUP_FOOTER

protected static final int SECT_GROUP_FOOTER
See Also:
Constant Field Values

SECT_DETAIL

protected static final int SECT_DETAIL
See Also:
Constant Field Values

report

protected Report report
Set by report in Report.setLayoutEngine.


pageNumber

protected int pageNumber

out

protected java.io.PrintWriter out

newPage

protected boolean newPage

pageHeight

protected double pageHeight

pageWidth

protected double pageWidth

pageHeightUsed

protected double pageHeightUsed

currentSection

protected Section currentSection

wantsMoreData

protected boolean wantsMoreData

previousSectionArea

protected int previousSectionArea
Constructor Detail

LayoutEngine

public LayoutEngine()
Constructor.


LayoutEngine

public LayoutEngine(java.io.PrintWriter out)
Constructor.

Parameters:
out - output print writer
Method Detail

setReport

public void setReport(Report r)

pageWidth

public double pageWidth()
Returns the page width in points. This value is only valid after start() has been called.

Returns:
the page width in points

pageHeight

public double pageHeight()
Returns the page height in points. This value is only valid after start() has been called.

Returns:
the page height in points

wantsMoreData

public boolean wantsMoreData()
Called by a report before retrieving each row of data, this method returns true if this layout engine wants more data. Concrete subclasses can set the wantsMoreData instance variable to false if the user cancells a report run, for example.

Returns:
true if this layout engine would like more data

cancel

public void cancel()
Called by someone else running the report to cancel all the hard work this layout engine has performed.


start

public void start()
Called by the report at the beginning of a report run.

By this time, report will be non-null because we have been added to a report (which in turn sets our report instance variable).


doStart

protected void doStart()
Called by start as a chance to insert behavior when the report starts.


end

public void end()
Called by the report at the end of a report run.


doEnd

protected void doEnd()
Called by end as a chance to insert behavior when the report ends.


closeOutput

protected void closeOutput()
Called by end to let this layout engine clean up a bit.


groupHeaders

public void groupHeaders(boolean isLastRow)
Called by the report when group headers need to be output. Once one group header is output, we output all remaining group headers.

We need to explicitly evaluate all formulas in the headers that will be output because checkRemainingPageLength(boolean, boolean) causes formulas in detail and footers to be evaluated. Those formulas may depend upon values in these headers.

Parameters:
isLastRow - if true, this is the last row of the report

detail

public void detail(boolean isLastRow)
Called by the report when a single detail row needs to be output.

Parameters:
isLastRow - if true, this is the last row of the report

groupFooters

public void groupFooters(boolean isLastRow)
Called by the report when group footers need to be output. When one group footer is output, we make sure all of the footers before (above) it are also output.

Parameters:
isLastRow - if true, this is the last row of the report

checkRemainingPageLength

protected void checkRemainingPageLength(boolean isLastRow,
                                        boolean includeDetail)
Checks remaining page length and outputs a new page if we are at the bottom of the page.

Parameters:
isLastRow - if true, this is the last row of the report
includeDetail - if true, include height of detail sections

pageNumber

public int pageNumber()
Returns the current page number.

Returns:
the current page number

startPage

protected void startPage()
Starts a new page.


doStartPage

protected void doStartPage()
Called by startPage as a chance to insert behavior when a new page starts.


endPage

protected void endPage(boolean isLastPage)
Ends a new page.

Parameters:
isLastPage - if true, this is the last page of the report

doEndPage

protected void doEndPage()
Called by endPage as a chance to insert behavior when a new page ends.


outputSection

protected void outputSection(Section sect,
                             int which)
Outputs a section.

Parameters:
sect - the section to output
which - the type of section (for example, SECT_PAGE_FOOTER)

doOutputSection

protected void doOutputSection(Section sect)
Called by outputSection as a chance to insert behavior when a section is output.

Parameters:
sect - a section

outputField

protected void outputField(Field field)
Outputs a field.

Parameters:
field - the field to output

doOutputField

protected abstract void doOutputField(Field field)
Called by outputField as a chance to insert behavior when a field is output.

Parameters:
field - a field

outputImage

protected void outputImage(ImageField image)
Outputs a image.

Parameters:
image - the image field to output

doOutputImage

protected abstract void doOutputImage(ImageField image)
Called by outputImage as a chance to insert behavior when a image is output.

Parameters:
image - an image field

outputLine

protected void outputLine(Line line)
Outputs a line.

Parameters:
line - the line to output

doOutputLine

protected abstract void doOutputLine(Line line)
Called by outputLine as a chance to insert behavior when a line is output.

Parameters:
line - a line

currentSectionTypeAsString

protected java.lang.String currentSectionTypeAsString()
Returns the current section type (header, footer, detail) as a string.

Returns:
a string representation of the current section type

calcSectionHeights

protected double calcSectionHeights(SectionArea area)
Returns the total height of all sections in the specified list.

Parameters:
area - a section area
Returns:
the total height of all sections in the list

calcDetailHeight

protected double calcDetailHeight()
Returns the total height of all detail sections.

Returns:
the total height of all detail sections

calcPageFooterHeight

protected double calcPageFooterHeight()
Returns the total height of all page footer sections.

Returns:
the total height of all page footer sections

calcReportFooterHeight

protected double calcReportFooterHeight()
Returns the total height of all report footer sections.

Returns:
the total height of all report footer sections