org.jfree.report
Class JFreeReport

java.lang.Object
  extended byorg.jfree.report.JFreeReport
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class JFreeReport
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

This class co-ordinates the process of generating a report from a TableModel. The report is made up of 'bands', which are used repeatedly as necessary to generate small sections of the report.

Accessing the bands and the elements:

The different bands can be accessed using the main report definition (this class):

Groups can be queried using getGroup(int groupLevel). The group header and footer are accessible through the group object, so use getGroup(int groupLevel).getGroupHeader() and getGroup(int groupLevel).getGroupFooter().

Elements on a band can be reached by using Band.getElement (String elementName) or by retrieving all elements using Band.getElements() and performing a search on the returned list.

All report elements share the same stylesheet collection. Report elements cannot be shared between two different report instances.

Author:
David Gilbert, Thomas Morgner
See Also:
Serialized Form

Field Summary
static java.lang.String NAME_PROPERTY
          Key for the 'report name' property.
static java.lang.String REPORT_DATE_PROPERTY
          Key for the 'report date' property.
static java.lang.String REPORT_DEFINITION_CONTENTBASE
          Key for the 'report definition content base' property.
static java.lang.String REPORT_DEFINITION_SOURCE
          Key for the 'report definition source' property.
static java.lang.String REPORT_PAGEFORMAT_PROPERTY
          Key for the 'report page format' property.
static java.lang.String REPORT_PREPARERUN_PROPERTY
          Key for the 'report prepare run' property.
 
Constructor Summary
JFreeReport()
          The default constructor.
 
Method Summary
 void addExpression(Expression function)
          Adds a function to the report's collection of functions.
 void addFunction(Function function)
          Adds a function to the report's collection of functions.
 void addGroup(Group group)
          Adds a group to the report.
protected  void checkGroups()
          Verifies the group list and adds the default group to the list if necessary.
 java.lang.Object clone()
          Clones the report.
 javax.swing.table.TableModel getData()
          Returns the current data for this report.
 java.awt.print.PageFormat getDefaultPageFormat()
          Returns the default page format.
 ExpressionCollection getExpressions()
          Returns the expressions for the report.
 ExpressionCollection getFunctions()
          Returns the report's collection of functions.
 Group getGroup(int count)
          Returns the group at the specified index or null, if there is no such group.
 Group getGroupByName(java.lang.String name)
          Searches a group by its defined name.
 int getGroupCount()
          Returns the number of groups in this report.
 GroupList getGroups()
          Returns a clone of the list of groups for the report.
static JFreeReportInfo getInfo()
          Returns information about the JFreeReport class library.
 ItemBand getItemBand()
          Returns the report's item band.
 java.lang.String getName()
          Returns the name of the report.
 PageFooter getPageFooter()
          Returns the page footer.
 PageHeader getPageHeader()
          Returns the page header.
 ReportProperties getProperties()
          Returns the report properties collection for this report.
 java.lang.Object getProperty(java.lang.String key)
          Returns the value of the property with the specified key.
 ReportBuilderHints getReportBuilderHints()
          Returns the report builder hints collection assigned with this report.
 ReportConfiguration getReportConfiguration()
          Returns the report configuration.
 ReportFooter getReportFooter()
          Returns the page footer.
 ReportHeader getReportHeader()
          Returns the report header.
 StyleSheetCollection getStyleSheetCollection()
          Returns the stylesheet collection of this report.
 Watermark getWatermark()
          Returns the report's watermark band.
 boolean isPropertyMarked(java.lang.String key)
          Returns the value of the property with the specified key.
 void setData(javax.swing.table.TableModel data)
          Sets the data for the report.
 void setDefaultPageFormat(java.awt.print.PageFormat format)
          Defines the default page format for this report.
 void setExpressions(ExpressionCollection expressions)
          Sets the expressions for the report.
 void setFunctions(ExpressionCollection functions)
          Sets the function collection.
 void setGroups(GroupList groupList)
          Sets the groups for this report.
 void setItemBand(ItemBand band)
          Sets the item band for the report.
 void setName(java.lang.String name)
          Sets the name of the report.
 void setPageFooter(PageFooter footer)
          Sets the page footer.
 void setPageHeader(PageHeader header)
          Sets the page header.
 void setProperty(java.lang.String key, java.lang.Object value)
          Adds a property to the report.
 void setPropertyMarked(java.lang.String key, boolean mark)
          Returns the value of the property with the specified key.
 void setReportFooter(ReportFooter footer)
          Sets the report footer.
 void setReportHeader(ReportHeader header)
          Sets the report header.
 void setWatermark(Watermark band)
          Sets the watermark band for the report.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NAME_PROPERTY

