001: /**
002: * ===========================================
003: * JFreeReport : a free Java reporting library
004: * ===========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * ComponentFieldTemplate.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.filter.templates;
030:
031: import org.jfree.report.filter.ComponentDrawableFilter;
032: import org.jfree.report.filter.DataRowDataSource;
033: import org.jfree.report.function.ExpressionRuntime;
034:
035: /**
036: * An drawable field template. The drawable content will be read from the datarow.
037: *
038: * @author Thomas Morgner
039: */
040: public class ComponentFieldTemplate extends AbstractTemplate {
041: /**
042: * The data row reader.
043: */
044: private DataRowDataSource dataRowDataSource;
045:
046: /**
047: * The filter that converts the AWT-Components into Drawables.
048: */
049: private ComponentDrawableFilter drawableFilter;
050:
051: /**
052: * Creates a new image field template.
053: */
054: public ComponentFieldTemplate() {
055: dataRowDataSource = new DataRowDataSource();
056: drawableFilter = new ComponentDrawableFilter();
057: drawableFilter.setDataSource(dataRowDataSource);
058: }
059:
060: /**
061: * Returns the field name.
062: *
063: * @return The field name.
064: */
065: public String getField() {
066: return dataRowDataSource.getDataSourceColumnName();
067: }
068:
069: /**
070: * Sets the field name.
071: *
072: * @param field the field name.
073: */
074: public void setField(final String field) {
075: dataRowDataSource.setDataSourceColumnName(field);
076: }
077:
078: /**
079: * Returns the formula used to compute the value of the data source.
080: *
081: * @return the formula.
082: */
083: public String getFormula() {
084: return dataRowDataSource.getFormula();
085: }
086:
087: /**
088: * Defines the formula used to compute the value of this data source.
089: *
090: * @param formula the formula for the data source.
091: */
092: public void setFormula(final String formula) {
093: dataRowDataSource.setFormula(formula);
094: }
095:
096: /**
097: * Returns the current value for the data source.
098: *
099: * @param runtime the expression runtime that is used to evaluate formulas and expressions when computing the value of
100: * this filter.
101: * @return the value.
102: */
103: public Object getValue(final ExpressionRuntime runtime) {
104: return drawableFilter.getValue(runtime);
105: }
106:
107: /**
108: * Clones the template.
109: *
110: * @return the clone.
111: *
112: * @throws CloneNotSupportedException this should never happen.
113: */
114: public Object clone() throws CloneNotSupportedException {
115: final ComponentFieldTemplate template = (ComponentFieldTemplate) super
116: .clone();
117: template.drawableFilter = (ComponentDrawableFilter) template.drawableFilter
118: .clone();
119: template.dataRowDataSource = (DataRowDataSource) template.drawableFilter
120: .getDataSource();
121: return template;
122: }
123:
124: /**
125: * Returns the datarow data source used in this template.
126: *
127: * @return the datarow data source.
128: */
129: protected DataRowDataSource getDataRowDataSource() {
130: return dataRowDataSource;
131: }
132:
133: /**
134: * Returns the filter that converts the components into Drawable objects.
135: *
136: * @return the drawable filter.
137: */
138: protected ComponentDrawableFilter getDrawableFilter() {
139: return drawableFilter;
140: }
141: }
|