com.jrefinery.report.filter
Class FormatFilter

java.lang.Object
  extended bycom.jrefinery.report.filter.FormatFilter
All Implemented Interfaces:
java.lang.Cloneable, DataFilter, DataSource, DataTarget, java.io.Serializable
Direct Known Subclasses:
DateFormatFilter, NumberFormatFilter

public class FormatFilter
extends java.lang.Object
implements DataFilter, java.io.Serializable

The base class for filters that format data. Data is received from a DataSource and formatted. The data source might be a field in the TableModel or a report function, or even another format filter (since filters implement the DataSource interface).

Formating is done by a java.text.Format object. This filter will always return a String object on getValue().

If the formater does not understand the object returned by the defined datasource, the defined null value is returned.

The nullValue is set to "-" by default.

Author:
Thomas Morgner
See Also:
Serialized Form

Constructor Summary
FormatFilter()
          Default constructor.
 
Method Summary
 java.lang.Object clone()
          Clones the filter.
 DataSource getDataSource()
          Returns the data source for the filter.
 java.text.Format getFormatter()
          Returns the format for the filter.
 java.lang.String getNullValue()
          Returns the string representing a null value from the data source.
 java.lang.Object getValue()
          Returns the formatted string.
 void setDataSource(DataSource ds)
          Sets the data source.
 void setFormatter(java.text.Format format)
          Sets the format for the filter.
 void setNullValue(java.lang.String nullvalue)
          Sets the value that will be displayed if the data source supplies a null value.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FormatFilter

public FormatFilter()
Default constructor.

Method Detail

setFormatter

public void setFormatter(java.text.Format format)
Sets the format for the filter.

Parameters:
format - The format.
Throws:
java.lang.NullPointerException - if the given format is null

getFormatter

public java.text.Format getFormatter()
Returns the format for the filter.

Returns:
The format.

getValue

public java.lang.Object getValue()
Returns the formatted string. The value is read using the data source given and formated using the formatter of this object. The formating is guaranteed to completly form the object to an string or to return the defined NullValue.

If format, datasource or object are null, the NullValue is returned.

Specified by:
getValue in interface DataSource
Returns:
The formatted value.

setNullValue

public void setNullValue(java.lang.String nullvalue)
Sets the value that will be displayed if the data source supplies a null value.

Parameters:
nullvalue - The string.

getNullValue

public java.lang.String getNullValue()
Returns the string representing a null value from the data source.

Returns:
The string.

getDataSource

public DataSource getDataSource()
Returns the data source for the filter.

Specified by:
getDataSource in interface DataTarget
Returns:
The data source.

setDataSource

public void setDataSource(DataSource ds)
Sets the data source.

Specified by:
setDataSource in interface DataTarget
Parameters:
ds - The data source.

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Clones the filter.

Specified by:
clone in interface DataSource
Returns:
a clone.
Throws:
java.lang.CloneNotSupportedException - this should never happen.