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

📄 simplepagelayouter.java

📁 swing编写的库存管理程序。毕业设计类
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/**
 * ========================================
 * JFreeReport : a free Java report library
 * ========================================
 *
 * Project Info:  http://www.jfree.org/jfreereport/index.html
 * Project Lead:  Thomas Morgner;
 *
 * (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.
 *
 * -----------------------
 * SimplePageLayouter.java
 * -----------------------
 * (C)opyright 2002, 2003, by Thomas Morgner and Contributors.
 *
 * Original Author:  Thomas Morgner;
 * Contributor(s):   David Gilbert (for Simba Management Limited);
 *
 * $Id: SimplePageLayouter.java,v 1.13.2.1 2003/12/21 23:28:45 taqua Exp $
 *
 * Changes
 * -------
 * 05-Dec-2002 : Updated Javadocs (DG);
 * 07-Dec-2002 : Removed manual-pagebreak flag, was a left-over. PageFinished
 *               did not query the DISPLAY_ON_FIRSTPAGE flag.
 * 12-Dec-2002 : Layouting Fix    I: Layouting failed for non-absolute band elements if no
 *               absolute positioned elements were defined.
 * 18-Dec-2002 : Layouting Fix  II: PageFooter on own page failed
 * 07-Jan-2003 : Layouting Fix III: Limited max band height to the available space of a single page
 * 08-Jan-2003 : Layouting Fix IIa: PageFooter fix fix
 * 27-Jan-2003 : BugFix: printing empty bands caused a commit spooled operations
 * 01-Feb-2003 : Layouting moved into BandLayoutManagerUtil (Common code)
 */

package org.jfree.report.modules.output.pageable.base.pagelayout;

import java.awt.geom.Rectangle2D;

import org.jfree.report.Band;
import org.jfree.report.Group;
import org.jfree.report.ReportDefinition;
import org.jfree.report.ReportProcessingException;
import org.jfree.report.event.PrepareEventListener;
import org.jfree.report.event.ReportEvent;
import org.jfree.report.function.Expression;
import org.jfree.report.function.FunctionProcessingException;
import org.jfree.report.layout.BandLayoutManagerUtil;
import org.jfree.report.modules.output.pageable.base.LogicalPage;
import org.jfree.report.modules.output.pageable.base.OutputTargetException;
import org.jfree.report.modules.output.pageable.base.Spool;
import org.jfree.report.modules.output.support.pagelayout.SimplePageLayoutDelegate;
import org.jfree.report.modules.output.support.pagelayout.SimplePageLayoutWorker;
import org.jfree.report.states.ReportState;
import org.jfree.report.style.BandStyleSheet;

/**
 * A simple page layouter.  This class replicates the 'old' behaviour of JFreeReport,
 * simple and straightforward.
 * <p>
 * Layout Constraints used:
 * <ul>
 * <li>PageHeader, PageFooter: BandStyleSheet.DISPLAY_ON_FIRST_PAGE
 * <p>Defines whether a PageHeader or ~footer should be printed on the first page.</p>
 * <li>PageHeader, PageFooter: BandStyleSheet.DISPLAY_ON_LAST_PAGE
 * <p>Defines whether a PageHeader or ~footer should be printed on the last page.
 * A warning: For the PageHeader this works only if the ReportFooter has a pagebreak
 * before printing.
 * </p>
 * <li>GroupHeader: BandStyleSheet.REPEAT_HEADER
 * <p>Defines whether this GroupHeader should be repeated on every page as long as this
 * group is active</p>
 * <li>All Bands: BandStyleSheet.PAGEBREAK_BEFORE, BandStyleSheet.PAGEBREAK_AFTER
 * <p>defines whether to start a new page before the band is printed or after the
 * band is printed. This request is ignored, if the current page is empty (not counting
 * the PageHeader and the repeating GroupHeader).</p>
 * </ul>
 *
 * @author Thomas Morgner
 */
