com.jrefinery.report.targets.pageable.pagelayout
Class SimplePageLayouter

java.lang.Object
  |
  +--com.jrefinery.report.function.AbstractFunction
        |
        +--com.jrefinery.report.targets.pageable.pagelayout.PageLayouter
              |
              +--com.jrefinery.report.targets.pageable.pagelayout.SimplePageLayouter
All Implemented Interfaces:
java.lang.Cloneable, java.util.EventListener, Expression, Function, PrepareEventListener, ReportListener

public class SimplePageLayouter
extends PageLayouter
implements PrepareEventListener

A simple page layouter. This class replicates the 'old' behaviour of JFreeReport, simple and straightforward.

Layout Constraints used:

Author:
Thomas Morgner

Nested Class Summary
protected static class SimplePageLayouter.SimpleLayoutManagerState
          Represents the current state of the page layouter.
 
Nested classes inherited from class com.jrefinery.report.targets.pageable.pagelayout.PageLayouter
 
Field Summary
 
Fields inherited from interface com.jrefinery.report.function.Expression
AUTOACTIVATE_PROPERTY
 
Constructor Summary
SimplePageLayouter()
          Creates a new page layouter.
 
Method Summary
protected  void clearSaveState()
          Clears the layout state.
 java.lang.Object clone()
          Clones the layouter.
protected  void createSaveState(Band b)
          Records state information.
protected  java.awt.geom.Rectangle2D doLayout(Band band, boolean fireEvent)
          Perform the layout of a band.
protected  boolean doPrint(java.awt.geom.Rectangle2D bounds, Band band, boolean spool)
          Prints a band.
protected  boolean endPage(boolean force)
          Ends the page.
protected  SimplePageLayoutCursor getCursor()
          Returns the cursor.
 Expression getInstance()
          Return a completly separated copy of this function.
 int getMaxPage()
          Returns the highest pagenumber found during the repagination process.
 void groupFinished(ReportEvent event)
          Receives notification that a group has finished.
 void groupStarted(ReportEvent event)
          Receives notification that a group has started.
 boolean isNewPageStarted()
          Returns true, if the PageLayouter has successfully started a new page.
 boolean isSpaceFor(float height)
          Determines whether or not there is space remaining on the page for a band of the specified height.
 void itemsAdvanced(ReportEvent event)
          Receives notification that a row of data is being processed.
 void itemsFinished(ReportEvent event)
          Receives notification that a group of item bands has been completed.
 void itemsStarted(ReportEvent event)
          Receives notification that a group of item bands is about to be processed.
 void pageFinished(ReportEvent event)
          Receives notification that a page has ended.
 void pageStarted(ReportEvent event)
          Receives notification that a page has started.
 void prepareEvent(ReportEvent event)
          Receives notification of a prepare event.
 void reportDone(ReportEvent event)
          Receives notification that report generation has completed, the report footer was printed, no more output is done.
 void reportFinished(ReportEvent event)
          Receives notification that the report has finished.
 void reportStarted(ReportEvent event)
          Receives notification that the report has started.
 void restartPage()
          Handles the restarting of the page.
 void restoreSaveState(ReportState anchestor)
          Restores the state.
protected  PageLayouter.LayoutManagerState saveCurrentState()
          Returns the current state.
protected  void setCursor(SimplePageLayoutCursor cursor)
          Sets the cursor.
 void setLogicalPage(LogicalPage logicalPage)
          Sets the logical page and adjust the cursor.
protected  void setMaxPage(int maxPage)
          Defines the highest pagenumber found during the repagination process.
 void setStartNewPage(boolean startNewPage)
          Defines whether the PageLayouter has successfully started a new page.
 
Methods inherited from class com.jrefinery.report.targets.pageable.pagelayout.PageLayouter
clearCurrentEvent, clearLogicalPage, endPage, getCurrentEvent, getDependencyLevel, getLayoutManagerState, getLogicalPage, getReport, getValue, isFinishingPage, isGeneratedPageEmpty, isPageEnded, isPageRestartDone, isRestartingPage, setCurrentEvent, setDependencyLevel, setFinishingPage, setGeneratedPageEmpty, setPageRestartDone, setRestartingPage, startPage
 
Methods inherited from class com.jrefinery.report.function.AbstractFunction
getDataRow, getName, getProperties, getProperty, getProperty, initialize, isActive, reportInitialized, setDataRow, setName, setProperties, setProperty
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimplePageLayouter

