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