KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > charts > base > JRBaseMeterPlot


1 /*
2  * ============================================================================
3  * GNU Lesser General Public License
4  * ============================================================================
5  *
6  * JasperReports - Free Java report-generating library.
7  * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * 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,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * JasperSoft Corporation
24  * 303 Second Street, Suite 450 North
25  * San Francisco, CA 94107
26  * http://www.jaspersoft.com
27  */

28 package net.sf.jasperreports.charts.base;
29
30 import net.sf.jasperreports.charts.JRDataRange;
31 import net.sf.jasperreports.charts.JRMeterPlot;
32 import net.sf.jasperreports.charts.JRValueDisplay;
33 import net.sf.jasperreports.charts.base.JRBaseDataRange;
34 import net.sf.jasperreports.charts.util.JRMeterInterval;
35 import net.sf.jasperreports.charts.base.JRBaseValueDisplay;
36 import net.sf.jasperreports.engine.JRChartPlot;
37 import net.sf.jasperreports.engine.JRConstants;
38 import net.sf.jasperreports.engine.JRExpressionCollector;
39 import net.sf.jasperreports.engine.base.JRBaseChartPlot;
40 import net.sf.jasperreports.engine.base.JRBaseObjectFactory;
41
42 import java.awt.Color JavaDoc;
43 import java.util.Iterator JavaDoc;
44 import java.util.List JavaDoc;
45
46 /**
47  * An immutable representation of the layout of a Meter chart.
48  *
49  * @author Barry Klawans (bklawans@users.sourceforge.net)
50  * @version $Id: JRBaseMeterPlot.java 1386 2006-09-06 00:33:02 +0300 (Wed, 06 Sep 2006) bklawans $
51  */

52 public class JRBaseMeterPlot extends JRBaseChartPlot implements JRMeterPlot
53 {
54
55
56     /**
57      *
58      */

59     private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
60
61     /**
62      * The range displayed by the Meter.
63      */

64     protected JRDataRange dataRange = null;
65     
66     /**
67      * Formatting information for the textual display of the value.
68      */

69     protected JRValueDisplay valueDisplay = null;
70     
71     /**
72      * The shape to use when drawing the Meter. Only applied if the meter is
73      * over 180 degrees wide and less than a full circle.
74      */

75     protected byte shape = JRMeterPlot.SHAPE_PIE;
76     
77     /**
78      * The defined intervals for the Meter. Each interval indicates a
79      * subsection of the meter and a color to use for that section.
80      */

81     protected List JavaDoc intervals = new java.util.ArrayList JavaDoc();
82     
83     /**
84      * The extend of the meter face in degrees. It will always be centered
85      * around the straight up position.
86      */

87     protected int meterAngle = 180;
88     
89     /**
90      * Optional description of what the meter is displaying. It will be
91      * appended to the textual representation of the value.
92      */

93     protected String JavaDoc units = null;
94     
95     /**
96      * How often to draw ticks around the face of the meter. The interval
97      * is relative to the meter range - if the meter displays 100 to 200 and
98      * the tickInterval is 20, there will be 4 ticks at 120, 140, 160 and 180.
99      */

100     protected double tickInterval = 10.0;
101
102     /**
103      * The color to use for the face of the meter.
104      */

105     protected Color JavaDoc meterBackgroundColor = null;
106     
107     /**
108      * The color to use for the pointer on the meter.
109      */

110     protected Color JavaDoc needleColor = null;
111     
112     /**
113      * The color to use for each tick on the face of the meter.
114      */

115     protected Color JavaDoc tickColor = null;
116     
117
118     
119     /**
120      * Constructs a copy of an existing meter.
121      *
122      * @param meterPlot the meter to copy
123      */

124     public JRBaseMeterPlot(JRChartPlot meterPlot)
125     {
126         super(meterPlot);
127     }
128     
129     /**
130      * Constructs a copy of an existing meter and registers all expressions
131      * maintained by the meter plot with a factory.
132      *
133      * @param meterPlot the meter to copy
134      * @param factory the factory to register expressions with
135      */

136     public JRBaseMeterPlot(JRMeterPlot meterPlot, JRBaseObjectFactory factory)
137     {
138         super(meterPlot, factory);
139
140         dataRange = new JRBaseDataRange(meterPlot.getDataRange(), factory);
141         valueDisplay = new JRBaseValueDisplay(meterPlot.getValueDisplay(), factory);
142         shape = meterPlot.getShape();
143         List JavaDoc origIntervals = meterPlot.getIntervals();
144         intervals.clear();
145         if (origIntervals != null)
146         {
147             Iterator JavaDoc iter = origIntervals.iterator();
148             while (iter.hasNext())
149             {
150                 JRMeterInterval interval = (JRMeterInterval)iter.next();
151                 intervals.add(new JRMeterInterval(interval, factory));
152             }
153         }
154         
155         meterAngle = meterPlot.getMeterAngle();
156         units = meterPlot.getUnits();
157         tickInterval = meterPlot.getTickInterval();
158
159         meterBackgroundColor = meterPlot.getMeterBackgroundColor();
160         needleColor = meterPlot.getNeedleColor();
161         tickColor = meterPlot.getTickColor();
162     }
163
164         
165         
166     /**
167      *
168      */

169     public JRDataRange getDataRange()
170     {
171         return dataRange;
172     }
173
174     /**
175      *
176      */

177     public JRValueDisplay getValueDisplay()
178     {
179         return valueDisplay;
180     }
181
182     /**
183      *
184      */

185     public byte getShape()
186     {
187         return shape;
188     }
189
190     /**
191      *
192      */

193     public List JavaDoc getIntervals(){
194         return intervals;
195     }
196     
197     /**
198      *
199      */

200     public int getMeterAngle()
201     {
202         return meterAngle;
203     }
204
205     /**
206      *
207      */

208     public String JavaDoc getUnits()
209     {
210         return units;
211     }
212
213     /**
214      *
215      */

216     public double getTickInterval()
217     {
218         return tickInterval;
219     }
220
221     /**
222      *
223      */

224     public Color JavaDoc getMeterBackgroundColor()
225     {
226         return meterBackgroundColor;
227     }
228
229     /**
230      *
231      */

232     public Color JavaDoc getNeedleColor()
233     {
234         return needleColor;
235     }
236
237     /**
238      *
239      */

240     public Color JavaDoc getTickColor()
241     {
242         return tickColor;
243     }
244
245     /**
246      * Adds all the expression used by this plot with the specified collector.
247      * All collected expression that are also registered with a factory will
248      * be included with the report is compiled.
249      *
250      * @param collector the expression collector to use
251      */

252     public void collectExpressions(JRExpressionCollector collector)
253     {
254         collector.collect(this);
255     }
256
257 }
258
Popular Tags