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