001 /** 002 * ======================================== 003 * JFreeReport : a free Java report library 004 * ======================================== 005 * 006 * Project Info: http://reporting.pentaho.org/ 007 * 008 * (C) Copyright 2000-2007, by Object Refinery Limited, 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 * $Id: SurveyScaleExpression.java 3525 2007-10-16 11:43:48Z tmorgner $ 027 * ------------ 028 * (C) Copyright 2000-2005, by Object Refinery Limited. 029 * (C) Copyright 2005-2007, by Pentaho Corporation. 030 */ 031 032 package org.jfree.report.modules.misc.survey; 033 034 import java.awt.Paint; 035 import java.awt.Shape; 036 import java.io.Serializable; 037 038 import org.jfree.report.DataSourceException; 039 import org.jfree.report.expressions.ColumnAggregationExpression; 040 import org.jfree.ui.Drawable; 041 042 /** 043 * An expression that takes values from one or more fields in the current row of the 044 * report, builds a {@link SurveyScale} instance that will present those values, and 045 * returns that instance as the expression result. The fields used by the expression are 046 * defined using properties named '0', '1', ... 'N', which need to be specified after the 047 * expression is created. These fields should contain {@link Number} instances.The {@link 048 * SurveyScale} class implements the {@link Drawable} interface, so it can be displayed 049 * using a {@link DrawableElement}. 050 */ 051 public class SurveyScaleExpression extends 052 ColumnAggregationExpression 053 { 054 /** 055 * The name of the field containing the lower bound of the highlighted range. 056 */ 057 private Number rangeLowerBound; 058 059 /** 060 * The name of the field containing the upper bound of the highlighted range. 061 */ 062 private Number rangeUpperBound; 063 064 /** 065 * The range paint. 066 */ 067 private Paint rangePaint; 068 069 /** 070 * An optional shape that is used (if present) for the first data value. 071 */ 072 private Shape overrideShape; 073 074 /** 075 * A flag that controls whether or not the override shape is filled or not filled. 076 */ 077 private boolean overrideShapeFilled; 078 079 private int lowestValue; 080 private int highestValue; 081 082 public SurveyScaleExpression () 083 { 084 } 085 086 protected int getFieldListParameterPosition() 087 { 088 return 2; 089 } 090 091 public Number getRangeLowerBound() 092 { 093 return rangeLowerBound; 094 } 095 096 public void setRangeLowerBound(final Number rangeLowerBound) 097 { 098 this.rangeLowerBound = rangeLowerBound; 099 } 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 }