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: * AbstractRootLevelBand.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report;
030:
031: import java.util.ArrayList;
032:
033: /**
034: * The root-level band is the container that is processed by a report-state. The root-level band processing
035: * is atomic - so either the full band is processed or not processed at all.
036: *
037: * @author Thomas Morgner
038: */
039: public abstract class AbstractRootLevelBand extends Band implements
040: RootLevelBand {
041: /**
042: * A empty array. (For performance reasons.)
043: */
044: private static final SubReport[] EMPTY_SUBREPORTS = new SubReport[0];
045: /**
046: * The list of follow-up root-level sub-reports.
047: */
048: private ArrayList subReports;
049:
050: /**
051: * Constructs a new band (initially empty).
052: */
053: protected AbstractRootLevelBand() {
054: }
055:
056: /**
057: * Constructs a new band with the given pagebreak attributes. Pagebreak
058: * attributes have no effect on subbands.
059: *
060: * @param pagebreakAfter defines, whether a pagebreak should be done after
061: * that band was printed.
062: * @param pagebreakBefore defines, whether a pagebreak should be done before
063: * that band gets printed.
064: */
065: protected AbstractRootLevelBand(final boolean pagebreakBefore,
066: final boolean pagebreakAfter) {
067: super (pagebreakBefore, pagebreakAfter);
068: }
069:
070: /**
071: * Assigns the report definition. Don't play with that function, unless you
072: * know what you are doing. You might get burned.
073: *
074: * @param reportDefinition the report definition.
075: */
076: public void setReportDefinition(
077: final ReportDefinition reportDefinition) {
078: super .setReportDefinition(reportDefinition);
079: }
080:
081: /**
082: * Returns the number of subreports attached to this root level band.
083: *
084: * @return the number of subreports.
085: */
086: public int getSubReportCount() {
087: if (subReports == null) {
088: return 0;
089: }
090: return subReports.size();
091: }
092:
093: /**
094: * Clones this band and all elements contained in this band. After the cloning
095: * the band is no longer connected to a report definition.
096: *
097: * @return the clone of this band.
098: *
099: * @throws CloneNotSupportedException if this band or an element contained in
100: * this band does not support cloning.
101: */
102: public Object clone() throws CloneNotSupportedException {
103: final AbstractRootLevelBand rootLevelBand = (AbstractRootLevelBand) super
104: .clone();
105: if (rootLevelBand.subReports != null) {
106: rootLevelBand.subReports.clone();
107: }
108: return rootLevelBand;
109: }
110:
111: /**
112: * Returns the subreport at the given index-position.
113: *
114: * @param index the index
115: * @return the subreport stored at the given index.
116: *
117: * @throws IndexOutOfBoundsException if there is no such subreport.
118: */
119: public SubReport getSubReport(final int index) {
120: if (subReports == null) {
121: throw new IndexOutOfBoundsException();
122: }
123: return (SubReport) subReports.get(index);
124: }
125:
126: /**
127: * Attaches a new subreport at the end of the list.
128: *
129: * @param report the subreport, never null.
130: */
131: public void addSubReport(final SubReport report) {
132: if (report == null) {
133: throw new NullPointerException(
134: "Parameter 'report' must not be null");
135: }
136:
137: if (subReports == null) {
138: subReports = new ArrayList();
139: }
140: subReports.add(report);
141: }
142:
143: /**
144: * Removes the given subreport from the list of attached sub-reports.
145: *
146: * @param report the subreport to be removed.
147: */
148: public void removeSubreport(final SubReport report) {
149: if (report == null) {
150: throw new NullPointerException(
151: "Parameter 'report' must not be null");
152: }
153: if (subReports == null) {
154: return;
155: }
156: subReports.remove(report);
157: }
158:
159: /**
160: * Returns all sub-reports as array.
161: *
162: * @return the sub-reports as array.
163: */
164: public SubReport[] getSubReports() {
165: if (subReports == null) {
166: return EMPTY_SUBREPORTS;
167: }
168: return (SubReport[]) subReports
169: .toArray(new SubReport[subReports.size()]);
170: }
171: }
|