org.jfree.report.states
Class ReportState

java.lang.Object
  extended byorg.jfree.report.states.ReportState
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
FinishState, InItemGroupState, PostGroupFooterState, PostGroupHeaderState, PostItemGroupState, PostReportFooterState, PostReportInitializedState, PreGroupFooterState, PreGroupHeaderState, PreItemGroupState, PreReportFooterState, StartState

public abstract class ReportState
extends java.lang.Object
implements java.lang.Cloneable

Captures state information for a report while it is in the process of being displayed or printed. JFreeReport uses a state transition diagram to track progress through the report generation.

The report processing will usually pass through many states for each page generated. We record the report state at the end of each page, so that we can jump directly to the start of any page without having to regenerate all the preceding pages.

Author:
David Gilbert, Thomas Morgner

Field Summary
static int BEFORE_FIRST_GROUP
          A group number that is 'before' the first group.
static int BEFORE_FIRST_PAGE
          The first page.
static int BEFORE_FIRST_ROW
          A row number that is 'before' the first row.
 
Constructor Summary
protected ReportState(JFreeReport reportPar)
          Constructs a new state for the specified report.
protected ReportState(ReportState clone)
          Constructs a ReportState from an existing ReportState.
protected ReportState(ReportState clone, boolean reset)
          Constructs a ReportState from an existing ReportState and optionally resets the state.
 
Method Summary
abstract  ReportState advance()
          The advance method performs a transition from the current report state to the next report state.
 void advanceItem()
          Advances the active data row to the next line.
 java.lang.Object clone()
          Clones the report state.
 ReportStateProgress createStateProgress(ReportStateProgress progress)
          Creates a shallow clone.
 void enterGroup()
          Activates the next group by incrementing the current group index.
 void fireGroupFinishedEvent()
          Fires a 'group-finished' event.
 void fireGroupStartedEvent()
          Fires a 'group-started' event.
 void fireItemsAdvancedEvent()
          Fires an 'items-advanced' event.
 void fireItemsFinishedEvent()
          Fires an 'items-finished' event.
 void fireItemsStartedEvent()
          Fires an 'items-started' event.
 void fireLayoutCompleteEvent(Band band, int type)
          Fires an 'layout-complete' event.
 void firePageCanceledEvent()
          Fires a 'page-canceled' event.
 void firePageFinishedEvent()
          Fires a 'page-finished' event.
 void firePageStartedEvent(int baseEvent)
          Fires a 'page-started' event.
 void firePrepareEvent(int type)
          Fires a 'prepare' event.
 void fireReportDoneEvent()
          Fires a 'report-finished' event.
 void fireReportFinishedEvent()
          Fires a 'report-finished' event.
 void fireReportInitializedEvent()
          Fires a 'report-started' event.
 void fireReportStartedEvent()
          Fires a 'report-started' event.
 int getAncestorHashcode()
          Returns the ancestor hash code.
 int getCurrentDataItem()
          Returns the current item (that is, the current row of the data in the TableModel).
 int getCurrentDisplayItem()
          Returns the current item that should be displayed for this state.
 int getCurrentGroupIndex()
          Returns the current group index.
 int getCurrentPage()
          Returns the page number.
 DataRow getDataRow()
          Returns the current data row.
protected  DataRowBackend getDataRowBackend()
          Returns the data row backend.
protected  DataRowPreview getDataRowPreview()
          Implements a singleton datarow preview.
 java.util.List getErrors()
          Returns the errors that occured during the last event dispatching.
protected  LevelledExpressionList getFunctions()
          Returns the function collection.
 int getLevel()
          Returns the current function level.
 java.util.Iterator getLevels()
          Returns an iterator over the function levels.
 int getNumberOfRows()
          Returns the number of rows.
 ReportProperties getProperties()
          Returns the report properties.
 java.lang.Object getProperty(java.lang.String key)
          Returns the value of a property with the specified name.
 java.lang.Object getProperty(java.lang.String key, java.lang.Object def)
          Returns a property with the specified name.
 ReportDefinition getReport()
          Returns the report this state is assigned to.
protected  ReportDefinitionImpl getReportDefinition()
          Returns the report definition implementation used as backend when generating the report.
 boolean isAncestor(ReportState state)
          Returns true if a state is an ancestor of this state, and false otherwise.
 boolean isErrorOccured()
          Checks, whether the last report event caused errors.
 boolean isFinish()
          Tests whether this state is a defined ending point for report generation.
static boolean isLastItemInGroup(Group g, DataRowBackend currentDataRow, DataRowBackend nextDataRow)
          Returns true if this is the last item in the group, and false otherwise.
 boolean isPrefetchState()
          Returns the 'prefetch' state for this report state (defaults to false).
 boolean isPrepareRun()
          Returns a flag indicating whether this is the 'prepare' run.
 boolean isProceeding(ReportStateProgress oldstate)
          This is a helper function used to detect infinite loops on report processing.
 boolean isStart()
          Tests whether this state is a defined starting point for report generation.
 void leaveGroup()
          Deactivates the current group by decrementing the current group index.
 void nextPage()
          Advances the current page by one.
