⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jfreereport.java

📁 swing编写的库存管理程序。毕业设计类
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**
 * ========================================
 * JFreeReport : a free Java report library
 * ========================================
 *
 * Project Info:  http://www.jfree.org/jfreereport/index.html
 * Project Lead:  Thomas Morgner;
 *
 * (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
 *
 * This library is free software; you can redistribute it and/or modify it under the terms
 * of the GNU Lesser General Public License as published by the Free Software Foundation;
 * either version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this
 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * ----------------
 * JFreeReport.java
 * ----------------
 * (C)opyright 2000-2003, by Object Refinery Limited and Contributors.
 *
 * Original Author:  David Gilbert (for Object Refinery Limited);
 * Contributor(s):   Thomas Morgner;
 *
 * $Id: JFreeReport.java,v 1.7.2.1 2003/12/21 23:28:44 taqua Exp $
 *
 * Changes (from 8-Feb-2002)
 * -------------------------
 * 08-Feb-2002 : Updated code to work with latest version of the JCommon class library (DG);
 * 04-Mar-2002 : Major changes to report engine to incorporate functions and different output
 *               targets (DG);
 * 24-Apr-2002 : ItemBand and Groups are Optional Elements, default Elements are created as needed
 * 01-May-2002 : Renamed addProperty to setProperty to create consistent naming among other
 *               property uses.
 * 07-May-2002 : Fixed bug where last row of data is left off the report if it is alone in a
 *               group, reported by Steven Feinstein (DG);
 * 10-May-2002 : Rewrote report-processing. All reportstate-changes are handled by ReportState
 *               Objects. Created AccessorMethods for Properties. (TM)
 * 11-May-2002 : All bands have to be initialized. Null is no longer allowed for pageHeader,
 *               pageFooter, reportHeader, reportFooter, itemBand, functionCollection.
 * 17-May-2002 : Fixed reportPropertyInitialisation and checked if the report is proceeding on
 *               print.
 * 26-May-2002 : Changed repagination behaviour. Reports are repaginated before printed, so that
 *               global initialisations can be done.
 * 05-Jun-2002 : Updated Javadoc comments (DG);
 * 08-Jun-2002 : The defaultPageFormat is now always filled (and used in PreviewFrame)
 * 19-Jun-2002 : more documentation
 * 03-Jul-2002 : Serializable and cloneable, Removed JFreeReportInfo field, it disrupts the
 *               serializable process
 * 26-Jul-2002 : Removed method "isLastItemInHigherGroups()". The same functionality is implemented
 *               in Group.isLastItemInGroup()
 * 05-Dec-2002 : Updated Javadocs (DG);
 * 03-Jan-2003 : More Javadocs (DG);
 * 05-Feb-2003 : Fixed serialisation problem
 */

package org.jfree.report;

import java.awt.print.PageFormat;
import java.awt.print.PrinterJob;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Iterator;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

import org.jfree.report.function.Expression;
import org.jfree.report.function.ExpressionCollection;
import org.jfree.report.function.Function;
import org.jfree.report.function.FunctionInitializeException;
import org.jfree.report.style.StyleSheetCollection;
import org.jfree.report.util.ReportConfiguration;
import org.jfree.report.util.ReportProperties;
import org.jfree.report.util.SerializerHelper;

/**
 * This class co-ordinates the process of generating a report from a <code>TableModel</code>.
 * The report is made up of 'bands', which are used repeatedly as necessary to generate small
 * sections of the report.
 * <p>
 * Accessing the bands and the elements:
 * <p>
 * The different bands can be accessed using the main report definition (this class):
 * <ul>
 * <li>the report header and footer can be reached by using
 *     <code>getReportHeader()</code> and <code>getReportFooter()</code>
 * <li>the page header and page footer can be reached by using
 *     <code>getPageHeader()</code> and <code>getPageFooter()</code>
 * <li>the item band is reachable with <code>getItemBand()</code>
 * </ul>
 *
 * Groups can be queried using <code>getGroup(int groupLevel)</code>.  The group header and
 * footer are accessible through the group object, so use
 * <code>getGroup(int groupLevel).getGroupHeader()<code> and
 * <code>getGroup(int groupLevel).getGroupFooter()<code>.
 * <p>
 * Elements on a band can be reached by using <code>Band.getElement (String elementName)</code>
 * or by retrieving all elements using <code>Band.getElements()</code> and performing a search on
 * the returned list.
 * <p>
 * All report elements share the same stylesheet collection. Report elements
 * cannot be shared between two different report instances.
 *
 * @author David Gilbert
 * @author Thomas Morgner
 */
public class JFreeReport implements Cloneable, Serializable
{

  /** Key for the 'report name' property. */
  public static final String NAME_PROPERTY = "report.name";

  /** Key for the 'report date' property. */
  public static final String REPORT_DATE_PROPERTY = "report.date";

  /** Key for the 'report page format' property. */
  public static final String REPORT_PAGEFORMAT_PROPERTY = "report.pageformat";

  /** Key for the 'report prepare run' property. */
  public static final String REPORT_PREPARERUN_PROPERTY = "report.preparerun";

  /** Key for the 'report definition source' property. */
  public static final String REPORT_DEFINITION_SOURCE = "report.definition.source";

  /** Key for the 'report definition content base' property. */
  public static final String REPORT_DEFINITION_CONTENTBASE = "report.definition.contentbase";

  /** Information about the JFreeReport class library. */
  private static JFreeReportInfo info;

  /** The table model containing the data for the report. */
  private TableModel data;

  /** The page format for the report (determines the page size, and therefore the report width). */
  private transient PageFormat defaultPageFormat;

  /** Storage for arbitrary properties that a user can assign to the report. */
  private ReportProperties properties;

  /** Storage for the functions in the report. */
  private ExpressionCollection functions;

  /** Storage for the expressions in the report. */
  private ExpressionCollection expressions;

  /** An ordered list of report groups (each group defines its own header and footer). */
  private GroupList groups;

  /** The report header band (if not null, printed once at the start of the report). */
  private ReportHeader reportHeader;

  /** The report footer band (if not null, printed once at the end of the report). */
  private ReportFooter reportFooter;

  /** The page header band (if not null, printed at the start of every page). */
  private PageHeader pageHeader;

  /** The page footer band (if not null, printed at the end of every page). */
  private PageFooter pageFooter;

  /** The item band - used once for each row of data. */
  private ItemBand itemBand;

  /** The watermark band. */
  private Watermark watermark;

  /** The report configuration. */
  private final ReportConfiguration reportConfiguration;

  /** The stylesheet collection used for this report. */
  private StyleSheetCollection styleSheetCollection;

  /**
   * The report builder hints support writer and other report definition
   * processing tools by spicing up the report object with specific properties.
   * ReportBuilderHints do not get cloned and are removed from the clone.
   */
  private ReportBuilderHints reportBuilderHints;

  /**
   * The default constructor. Creates an empty but fully initialized report.
   */
  public JFreeReport()
  {
    this.reportConfiguration = new ReportConfiguration(ReportConfiguration.getGlobalConfig());
    this.properties = new ReportProperties();
    this.styleSheetCollection = new StyleSheetCollection();
    this.reportBuilderHints = new ReportBuilderHints();

    this.groups = new GroupList();
    checkGroups();
    this.groups.registerStyleSheetCollection(this.styleSheetCollection);

    this.reportHeader = new ReportHeader();
    this.reportHeader.registerStyleSheetCollection(this.styleSheetCollection);
    this.reportFooter = new ReportFooter();
    this.reportFooter.registerStyleSheetCollection(this.styleSheetCollection);
    this.pageHeader = new PageHeader();
    this.pageHeader.registerStyleSheetCollection(this.styleSheetCollection);
    this.pageFooter = new PageFooter();
    this.pageFooter.registerStyleSheetCollection(this.styleSheetCollection);
    this.itemBand = new ItemBand();
    this.itemBand.registerStyleSheetCollection(this.styleSheetCollection);
    this.watermark = new Watermark();
    this.watermark.registerStyleSheetCollection(this.styleSheetCollection);

    this.data = new DefaultTableModel();
    this.functions = new ExpressionCollection();
    this.expressions = new ExpressionCollection();
    setDefaultPageFormat(null);
  }

  /**
   * Returns the name of the report.
   * <p>
   * You can reference the report name in your XML report template file using the key
   * '<code>report.name</code>'.
   *
   * @return the name.
   */
  public String getName()
  {
    final Object name = getProperty(NAME_PROPERTY);
    return String.valueOf(name);
  }

  /**
   * Sets the name of the report.
   * <P>
   * The report name is stored as a property (key: <code>NAME_PROPERTY = "report.name"</code>) of
   * the report.  If you supply <code>null</code> as the name, the property is removed.
   *
   * @param name  the name of the report.
   */
  public void setName(final String name)
  {
    setProperty(NAME_PROPERTY, name);
  }

  /**
   * Adds a property to the report. If a property with the given name
   * already exists, the property will be updated with the new value. If the
   * supplied value is <code>null</code>, the property will be removed.
   * <P>
   * Developers are free to add any properties they want to a report, and then display those
   * properties in the report.  For example, you might add a 'user.name' property, so that you
   * can display the username in the header of a report.
   *
   * @param key  the key.
   * @param value  the value.
   */
  public void setProperty(final String key, final Object value)
  {
    this.properties.put(key, value);
  }

  /**
   * Returns the report properties collection for this report.
   * <p>
   * These properties are inherited to all ReportStates generated for this report.
   *
   * @return the report properties.
   */
  public ReportProperties getProperties()
  {
    return properties;
  }

  /**
   * Returns the value of the property with the specified key.
   *
   * @param key  the key.
   *
   * @return the property value.
   */
  public Object getProperty(final String key)
  {
    if (key == null)
    {
      throw new NullPointerException();
    }
    return this.properties.get(key);
  }

  /**
   * Returns the value of the property with the specified key.
   *
   * @param key  the key.
   *
   * @return the property value.
   */
  public boolean isPropertyMarked(final String key)
  {
    return this.properties.isMarked(key);
  }

  /**
   * Returns the value of the property with the specified key.
   *
   * @param key  the key.
   * @param mark the new marking flag
   */
  public void setPropertyMarked(final String key, final boolean mark)
  {
    this.properties.setMarked(key, mark);
  }

  /**
   * Sets the report header.
   *
   * @param header  the report header (<code>null</code> not permitted).
   */
  public void setReportHeader(final ReportHeader header)
  {
    if (header == null)
    {
      throw new NullPointerException("JFreeReport.setReportHeader(...) : null not permitted.");
    }

    this.reportHeader.unregisterStyleSheetCollection(getStyleSheetCollection());
    this.reportHeader = header;
    this.reportHeader.registerStyleSheetCollection(getStyleSheetCollection());
  }

  /**
   * Returns the report header.
   *
   * @return the report header (never <code>null</code>).
   */
  public ReportHeader getReportHeader()
  {
    return reportHeader;
  }

  /**
   * Sets the report footer.
   *
   * @param footer  the report footer (<code>null</code> not permitted).
   */
  public void setReportFooter(final ReportFooter footer)
  {
    if (footer == null)
    {
      throw new NullPointerException("JFreeReport.setReportFooter(...) : null not permitted.");
    }

    this.reportFooter.unregisterStyleSheetCollection(getStyleSheetCollection());
    this.reportFooter = footer;
    this.reportFooter.registerStyleSheetCollection(getStyleSheetCollection());
  }

  /**
   * Returns the page footer.
   *
   * @return the report footer (never <code>null</code>).
   */
  public ReportFooter getReportFooter()
  {
    return reportFooter;
  }

  /**
   * Sets the page header.
   *
   * @param header  the page header (<code>null</code> not permitted).
   */
  public void setPageHeader(final PageHeader header)
  {
    if (header == null)
    {
      throw new NullPointerException("JFreeReport.setPageHeader(...) : null not permitted.");
    }

    this.pageHeader.unregisterStyleSheetCollection(getStyleSheetCollection());
    this.pageHeader = header;
    this.pageHeader.registerStyleSheetCollection(getStyleSheetCollection());
  }

  /**
   * Returns the page header.
   *
   * @return the page header (never <code>null</code>).
   */
  public PageHeader getPageHeader()
  {
    return pageHeader;
  }

  /**
   * Sets the page footer.
   *
   * @param footer  the page footer (<code>null</code> not permitted).
   */
  public void setPageFooter(final PageFooter footer)
  {
    if (footer == null)
    {
      throw new NullPointerException("JFreeReport.setPageFooter(...) : null not permitted.");
    }

    this.pageFooter.unregisterStyleSheetCollection(getStyleSheetCollection());
    this.pageFooter = footer;
    this.pageFooter.registerStyleSheetCollection(getStyleSheetCollection());
  }

  /**
   * Returns the page footer.
   *
   * @return the page footer (never <code>null</code>).
   */
  public PageFooter getPageFooter()
  {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -