1 /**
2 * =========================================================
3 * Pentaho-Reporting-Classic : a free Java reporting library
4 * =========================================================
5 *
6 * Project Info: http://reporting.pentaho.org/
7 *
8 * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
9 *
10 * This library is free software; you can redistribute it and/or modify it under the terms
11 * of the GNU Lesser General Public License as published by the Free Software Foundation;
12 * either version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 * See the GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License along with this
19 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 * Boston, MA 02111-1307, USA.
21 *
22 * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
23 * in the United States and other countries.]
24 *
25 * ------------
26 * ImageFieldTemplate.java
27 * ------------
28 * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
29 */
30
31 package org.jfree.report.filter.templates;
32
33 import org.jfree.report.Element;
34 import org.jfree.report.filter.DataRowDataSource;
35 import org.jfree.report.filter.ImageLoadFilter;
36 import org.jfree.report.filter.ImageRefFilter;
37 import org.jfree.report.function.ExpressionRuntime;
38
39 /**
40 * An image field template. The image content will be read from the datarow.
41 *
42 * @author Thomas Morgner
43 */
44 public class ImageFieldTemplate extends AbstractTemplate
45 {
46 /**
47 * The data row reader.
48 */
49 private DataRowDataSource dataRowDataSource;
50
51 /**
52 * An image reference filter.
53 */
54 private ImageRefFilter imageRefFilter;
55
56 /**
57 * The filter that is used to load the image from a URL, file or Blob.
58 */
59 private ImageLoadFilter imageLoadFilter;
60
61 /**
62 * Creates a new image field template.
63 */
64 public ImageFieldTemplate ()
65 {
66 dataRowDataSource = new DataRowDataSource();
67 imageLoadFilter = new ImageLoadFilter();
68 imageLoadFilter.setDataSource(dataRowDataSource);
69 imageRefFilter = new ImageRefFilter();
70 imageRefFilter.setDataSource(imageLoadFilter);
71 }
72
73 /**
74 * Returns the field name.
75 *
76 * @return The field name.
77 */
78 public String getField ()
79 {
80 return dataRowDataSource.getDataSourceColumnName();
81 }
82
83 /**
84 * Sets the field name.
85 *
86 * @param field the field name.
87 */
88 public void setField (final String field)
89 {
90 dataRowDataSource.setDataSourceColumnName(field);
91 }
92
93 /**
94 * Returns the formula used to compute the value of the data source.
95 *
96 * @return the formula.
97 */
98 public String getFormula()
99 {
100 return dataRowDataSource.getFormula();
101 }
102
103 /**
104 * Defines the formula used to compute the value of this data source.
105 *
106 * @param formula the formula for the data source.
107 */
108 public void setFormula(final String formula)
109 {
110 dataRowDataSource.setFormula(formula);
111 }
112
113
114 /**
115 * Returns the current value for the data source.
116 *
117 * @param runtime the expression runtime that is used to evaluate formulas and expressions when computing the value of
118 * this filter.
119 * @param element
120 * @return the value.
121 */
122 public Object getValue(final ExpressionRuntime runtime, final Element element)
123 {
124 return imageRefFilter.getValue(runtime, element);
125 }
126
127 /**
128 * Clones the template.
129 *
130 * @return the clone.
131 *
132 * @throws CloneNotSupportedException this should never happen.
133 */
134 public Object clone ()
135 throws CloneNotSupportedException
136 {
137 final ImageFieldTemplate template = (ImageFieldTemplate) super.clone();
138 template.imageRefFilter = (ImageRefFilter) imageRefFilter.clone();
139 template.imageLoadFilter = (ImageLoadFilter) imageRefFilter.getDataSource();
140 template.dataRowDataSource = (DataRowDataSource) template.imageLoadFilter.getDataSource();
141 return template;
142 }
143
144 /**
145 * Returns the datarow data source used in this template.
146 *
147 * @return the datarow data source.
148 */
149 protected DataRowDataSource getDataRowDataSource ()
150 {
151 return dataRowDataSource;
152 }
153 }