protected  void resetState()
          Resets the state, so that the datarow points to the first row.
protected  void setAncestorHashcode(int ancestorHashcode)
          Sets the ancestor hash code.
 void setCurrentGroupIndex(int index)
          Sets the current group index (zero is the item group).
 void setCurrentItem(int itemIndex)
          Sets the current item index (corresponds to a row in the TableModel).
 void setCurrentPage(int page)
          Sets the current page number.
 void setProperty(java.lang.String key, java.lang.Object o)
          Sets a property.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BEFORE_FIRST_ROW

public static final int BEFORE_FIRST_ROW
A row number that is 'before' the first row.

See Also:
Constant Field Values

BEFORE_FIRST_GROUP

public static final int BEFORE_FIRST_GROUP
A group number that is 'before' the first group.

See Also:
Constant Field Values

BEFORE_FIRST_PAGE

public static final int BEFORE_FIRST_PAGE
The first page.

See Also:
Constant Field Values
Constructor Detail

ReportState

protected ReportState(JFreeReport reportPar)
               throws java.lang.CloneNotSupportedException
Constructs a new state for the specified report. The report (which encapsulates a reference to the data, plus definitions for the required layout) is cloned to isolate the reporting engine from changes to the report that occur after report processing begins.

This constructor is protected, it is intended to be used by subclasses only.

Parameters:
reportPar - the report.
Throws:
java.lang.CloneNotSupportedException - if the initial cloning of the report definition fails.

ReportState

protected ReportState(ReportState clone,
                      boolean reset)
Constructs a ReportState from an existing ReportState and optionally resets the state.

Parameters:
clone - the base report state from which to initialize.
reset - true, if the state should be reseted, false otherwise.

ReportState

protected ReportState(ReportState clone)
Constructs a ReportState from an existing ReportState.

Parameters:
clone - the existing state.
Method Detail

resetState

protected void resetState()
Resets the state, so that the datarow points to the first row.


getDataRowPreview

protected DataRowPreview getDataRowPreview()
Implements a singleton datarow preview.

Returns:
the preview instance of the datarow.

getNumberOfRows

public int getNumberOfRows()
Returns the number of rows.

Returns:
The number of row.

getDataRow

public DataRow getDataRow()
Returns the current data row.

Returns:
the current data row.

getDataRowBackend

protected DataRowBackend getDataRowBackend()
Returns the data row backend.

Returns:
the data row backend.

getReport

public ReportDefinition getReport()
Returns the report this state is assigned to.

Returns:
the report.

advance

public abstract ReportState advance()
                             throws ReportProcessingException
The advance method performs a transition from the current report state to the next report state. Each transition will usually involve some processing of the report.

Returns:
the next report state.
Throws:
ReportProcessingException - if there is a problem processing the report.

getReportDefinition

protected ReportDefinitionImpl getReportDefinition()
Returns the report definition implementation used as backend when generating the report. Don't play with it!

Returns:
the internal report definition.

getCurrentDataItem

public int getCurrentDataItem()
Returns the current item (that is, the current row of the data in the TableModel).

Returns:
The current row index.

getCurrentDisplayItem

public final int getCurrentDisplayItem()
Returns the current item that should be displayed for this state. Before any item has advanced, dataItem is -1. This function automatically corrects the currentRow according to the current state of the report (if the header is processed, add +1).

Returns:
the row to use for obtaining data from the TableModel.

isPrefetchState

public boolean isPrefetchState()
Returns the 'prefetch' state for this report state (defaults to false).

Some states will override this method and return true...in this case, any access to the report's TableModel will look to the current row + 1.

Returns:
always false (subclasses may override).

setCurrentItem

public void setCurrentItem(int itemIndex)
Sets the current item index (corresponds to a row in the TableModel). This element is -1 before a row is read.

Parameters:
itemIndex - The new item index.

getCurrentPage

public int getCurrentPage()
Returns the page number.

Returns:
the page number.

setCurrentPage

public void setCurrentPage(int page)
Sets the current page number.

Parameters:
page - The new page number.

getCurrentGroupIndex

public int getCurrentGroupIndex()
Returns the current group index.

This starts at zero for the item group, and increases for each higher level group.

Returns:
The current group index.

setCurrentGroupIndex

public void setCurrentGroupIndex(int index)
Sets the current group index (zero is the item group).

Parameters:
index - The new group index.

getFunctions

protected final LevelledExpressionList getFunctions()
Returns the function collection.

Returns:
the functions.

getProperty

public java.lang.Object getProperty(java.lang.String key)
Returns the value of a property with the specified name.

Parameters:
key - the property name.
Returns:
the property value.

getProperty

public java.lang.Object getProperty(java.lang.String key,
                                    java.lang.Object def)
Returns a property with the specified name. If no property with the specified name is found, returns def.

Parameters:
key - the property name.
def - the default value.
Returns:
the property value.

setProperty

public void setProperty(java.lang.String key,
                        java.lang.Object o)
Sets a property.

Parameters:
key - the property name.
o - the property value.

getProperties

