001: /*
002: * ============================================================================
003: * GNU Lesser General Public License
004: * ============================================================================
005: *
006: * JasperReports - Free Java report-generating library.
007: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * 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,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * JasperSoft Corporation
024: * 303 Second Street, Suite 450 North
025: * San Francisco, CA 94107
026: * http://www.jaspersoft.com
027: */
028: package net.sf.jasperreports.charts.base;
029:
030: import net.sf.jasperreports.charts.JRDataRange;
031: import net.sf.jasperreports.charts.JRMeterPlot;
032: import net.sf.jasperreports.charts.JRValueDisplay;
033: import net.sf.jasperreports.charts.base.JRBaseDataRange;
034: import net.sf.jasperreports.charts.util.JRMeterInterval;
035: import net.sf.jasperreports.charts.base.JRBaseValueDisplay;
036: import net.sf.jasperreports.engine.JRChart;
037: import net.sf.jasperreports.engine.JRChartPlot;
038: import net.sf.jasperreports.engine.JRConstants;
039: import net.sf.jasperreports.engine.JRExpressionCollector;
040: import net.sf.jasperreports.engine.base.JRBaseChartPlot;
041: import net.sf.jasperreports.engine.base.JRBaseObjectFactory;
042:
043: import java.awt.Color;
044: import java.util.Iterator;
045: import java.util.List;
046:
047: /**
048: * An immutable representation of the layout of a Meter chart.
049: *
050: * @author Barry Klawans (bklawans@users.sourceforge.net)
051: * @version $Id: JRBaseMeterPlot.java 1793 2007-07-30 09:06:18Z teodord $
052: */
053: public class JRBaseMeterPlot extends JRBaseChartPlot implements
054: JRMeterPlot {
055:
056: /**
057: *
058: */
059: private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
060:
061: /**
062: * The range displayed by the Meter.
063: */
064: protected JRDataRange dataRange = null;
065:
066: /**
067: * Formatting information for the textual display of the value.
068: */
069: protected JRValueDisplay valueDisplay = null;
070:
071: /**
072: * The shape to use when drawing the Meter. Only applied if the meter is
073: * over 180 degrees wide and less than a full circle.
074: */
075: protected byte shape = JRMeterPlot.SHAPE_PIE;
076:
077: /**
078: * The defined intervals for the Meter. Each interval indicates a
079: * subsection of the meter and a color to use for that section.
080: */
081: protected List intervals = new java.util.ArrayList();
082:
083: /**
084: * The extend of the meter face in degrees. It will always be centered
085: * around the straight up position.
086: */
087: protected int meterAngle = 180;
088:
089: /**
090: * Optional description of what the meter is displaying. It will be
091: * appended to the textual representation of the value.
092: */
093: protected String units = null;
094:
095: /**
096: * How often to draw ticks around the face of the meter. The interval
097: * is relative to the meter range - if the meter displays 100 to 200 and
098: * the tickInterval is 20, there will be 4 ticks at 120, 140, 160 and 180.
099: */
100: protected double tickInterval = 10.0;
101:
102: /**
103: * The color to use for the face of the meter.
104: */
105: protected Color meterBackgroundColor = null;
106:
107: /**
108: * The color to use for the pointer on the meter.
109: */
110: protected Color needleColor = null;
111:
112: /**
113: * The color to use for each tick on the face of the meter.
114: */
115: protected Color tickColor = null;
116:
117: /**
118: * Constructs a copy of an existing meter.
119: *
120: * @param meterPlot the meter to copy
121: */
122: public JRBaseMeterPlot(JRChartPlot meterPlot, JRChart chart) {
123: super (meterPlot, chart);
124: }
125:
126: /**
127: * Constructs a copy of an existing meter and registers all expressions
128: * maintained by the meter plot with a factory.
129: *
130: * @param meterPlot the meter to copy
131: * @param factory the factory to register expressions with
132: */
133: public JRBaseMeterPlot(JRMeterPlot meterPlot,
134: JRBaseObjectFactory factory) {
135: super (meterPlot, factory);
136:
137: dataRange = new JRBaseDataRange(meterPlot.getDataRange(),
138: factory);
139: valueDisplay = new JRBaseValueDisplay(meterPlot
140: .getValueDisplay(), factory);
141: shape = meterPlot.getShape();
142: List origIntervals = meterPlot.getIntervals();
143: intervals.clear();
144: if (origIntervals != null) {
145: Iterator iter = origIntervals.iterator();
146: while (iter.hasNext()) {
147: JRMeterInterval interval = (JRMeterInterval) iter
148: .next();
149: intervals.add(new JRMeterInterval(interval, factory));
150: }
151: }
152:
153: meterAngle = meterPlot.getMeterAngle();
154: units = meterPlot.getUnits();
155: tickInterval = meterPlot.getTickInterval();
156:
157: meterBackgroundColor = meterPlot.getMeterBackgroundColor();
158: needleColor = meterPlot.getNeedleColor();
159: tickColor = meterPlot.getTickColor();
160: }
161:
162: /**
163: *
164: */
165: public JRDataRange getDataRange() {
166: return dataRange;
167: }
168:
169: /**
170: *
171: */
172: public JRValueDisplay getValueDisplay() {
173: return valueDisplay;
174: }
175:
176: /**
177: *
178: */
179: public byte getShape() {
180: return shape;
181: }
182:
183: /**
184: *
185: */
186: public List getIntervals() {
187: return intervals;
188: }
189:
190: /**
191: *
192: */
193: public int getMeterAngle() {
194: return meterAngle;
195: }
196:
197: /**
198: *
199: */
200: public String getUnits() {
201: return units;
202: }
203:
204: /**
205: *
206: */
207: public double getTickInterval() {
208: return tickInterval;
209: }
210:
211: /**
212: *
213: */
214: public Color getMeterBackgroundColor() {
215: return meterBackgroundColor;
216: }
217:
218: /**
219: *
220: */
221: public Color getNeedleColor() {
222: return needleColor;
223: }
224:
225: /**
226: *
227: */
228: public Color getTickColor() {
229: return tickColor;
230: }
231:
232: /**
233: * Adds all the expression used by this plot with the specified collector.
234: * All collected expression that are also registered with a factory will
235: * be included with the report is compiled.
236: *
237: * @param collector the expression collector to use
238: */
239: public void collectExpressions(JRExpressionCollector collector) {
240: collector.collect(this);
241: }
242:
243: }
|