001: /**
002: * ========================================
003: * JFreeReport : a free Java report library
004: * ========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2000-2007, by Object Refinery Limited, 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: * $Id: JFreeReport.java 3525 2007-10-16 11:43:48Z tmorgner $
027: * ------------
028: * (C) Copyright 2000-2005, by Object Refinery Limited.
029: * (C) Copyright 2005-2007, by Pentaho Corporation.
030: */package org.jfree.report;
031:
032: import java.awt.print.PageFormat;
033: import java.util.ArrayList;
034: import java.util.Locale;
035: import javax.swing.table.TableModel;
036:
037: import org.jfree.base.config.HierarchicalConfiguration;
038: import org.jfree.base.config.ModifiableConfiguration;
039: import org.jfree.layouting.input.style.CSSPageRule;
040: import org.jfree.layouting.input.style.StyleSheet;
041: import org.jfree.layouting.input.style.StyleSheetUtility;
042: import org.jfree.report.flow.ReportStructureRoot;
043: import org.jfree.report.structure.ReportDefinition;
044: import org.jfree.report.util.ReportParameters;
045: import org.jfree.resourceloader.ResourceKey;
046: import org.jfree.resourceloader.ResourceManager;
047: import org.jfree.util.Configuration;
048:
049: /**
050: * A JFreeReport instance is used as report template to define the visual layout
051: * of a report and to collect all data sources for the reporting. Possible data
052: * sources are the {@link TableModel}, {@link org.jfree.report.expressions.Expression}s
053: * or {@link ReportParameters}.
054: * <p/>
055: * New since 0.9: Report properties contain data. They do not contain processing
056: * objects (like the outputtarget) or attribute values. Report properties should
057: * only contains things, which are intended for printing.
058: * <p/>
059: * The report data source is no longer part of the report definition. It is an
060: * extra object passed over to the report processor or generated using a report
061: * data factory.
062: *
063: * @author David Gilbert
064: * @author Thomas Morgner
065: */
066: public class JFreeReport extends ReportDefinition implements
067: ReportStructureRoot {
068: /**
069: * The report configuration.
070: */
071: private ModifiableConfiguration reportConfiguration;
072:
073: private ArrayList styleSheets;
074: private StyleSheet pageFormatStyleSheet;
075: private CSSPageRule pageRule;
076:
077: private ReportParameters parameters;
078:
079: private ReportDataFactory dataFactory;
080:
081: private ResourceManager resourceManager;
082: private ResourceKey baseResource;
083:
084: /**
085: * The default constructor. Creates an empty but fully initialized report.
086: */
087: public JFreeReport() {
088: setType("report");
089: this .reportConfiguration = new HierarchicalConfiguration(
090: JFreeReportBoot.getInstance().getGlobalConfig());
091:
092: this .styleSheets = new ArrayList();
093: this .parameters = new ReportParameters();
094: this .dataFactory = new EmptyReportDataFactory();
095:
096: this .pageFormatStyleSheet = new StyleSheet();
097: this .pageRule = new CSSPageRule(pageFormatStyleSheet, null,
098: null, null);
099: this .pageFormatStyleSheet.addRule(pageRule);
100:
101: setQuery("default");
102: }
103:
104: /**
105: * Returns the report configuration.
106: * <p/>
107: * The report configuration is automatically set up when the report is first
108: * created, and uses the global JFreeReport configuration as its parent.
109: *
110: * @return the report configuration.
111: */
112: public Configuration getConfiguration() {
113: return reportConfiguration;
114: }
115:
116: public void addStyleSheet(final StyleSheet s) {
117: if (s == null) {
118: throw new NullPointerException();
119: }
120: styleSheets.add(s);
121: }
122:
123: public void removeStyleSheet(final StyleSheet s) {
124: styleSheets.remove(s);
125: }
126:
127: public StyleSheet getStyleSheet(final int i) {
128: if (i == 0) {
129: return pageFormatStyleSheet;
130: }
131: return (StyleSheet) styleSheets.get(i - 1);
132: }
133:
134: public int getStyleSheetCount() {
135: return styleSheets.size() + 1;
136: }
137:
138: public JFreeReport getRootReport() {
139: return this ;
140: }
141:
142: public ReportParameters getInputParameters() {
143: return parameters;
144: }
145:
146: public ReportDataFactory getDataFactory() {
147: return dataFactory;
148: }
149:
150: public void setDataFactory(final ReportDataFactory dataFactory) {
151: if (dataFactory == null) {
152: throw new NullPointerException();
153: }
154:
155: this .dataFactory = dataFactory;
156: }
157:
158: public ResourceManager getResourceManager() {
159: if (resourceManager == null) {
160: resourceManager = new ResourceManager();
161: resourceManager.registerDefaults();
162: }
163: return resourceManager;
164: }
165:
166: public void setResourceManager(final ResourceManager resourceManager) {
167: this .resourceManager = resourceManager;
168: }
169:
170: public ResourceKey getBaseResource() {
171: return baseResource;
172: }
173:
174: public void setBaseResource(final ResourceKey baseResource) {
175: this .baseResource = baseResource;
176: }
177:
178: public void setPageFormat(final PageFormat format) {
179: pageRule.clear();
180: StyleSheetUtility.updateRuleForPage(pageRule, format);
181: }
182:
183: public PageFormat getPageFormat() {
184: return StyleSheetUtility.getPageFormat(pageRule);
185: }
186:
187: public ModifiableConfiguration getEditableConfiguration() {
188: return reportConfiguration;
189: }
190:
191: public Locale getLocale() {
192: final Locale locale = super .getLocale();
193: if (locale == null) {
194: return Locale.getDefault();
195: }
196: return locale;
197: }
198:
199: /**
200: private ModifiableConfiguration reportConfiguration;
201:
202: private ArrayList styleSheets;
203: private StyleSheet pageFormatStyleSheet;
204: private CSSPageRule pageRule;
205:
206: private ReportParameters parameters;
207:
208: private ReportDataFactory dataFactory;
209:
210: private ResourceManager resourceManager;
211: private ResourceKey baseResource;
212: *
213: * @return
214: * @throws CloneNotSupportedException
215: */
216: public Object clone() throws CloneNotSupportedException {
217: final JFreeReport report = (JFreeReport) super .clone();
218: report.dataFactory = dataFactory.derive();
219: report.parameters = (ReportParameters) parameters.clone();
220: report.pageRule = (CSSPageRule) pageRule.clone();
221: report.styleSheets = (ArrayList) styleSheets.clone();
222: report.pageFormatStyleSheet = pageFormatStyleSheet;
223: return report;
224: }
225: }
|