public SimplePageLayouter()
Creates a new page layouter.

Method Detail

getInstance

public Expression getInstance()
Return a completly separated copy of this function. The copy does no longer share any changeable objects with the original function.

Specified by:
getInstance in interface Expression
Overrides:
getInstance in class AbstractFunction
Returns:
a copy of this function.

getMaxPage

public int getMaxPage()
Returns the highest pagenumber found during the repagination process.

Returns:
the highest page number.

setMaxPage

protected void setMaxPage(int maxPage)
Defines the highest pagenumber found during the repagination process.

Parameters:
maxPage - the highest page number.

reportStarted

public void reportStarted(ReportEvent event)
Receives notification that the report has started. Also invokes the start of the first page ...

Layout and draw the report header after the PageStartEvent was fired.

Specified by:
reportStarted in interface ReportListener
Overrides:
reportStarted in class AbstractFunction
Parameters:
event - the event.

itemsFinished

public void itemsFinished(ReportEvent event)
Receives notification that a group of item bands has been completed.

The itemBand is finished, the report starts to close open groups.

Specified by:
itemsFinished in interface ReportListener
Overrides:
itemsFinished in class AbstractFunction
Parameters:
event - The event.

reportDone

public void reportDone(ReportEvent event)
Receives notification that report generation has completed, the report footer was printed, no more output is done. This is a helper event to shut down the output service.

Specified by:
reportDone in interface ReportListener
Overrides:
reportDone in class AbstractFunction
Parameters:
event - The event.

itemsStarted

public void itemsStarted(ReportEvent event)
Receives notification that a group of item bands is about to be processed.

The next events will be itemsAdvanced events until the itemsFinished event is raised.

Specified by:
itemsStarted in interface ReportListener
Overrides:
itemsStarted in class AbstractFunction
Parameters:
event - The event.

pageStarted

public void pageStarted(ReportEvent event)
Receives notification that a page has started.

This prints the PageHeader. If this is the first page, the header is not printed if the pageheader style-flag DISPLAY_ON_FIRSTPAGE is set to false. If this event is known to be the last pageStarted event, the DISPLAY_ON_LASTPAGE is evaluated and the header is printed only if this flag is set to TRUE.

If there is an active repeating GroupHeader, print the last one. The GroupHeader is searched for the current group and all parent groups, starting at the current group and ascending to the parents. The first goupheader that has the StyleFlag REPEAT_HEADER set to TRUE is printed.

The PageHeader and the repeating GroupHeader are spooled until the first real content is printed. This way, the LogicalPage remains empty until an other band is printed.

Specified by:
pageStarted in interface ReportListener
Overrides:
pageStarted in class AbstractFunction
Parameters:
event - Information about the event.

pageFinished

public void pageFinished(ReportEvent event)
Receives notification that a page has ended.

This prints the PageFooter. If this is the first page, the footer is not printed if the pagefooter style-flag DISPLAY_ON_FIRSTPAGE is set to false. If this event is known to be the last pageFinished event, the DISPLAY_ON_LASTPAGE is evaluated and the footer is printed only if this flag is set to TRUE.

Specified by:
pageFinished in interface ReportListener
Overrides:
pageFinished in class AbstractFunction
Parameters:
event - the report event.

reportFinished

public void reportFinished(ReportEvent event)
Receives notification that the report has finished.

Prints the ReportFooter and forces the last pagebreak.

Specified by:
reportFinished in interface ReportListener
Overrides:
reportFinished in class AbstractFunction
Parameters:
event - Information about the event.

groupStarted

public void groupStarted(ReportEvent event)
Receives notification that a group has started.

Prints the GroupHeader

Specified by:
groupStarted in interface ReportListener
Overrides:
groupStarted in class AbstractFunction
Parameters:
event - Information about the event.

groupFinished

public void groupFinished(ReportEvent event)
Receives notification that a group has finished.

Prints the GroupFooter.

Specified by:
groupFinished in interface ReportListener
Overrides:
groupFinished in class AbstractFunction
Parameters:
event - Information about the event.

itemsAdvanced

public void itemsAdvanced(ReportEvent event)
Receives notification that a row of data is being processed.

prints the ItemBand.

Specified by:
itemsAdvanced in interface ReportListener
Overrides:
itemsAdvanced in class AbstractFunction
Parameters:
event - Information about the event.

doLayout

