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