com.jrefinery.report
Class Element

java.lang.Object
  |
  +--com.jrefinery.report.Element
All Implemented Interfaces:
java.lang.Cloneable, DataTarget, java.io.Serializable
Direct Known Subclasses:
Band, DrawableElement, ImageElement, ShapeElement, TextElement

public abstract class Element
extends java.lang.Object
implements DataTarget, java.io.Serializable, java.lang.Cloneable

Base class for all report elements (display items that can appear within a report band).

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, Thomas Morgner
See Also:
Serialized Form

Field Summary
static int BOTTOM
          Deprecated. use ElementAlignment objects instead.
static int CENTER
          Deprecated. use ElementAlignment objects instead.
static int LEFT
          Deprecated. use ElementAlignment objects instead.
static int MIDDLE
          Deprecated. use ElementAlignment objects instead.
static int RIGHT
          Deprecated. use ElementAlignment objects instead.
static int TOP
          Deprecated. use ElementAlignment objects instead.
 
Constructor Summary
protected Element()
          Constructs an element.
 
Method Summary
 java.lang.Object clone()
          Clones this Element, the datasource and the private stylesheet of this element.
abstract  java.lang.String getContentType()
          Defines the content-type for this element.
 DataSource getDataSource()
          Returns the datasource for this element.
 java.lang.String getName()
          Returns the name of the element.
 java.awt.Paint getPaint()
          Deprecated. don't store and access the paint directly, use the stylesheet.
 Band getParent()
          Return the parent of the element.
 ElementStyleSheet getStyle()
          Returns this elements private stylesheet.
 StyleSheetCollection getStyleSheetCollection()
           
 java.lang.Object getValue()
          Queries this element's datasource for a value.
 boolean isVisible()
          Defines whether this element should be painted.
protected  void registerStyleSheetCollection()
           
 void setDataSource(DataSource ds)
          Sets the data source for this element.
 void setName(java.lang.String name)
          Defines the name for this element.
 void setPaint(java.awt.Paint p)
          Deprecated. use a stylesheet to define the paint. The paint object must be an instance of color.
protected  void setParent(Band parent)
          defines the parent of the element.
 void setStyleSheetCollection(StyleSheetCollection styleSheetCollection)
           
 void setVisible(boolean b)
          Defines, whether this element should be drawn.
protected  void unregisterStyleSheetCollection()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LEFT

public static final int LEFT
Deprecated. use ElementAlignment objects instead.

ElementStyle constant for horizontal left alignment. For StyleSheet definition use the ElementAlignment-Objects.


RIGHT

public static final int RIGHT
Deprecated. use ElementAlignment objects instead.

ElementStyle constant for horizontal right alignment. For StyleSheet definition use the ElementAlignment-Objects.


CENTER

public static final int CENTER
Deprecated. use ElementAlignment objects instead.

ElementStyle constant for horizontal center alignment. For StyleSheet definition use the ElementAlignment-Objects.


TOP

public static final int TOP
Deprecated. use ElementAlignment objects instead.

ElementStyle constant for vertical top alignment. For StyleSheet definition use the ElementAlignment-Objects.


MIDDLE

public static final int MIDDLE
Deprecated. use ElementAlignment objects instead.

ElementStyle constant for vertical middle alignment. For StyleSheet definition use the ElementAlignment-Objects.


BOTTOM

public static final int BOTTOM
Deprecated. use ElementAlignment objects instead.

ElementStyle constant for vertical bottom alignment. For StyleSheet definition use the ElementAlignment-Objects.

Constructor Detail

Element

protected Element()
Constructs an element.

The element inherits the DefaultElementStyleSheet. When the element is added to the band, the bands default stylesheet is also added to the elements style.

A datasource is assigned with this element is set to a default source, which always returns null.

Method Detail

getParent

public final Band getParent()
Return the parent of the element. You can use this to explore the component tree.

Returns:
the parent of the element.

setParent

protected final void setParent(Band parent)
defines the parent of the element. Only a band should call this method.

Parameters:
parent - (null allowed).

setName

public void setName(java.lang.String name)
Defines the name for this element. The name must not be empty, or a NullPointerException is thrown.

Parameters:
name - the name of this element (null not permitted)

getName

public java.lang.String getName()
Returns the name of the element. The name of the element cannot be null.

Returns:
the name.

getDataSource

public final DataSource getDataSource()
Returns the datasource for this element. You cannot override this function as the element needs always be the last consumer in the chain of filters. This function must never return null.

Specified by:
getDataSource in interface DataTarget
Returns:
the assigned datasource.

setDataSource

public void setDataSource(DataSource ds)
Sets the data source for this element. This datasource is queried on populateElements(), to fill in the values.

Specified by:
setDataSource in interface DataTarget
Parameters:
ds - the datasource (null not permitted).

getValue

public java.lang.Object getValue()
Queries this element's datasource for a value.

Returns:
the value of the datasource, which can be null.

isVisible

public boolean isVisible()
Defines whether this element should be painted. The detailed implementation is up to the outputtarget.

Returns:
the current visiblity state.

setVisible

public void setVisible(boolean b)
Defines, whether this element should be drawn.

Parameters:
b - the new visibility state

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Clones this Element, the datasource and the private stylesheet of this element. If this element was previously assigned with an stylesheet collection, then the clone is no longer assiged with that collection. You will have to register the element manually again.

Specified by:
clone in interface DataTarget
Overrides:
clone in class java.lang.Object
Returns:
a clone of this element.
Throws:
java.lang.CloneNotSupportedException - should never happen.

getStyle

public ElementStyleSheet getStyle()
Returns this elements private stylesheet. This sheet can be used to override the default values set in one of the parent-stylesheets.

Returns:
the element's stylesheet

getContentType

public abstract java.lang.String getContentType()
Defines the content-type for this element. The content-type is used as a hint how to process the contents of this element. An element implementation should restrict itself to the content-type set here, or the reportprocessing may fail or the element may not be printed.

An element is not allowed to change its content-type after ther report processing has started.

If an content-type is unknown to the output-target, the processor should ignore the content or clearly document its internal reprocessing. Ignoring is preferred.

Returns:
the content-type as string.

getStyleSheetCollection

public StyleSheetCollection getStyleSheetCollection()

setStyleSheetCollection

public void setStyleSheetCollection(StyleSheetCollection styleSheetCollection)

unregisterStyleSheetCollection

protected void unregisterStyleSheetCollection()

registerStyleSheetCollection

protected void registerStyleSheetCollection()

getPaint

public java.awt.Paint getPaint()
Deprecated. don't store and access the paint directly, use the stylesheet.

Returns the paint used to draw this element. There is alway a paint defined for an element.

Returns:
The paint.

setPaint

public void setPaint(java.awt.Paint p)
Deprecated. use a stylesheet to define the paint. The paint object must be an instance of color.

Sets the paint for this element. The paint can be null, in this case the default paint of the band used to draw this element is used.

The paint object must be an instance of color. Generic paints are not permitted.

Parameters:
p - the paint for this element (null permitted).