public static final java.lang.String NAME_PROPERTY
Key for the 'report name' property.

See Also:
Constant Field Values

REPORT_DATE_PROPERTY

public static final java.lang.String REPORT_DATE_PROPERTY
Key for the 'report date' property.

See Also:
Constant Field Values

REPORT_PAGEFORMAT_PROPERTY

public static final java.lang.String REPORT_PAGEFORMAT_PROPERTY
Key for the 'report page format' property.

See Also:
Constant Field Values

REPORT_PREPARERUN_PROPERTY

public static final java.lang.String REPORT_PREPARERUN_PROPERTY
Key for the 'report prepare run' property.

See Also:
Constant Field Values

REPORT_DEFINITION_SOURCE

public static final java.lang.String REPORT_DEFINITION_SOURCE
Key for the 'report definition source' property.

See Also:
Constant Field Values

REPORT_DEFINITION_CONTENTBASE

public static final java.lang.String REPORT_DEFINITION_CONTENTBASE
Key for the 'report definition content base' property.

See Also:
Constant Field Values
Constructor Detail

JFreeReport

public JFreeReport()
The default constructor. Creates an empty but fully initialized report.

Method Detail

getName

public java.lang.String getName()
Returns the name of the report.

You can reference the report name in your XML report template file using the key 'report.name'.

Returns:
the name.

setName

public void setName(java.lang.String name)
Sets the name of the report.

The report name is stored as a property (key: NAME_PROPERTY = "report.name") of the report. If you supply null as the name, the property is removed.

Parameters:
name - the name of the report.

setProperty

public void setProperty(java.lang.String key,
                        java.lang.Object value)
Adds a property to the report. If a property with the given name already exists, the property will be updated with the new value. If the supplied value is null, the property will be removed.

Developers are free to add any properties they want to a report, and then display those properties in the report. For example, you might add a 'user.name' property, so that you can display the username in the header of a report.

Parameters:
key - the key.
value - the value.

getProperties

public ReportProperties getProperties()
Returns the report properties collection for this report.

These properties are inherited to all ReportStates generated for this report.

Returns:
the report properties.

getProperty

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

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

isPropertyMarked

public boolean isPropertyMarked(java.lang.String key)
Returns the value of the property with the specified key.

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

setPropertyMarked

public void setPropertyMarked(java.lang.String key,
                              boolean mark)
Returns the value of the property with the specified key.

Parameters:
key - the key.
mark - the new marking flag

setReportHeader

public void setReportHeader(ReportHeader header)
Sets the report header.

Parameters:
header - the report header (null not permitted).

getReportHeader

public ReportHeader getReportHeader()
Returns the report header.

Returns:
the report header (never null).

setReportFooter

public void setReportFooter(ReportFooter footer)
Sets the report footer.

Parameters:
footer - the report footer (null not permitted).

getReportFooter

public ReportFooter getReportFooter()
Returns the page footer.

Returns:
the report footer (never null).

setPageHeader

public void setPageHeader(PageHeader header)
Sets the page header.

Parameters:
header - the page header (null not permitted).

getPageHeader

public PageHeader getPageHeader()
Returns the page header.

Returns:
the page header (never null).

setPageFooter

public void setPageFooter(PageFooter footer)
Sets the page footer.

Parameters:
footer - the page footer (null not permitted).

getPageFooter

public PageFooter getPageFooter()
Returns the page footer.

Returns:
the page footer (never null).

setWatermark

public void setWatermark(Watermark band)
Sets the watermark band for the report.

Parameters:
band - the new watermark band (null not permitted).

getWatermark

public Watermark getWatermark()
Returns the report's watermark band.

Returns:
the watermark band (never null).

setItemBand

public void setItemBand(ItemBand band)
Sets the item band for the report.

