001: /**
002: * ===========================================
003: * JFreeReport : a free Java reporting library
004: * ===========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * PageHeader.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report;
030:
031: import org.jfree.report.style.BandStyleKeys;
032:
033: /**
034: * A report band used to print information at the top of every page in the report. The page header is the first band
035: * that is printed on each page. There is an option to suppress the page header on the first page and the last page of
036: * the report (this is often useful if you are using a report header and/or report footer). If the header is marked
037: * sticky, the header will even be printed for all sub-report pages.
038: * <p/>
039: * A page header or footer cannot have subreports.
040: *
041: * @author David Gilbert
042: */
043: public class PageHeader extends Band implements RootLevelBand {
044: /** A helper array to prevent unnecessary object creation. */
045: private static final SubReport[] EMPTY_SUB_REPORTS = new SubReport[0];
046:
047: /**
048: * Constructs a page header.
049: */
050: public PageHeader() {
051: }
052:
053: /**
054: * Constructs a page footer containing no elements.
055: *
056: * @param onFirstPage defines, whether the page header will be printed on the first page
057: * @param onLastPage defines, whether the page footer will be printed on the last page.
058: */
059: public PageHeader(final boolean onFirstPage,
060: final boolean onLastPage) {
061: super ();
062: setDisplayOnFirstPage(onFirstPage);
063: setDisplayOnLastPage(onLastPage);
064: }
065:
066: /**
067: * Returns true if the header should be shown on page 1, and false otherwise.
068: *
069: * @return true or false.
070: */
071: public boolean isDisplayOnFirstPage() {
072: return getStyle().getBooleanStyleProperty(
073: BandStyleKeys.DISPLAY_ON_FIRSTPAGE);
074: }
075:
076: /**
077: * Defines whether the header should be shown on the first page.
078: *
079: * @param b a flag indicating whether or not the header is shown on the first page.
080: */
081: public void setDisplayOnFirstPage(final boolean b) {
082: getStyle().setBooleanStyleProperty(
083: BandStyleKeys.DISPLAY_ON_FIRSTPAGE, b);
084: }
085:
086: /**
087: * Returns true if the header should be shown on the last page, and false otherwise.
088: *
089: * @return true or false.
090: */
091: public boolean isDisplayOnLastPage() {
092: return getStyle().getBooleanStyleProperty(
093: BandStyleKeys.DISPLAY_ON_LASTPAGE);
094: }
095:
096: /**
097: * Defines whether the header should be shown on the last page.
098: *
099: * @param b a flag indicating whether or not the header is shown on the last page.
100: */
101: public void setDisplayOnLastPage(final boolean b) {
102: getStyle().setBooleanStyleProperty(
103: BandStyleKeys.DISPLAY_ON_LASTPAGE, b);
104: }
105:
106: /**
107: * Assigns the report definition. Don't play with that function, unless you know what you are doing. You might get
108: * burned.
109: *
110: * @param reportDefinition the report definition.
111: */
112: public void setReportDefinition(
113: final ReportDefinition reportDefinition) {
114: super .setReportDefinition(reportDefinition);
115: }
116:
117: /**
118: * Returns the number of subreports on this band. This returns zero, as page-bands cannot have subreports.
119: *
120: * @return the subreport count.
121: */
122: public final int getSubReportCount() {
123: return 0;
124: }
125:
126: /**
127: * Throws an IndexOutOfBoundsException as page-footer cannot have sub-reports.
128: *
129: * @param index the index.
130: * @return nothing, as an exception is thrown instead.
131: */
132: public final SubReport getSubReport(final int index) {
133: throw new IndexOutOfBoundsException(
134: "PageHeader cannot have subreports");
135: }
136:
137: /**
138: * Returns true if the footer should be shown on all subreports.
139: *
140: * @return true or false.
141: */
142: public boolean isSticky() {
143: return getStyle().getBooleanStyleProperty(BandStyleKeys.STICKY,
144: false);
145: }
146:
147: /**
148: * Defines whether the footer should be shown on all subreports.
149: *
150: * @param b a flag indicating whether or not the footer is shown on the first page.
151: */
152: public void setSticky(final boolean b) {
153: getStyle().setBooleanStyleProperty(BandStyleKeys.STICKY, b);
154: }
155:
156: /**
157: * Returns an empty array, as page-footer cannot have subreports.
158: *
159: * @return the sub-reports as array.
160: */
161: public SubReport[] getSubReports() {
162: return EMPTY_SUB_REPORTS;
163: }
164: }
|