org.jfree.report.function
Class ElementVisibilitySwitchFunction

java.lang.Object
  extended byorg.jfree.report.function.AbstractFunction
      extended byorg.jfree.report.function.ElementVisibilitySwitchFunction
All Implemented Interfaces:
java.lang.Cloneable, java.util.EventListener, Expression, Function, PageEventListener, ReportListener, java.io.Serializable

public class ElementVisibilitySwitchFunction
extends AbstractFunction
implements java.io.Serializable, PageEventListener

A function that alternates between true and false for each item within a group. The functions value affects a defined elements visibility. If the function evaluates to true, the named element is visible, else the element is invisible.

Elements in JFreeReport do not define their own background color attribute. To create a background, you would place a rectangle shape element behind the element.

The ElementVisibilitySwitchFunction is used to trigger the visibility of an named element. If the element is your background, you will get the alternating effect.

The ElementVisibilitySwitchFunction defines two parameters:

Author:
Thomas Morgner
See Also:
Serialized Form

Field Summary
static java.lang.String ELEMENT_PROPERTY
          the Property key for the name of the ItemBand element.
static java.lang.String INITIAL_STATE_PROPERTY
          The initial state property key.
 
Fields inherited from interface org.jfree.report.function.Expression
AUTOACTIVATE_PROPERTY
 
Constructor Summary
ElementVisibilitySwitchFunction()
          Default constructor.
 
Method Summary
 java.lang.String getElement()
          Returns the element name.
 boolean getInitialTriggerValue()
          Gets the initial value for the visible trigger, either "true" or "false".
 java.lang.Object getValue()
          Returns the defined visibility of the element.
 void initialize()
          Checks that the function has been correctly initialized.
 void itemsAdvanced(ReportEvent event)
          Triggers the visibility of an element.
 void itemsStarted(ReportEvent event)
          Receives notification that the items are being processed.
 void pageCanceled(ReportEvent event)
          Receives notification that a page was canceled by the ReportProcessor.
 void pageFinished(ReportEvent event)
          Receives notification that a page is completed.
 void pageStarted(ReportEvent event)
          Receives notification that a page has started.
 void setElement(java.lang.String name)
          Sets the element name.
 
Methods inherited from class org.jfree.report.function.AbstractFunction
clone, getDataRow, getDependencyLevel, getInstance, getName, getProperties, getProperty, getProperty, groupFinished, groupStarted, isActive, itemsFinished, reportDone, reportFinished, reportInitialized, reportStarted, setDataRow, setDependencyLevel, setName, setProperties, setProperty
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ELEMENT_PROPERTY

public static final java.lang.String ELEMENT_PROPERTY
the Property key for the name of the ItemBand element.

See Also:
Constant Field Values

INITIAL_STATE_PROPERTY

public static final java.lang.String INITIAL_STATE_PROPERTY
The initial state property key.

See Also:
Constant Field Values
Constructor Detail

ElementVisibilitySwitchFunction

public ElementVisibilitySwitchFunction()
Default constructor.

Method Detail

pageStarted

public void pageStarted(ReportEvent event)
Receives notification that a page has started.

Specified by:
pageStarted in interface PageEventListener
Parameters:
event - the event.

pageCanceled

public void pageCanceled(ReportEvent event)
Receives notification that a page was canceled by the ReportProcessor. This method is called, when a page was removed from the report after it was generated.

Specified by:
pageCanceled in interface PageEventListener
Parameters:
event - The event.

pageFinished

public void pageFinished(ReportEvent event)
Receives notification that a page is completed.

Specified by:
pageFinished in interface PageEventListener
Parameters:
event - The event.

itemsStarted

public void itemsStarted(ReportEvent event)
Receives notification that the items are being processed. Sets the function value to false.

Following this event, there will be a sequence of itemsAdvanced events until the itemsFinished event is raised.

Specified by:
itemsStarted in interface ReportListener
Overrides:
itemsStarted in class AbstractFunction
Parameters:
event - Information about the event.

itemsAdvanced

public void itemsAdvanced(ReportEvent event)
Triggers the visibility of an element. If the named element was visible at the last itemsAdvanced call, it gets now invisible and vice versa. This creates the effect, that an element is printed every other line.

Specified by:
itemsAdvanced in interface ReportListener
Overrides:
itemsAdvanced in class AbstractFunction
Parameters:
event - the report event.

initialize

public void initialize()
                throws FunctionInitializeException
Checks that the function has been correctly initialized. The functions name or the elements name have not been set, and FunctionInitializeException is thrown.

Specified by:
initialize in interface Expression
Overrides:
initialize in class AbstractFunction
Throws:
FunctionInitializeException - if required parameters were missing and initialisation cannot be performed.

getInitialTriggerValue

public boolean getInitialTriggerValue()
Gets the initial value for the visible trigger, either "true" or "false".

Returns:
the initial value for the trigger.

setElement

public void setElement(java.lang.String name)
Sets the element name. The name denotes an element within the item band. The element will be retrieved using the getElement(String) function.

Parameters:
name - The element name.
See Also:
Band.getElement(String)

getElement

public java.lang.String getElement()
Returns the element name.

Returns:
The element name.

getValue

public java.lang.Object getValue()
Returns the defined visibility of the element. Returns either true or false as java.lang.Boolean.

Specified by:
getValue in interface Expression
Returns:
the visibility of the element, either Boolean.TRUE or Boolean.FALSE.