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

📄 tablewriter.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 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.
 *
 * ----------------
 * TableWriter.java
 * ----------------
 * (C)opyright 2003, by Thomas Morgner and Contributors.
 *
 * Original Author:  Thomas Morgner;
 * Contributor(s):   David Gilbert (for Simba Management Limited);
 *
 * $Id: TableWriter.java,v 1.10.2.1 2003/12/21 23:28:46 taqua Exp $
 *
 * Changes
 * -------
 * 24-Jan-2003 : Initial version
 * 17-Feb-2003 : Documentation
 * 24-Feb-2003 : Fixed Checkstyle issues (DG);
 *
 */
package org.jfree.report.modules.output.table.base;

import java.awt.geom.Rectangle2D;

import org.jfree.report.Band;
import org.jfree.report.ReportProcessingException;
import org.jfree.report.event.PageEventListener;
import org.jfree.report.event.ReportEvent;
import org.jfree.report.function.AbstractFunction;
import org.jfree.report.function.Expression;
import org.jfree.report.layout.BandLayoutManagerUtil;
import org.jfree.report.layout.DefaultLayoutSupport;
import org.jfree.report.layout.LayoutSupport;
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;

/**
 * The TableWriter is the content creation function used to collect the cell data.
 * After the layouting is done, the layouted bands are forwarded to the TableProducer.
 * The virtual page has an unlimited size, only when a manual pagebreak is encountered,
 * a new page is started.
 * <p>
 * This can be used to f.i. to create separate sheets in Excel-Workbooks, the detailed
 * semantics depend on concrete implementation of the TableProducer.
 * <p>
 * This writer is not thread-safe.
 *
 * @author Thomas Morgner
 */