protected java.awt.geom.Rectangle2D doLayout(Band band,
                                             boolean fireEvent)
Perform the layout of a band. The height of the band is calculated according to the contents of the band. The width of the band will always span the complete printable width.

Parameters:
band - the band.
fireEvent - a flag to control whether or not a report event is fired.
Returns:
the dimensions of the band.

doPrint

protected boolean doPrint(java.awt.geom.Rectangle2D bounds,
                          Band band,
                          boolean spool)
                   throws ReportProcessingException
Prints a band.

Parameters:
bounds - the bounds of the band within the logical page
band - the band that should be printed. The internal band layouting is already done, all Elements contain a valid BOUNDS property.
spool - a flag that controls whether to print the contents directly or to cache the printing operation for later usage.
Returns:
true, if the band was printed, and false if the printing is delayed until a new page gets started.
Throws:
ReportProcessingException - if the printing caused an detectable error while printing the band
See Also:
LogicalPage.spoolBand(java.awt.geom.Rectangle2D, com.jrefinery.report.Band)

isSpaceFor

public boolean isSpaceFor(float height)
Determines whether or not there is space remaining on the page for a band of the specified height. Perform layouting for the pageFooter to guess the height.

Parameters:
height - the height (in Java2D user space units).
Returns:
true or false.

getCursor

protected SimplePageLayoutCursor getCursor()
Returns the cursor.

Returns:
the cursor.
Throws:
java.lang.IllegalStateException - if a cursor is requested but no OutputTarget is set.

setCursor

protected void setCursor(SimplePageLayoutCursor cursor)
Sets the cursor.

Parameters:
cursor - the cursor (null not permitted).
Throws:
java.lang.NullPointerException - if the given cursor is null

createSaveState

protected void createSaveState(Band b)
Records state information.

Parameters:
b - the band.

saveCurrentState

protected PageLayouter.LayoutManagerState saveCurrentState()
Returns the current state. The state was previously recorded using the createSaveState(Band b) method.

Specified by:
saveCurrentState in class PageLayouter
Returns:
the current state, never null

restoreSaveState

public void restoreSaveState(ReportState anchestor)
                      throws ReportProcessingException
Restores the state.

Overrides:
restoreSaveState in class PageLayouter
Parameters:
anchestor - the ancestor state.
Throws:
ReportProcessingException - if the printing failed or a pagebreak is requested while the page is restored.
java.lang.IllegalStateException - if there is no SavedState but this is not the first page.

restartPage

public void restartPage()
                 throws ReportProcessingException
Handles the restarting of the page. Fires the pageStarted event and prints the pageheader. Restarting the page is done once after the PageLayouterState was restored.

Throws:
ReportProcessingException - if restarting the page failed.

clearSaveState

protected void clearSaveState()
Clears the layout state.

Overrides:
clearSaveState in class PageLayouter

setLogicalPage

public void setLogicalPage(LogicalPage logicalPage)
Sets the logical page and adjust the cursor.

Overrides:
setLogicalPage in class PageLayouter
Parameters:
logicalPage - the logical page.

endPage

protected boolean endPage(boolean force)
                   throws ReportProcessingException
Ends the page.

Parameters:
force - set to true, to skip the test whether the logical page is empty and to enforce an pagebreak. This is a requirement when an completly empty report (no bands or elements printed) should be finished.
Returns:
true if the pageBreak is done, false otherwise.
Throws:
ReportProcessingException - if finishing the page failed.

isNewPageStarted

public boolean isNewPageStarted()
Returns true, if the PageLayouter has successfully started a new page. The start of the new page is delayed, until the first content is printed.

Specified by:
isNewPageStarted in class PageLayouter
Returns:
true, if a new page has already been started, false otherwise.

setStartNewPage

public void setStartNewPage(boolean startNewPage)
Defines whether the PageLayouter has successfully started a new page. The start of the new page is delayed, until the first content is printed, this flag is used to keep track of the page initialization state.

Parameters:
startNewPage - true, if a new page has already been started, false otherwise.

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Clones the layouter.

Specified by:
clone in interface Function
Overrides:
clone in class PageLayouter
Returns:
the clone.
Throws:
java.lang.CloneNotSupportedException - if there is a problem cloning.

prepareEvent

public void prepareEvent(ReportEvent event)
Receives notification of a prepare event.

Specified by:
prepareEvent in interface PrepareEventListener
Parameters:
event - the event.