📄 element.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.
*
* ------------
* Element.java
* ------------
* (C)opyright 2000-2003, by Simba Management Limited and Contributors.
*
* Original Author: David Gilbert (for Simba Management Limited);
* Contributor(s): Thomas Morgner;
*
* $Id: Element.java,v 1.37.2.1 2003/08/24 14:17:59 taqua Exp $
*
* Changes (from 8-Feb-2002)
* -------------------------
* 08-Feb-2002 : Updated code to work with latest version of the JCommon class library (DG);
* 05-Mar-2002 : Integration of Thomas Morgner's code, plus PDF report generation via iText (DG);
* 10-May-2002 : Removed complex-Constructor to support automatic generation of elements using
* generic parsers.
* 16-May-2002 : Line delimiters adjusted
* paint now protected member
* 20-May-2002 : Support for DataTarget interface added. The drawing scheme has changed to fit
* the new OutputTarget implementation
* 26-May-2002 : Elements visible property controls whether an element is drawn by its band
* 04-Jun-2002 : Documentation tags changed. A default name is generated, a default datasource
* is set. Elements paint is no longer protected, the paint is retrieved by the
* getPaint (Band) method. If neither band nor element have a paint declared, fail
* with and exception.
* 04-Jul-2002 : Serializable and Cloneable
* 05-Sep-2002 : Documentation
* 06-Dec-2002 : Updated Javadocs (DG);
* 06-Dec-2002 : Also updated the docs, declared setPaint(),getPaint deprecated, removed
* setStyleSheet
* 13-Dec-2002 : Added support for parent property
* 22-Jan-2003 : Paint parameter is now restricted to java.awt.Color
* 27-Jan-2003 : Changed ParentRegistration, now the band is responsible for setting the parent
* property and the BandDefaultStyleSheet.
* 04-Feb-2003 : removed equals() method. Element equality is no longer bound to names.
*/
package com.jrefinery.report;
import java.awt.Color;
import java.awt.Paint;
import java.io.Serializable;
import com.jrefinery.report.filter.DataSource;
import com.jrefinery.report.filter.DataTarget;
import com.jrefinery.report.filter.EmptyDataSource;
import com.jrefinery.report.targets.style.ElementDefaultStyleSheet;
import com.jrefinery.report.targets.style.ElementStyleSheet;
import com.jrefinery.report.targets.style.InvalidStyleSheetCollectionException;
import com.jrefinery.report.targets.style.StyleSheetCollection;
import com.jrefinery.report.targets.style.StyleSheetCollectionHelper;
/**
* Base class for all report elements (display items that can appear within a report band).
* <p>
* All elements have a non-null name and have a style sheet defined. The style sheet is
* used to store and access all element properties that can be used to layout the
* element or affect the elements appeareance in a ReportProcessor.
*
* @author David Gilbert
* @author Thomas Morgner
*/
public abstract class Element implements DataTarget, Serializable, Cloneable
{
/**
* Internal helper class to handle the style sheet collection properly.
*/
private static class ElementStyleSheetCollectionHelper extends StyleSheetCollectionHelper
{
/** The Element for which we handle the style sheet collection. */
private Element element;
/**
* Creates a new ElementStyleSheetCollectionHelper for the given element.
*
* @param e the element.
* @throws NullPointerException if the given element is null.
*/
public ElementStyleSheetCollectionHelper(final Element e)
{
if (e == null)
{
throw new NullPointerException();
}
this.element = e;
}
/**
* Handles the stylesheet collection registration.
* Forwards the call to the element.
*/
protected void handleRegisterStyleSheetCollection()
{
element.handleRegisterStyleSheetCollection();
}
/**
* Handles the stylesheet collection removal.
* Forwards the call to the element.
*/
protected void handleUnregisterStyleSheetCollection()
{
element.handleUnregisterStyleSheetCollection();
}
}
/** A null datasource. */
private static final DataSource NULL_DATASOURCE = new EmptyDataSource();
/** The head of the data source chain. */
private DataSource datasource;
/** The name of the element. */
private String name;
/** The stylesheet defines global appearance for elements. */
private ElementStyleSheet style;
/**
* The stylesheet collection helper is used to manage the StyleSheetCollection of
* this element. The use of the stylesheet collection is evil voodo, so we dont
* handle it in the element ...
*/
private ElementStyleSheetCollectionHelper styleSheetCollectionHelper;
/**
* ElementStyle constant for horizontal left alignment.
* For StyleSheet definition use the ElementAlignment-Objects.
*
* @deprecated use ElementAlignment objects instead.
*/
public static final int LEFT = ElementAlignment.LEFT.getOldAlignment();
/**
* ElementStyle constant for horizontal right alignment.
* For StyleSheet definition use the ElementAlignment-Objects.
*
* @deprecated use ElementAlignment objects instead.
*/
public static final int RIGHT = ElementAlignment.RIGHT.getOldAlignment();
/**
* ElementStyle constant for horizontal center alignment.
* For StyleSheet definition use the ElementAlignment-Objects.
*
* @deprecated use ElementAlignment objects instead.
*/
public static final int CENTER = ElementAlignment.CENTER.getOldAlignment();
/**
* ElementStyle constant for vertical top alignment.
* For StyleSheet definition use the ElementAlignment-Objects.
*
* @deprecated use ElementAlignment objects instead.
*/
public static final int TOP = ElementAlignment.TOP.getOldAlignment();
/**
* ElementStyle constant for vertical middle alignment.
* For StyleSheet definition use the ElementAlignment-Objects.
*
* @deprecated use ElementAlignment objects instead.
*/
public static final int MIDDLE = ElementAlignment.MIDDLE.getOldAlignment();
/**
* ElementStyle constant for vertical bottom alignment.
* For StyleSheet definition use the ElementAlignment-Objects.
*
* @deprecated use ElementAlignment objects instead.
*/
public static final int BOTTOM = ElementAlignment.BOTTOM.getOldAlignment();
/** the parent for the element (the band where the element is contained in). */
private Band parent;
/**
* Constructs an element.
* <p>
* The element inherits the DefaultElementStyleSheet. When the element is added
* to the band, the bands default stylesheet is also added to the elements style.
* <p>
* A datasource is assigned with this element is set to a default source,
* which always returns null.
*/
protected Element()
{
setName("anonymousElement@" + super.hashCode());
datasource = NULL_DATASOURCE;
style = new ElementStyleSheet(getName());
style.setAllowCaching(true);
style.addDefaultParent(ElementDefaultStyleSheet.getDefaultStyle());
styleSheetCollectionHelper = new ElementStyleSheetCollectionHelper(this);
}
/**
* Return the parent of the element.
* You can use this to explore the component tree.
*
* @return the parent of the element.
*/
public final Band getParent()
{
return parent;
}
/**
* defines the parent of the element. Only a band should call this method.
*
* @param parent (null allowed).
*/
protected final void setParent(final Band parent)
{
this.parent = parent;
}
/**
* Defines the name for this element. The name must not be empty,
* or a NullPointerException is thrown.
*
* @param name the name of this element (null not permitted)
*/
public void setName(final String name)
{
if (name == null)
{
throw new NullPointerException("Element.setName(...): name is null.");
}
this.name = name;
}
/**
* Returns the name of the element. The name of the element cannot be null.
*
* @return the name.
*/
public String getName()
{
return this.name;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -