Source for org.jfree.report.JFreeReport

   1: /**
   2:  * ========================================
   3:  * JFreeReport : a free Java report library
   4:  * ========================================
   5:  *
   6:  * Project Info:  http://reporting.pentaho.org/
   7:  *
   8:  * (C) Copyright 2000-2007, by Object Refinery Limited, Pentaho Corporation and Contributors.
   9:  *
  10:  * This library is free software; you can redistribute it and/or modify it under the terms
  11:  * of the GNU Lesser General Public License as published by the Free Software Foundation;
  12:  * either version 2.1 of the License, or (at your option) any later version.
  13:  *
  14:  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  15:  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16:  * See the GNU Lesser General Public License for more details.
  17:  *
  18:  * You should have received a copy of the GNU Lesser General Public License along with this
  19:  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  20:  * Boston, MA 02111-1307, USA.
  21:  *
  22:  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  23:  * in the United States and other countries.]
  24:  *
  25:  * ------------
  26:  * $Id: JFreeReport.java 3525 2007-10-16 11:43:48Z tmorgner $
  27:  * ------------
  28:  * (C) Copyright 2000-2005, by Object Refinery Limited.
  29:  * (C) Copyright 2005-2007, by Pentaho Corporation.
  30:  */
  31: 
  32: package org.jfree.report;
  33: 
  34: import java.awt.print.PageFormat;
  35: import java.util.ArrayList;
  36: import java.util.Locale;
  37: import javax.swing.table.TableModel;
  38: 
  39: import org.jfree.base.config.HierarchicalConfiguration;
  40: import org.jfree.base.config.ModifiableConfiguration;
  41: import org.jfree.layouting.input.style.CSSPageRule;
  42: import org.jfree.layouting.input.style.StyleSheet;
  43: import org.jfree.layouting.input.style.StyleSheetUtility;
  44: import org.jfree.report.flow.ReportStructureRoot;
  45: import org.jfree.report.structure.ReportDefinition;
  46: import org.jfree.report.util.ReportParameters;
  47: import org.jfree.resourceloader.ResourceKey;
  48: import org.jfree.resourceloader.ResourceManager;
  49: import org.jfree.util.Configuration;
  50: 
  51: /**
  52:  * A JFreeReport instance is used as report template to define the visual layout
  53:  * of a report and to collect all data sources for the reporting. Possible data
  54:  * sources are the {@link TableModel}, {@link org.jfree.report.expressions.Expression}s
  55:  * or {@link ReportParameters}.
  56:  * <p/>
  57:  * New since 0.9: Report properties contain data. They do not contain processing
  58:  * objects (like the outputtarget) or attribute values. Report properties should
  59:  * only contains things, which are intended for printing.
  60:  * <p/>
  61:  * The report data source is no longer part of the report definition. It is an
  62:  * extra object passed over to the report processor or generated using a report
  63:  * data factory.
  64:  *
  65:  * @author David Gilbert
  66:  * @author Thomas Morgner
  67:  */
  68: public class JFreeReport extends ReportDefinition
  69:     implements ReportStructureRoot
  70: {
  71:   /**
  72:    * The report configuration.
  73:    */
  74:   private ModifiableConfiguration reportConfiguration;
  75: 
  76:   private ArrayList styleSheets;
  77:   private StyleSheet pageFormatStyleSheet;
  78:   private CSSPageRule pageRule;
  79: 
  80:   private ReportParameters parameters;
  81: 
  82:   private ReportDataFactory dataFactory;
  83: 
  84:   private ResourceManager resourceManager;
  85:   private ResourceKey baseResource;
  86: 
  87:   /**
  88:    * The default constructor. Creates an empty but fully initialized report.
  89:    */
  90:   public JFreeReport()
  91:   {
  92:     setType("report");
  93:     this.reportConfiguration = new HierarchicalConfiguration
  94:         (JFreeReportBoot.getInstance().getGlobalConfig());
  95: 
  96:     this.styleSheets = new ArrayList();
  97:     this.parameters = new ReportParameters();
  98:     this.dataFactory = new EmptyReportDataFactory();
  99: 
 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: }