org.jfree.report
Class Element

java.lang.Object
  extended byorg.jfree.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 java.lang.String ANONYMOUS_ELEMENT_PREFIX
          The internal constant to mark anonymous element names.
 
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.awt.geom.Dimension2D getMaximumSize()
          Returns the maximum size of this element, if defined.
 java.awt.geom.Dimension2D getMinimumSize()
          Returns the minimum size of this element, if defined.
 java.lang.String getName()
          Returns the name of the element.
 Band getParent()
          Return the parent of the element.
 java.awt.geom.Dimension2D getPreferredSize()
          Returns the preferred size of this element, if defined.
 ElementStyleSheet getStyle()
          Returns this elements private stylesheet.
 StyleSheetCollection getStyleSheetCollection()
          Returns the stylesheet collection which is assigned with this element and all stylesheets of this element.
 java.lang.Object getTreeLock()
          Returns the tree lock object for the element tree.
 java.lang.Object getValue()
          Queries this element's datasource for a value.
protected  void handleRegisterStyleSheetCollection()
          Handles the registration of the stylesheet collection.
protected  void handleUnregisterStyleSheetCollection()
          Handles the unregistration of the stylesheet collection.
 boolean isDynamicContent()
          Checks, whether the layout manager should compute the size of this element based on the current content.
 boolean isLayoutCacheable()
          Returns whether the layout of this element is cacheable.
 boolean isVisible()
          Defines whether this element should be painted.
 void registerStyleSheetCollection(StyleSheetCollection styleSheetCollection)
          Registers the given StyleSheet collection with this element.
 void setDataSource(DataSource ds)
          Sets the data source for this element.
 void setDynamicContent(boolean dynamicContent)
          Defines the stylesheet property for the dynamic attribute.
 void setLayoutCacheable(boolean layoutCacheable)
          Defines whether the layout of this element can be cached.
 void setMaximumSize(java.awt.geom.Dimension2D maximumSize)
          Defines the stylesheet property for the maximum element size.
 void setMinimumSize(java.awt.geom.Dimension2D minimumSize)
          Defines the stylesheet property for the minimum element size.
 void setName(java.lang.String name)
          Defines the name for this element.
protected  void setParent(Band parent)
          defines the parent of the element.
 void setPreferredSize(java.awt.geom.Dimension2D preferredSize)
          Defines the stylesheet property for the preferred element size.
 void setVisible(boolean b)
          Defines, whether this element should be drawn.
 void unregisterStyleSheetCollection(StyleSheetCollection styleSheetCollection)
          Unregisters the given stylesheet collection from this element.
 void updateStyleSheetCollection(StyleSheetCollection sc)
          Updates the stylesheet collection for this element and all substylesheets.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ANONYMOUS_ELEMENT_PREFIX

public static final java.lang.String ANONYMOUS_ELEMENT_PREFIX
The internal constant to mark anonymous element names.

See Also:
Constant Field Values
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
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()
Returns the stylesheet collection which is assigned with this element and all stylesheets of this element.

Returns:
the element stylesheet collection or null, if no collection is assigned.

registerStyleSheetCollection

public void registerStyleSheetCollection(StyleSheetCollection styleSheetCollection)
                                  throws InvalidStyleSheetCollectionException
Registers the given StyleSheet collection with this element. If there is already another stylesheet collection registered, this method will throw an InvalidStyleSheetCollectionException.

Parameters:
styleSheetCollection - the stylesheet collection that should be registered.
Throws:
InvalidStyleSheetCollectionException - if there is already an other stylesheet registered.
java.lang.NullPointerException - if the given stylesheet collection is null.

unregisterStyleSheetCollection

public void unregisterStyleSheetCollection(StyleSheetCollection styleSheetCollection)
                                    throws InvalidStyleSheetCollectionException
Unregisters the given stylesheet collection from this element. If this stylesheet collection is not registered with this element, this method will throw an InvalidStyleSheetCollectionException

Parameters:
styleSheetCollection - the stylesheet collection that should be unregistered.
Throws:
InvalidStyleSheetCollectionException - if there is already an other stylesheet registered.
java.lang.NullPointerException - if the given stylesheet collection is null.

handleUnregisterStyleSheetCollection

protected void handleUnregisterStyleSheetCollection()
Handles the unregistration of the stylesheet collection.


handleRegisterStyleSheetCollection

protected void handleRegisterStyleSheetCollection()
Handles the registration of the stylesheet collection.


updateStyleSheetCollection

public void updateStyleSheetCollection(StyleSheetCollection sc)
                                throws InvalidStyleSheetCollectionException
Updates the stylesheet collection for this element and all substylesheets. This method must be called after the element was cloned, to make sure that all stylesheets are registered properly.

If you don't call this function after cloning prepare to be doomed. This method will replace all inherited stylesheets with clones from the stylesheet collection.

Parameters:
sc - the stylesheet collection that contains the updated information and that should be assigned with that element.
Throws:
java.lang.NullPointerException - if the given stylesheet collection is null.
InvalidStyleSheetCollectionException - if there is an other stylesheet collection already registered with that element.

getTreeLock

public final java.lang.Object getTreeLock()
Returns the tree lock object for the element tree.

Returns:
the treelock object.

isDynamicContent

public boolean isDynamicContent()
Checks, whether the layout manager should compute the size of this element based on the current content.

Returns:
true, if the element is dynamic, false otherwise.

setDynamicContent

public void setDynamicContent(boolean dynamicContent)
Defines the stylesheet property for the dynamic attribute. Calling this function with either parameter will override any previously defined value for the dynamic attribute. The value can no longer be inherited from parent stylesheets.

Parameters:
dynamicContent - the new state of the dynamic flag.

isLayoutCacheable

public boolean isLayoutCacheable()
Returns whether the layout of this element is cacheable.

Returns:
true, if the layout is cacheable, false otherwise.

setLayoutCacheable

public void setLayoutCacheable(boolean layoutCacheable)
Defines whether the layout of this element can be cached.

Calling this function with either parameter will override any previously defined value for the layoutcachable attribute. The value can no longer be inherited from parent stylesheets.

Parameters:
layoutCacheable - true, if the layout is cacheable, false otherwise.

getMinimumSize

public java.awt.geom.Dimension2D getMinimumSize()
Returns the minimum size of this element, if defined. Warning: The returned object is not immutable and should not be changed.

Returns:
the minimum size

setMinimumSize

public void setMinimumSize(java.awt.geom.Dimension2D minimumSize)
Defines the stylesheet property for the minimum element size.

Parameters:
minimumSize - the new minimum size or null, if the value should be inherited.

getMaximumSize

public java.awt.geom.Dimension2D getMaximumSize()
Returns the maximum size of this element, if defined. Warning: The returned object is not immutable and should not be changed.

Returns:
the maximum size

setMaximumSize

public void setMaximumSize(java.awt.geom.Dimension2D maximumSize)
Defines the stylesheet property for the maximum element size.

Parameters:
maximumSize - the new maximum size or null, if the value should be inherited.

getPreferredSize

public java.awt.geom.Dimension2D getPreferredSize()
Returns the preferred size of this element, if defined. Warning: The returned object is not immutable and should not be changed.

Returns:
the preferred size

setPreferredSize

public void setPreferredSize(java.awt.geom.Dimension2D preferredSize)
Defines the stylesheet property for the preferred element size.

Parameters:
preferredSize - the new preferred size or null, if the value should be inherited.