bandfactory.java
来自「swing编写的库存管理程序。毕业设计类」· Java 代码 · 共 559 行 · 第 1/2 页
JAVA
559 行
/**
* ========================================
* 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.
*
* ----------------
* BandFactory.java
* ----------------
* (C)opyright 2002, 2003, by Thomas Morgner and Contributors.
*
* Original Author: Thomas Morgner;
* Contributor(s): David Gilbert (for Simba Management Limited);
*
* $Id: BandFactory.java,v 1.7.2.1 2003/12/21 23:28:46 taqua Exp $
*
* Changes
* -------
* 10-May-2002 : Initial version
* 22-May-2002 : Structured parsing functions: all tags have a startXXX and endXXX function
* 05-Jun-2002 : Updated Javadoc comments (DG);
* 10-Dec-2002 : Fixed issues reported by Checkstyle (DG);
*
*/
package org.jfree.report.modules.parser.simple;
import org.jfree.report.ItemBand;
import org.jfree.report.PageFooter;
import org.jfree.report.PageHeader;
import org.jfree.report.ReportFooter;
import org.jfree.report.ReportHeader;
import org.jfree.report.Band;
import org.jfree.report.modules.parser.base.ReportParser;
import org.jfree.report.modules.parser.base.ReportParserUtil;
import org.jfree.report.style.BandStyleSheet;
import org.jfree.report.style.ElementStyleSheet;
import org.jfree.ui.FloatDimension;
import org.jfree.xml.ParserUtil;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
/**
* This class handles the SAX events generated for report bands.
* <p>
* Recognized root bands are:
* <ul>
* <li>pageheader</li>
* <li>pagefooter</li>
* <li>reportheader</li>
* <li>reporthooter</li>
* <li>items</li>
* </ul>
*
* @author Thomas Morgner
*/
public class BandFactory extends AbstractReportDefinitionHandler
implements ReportDefinitionTags
{
/**
* Initializes this BandFactory based on the data contained in the ReportFactory.
*
* @param parser the used parser to coordinate the parsing process.
* @param finishTag the finish tag, that should trigger the deactivation of this parser.
* @throws NullPointerException if the finishTag or the parser are null.
*/
public BandFactory(final ReportParser parser, final String finishTag)
{
super(parser, finishTag);
}
/**
* SAX-Handler function that is forwarded from the ReportDefinitionContentHandler.
* StartTag-occurences for ReportFooter and -header, PageFooter and -header and
* the itemBand are handled. If an unknown element is encountered, a SAXException is
* thrown.
*
* @param qName the element name.
* @param atts the element attributes.
*
* @throws SAXException if an unknown tag is encountered.
*/
public void startElement(final String qName,
final Attributes atts) throws SAXException
{
final String elementName = qName.toLowerCase().trim();
if (elementName.equals(REPORT_HEADER_TAG))
{
startReportHeader(atts);
}
// *** REPORT FOOTER ***
else if (elementName.equals(REPORT_FOOTER_TAG))
{
startReportFooter(atts);
}
// *** PAGE HEADER ***
else if (elementName.equals(PAGE_HEADER_TAG))
{
startPageHeader(atts);
}
// *** PAGE FOOTER ***
else if (elementName.equals(PAGE_FOOTER_TAG))
{
startPageFooter(atts);
}
else if (elementName.equals(WATERMARK_TAG))
{
startWatermark(atts);
}
else if (elementName.equals(ITEMS_TAG))
{
startItems(atts);
}
else
{
throw new SAXException("Expected one of: reportheader, reportfooter, pageheader, "
+ "pagefooter or items. " + qName + " - " + getFinishTag());
}
}
/**
* SAX-Handler function that is forwarded from the ReportDefinitionContentHandler.
* EndTag-occurences for ReportFooter and -header, PageFooter and -header and
* the itemBand are handled. If an unknown element is encountered, a SAXException is
* thrown.
*
* @param qName the element name.
*
* @throws SAXException if an unknown tag is encountered.
*/
public void endElement(final String qName) throws SAXException
{
final String elementName = qName.toLowerCase().trim();
if (elementName.equals(REPORT_HEADER_TAG))
{
endReportHeader();
}
// *** REPORT FOOTER ***
else if (elementName.equals(REPORT_FOOTER_TAG))
{
endReportFooter();
}
// *** PAGE HEADER ***
else if (elementName.equals(PAGE_HEADER_TAG))
{
endPageHeader();
}
// *** PAGE FOOTER ***
else if (elementName.equals(PAGE_FOOTER_TAG))
{
endPageFooter();
}
else if (elementName.equals(WATERMARK_TAG))
{
endWatermark();
}
else if (elementName.equals(ITEMS_TAG))
{
endItems();
}
else if (elementName.equals(getFinishTag()))
{
getParser().popFactory().endElement(qName);
}
else
{
throw new SAXException("Expected one of: reportheader, reportfooter, pageheader, "
+ "pagefooter or items, but found " + qName);
}
}
/**
* Handles the start of a reportheader definition.
*
* @param attr the element attributes.
*
* @throws SAXException if there is a parsing problem.
*
* @see org.jfree.report.ReportHeader
*/
private void startReportHeader(final Attributes attr)
throws SAXException
{
// create the report header...
final ReportHeader reportHeader = getReport().getReportHeader();
final String height = attr.getValue("height");
if (height != null)
{
final float heightValue = ParserUtil.parseFloat(height, 0);
reportHeader.getStyle().setStyleProperty(ElementStyleSheet.MINIMUMSIZE,
new FloatDimension(0, heightValue));
}
final String ownPageAttr = attr.getValue("ownpage");
if (ownPageAttr != null)
{
final boolean ownPage = ParserUtil.parseBoolean(ownPageAttr, false);
reportHeader.getStyle().setBooleanStyleProperty
(BandStyleSheet.PAGEBREAK_AFTER, ownPage);
}
final FontFactory.FontInformation fi = FontFactory.createFont(attr);
FontFactory.applyFontInformation(reportHeader.getBandDefaults(), fi);
final String valign = attr.getValue(VALIGNMENT_ATT);
if (valign != null)
{
reportHeader.getBandDefaults().setStyleProperty(ElementStyleSheet.VALIGNMENT,
ReportParserUtil.parseVerticalElementAlignment(valign));
}
final String halign = attr.getValue(ALIGNMENT_ATT);
if (halign != null)
{
reportHeader.getBandDefaults().setStyleProperty(ElementStyleSheet.ALIGNMENT,
ReportParserUtil.parseHorizontalElementAlignment(halign));
}
getParser().pushFactory(new ElementFactory(getReportParser(), REPORT_HEADER_TAG, reportHeader));
}
/**
* Handles the start of a reportfooter definition.
*
* @param attr the element attributes.
*
* @throws SAXException if there is a parsing problem.
*
* @see org.jfree.report.ReportFooter
*/
private void startReportFooter(final Attributes attr)
throws SAXException
{
// create the report footer...
final ReportFooter reportFooter = getReport().getReportFooter();
// get the height...
final String height = attr.getValue("height");
if (height != null)
{
final float heightValue = ParserUtil.parseFloat(height, 0);
reportFooter.getStyle().setStyleProperty(ElementStyleSheet.MINIMUMSIZE,
new FloatDimension(0, heightValue));
}
final String ownPageAttr = attr.getValue("ownpage");
if (ownPageAttr != null)
{
final boolean ownPage = ParserUtil.parseBoolean(ownPageAttr, false);
reportFooter.getStyle().setBooleanStyleProperty
(BandStyleSheet.PAGEBREAK_AFTER, ownPage);
}
final FontFactory.FontInformation fi = FontFactory.createFont(attr);
FontFactory.applyFontInformation(reportFooter.getBandDefaults(), fi);
final String valign = attr.getValue(VALIGNMENT_ATT);
if (valign != null)
{
reportFooter.getBandDefaults().setStyleProperty(ElementStyleSheet.VALIGNMENT,
ReportParserUtil.parseVerticalElementAlignment(valign));
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?