public strictfp class SimplePageLayouter extends PageLayouter
    implements PrepareEventListener, SimplePageLayoutWorker
{
  /**
   * Represents the current state of the page layouter.
   */
  protected static class SimpleLayoutManagerState extends PageLayouter.LayoutManagerState
  {
    /** The band. */
    private final Object bandID;

    /**
     * Creates a new state.  The band can be <code>null</code> if there is no band to be printed
     * on the next page.
     *
     * @param bandID  the band.
     */
    public SimpleLayoutManagerState(final Object bandID)
    {
      this.bandID = bandID;
    }

    /**
     * Returns the band.
     *
     * @return the band.
     */
    public Object getBandID()
    {
      return bandID;
    }

    /**
     * Returns a string describing the object.
     *
     * @return The string.
     */
    public String toString()
    {
      return "State={" + bandID + "}";
    }
  }

  /**
   * A flag value indicating that the current page should be finished,
   * regardless of the current state or fill level.
   */
  private static final boolean ENDPAGE_FORCED = true;

  /**
   * A flag value indicating, that the current page should be finished,
   * if it contains printed content. Spooled content is not considered
   * to be printed.
   */
  private static final boolean ENDPAGE_REQUESTED = false;

  /** A flag that indicates that the current pagebreak will be the last one. */
  private boolean isLastPageBreak;

  /**
   * A flag which indicates that a new page should be started before the next band
   * is printed. Bool-or this flag with PageBreakBefore ...
   */
  private boolean startNewPage;

  /** The cursor used by the layouter. */
  private SimplePageLayoutCursor cursor;

  /** The current state. */
  private SimpleLayoutManagerState state;
  /** The delegate which is used to perform the layouting. */
  private SimplePageLayoutDelegate delegate;

  /** The spool. */
  private Spool spooledBand;

  /**
   * Creates a new page layouter.
   */
  public SimplePageLayouter()
  {
    setName("Layout");
    delegate = new SimplePageLayoutDelegate(this);
  }

  /**
   * Reinitialize the cursor of the layout worker. Called when
   * a new page is started.
   */
  public void resetCursor()
  {
    setCursor(new SimplePageLayoutCursor(getLogicalPage().getHeight()));
  }

  /**
   * Returns the current position of the cursor. 
   * 
   * @return the cursor position.
   */
  public float getCursorPosition()
  {
    if (getCursor() == null)
    {
      throw new IllegalStateException("Cursor is not initialized.");
    }
    return getCursor().getY();
  }

  /**
   * Defines the reserved space on the current page. 
   *  
   * @param reserved the reserved space.
   */
  public void setReservedSpace(final float reserved)
  {
    if (getCursor() == null)
    {
      throw new IllegalStateException("Cursor is not initialized.");
    }
    getCursor().setReservedSpace(reserved);
  }

  /**
   * Returns the reserved space on the current page. 
   *  
   * @return the reserved space.
   */
  public float getReservedSpace()
  {
    if (getCursor() == null)
    {
      throw new IllegalStateException("Cursor is not initialized.");
    }
    return getCursor().getReservedSpace();
  }

  /**
   * Marks the position of the first content after the page header.
   * This can be used to limit the maximum size of bands so that they
   * do not exceed the available page space.
   * <p>
   * This feature will be obsolete when bands can span multiple pages.
   *
   * @param topContentPosition the first content position.
   */
  public void setTopPageContentPosition(final float topContentPosition)
  {
    if (getCursor() == null)
    {
      throw new IllegalStateException("Cursor is not initialized.");
    }
    getCursor().setPageTop(topContentPosition);
  }

  /**
   * Returns the position of the first content.
   * @return the first content position.
   */
  public float getTopContentPosition()
  {
    if (getCursor() == null)
    {
      throw new IllegalStateException("Cursor is not initialized.");
    }
    return getCursor().getPageTop();
  }

  /**
   * Checks, whether the current page is empty. 
   * 
   * @return true, if the current page is empty, false otherwise.
   */
  public boolean isPageEmpty()
  {
    return getLogicalPage().isEmpty();
  }

  /**
   * Receives notification that the report has started. Also invokes the
   * start of the first page ...
   * <P>
   * Layout and draw the report header after the PageStartEvent was fired.
   *
   * @param event  the event.
   */
  public void reportStarted(final ReportEvent event)
  {
    // activating this state after the page has ended is invalid.
    if (isPageEnded())
    {
      throw new IllegalStateException();
    }
    setCurrentEvent(event);
    try
    {
      delegate.reportStarted(event);
    }
    catch (FunctionProcessingException fe)
    {
      throw fe;
    }
    catch (Exception e)
    {
      throw new FunctionProcessingException("ReportStarted failed", e);
    }
    finally
    {
      clearCurrentEvent();
    }
  }

  /**
   * Receives notification that a group of item bands has been completed.
   * <P>
   * The itemBand is finished, the report starts to close open groups.
   *
   * @param event The event.
   */
  public void itemsFinished(final ReportEvent event)
  {
    setCurrentEvent(event);
    delegate.itemsFinished(event);
    clearCurrentEvent();
  }

  /**
   * Receives notification that report generation has completed, the report footer was printed,
   * no more output is done. This is a helper event to shut down the output service.
   *
   * @param event The event.
   */
  public void reportDone(final ReportEvent event)
  {
    // activating this state after the page has ended is invalid.
    if (isPageEnded())
    {
      throw new IllegalStateException("AssertationFailed: Page ended.");
    }
    try
    {
      setCurrentEvent(event);
      restartPage();
      createSaveState(null);
      saveCurrentState();

      endPage(ENDPAGE_FORCED);
    }
    catch (Exception e)
    {
      throw new FunctionProcessingException("ReportDone", e);
    }
    finally
    {
      clearCurrentEvent();
    }
  }

  /**
   * Receives notification that a group of item bands is about to be processed.
   * <P>
   * The next events will be itemsAdvanced events until the itemsFinished event is raised.
   *
   * @param event The event.
   */
  public void itemsStarted(final ReportEvent event)
  {
    setCurrentEvent(event);
    delegate.itemsStarted(event);
    clearCurrentEvent();
  }

  /**
   * 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

⌨️ 快捷键说明

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