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: * ImageFieldTemplate.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.DataRowDataSource;
032: import org.jfree.report.filter.ImageLoadFilter;
033: import org.jfree.report.filter.ImageRefFilter;
034: import org.jfree.report.function.ExpressionRuntime;
035:
036: /**
037: * An image field template. The image content will be read from the datarow.
038: *
039: * @author Thomas Morgner
040: */
041: public class ImageFieldTemplate extends AbstractTemplate {
042: /**
043: * The data row reader.
044: */
045: private DataRowDataSource dataRowDataSource;
046:
047: /**
048: * An image reference filter.
049: */
050: private ImageRefFilter imageRefFilter;
051:
052: /**
053: * The filter that is used to load the image from a URL, file or Blob.
054: */
055: private ImageLoadFilter imageLoadFilter;
056:
057: /**
058: * Creates a new image field template.
059: */
060: public ImageFieldTemplate() {
061: dataRowDataSource = new DataRowDataSource();
062: imageLoadFilter = new ImageLoadFilter();
063: imageLoadFilter.setDataSource(dataRowDataSource);
064: imageRefFilter = new ImageRefFilter();
065: imageRefFilter.setDataSource(imageLoadFilter);
066: }
067:
068: /**
069: * Returns the field name.
070: *
071: * @return The field name.
072: */
073: public String getField() {
074: return dataRowDataSource.getDataSourceColumnName();
075: }
076:
077: /**
078: * Sets the field name.
079: *
080: * @param field the field name.
081: */
082: public void setField(final String field) {
083: dataRowDataSource.setDataSourceColumnName(field);
084: }
085:
086: /**
087: * Returns the formula used to compute the value of the data source.
088: *
089: * @return the formula.
090: */
091: public String getFormula() {
092: return dataRowDataSource.getFormula();
093: }
094:
095: /**
096: * Defines the formula used to compute the value of this data source.
097: *
098: * @param formula the formula for the data source.
099: */
100: public void setFormula(final String formula) {
101: dataRowDataSource.setFormula(formula);
102: }
103:
104: /**
105: * Returns the current value for the data source.
106: *
107: * @param runtime the expression runtime that is used to evaluate formulas and expressions when computing the value of
108: * this filter.
109: * @return the value.
110: */
111: public Object getValue(final ExpressionRuntime runtime) {
112: return imageRefFilter.getValue(runtime);
113: }
114:
115: /**
116: * Clones the template.
117: *
118: * @return the clone.
119: *
120: * @throws CloneNotSupportedException this should never happen.
121: */
122: public Object clone() throws CloneNotSupportedException {
123: final ImageFieldTemplate template = (ImageFieldTemplate) super
124: .clone();
125: template.imageRefFilter = (ImageRefFilter) imageRefFilter
126: .clone();
127: template.imageLoadFilter = (ImageLoadFilter) imageRefFilter
128: .getDataSource();
129: template.dataRowDataSource = (DataRowDataSource) template.imageLoadFilter
130: .getDataSource();
131: return template;
132: }
133:
134: /**
135: * Returns the datarow data source used in this template.
136: *
137: * @return the datarow data source.
138: */
139: protected DataRowDataSource getDataRowDataSource() {
140: return dataRowDataSource;
141: }
142: }
|