public ReportProperties getProperties()
Returns the report properties.

Returns:
the report properties.

isPrepareRun

public boolean isPrepareRun()
Returns a flag indicating whether this is the 'prepare' run.

This run is used to do repagination, and is only done when the pageformat changes.

Returns:
true, if this is a prepare run of the report engine.

createStateProgress

public ReportStateProgress createStateProgress(ReportStateProgress progress)
Creates a shallow clone. Handle with care. This is a relativly cheap operation, so we have a copy to check whether some progress was made, without having to pay for the complete (deep) cloning.

Don't use that function to store/copy a report state for a longer storage time. The next few advances may render the reportstate copy invalid.

Parameters:
progress - a carrier for the result.
Returns:
a progress object of this state.

clone

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

Returns:
a clone.
Throws:
java.lang.CloneNotSupportedException - if there is a cloning problem.

isProceeding

public boolean isProceeding(ReportStateProgress oldstate)
This is a helper function used to detect infinite loops on report processing. Returns true, if the report did proceed over at least one element.

If this method returns false, we need to bail out of processing the report because there is some problem.

Parameters:
oldstate - the previous state.
Returns:
true if some progress has been made, false otherwise.

nextPage

public void nextPage()
Advances the current page by one.


isStart

public boolean isStart()
Tests whether this state is a defined starting point for report generation.

Returns:
false (subclasses may override).

isFinish

public boolean isFinish()
Tests whether this state is a defined ending point for report generation.

Returns:
false (subclasses may override).

enterGroup

public void enterGroup()
Activates the next group by incrementing the current group index. The outer-most group is given an index of zero, and this increases for each subgroup that is defined.


leaveGroup

public void leaveGroup()
Deactivates the current group by decrementing the current group index.


advanceItem

public void advanceItem()
Advances the active data row to the next line.


fireReportInitializedEvent

public void fireReportInitializedEvent()
Fires a 'report-started' event.


fireReportStartedEvent

public void fireReportStartedEvent()
Fires a 'report-started' event.


firePrepareEvent

public void firePrepareEvent(int type)
Fires a 'prepare' event.

Parameters:
type - the event type of the event that should be prepared.

fireReportFinishedEvent

public void fireReportFinishedEvent()
Fires a 'report-finished' event.


fireReportDoneEvent

public void fireReportDoneEvent()
Fires a 'report-finished' event.


firePageStartedEvent

public void firePageStartedEvent(int baseEvent)
Fires a 'page-started' event.

Parameters:
baseEvent - the type of the base event which caused the page start to be triggered.

firePageFinishedEvent

public void firePageFinishedEvent()
Fires a 'page-finished' event. The pageFinished(...) method is called for every report function.


firePageCanceledEvent

public void firePageCanceledEvent()
Fires a 'page-canceled' event. The pageCanceled(...) method is called for every report function that implements the PageListener interface.


fireGroupStartedEvent

public void fireGroupStartedEvent()
Fires a 'group-started' event. The groupStarted(...) method is called for every report function.


fireGroupFinishedEvent

public void fireGroupFinishedEvent()
Fires a 'group-finished' event.


fireItemsStartedEvent

public void fireItemsStartedEvent()
Fires an 'items-started' event.


fireItemsFinishedEvent

public void fireItemsFinishedEvent()
Fires an 'items-finished' event.


fireItemsAdvancedEvent

public void fireItemsAdvancedEvent()
Fires an 'items-advanced' event.


fireLayoutCompleteEvent

public void fireLayoutCompleteEvent(Band band,
                                    int type)
Fires an 'layout-complete' event.

Parameters:
band - the band, that completed layouting.
type - the type of the base event fireing the laout complete event.

getLevel

public int getLevel()
Returns the current function level.

Returns:
the function level.

getLevels

public java.util.Iterator getLevels()
Returns an iterator over the function levels.

Returns:
an iterator.

getAncestorHashcode

public int getAncestorHashcode()
Returns the ancestor hash code.

Returns:
the ancestor hash code.

setAncestorHashcode

protected void setAncestorHashcode(int ancestorHashcode)
Sets the ancestor hash code.

Parameters:
ancestorHashcode - the ancestor hash code.

isAncestor

public boolean isAncestor(ReportState state)
Returns true if a state is an ancestor of this state, and false otherwise.

Parameters:
state - the state.
Returns:
true or false.

getErrors

public java.util.List getErrors()
Returns the errors that occured during the last event dispatching. This list gets cleared when the next event gets dispatched.

Returns:
the error list.

isErrorOccured

public boolean isErrorOccured()
Checks, whether the last report event caused errors.

Returns:
true, if there were errors recorded, false otherwise.

isLastItemInGroup

public static boolean isLastItemInGroup(Group g,
                                        DataRowBackend currentDataRow,
                                        DataRowBackend nextDataRow)
Returns true if this is the last item in the group, and false otherwise.

Parameters:
g - the group that should be checked.
currentDataRow - the current data row.
nextDataRow - the next data row, or null, if this is the last datarow.
Returns:
A flag indicating whether or not the current item is the last in its group.