KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > charts > design > JRDesignMeterPlot


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.design;
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.JRBaseMeterPlot;
34 import net.sf.jasperreports.charts.util.JRMeterInterval;
35 import net.sf.jasperreports.engine.JRChartPlot;
36 import net.sf.jasperreports.engine.JRConstants;
37 import net.sf.jasperreports.engine.JRException;
38
39 import java.awt.Color JavaDoc;
40
41 /**
42  * A meter plot that displays a single value against a range of values. The
43  * range can be further subdivided into multiple color coded regions.
44  *
45  * @author Barry Klawans (bklawans@users.sourceforge.net)
46  * @version $Id: JRDesignMeterPlot.java 1386 2006-09-06 00:33:02 +0300 (Wed, 06 Sep 2006) bklawans $
47  */

48 public class JRDesignMeterPlot extends JRBaseMeterPlot
49 {
50     
51
52     /**
53      *
54      */

55     private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
56
57     
58     /**
59      * Construct a new meter plot by copying an existing one.
60      *
61      * @param meterPlot the plot to copy
62      */

63     public JRDesignMeterPlot(JRChartPlot meterPlot)
64     {
65         super(meterPlot);
66     }
67     
68     /**
69      * Sets the range of values that the meter can display. Before changing
70      * this for an existing meter you should clear any existing intervals to
71      * ensure that you don't end up with intervals that are outside of the new
72      * range.
73      *
74      * @param dataRange the range of values that the meter can display
75      */

76     public void setDataRange(JRDataRange dataRange) throws JRException
77     {
78         this.dataRange = dataRange;
79     }
80
81     /**
82      * Sets the value display formatting options.
83      *
84      * @param valueDisplay how to show the textual representation of the value
85      */

86     public void setValueDisplay(JRValueDisplay valueDisplay)
87     {
88         this.valueDisplay = valueDisplay;
89     }
90     
91     /**
92      * Sets the shape of the meter. Must be one of
93      * <code>JRMeterPlot.SHAPE_CHORD</code>, <code>JRMeterPlot.SHAPE_CIRCLE</code>
94      * or <code>JRMeterPlot.SHAPE_PIE</code>.
95      *
96      * @param shape the shape of the meter
97      * @throws JRException invalid shape was specified
98      */

99     public void setShape(byte shape) throws JRException
100     {
101         if (shape < 0 || shape > JRMeterPlot.SHAPE_PIE)
102         {
103             throw new JRException("Unknown shape for MeterPlot");
104         }
105         
106         this.shape = shape;
107     }
108     
109     /**
110      * Adds an interval to the meter. An interval is used to indicate a
111      * section of the meter.
112      *
113      * @param interval the interval to add to the meter
114      */

115     public void addInterval(JRMeterInterval interval)
116     {
117         intervals.add(interval);
118     }
119     
120     /**
121      * Removes all the intervals for the meter.
122      */

123     public void clearIntervals()
124     {
125         intervals.clear();
126     }
127     
128     
129     /**
130      * Sets the size of the meter face in degrees.
131      *
132      * @param meterAngle the size of the meter in degrees
133      */

134     public void setMeterAngle(int meterAngle)
135     {
136         this.meterAngle = meterAngle;
137     }
138
139     /**
140      * Sets the units string to use. This string is appended to the value
141      * when it is displayed.
142      *
143      * @param units the units string to use
144      */

145     public void setUnits(String JavaDoc units)
146     {
147         this.units = units;
148     }
149
150     /**
151      * Sets the space between tick marks on the face of the meter. The
152      * spacing is relative to the range of the meter. If the meter is
153      * displaying the range 100 to 200 and the tick interval is 20, four
154      * tick marks will be shown, one each at 120, 140, 160 and 180.
155      *
156      * @param tickInterval the space between tick marks on the meter
157      */

158     public void setTickInterval(double tickInterval)
159     {
160         this.tickInterval = tickInterval;
161     }
162
163     /**
164      * Sets the color to use for the meter face.
165      *
166      * @param meterBackgroundColor the color to use for the meter face
167      */

168     public void setMeterBackgroundColor(Color JavaDoc meterBackgroundColor)
169     {
170         this.meterBackgroundColor = meterBackgroundColor;
171     }
172
173     /**
174      * Sets the color to use for the meter pointer.
175      *
176      * @param needleColor the color to use for the meter pointer
177      */

178     public void setNeedleColor(Color JavaDoc needleColor)
179     {
180         this.needleColor = needleColor;
181     }
182
183     /**
184      * Sets the color to use when drawing tick marks on the meter.
185      *
186      * @param tickColor the color to use when drawing tick marks
187      */

188     public void setTickColor(Color JavaDoc tickColor)
189     {
190         this.tickColor = tickColor;
191     }
192 }
193
Popular Tags