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

📄 simplepagelayoutdelegate.java

📁 swing编写的库存管理程序。毕业设计类
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**
 * ========================================
 * JFreeReport : a free Java report library
 * ========================================
 *
 * Project Info:  http://www.jfree.org/jfreereport/index.html
 * Project Lead:  Thomas Morgner (taquera@sherito.org);
 *
 * (C) Copyright 2000-2003, by Simba Management 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.
 *
 * ------------------------------
 * SimplePageLayoutDelegate.java
 * ------------------------------
 * (C)opyright 2003, by Thomas Morgner and Contributors.
 *
 * Original Author:  Thomas Morgner;
 * Contributor(s):   David Gilbert (for Simba Management Limited);
 *
 * $Id: SimplePageLayoutDelegate.java,v 1.6.2.1 2003/12/21 23:28:45 taqua Exp $
 *
 * Changes
 * -------------------------
 * 26.09.2003 : Initial version
 *
 */

package org.jfree.report.modules.output.support.pagelayout;

import java.io.Serializable;

import org.jfree.report.Band;
import org.jfree.report.Group;
import org.jfree.report.JFreeReport;
import org.jfree.report.ReportDefinition;
import org.jfree.report.ReportProcessingException;
import org.jfree.report.event.PageEventListener;
import org.jfree.report.event.ReportEvent;
import org.jfree.report.event.ReportListener;
import org.jfree.report.function.FunctionProcessingException;
import org.jfree.report.style.BandStyleSheet;

/**
 * The simple page layout delegate encasulates all required tasks to perform
 * a plain top-to-bottom pagelayouting. It gets fed with report states and 
 * will perform all necessary steps to prepare the content generation. The
 * final printing is done in the simple page layout worker (in most cases
 * the report processor function).
 * 
 * @author Thomas Morgner
 */