Parameters:
band - the new item band (null not permitted).

getItemBand

public ItemBand getItemBand()
Returns the report's item band.

Returns:
the item band (never null).

addGroup

public void addGroup(Group group)
Adds a group to the report.

Parameters:
group - the group.

setGroups

public void setGroups(GroupList groupList)
Sets the groups for this report. If no list (null) or an empty list is given, an default group is created. This default group contains no elements and starts at the first record of the data and ends on the last record.

Parameters:
groupList - the list of groups.

checkGroups

protected void checkGroups()
Verifies the group list and adds the default group to the list if necessary.


getGroups

public GroupList getGroups()
Returns a clone of the list of groups for the report.

Returns:
the group list.

getGroupCount

public int getGroupCount()
Returns the number of groups in this report.

Every report has at least one group defined.

Returns:
the group count.

getGroup

public Group getGroup(int count)
Returns the group at the specified index or null, if there is no such group.

Parameters:
count - the group index.
Returns:
the requested group.
Throws:
java.lang.IllegalArgumentException - if the count is negative.
java.lang.IndexOutOfBoundsException - if the count is greater than the number of defined groups.

getGroupByName

public Group getGroupByName(java.lang.String name)
Searches a group by its defined name. This method returns null, if the group was not found.

Parameters:
name - the name of the group.
Returns:
the group or null if not found.
See Also:
GroupList.getGroupByName(java.lang.String)

addExpression

public void addExpression(Expression function)
                   throws FunctionInitializeException
Adds a function to the report's collection of functions.

Parameters:
function - the function.
Throws:
FunctionInitializeException - if any of the functions cannot be initialized.

addFunction

public void addFunction(Function function)
                 throws FunctionInitializeException
Adds a function to the report's collection of functions.

Parameters:
function - the function.
Throws:
FunctionInitializeException - if any of the functions cannot be initialized.

getFunctions

public ExpressionCollection getFunctions()
Returns the report's collection of functions.

Returns:
the function collection.

setFunctions

public void setFunctions(ExpressionCollection functions)
Sets the function collection.

Parameters:
functions - the collection of functions.

getDefaultPageFormat

public java.awt.print.PageFormat getDefaultPageFormat()
Returns the default page format.

Returns:
the page format.

setDefaultPageFormat

public void setDefaultPageFormat(java.awt.print.PageFormat format)
Defines the default page format for this report. The default is a hint to define at least one suitable format. If no format is defined the system's default page format is used.

Parameters:
format - the default format (null permitted).

setData

public void setData(javax.swing.table.TableModel data)
Sets the data for the report.

Reports are generated from a TableModel (as used by Swing's JTable). If you don't want to give data to the report, use an empty TableModel instead of null.

Parameters:
data - the data for the report (null not permitted).

getData

public javax.swing.table.TableModel getData()
Returns the current data for this report.

Returns:
the data in form of a table model.

clone

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

Returns:
the clone.
Throws:
java.lang.CloneNotSupportedException - this should never happen.

getInfo

public static final JFreeReportInfo getInfo()
Returns information about the JFreeReport class library.

Returns:
the information.

getExpressions

public ExpressionCollection getExpressions()
Returns the expressions for the report.

Returns:
the expressions.

setExpressions

public void setExpressions(ExpressionCollection expressions)
Sets the expressions for the report.

Parameters:
expressions - the expressions (null not permitted).

getReportConfiguration

public ReportConfiguration getReportConfiguration()
Returns the report configuration.

The report configuration is automatically set up when the report is first created, and uses the global JFreeReport configuration as its parent.

Returns:
the report configuration.

getStyleSheetCollection

public StyleSheetCollection getStyleSheetCollection()
Returns the stylesheet collection of this report. The stylesheet collection is fixed for the report and all elements of the report. When a band or group is added to the report it will get registered with this stylesheet collection and cannot be used in an different report.

Returns:
the stylesheet collection of the report, never null.

getReportBuilderHints

public ReportBuilderHints getReportBuilderHints()
Returns the report builder hints collection assigned with this report. Be aware that these hints are not cloned and that during the cloning all references to this ReportBuilderHints instance get replaced by an newly created instance.

Returns:
the report builder hints.