Debian Codegraph @

source/org/jfree/report/modules/misc/survey/SurveyScaleExpression.java

raw
1 /**
2 * ========================================
3 * JFreeReport : a free Java report library
4 * ========================================
5 *
6 * Project Info: http://reporting.pentaho.org/
7 *
8 * (C) Copyright 2000-2007, by Object Refinery Limited, 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 * $Id: SurveyScaleExpression.java 10756 2009-12-02 15:58:24Z tmorgner $
27 * ------------
28 * (C) Copyright 2000-2005, by Object Refinery Limited.
29 * (C) Copyright 2005-2007, by Pentaho Corporation.
30 */
31
32 package org.jfree.report.modules.misc.survey;
33
34 import java.awt.Paint;
35 import java.awt.Shape;
36 import java.io.Serializable;
37
38 import org.jfree.report.DataSourceException;
39 import org.jfree.report.expressions.ColumnAggregationExpression;
40
41 /**
42 * An expression that takes values from one or more fields in the current row of the
43 * report, builds a {@link SurveyScale} instance that will present those values, and
44 * returns that instance as the expression result. The fields used by the expression are
45 * defined using properties named '0', '1', ... 'N', which need to be specified after the
46 * expression is created. These fields should contain {@link Number} instances.The {@link
47 * SurveyScale} class implements the Drawable interface, so it can be displayed
48 * using a DrawableElement.
49 */
50 public class SurveyScaleExpression extends
51 ColumnAggregationExpression implements Serializable
52 {
53 /**
54 * The name of the field containing the lower bound of the highlighted range.
55 */
56 private Number rangeLowerBound;
57
58 /**
59 * The name of the field containing the upper bound of the highlighted range.
60 */
61 private Number rangeUpperBound;
62
63 /**
64 * The range paint.
65 */
66 private Paint rangePaint;
67
68 /**
69 * An optional shape that is used (if present) for the first data value.
70 */
71 private Shape overrideShape;
72
73 /**
74 * A flag that controls whether or not the override shape is filled or not filled.
75 */
76 private boolean overrideShapeFilled;
77
78 private int lowestValue;
79 private int highestValue;
80
81 public SurveyScaleExpression ()
82 {
83 }
84
85 protected int getFieldListParameterPosition()
86 {
87 return 2;
88 }
89
90 public Number getRangeLowerBound()
91 {
92 return rangeLowerBound;
93 }
94
95 public void setRangeLowerBound(final Number rangeLowerBound)
96 {
97 this.rangeLowerBound = rangeLowerBound;
98 }
99
100 public Number getRangeUpperBound()
101 {
102 return rangeUpperBound;
103 }
104
105 public void setRangeUpperBound(final Number rangeUpperBound)
106 {
107 this.rangeUpperBound = rangeUpperBound;
108 }
109
110 public int getLowestValue()
111 {
112 return lowestValue;
113 }
114
115 public void setLowestValue(final int lowestValue)
116 {
117 this.lowestValue = lowestValue;
118 }
119
120 public int getHighestValue()
121 {
122 return highestValue;
123 }
124
125 public void setHighestValue(final int highestValue)
126 {
127 this.highestValue = highestValue;
128 }
129
130 /**
131 * Returns the override shape.
132 *
133 * @return The override shape (possibly <code>null</code>).
134 */
135 public Shape getOverrideShape ()
136 {
137 return this.overrideShape;
138 }
139
140 /**
141 * Sets the override shape. The {@link SurveyScale} is created with a set of default
142 * shapes, this method allows you to clearFromParent the *first* shape if you need to (leave it
143 * as <code>null</code> otherwise).
144 *
145 * @param shape the shape (<code>null</code> permitted).
146 */
147 public void setOverrideShape (final Shape shape)
148 {
149 this.overrideShape = shape;
150 }
151
152 /**
153 * Sets a flag that controls whether the override shape is filled or not.
154 *
155 * @param b the flag.
156 */
157 public void setOverrideShapeFilled (final boolean b)
158 {
159 this.overrideShapeFilled = b;
160 }
161
162 /**
163 * Returns a {@link SurveyScale} instance that is set up to display the values in the
164 * current row.
165 *
166 * @return a {@link SurveyScale} instance.
167 */
168 public Object computeValue () throws DataSourceException
169 {
170 final Number[] fieldValues = (Number[]) getFieldValues(Number.class);
171 final SurveyScale result = new SurveyScale
172 (this.lowestValue, this.highestValue, fieldValues);
173
174 result.setRangeLowerBound(getRangeLowerBound());
175 result.setRangeUpperBound(getRangeUpperBound());
176 result.setRangePaint(this.rangePaint);
177
178 if (this.overrideShape != null)
179 {
180 result.setShape(0, this.overrideShape);
181 result.setShapeFilled(0, this.overrideShapeFilled);
182 }
183 return result;
184 }
185
186 public boolean isOverrideShapeFilled ()
187 {
188 return overrideShapeFilled;
189 }
190
191 public Paint getRangePaint ()
192 {
193 return rangePaint;
194 }
195
196 public void setRangePaint (final Paint rangePaint)
197 {
198 this.rangePaint = rangePaint;
199 }
200 }