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 * ShapeFieldTemplate.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.ShapeFilter;
36 import org.jfree.report.function.ExpressionRuntime;
37
38 /**
39 * A shape field template.
40 *
41 * @author Thomas Morgner.
42 */
43 public class ShapeFieldTemplate extends AbstractTemplate
44 {
45 /**
46 * The data row reader.
47 */
48 private DataRowDataSource dataRowDataSource;
49
50 /**
51 * A shape filter.
52 */
53 private ShapeFilter shapeFilter;
54
55 /**
56 * Creates a new shape field template.
57 */
58 public ShapeFieldTemplate ()
59 {
60 dataRowDataSource = new DataRowDataSource();
61 shapeFilter = new ShapeFilter();
62 shapeFilter.setDataSource(dataRowDataSource);
63 }
64
65 /**
66 * Returns the field name.
67 *
68 * @return The field name.
69 */
70 public String getField ()
71 {
72 return dataRowDataSource.getDataSourceColumnName();
73 }
74
75 /**
76 * Sets the field name.
77 *
78 * @param field the field name.
79 */
80 public void setField (final String field)
81 {
82 dataRowDataSource.setDataSourceColumnName(field);
83 }
84
85 /**
86 * Returns the formula used to compute the value of the data source.
87 *
88 * @return the formula.
89 */
90 public String getFormula()
91 {
92 return dataRowDataSource.getFormula();
93 }
94
95 /**
96 * Defines the formula used to compute the value of this data source.
97 *
98 * @param formula the formula for the data source.
99 */
100 public void setFormula(final String formula)
101 {
102 dataRowDataSource.setFormula(formula);
103 }
104
105
106 /**
107 * Returns the current value for the data source.
108 *
109 * @param runtime the expression runtime that is used to evaluate formulas and expressions when computing the value of
110 * this filter.
111 * @param element
112 * @return the value.
113 */
114 public Object getValue(final ExpressionRuntime runtime, final Element element)
115 {
116 return shapeFilter.getValue(runtime, element);
117 }
118
119 /**
120 * Clones the template.
121 *
122 * @return the clone.
123 *
124 * @throws CloneNotSupportedException this should never happen.
125 */
126 public Object clone ()
127 throws CloneNotSupportedException
128 {
129 final ShapeFieldTemplate template = (ShapeFieldTemplate) super.clone();
130 template.shapeFilter = (ShapeFilter) shapeFilter.clone();
131 template.dataRowDataSource = (DataRowDataSource) template.shapeFilter.getDataSource();
132 return template;
133 }
134
135 /**
136 * Returns the datarow data source used in this template.
137 *
138 * @return the datarow data source.
139 */
140 protected DataRowDataSource getDataRowDataSource ()
141 {
142 return dataRowDataSource;
143 }
144 }