public strictfp class TableWriter extends AbstractFunction
    implements PageEventListener, SimplePageLayoutWorker
{
  /** A constant defining the tablewriters default function level. */
  public static final int OUTPUT_LEVEL = -1;

  /**
   * The SheetName-function property, defines the name of an StringFunction
   * that creates the sheet names.
   */
  public static final String SHEET_NAME_FUNCTION_PROPERTY =
      "org.jfree.report.targets.table.TableWriter.SheetNameFunction";

  /** The current event, stored on every call to one of the ReportListener methods. */
  private ReportEvent currentEvent;

  /** The table producer used to create the layout. */
  private TableProducer producer;

  /** the cursor pointing to the current position on the sheet. */
  private TableWriterCursor cursor;

  /** the maximum width, required for the BandLayout. */
  private float maxWidth;

  /** the dependency level for this function, usually -1. */
  private int depLevel;

  /** A flag indicating whether the writer is currently handling the end of an page. */
  private boolean inEndPage;

  /** The layout delegate used to perform the page layout. */
  private SimplePageLayoutDelegate delegate;

  /**
   * Creates a new TableWriter. The dependency level is set to -1 and the maxwidth
   * is defined to be 1000.
   */
  public TableWriter()
  {
    setDependencyLevel(OUTPUT_LEVEL);
    delegate = new SimplePageLayoutDelegate(this);
  }

  /**
   * Clones the function.
   * <P>
   * Be aware, this does not create a deep copy. If you have complex
   * strucures contained in objects, you have to override this function.
   *
   * @return a clone of this function.
   *
   * @throws CloneNotSupportedException this should never happen.
   */
  public Object clone() throws CloneNotSupportedException
  {
    final TableWriter clone = (TableWriter) super.clone();
    clone.delegate = (SimplePageLayoutDelegate) delegate.clone();
    clone.delegate.setWorker(clone);
    return clone;
  }

  /**
   * Return a completly separated copy of this function. The copy does no
   * longer share any changeable objects with the original function.
   *
   * @return a copy of this function.
   */
  public Expression getInstance()
  {
    final TableWriter tw = (TableWriter) super.getInstance();
    tw.delegate = new SimplePageLayoutDelegate(tw);
    return tw;
  }

  /**
   * Checks, whether the current page is empty. An page is empty if it does
   * not contain printed content. An empty page may have spooled content.
   * 
   * @return true, if the page is empty, false otherwise.
   */
  public boolean isPageEmpty()
  {
    if (producer == null)
    {
      throw new IllegalStateException("Producer is null." + toString());
    }
    return producer.isLayoutContainsContent();
  }

  /**
   * Returns the position of the first content. As this writer does not limit
   * the height of the bands, this method returns 0.
   * 
   * @return the first content position.
   */
  public float getTopContentPosition()
  {
    return 0;
  }

  /**
   * This writer does not limit the height of an band and therefore does
   * not implement that feature.
   *
   * @param topPosition the first usable position to print content.
   */
  public void setTopPageContentPosition(final float topPosition)
  {
  }

  /**
   * Returns the reserved size for the current page. This size is not used
   * when performing a layout. This is usually used to preserve the pagefooters
   * space.  As this writer does not limit the height of the bands, this method 
   * returns 0.
   * 
   * @return the reserved page height.
   */
  public float getReservedSpace()
  {
    return 0;
  }

  /**
   * Defines the reserved size for the current page. This size is not used
   * when performing a layout. 
   * <p>
   * This method does nothing.
   * 
   * @param reserved the reserved page height.
   */
  public void setReservedSpace(final float reserved)
  {
  }

  /**
   * Returns the current cursor position. It is assumed, that the cursor goes
   * from top to down, columns are not used.
   * 
   * @return the cursor position.
   */
  public float getCursorPosition()
  {
    return getCursor().getY();
  }

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

  /**
   * Checks, whether the page has ended. Once a page that is completly filled,
   * only the page footer will be printed and a page break will be done after
   * that.
   * <p>
   * As this target has no notion of pages, the virtual page does never end 
   * automaticly.
   * 
   * @return true, if the page is finished, false otherwise.
   */
  public boolean isPageEnded()
  {
    return false;
  }

  /**
   * Prints the given band at the bottom of the page.
   * <p>
   * As we don't use the idea of pages here, this call is mapped to the
   * print method.
   * 
   * @param band the band.
   * @return true, if the band was printed successfully, false otherwise.
   * @throws ReportProcessingException if an exception occured while processing
   * the band.
   */
  public boolean printBottom(final Band band) throws ReportProcessingException
  {
    return print (band, false, false);
  }

  /**
   * Prints the given band at the current cursor position.
   * 
   * @param band the band to be printed.
   * @param spoolBand a flag defining whether the content should be spooled.
   * @param handlePagebreakBefore a flag defining whether the worker should check
   * for the 'pagebreak-before' flag.
   * @return true, if the band was printed, false otherwise.
   * @throws ReportProcessingException if an exception occured while processing
   * the band.
   */
  public boolean print(final Band band, final boolean spoolBand, 
                       final boolean handlePagebreakBefore)
      throws ReportProcessingException
  {
    if (!isInEndPage() && (isPageEmpty() == false)
        && band.getStyle().getBooleanStyleProperty(BandStyleSheet.PAGEBREAK_BEFORE) == true)
    {
      endPage();
      startPage();
    }

    final float y = getCursor().getY();
    // don't save the state if the current page is currently being finished
    // or restarted; PageHeader and PageFooter are printed out of order and
    // do not influence the reporting state

    final Rectangle2D bounds = doLayout(band);
    bounds.setRect(0, y, bounds.getWidth(), bounds.getHeight());
    doPrint(bounds, band);

    if (!isInEndPage() && (isPageEmpty() == false)
        && band.getStyle().getBooleanStyleProperty(BandStyleSheet.PAGEBREAK_AFTER) == true)
    {
      endPage();
      startPage();
    }
    return true;
  }

  /**
   * Gets the name of the SheetName function. The sheetname function defines the
   * names of the generated sheets.
   *
   * @return the name of the sheet name function, or null, if that name is not known yet.
   */
  private String getSheetNameFunction()
  {
    if (getCurrentEvent() == null)
    {
      return null;
    }
    return getCurrentEvent().getReport().getReportConfiguration()
        .getConfigProperty(SHEET_NAME_FUNCTION_PROPERTY);
  }

  /**
   * Returns true, if the tablewriter is currently handling the end of the current page.
   *
   * @return true, if the end of the page is currently handled.
   */
  private boolean isInEndPage()
  {
    return inEndPage;
  }

  /**
   * Gets the cursor for this writer. The cursor marks the current position in the
   * current sheet.
   *
   * @return the cursor.
   */
  private TableWriterCursor getCursor()
  {
    return cursor;
  }

  /**
   * Sets the cursor for the writer.
   * @param cursor the new cursor.
   */
  private void setCursor(final TableWriterCursor cursor)
  {
    this.cursor = cursor;
  }

  /**
   * Creates an output target that mimics a real output target, but produces no output.
   * This is used by the reporting engine when it makes its first pass through the report,
   * calculating page boundaries etc.  The second pass will use a real output target.
   *
   * @return a dummy output target.
   */
  private LayoutSupport getLayoutSupport()
  {
    return DefaultLayoutSupport.getDefaultInstance();
  }

  /**

⌨️ 快捷键说明

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