public class SimplePageLayoutDelegate implements
    PageEventListener, ReportListener, Cloneable, Serializable
{
  /** The pagelayout worker which performs the final printing. */ 
  private SimplePageLayoutWorker worker;

  /** small carrier class to transport the maximum page number for this report. */
  private static final class PageCarrier
  {
    /** stores the last page number of the report processing. */
    private int maxPages;
    
    /** DefaultConstructor. */
    public PageCarrier ()
    {
    }
    /**
     * Returns the maximum page number.
     * @return the maximum page.
     */
    public int getMaxPages ()
    {
      return maxPages;
    }
    
    /**
     * Defines the maximum page number.
     * @param pages the maximum page.
     */
    public void setMaxPages (int pages)
    {
      maxPages = pages;
    } 
  }

  /** the page carrier for this pagelayouter contains the number of the last page. */
  private final PageCarrier pageCarrier;

  /** A flag indicating whether the next pagebreak will be the last one. */
  private boolean lastPagebreak;
  /** The current group index (used to select the correct group header and footer).*/
  private int currentEffectiveGroupIndex;
  private boolean groupFinishPending;

  /**
   * DefaultConstructor. A worker needs to be assigned to use this delegate.
   *
   * @param worker the worker.
   */
  public SimplePageLayoutDelegate(final SimplePageLayoutWorker worker)
  {
    pageCarrier = new PageCarrier();
    setWorker(worker);
  }


  /**
   * Creates and returns a copy of this object.
   *
   * @return     a clone of this instance.
   * @exception  CloneNotSupportedException  if the object's class does not
   *               support the <code>Cloneable</code> interface. Subclasses
   *               that override the <code>clone</code> method can also
   *               throw this exception to indicate that an instance cannot
   *               be cloned.
   * @exception  OutOfMemoryError            if there is not enough memory.
   * @see        Cloneable
   */
  public Object clone() throws CloneNotSupportedException
  {
    return super.clone();
  }

  /**
   * Returns the simple page layout worker for this delegate.
   * 
   * @return the worker.
   */
  public SimplePageLayoutWorker getWorker()
  {
    return worker;
  }

  /**
   * Defines the simple page layout worker for this delegate.
   * 
   * @param worker the worker.
   * @throws NullPointerException if the given worker is null.
   */
  public void setWorker(final SimplePageLayoutWorker worker)
  {
    if (worker == null)
    {
      throw new NullPointerException("The given worker is null.");
    }
    this.worker = worker;
  }

  /**
   * Defines the currently effective group index. This index is used for
   * the repeating group headers feature.
   * 
   * @return the current group index.
   */
  protected int getCurrentEffectiveGroupIndex()
  {
    return currentEffectiveGroupIndex;
  }

  /**
   * Defines the currently effective group index. 
   * 
   * @param currentEffectiveGroupIndex the current group index.
   */
  protected void setCurrentEffectiveGroupIndex(final int currentEffectiveGroupIndex)
  {
    this.currentEffectiveGroupIndex = currentEffectiveGroupIndex;
  }

  /**
   * Checks, whether the next pagebreak will be the last one.
   * After that pagebreak, the report processing is completed.
   * 
   * @return true, if the last pagebreak has been reached, 
   * false otherwise
   */
  protected boolean isLastPagebreak()
  {
    return lastPagebreak;
  }

  /**
   * Defines, whether the next pagebreak will be the last one.
   * After that pagebreak, the report processing is completed.
   * 
   * @param lastPagebreak set to true, if the last pagebreak has been reached, 
   * false otherwise
   */
  protected void setLastPagebreak(final boolean lastPagebreak)
  {
    this.lastPagebreak = lastPagebreak;
  }

  /**
   * Returns the number of pages in the report (as currently known).
   * This property is filled during the pagination process and is later
   * used to support the surpression of the pageheader/footer on the last page. 
   * 
   * @return the number of pages in the report.
   */
  protected int getMaxPage()
  {
    return pageCarrier.getMaxPages();
  }

  /**
   * Defines the number of pages in the report (as currently known).
   * This property is filled during the pagination process and is later
   * used to support the surpression of the pageheader/footer on the last page. 
   * 
   * @param maxPage the number of pages in the report.
   */
  protected void setMaxPage(final int maxPage)
  {
    this.pageCarrier.setMaxPages(maxPage);
  }

  private boolean isPageHeaderPrinting (final Band b, final ReportEvent event)
  {
    if ((event.getState().getCurrentPage() == 1) &&
        (b.getStyle().getBooleanStyleProperty(BandStyleSheet.DISPLAY_ON_FIRSTPAGE) == false))
    {
      return false;
    }

    if ((event.getState().getCurrentPage() == getMaxPage()) &&
        (b.getStyle().getBooleanStyleProperty(BandStyleSheet.DISPLAY_ON_LASTPAGE) == false))
    {
      return false;
    }

    if  (isLastPagebreak() &&
        (b.getStyle().getBooleanStyleProperty(BandStyleSheet.DISPLAY_ON_LASTPAGE) == false))
    {
      return false;
    }
    return true;
  }
  
  /**
   * Receives notification that a page has started.
   * <P>
   * This prints the PageHeader. If this is the first page, the header is not
   * printed if the pageheader style-flag DISPLAY_ON_FIRSTPAGE is set to false.
   * If this event is known to be the last pageStarted event, the DISPLAY_ON_LASTPAGE
   * is evaluated and the header is printed only if this flag is set to TRUE.
   * <p>
   * If there is an active repeating GroupHeader, print the last one. The GroupHeader
   * is searched for the current group and all parent groups, starting at the
   * current group and ascending to the parents. The first goupheader that has the
   * StyleFlag REPEAT_HEADER set to TRUE is printed.
   * <p>
   * The PageHeader and the repeating GroupHeader are spooled until the first real
   * content is printed. This way, the LogicalPage remains empty until an other band
   * is printed.
   *
   * @param event Information about the event.
   */
  public void pageStarted(final ReportEvent event)
  {
    // activating this state after the page has ended is invalid.
    if (worker.isPageEnded())
    {
      throw new IllegalStateException();
    }
    try
    {
      final ReportDefinition report = event.getReport();

      final Band watermark = report.getWatermark();
      if (worker.isWatermarkSupported() && isPageHeaderPrinting(watermark, event))
      {
        // a new page has started, so reset the cursor ...
        worker.resetCursor();
        worker.printWatermark(watermark);
      }

      // after printing the watermark, we are still at the top of the page.
      worker.resetCursor();
      final Band b = report.getPageHeader();
      if (isPageHeaderPrinting(b, event))
      {
        worker.print(b, SimplePageLayoutWorker.BAND_SPOOLED,
            SimplePageLayoutWorker.PAGEBREAK_BEFORE_IGNORED);
      }

      /**
       * Repeating group header are only printed while ItemElements are
       * processed.
       */
      // was currentEffectiveGroupIndex - 1
      int groupsPrinted = getCurrentEffectiveGroupIndex();
      if (isGroupFinishPending())
      {
        groupsPrinted += 1;
      }

      for (int gidx = 0; gidx < groupsPrinted; gidx++)
      {
        final Group g = report.getGroup(gidx);
        if (g.getHeader().getStyle().getBooleanStyleProperty(BandStyleSheet.REPEAT_HEADER))
        {
          worker.print(g.getHeader(), SimplePageLayoutWorker.BAND_SPOOLED, 
            SimplePageLayoutWorker.PAGEBREAK_BEFORE_IGNORED);
        }
      }

      if (isGroupFinishPending())
      {
        // now as the group footer should get printed soon, we correct the
        // active groups ..
        setCurrentEffectiveGroupIndex(getCurrentEffectiveGroupIndex()- 1);
        setGroupFinishPending(false);
      }

⌨️ 快捷键说明

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