📄 tableproducer.java
字号:
/**
* ========================================
* 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.
*
* -------------------
* TableProducer.java
* -------------------
* (C)opyright 2003, by Thomas Morgner and Contributors.
*
* Original Author: Thomas Morgner;
* Contributor(s): David Gilbert (for Simba Management Limited);
*
* $Id: TableProducer.java,v 1.16.2.1 2003/12/21 23:28:46 taqua Exp $
*
* Changes
* -------
* 18-Jan-2003 : Initial version
* 24-Feb-2003 : Fixed Checkstyle issues (DG);
*
*/
package org.jfree.report.modules.output.table.base;
import java.awt.geom.Rectangle2D;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import org.jfree.report.Band;
import org.jfree.report.Element;
import org.jfree.report.JFreeReport;
import org.jfree.report.style.ElementStyleSheet;
/**
* The TableProducer is responsible for creating the produced Table. After
* the writer has finished the band layout process, the layouted bands are
* forwarded into the TableProducer. The TableProducer coordinates the cell
* creation process and collects the generated TableCellData. The raw CellData
* objects are later transformed into a TableGridLayout.
* <p>
* This class defines the global contract and provides some helper methods for
* the implementors.
*
* @author Thomas Morgner
*/
public abstract strictfp class TableProducer
{
/** Literal text for the 'title' property name. */
public static final String TITLE = "Title";
/** Literal text for the 'author' property name. */
public static final String AUTHOR = "Author";
/** A constant to define that this layout has not yet printed any pages. */
private static final int BEFORE_FIRST_PAGE = -1;
/** the dummy mode flag. */
private boolean dummy;
/** the strict layout flag. */
private boolean strictLayout;
/** Storage for the output target properties. */
private Properties properties;
/** The layout. If in dummy mode, then this contains only the Bounds. */
private TableGridBounds gridBounds;
/** The collected grid bounds. This collection is used to store the table grid layout. */
private TableLayoutInfo gridBoundsCollection;
/** The layouted elements. Used during the non-dummy mode. */
private TableGrid grid;
/** The number of the current page. */
private int page;
/**
* Creates a new TableProducer. This constructor should be used to create an
* producer for the repagination process.
*
* @param gridBoundsCollection the layout information implementation used to create
* the table layout.
* @param strictLayout the strict layout flag. Set to true, to enable the strict
* layout mode.
*/
public TableProducer(final TableLayoutInfo gridBoundsCollection,
final boolean strictLayout)
{
this.page = BEFORE_FIRST_PAGE;
this.properties = new Properties();
this.dummy = true;
this.strictLayout = strictLayout;
this.gridBoundsCollection = gridBoundsCollection;
}
/**
* Creates a new TableProducer. This constructor must be used to complete the content
* creation after the pagination was done.
*
* @param gridBoundsCollection the layout information implementation used to create
* the table layout.
*/
public TableProducer(final TableLayoutInfo gridBoundsCollection)
{
if (gridBoundsCollection.getPageCount() == 0)
{
throw new IllegalArgumentException("The bounds collection must not be empty.");
}
this.page = BEFORE_FIRST_PAGE;
this.properties = new Properties();
this.dummy = false;
this.gridBoundsCollection = gridBoundsCollection;
//this.grid = new TableGrid(gridBoundsCollection.getLayoutForPage(0));
}
/** A useful constant for specifying the creator constant. */
protected static final String CREATOR =
JFreeReport.getInfo().getName()
+ " version "
+ JFreeReport.getInfo().getVersion();
/**
* Starts the report writing. This method is called before any other report handling
* method is called. This method is called only once for a given instance.
*/
public abstract void open();
/**
* Closes the report and finishs the report writing. Any used resource should
* be freed when this method returns. The current page is already closed.
* This method is called only once for a given instance.
*/
public abstract void close();
/**
* Handles the end of a page. This calls commit() and clears the layout.
*/
public void endPage()
{
commit();
if (isDummy() == false)
{
clearCells();
}
}
/**
* Handles the start of a new page. The page name is given as parameter.
* The TableWriter starts a new page whenever a manual pagebreak is found
* in the report definition. The ReportProducer has been opened before.
* <p>
* Always make sure that you call <code>super.beginPage()</code> before
* any elements are added by the producer.
*
* @param name the page name
*/
public void beginPage(final String name)
{
page += 1;
// the global layout reuses the layout grid from the first page to
// unify the layout for all pages. The global layout is disabled by
// default.
if (isGlobalLayout() == false || page == 0)
{
if (isDummy())
{
gridBounds = new TableGridBounds(isStrictLayout());
gridBoundsCollection.addLayout(gridBounds);
}
else
{
gridBounds = gridBoundsCollection.getLayoutForPage(page);
grid = new TableGrid(gridBounds);
}
}
}
/**
* Gets the TableProducer implementation of this TableProducer.
*
* @return the TableProducers TableCellDataFactory, which is used to create
* the TableCellData.
*/
public abstract TableCellDataFactory getCellDataFactory();
/**
* Clears the grid, removes all created cell bounds.
*/
public void clearCellsBounds()
{
gridBounds.clear();
}
/**
* Clears the contents of the table grid. The layout itself is not cleared, only all
* data is removed.
*/
public void clearCells()
{
if (isDummy() == false)
{
grid.clear();
}
else
{
throw new IllegalStateException("This is the dummy mode, no layout possible.");
}
}
/**
* Checks whether the current layout contains some content. Returns false, if the table
* is empty.
*
* @return true, if there is content, false otherwise.
*/
public boolean isLayoutContainsContent()
{
if (grid == null)
{
return false;
}
return grid.size() != 0;
}
/**
* Calculates the positions for the table cells.
*
* @return The table grid layout.
* @throws IllegalStateException if called while this producer is in dummy mode.
*/
protected TableGridLayout layoutGrid()
{
if (isDummy() == false)
{
return grid.performLayout();
}
else
{
throw new IllegalStateException("This is the dummy mode, no layout possible.");
}
}
/**
* Adds a new TableCellData to the grid.
*
* @param data the new TableCellData.
*/
protected void addCell(final TableCellData data)
{
if (isDummy() == false)
{
grid.addData(data);
}
else
{
gridBounds.addData(data);
}
}
/**
* Returns true, if the TableProducer is open. Only open producers
* are able to write TableCells or to create TableCellData from Elements.
*
* @return checks, whether the TableProducer is open.
*/
public abstract boolean isOpen();
/**
* Processes the layouted band. The band is inserted on the specified bounds in
* the TableGrid.
*
* @param bounds the bounds that define where to print the given band on this logical page
* @param band the band that should be spooled/printed
* @return true, if at least one cell was accepted, false otherwise.
*/
public boolean processBand(final Rectangle2D bounds, final Band band)
{
if (isOpen() == false)
{
throw new IllegalStateException("Producer already closed");
}
// do nothing if the band is invisble
if (band.isVisible() == false)
{
return false;
}
// do nothing if the band has no height...
if (bounds.getHeight() == 0)
{
return false;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -