📄 itemfactory.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.
*
* ----------------
* ItemFactory.java
* ----------------
* (C)opyright 2002, 2003, by Thomas Morgner and Contributors.
*
* Original Author: Thomas Morgner;
* Contributor(s): David Gilbert (for Simba Management Limited);
*
* $Id: ItemFactory.java,v 1.47.2.1 2003/08/24 14:18:00 taqua Exp $
*
* Changes
* -------
* 16-May-2002 : Initial version
* 27-May-2002 : Support for the rectangle element
* 09-Jun-2002 : Documentation
* 30-Jun-2002 : Added Support for ImageField, ImageFunction
* 10-Jul-2002 : Added Support for ImageURLField, ImageURLFunction
* 31-Aug-2002 : Replaced ReportDataSource and FunctionDataSource with DataRowDataSource
* Deprecated create*Function and create*Field methods.
* 06-Dec-2002 : Fixed issues reported by Checkstyle (DG);
* 15-Jan-2003 : Use templates for all element datasources.
* 25-Jan-2003 : Added ResourceBundleElement and -Field
* 04-Feb-2003 : Added javaDoc for ResourceBundleElement and -Field
* 24-Feb-2003 : Fixed vertical alignment translation bug in createLabelElement(...) method (DG);
*/
package com.jrefinery.report;
import java.awt.Color;
import java.awt.Font;
import java.awt.Paint;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.AffineTransform;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.print.PageFormat;
import java.net.URL;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.List;
import javax.swing.table.TableModel;
import com.jrefinery.report.filter.DataRowDataSource;
import com.jrefinery.report.filter.DataSource;
import com.jrefinery.report.filter.DateFormatFilter;
import com.jrefinery.report.filter.NumberFormatFilter;
import com.jrefinery.report.filter.StaticDataSource;
import com.jrefinery.report.filter.templates.DateFieldTemplate;
import com.jrefinery.report.filter.templates.ImageFieldTemplate;
import com.jrefinery.report.filter.templates.ImageURLElementTemplate;
import com.jrefinery.report.filter.templates.ImageURLFieldTemplate;
import com.jrefinery.report.filter.templates.LabelTemplate;
import com.jrefinery.report.filter.templates.NumberFieldTemplate;
import com.jrefinery.report.filter.templates.ResourceFieldTemplate;
import com.jrefinery.report.filter.templates.ResourceLabelTemplate;
import com.jrefinery.report.filter.templates.StringFieldTemplate;
import com.jrefinery.report.function.ExpressionCollection;
import com.jrefinery.report.targets.FontDefinition;
import com.jrefinery.report.targets.base.bandlayout.StaticLayoutManager;
import com.jrefinery.report.targets.style.BandStyleSheet;
import com.jrefinery.report.targets.style.ElementStyleSheet;
import org.jfree.ui.FloatDimension;
/**
* A factory used to create elements and bands using a single line command.
* The factory creates elements suitable for the static layout.
*
* @author Thomas Morgner
*/
public class ItemFactory
{
/**
* Constructor. Not used.
*/
protected ItemFactory()
{
}
/**
* Creates a new {@link TextElement} containing a date filter structure.
*
* @param name the name of the new element
* @param bounds the bounds of the new element
* @param paint the text color of this text element
* @param alignment the horizontal text alignment.
* @param font the font for this element
* @param nullString the text used when the value of this element is <code>null</code>
* @param format the SimpleDateFormat-formatstring used to format the date
* @param field the fieldname to retrieve values from
*
* @return a report element for displaying a java.util.Date value.
*
* @throws NullPointerException if bounds, format or field are <code>null</code>
* @throws IllegalArgumentException if the given alignment is invalid
*/
public static TextElement createDateElement(final String name,
final Rectangle2D bounds,
final Paint paint,
final int alignment,
final Font font,
final String nullString,
final String format,
final String field)
{
return createDateElement(name,
bounds,
paint,
alignment,
ElementAlignment.TOP.getOldAlignment(),
font,
nullString,
format,
field);
}
/**
* Creates a new {@link TextElement} containing a date filter structure.
*
* @param name the name of the new element
* @param bounds the bounds of the new element
* @param paint the text color of this text element
* @param alignment the horizontal text alignment
* @param valign the vertical text alignment
* @param font the font for this element
* @param nullString the text used when the value of this element is <code>null</code>
* @param format the SimpleDateFormat-formatstring used to format the date
* @param field the fieldname to retrieve values from
*
* @return a report element for displaying a java.util.Date value.
*
* @throws NullPointerException if bounds, format or field are <code>null</code>
* @throws IllegalArgumentException if the given alignment is invalid
*/
public static TextElement createDateElement(final String name,
final Rectangle2D bounds,
final Paint paint,
final int alignment,
final int valign,
final Font font,
final String nullString,
final String format,
final String field)
{
final DateFieldTemplate dft = new DateFieldTemplate();
if (format != null)
{
dft.setFormat(format);
}
dft.setNullValue(nullString);
dft.setField(field);
final TextElement dateElement = new TextElement();
if (name != null)
{
dateElement.setName(name);
}
setElementBounds(dateElement, bounds);
if (paint != null)
{
dateElement.getStyle().setStyleProperty(ElementStyleSheet.PAINT, paint);
}
if (font != null)
{
dateElement.getStyle().setFontDefinitionProperty(new FontDefinition(font));
}
dateElement.getStyle().setStyleProperty(
ElementStyleSheet.ALIGNMENT,
ElementAlignment.translateHorizontalAlignment(alignment));
dateElement.getStyle().setStyleProperty(
ElementStyleSheet.VALIGNMENT,
ElementAlignment.translateVerticalAlignment(valign));
dateElement.setDataSource(dft);
return dateElement;
}
/**
* Creates a new {@link TextElement} containing a date filter structure.
*
* @param name the name of the new element
* @param bounds the bounds of the new element
* @param paint the text color of this text element
* @param alignment the horizontal text alignment
* @param font the font for this element
* @param nullString the text used when the value of this element is <code>null</code>
* @param format the SimpleDateFormat used to format the date
* @param field the fieldname to retrieve values from
*
* @return a report element for displaying a java.util.Date value.
*
* @throws NullPointerException if bounds, name, format or field are <code>null</code>
* @throws IllegalArgumentException if the given alignment is invalid
*/
public static TextElement createDateElement(final String name,
final Rectangle2D bounds,
final Paint paint,
final int alignment,
final Font font,
final String nullString,
final DateFormat format,
final String field)
{
return createDateElement(name, bounds, paint, alignment,
ElementAlignment.TOP.getOldAlignment(),
font, nullString, format, field);
}
/**
* Creates a new TextElement containing a date filter structure.
*
* @param name the name of the new element
* @param bounds the bounds of the new element
* @param paint the text color of this text element
* @param alignment the horizontal text alignment.
* @param valign the vertical text alignment
* @param font the font for this element
* @param nullString the text used when the value of this element is null
* @param format the SimpleDateFormat used to format the date
* @param field the fieldname to retrieve values from
*
* @return a report element for displaying a java.util.Date value.
*
* @throws NullPointerException if bounds, name, format or field are null
* @throws IllegalArgumentException if the given alignment is invalid
*/
public static TextElement createDateElement(final String name,
final Rectangle2D bounds,
final Paint paint,
final int alignment,
final int valign,
final Font font,
final String nullString,
final DateFormat format,
final String field)
{
final DataSource ds;
if (format instanceof SimpleDateFormat)
{
final DateFieldTemplate dft = new DateFieldTemplate();
dft.setDateFormat((SimpleDateFormat) format);
dft.setNullValue(nullString);
dft.setField(field);
ds = dft;
}
else
{
final DateFormatFilter filter = new DateFormatFilter();
if (format != null)
{
filter.setFormatter(format);
}
filter.setDataSource(new DataRowDataSource(field));
ds = filter;
}
final TextElement dateElement = new TextElement();
if (name != null)
{
dateElement.setName(name);
}
setElementBounds(dateElement, bounds);
if (paint != null)
{
dateElement.getStyle().setStyleProperty(ElementStyleSheet.PAINT, paint);
}
if (font != null)
{
dateElement.getStyle().setFontDefinitionProperty(new FontDefinition(font));
}
dateElement.getStyle().setStyleProperty(
ElementStyleSheet.ALIGNMENT,
ElementAlignment.translateHorizontalAlignment(alignment));
dateElement.getStyle().setStyleProperty(
ElementStyleSheet.VALIGNMENT,
ElementAlignment.translateVerticalAlignment(valign));
dateElement.setDataSource(ds);
return dateElement;
}
/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -