~brian-thomason/+junk/jasperreports3.7

1 by Brian Thomason
Initial import
1
/*
2
 * JasperReports - Free Java Reporting Library.
3
 * Copyright (C) 2001 - 2009 Jaspersoft Corporation. All rights reserved.
4
 * http://www.jaspersoft.com
5
 *
6
 * Unless you have purchased a commercial license agreement from Jaspersoft,
7
 * the following license terms apply:
8
 *
9
 * This program is part of JasperReports.
10
 *
11
 * JasperReports is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Lesser General Public License as published by
13
 * the Free Software Foundation, either version 3 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * JasperReports is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
 * GNU Lesser General Public License for more details.
20
 * 
21
 * You should have received a copy of the GNU Lesser General Public License
22
 * along with JasperReports. If not, see <http://www.gnu.org/licenses/>.
23
 */
24
package net.sf.jasperreports.charts.util;
25
26
import java.awt.Color;
27
import java.io.IOException;
28
import java.io.ObjectInputStream;
29
import java.io.Serializable;
30
31
import net.sf.jasperreports.charts.JRDataRange;
32
import net.sf.jasperreports.charts.base.JRBaseDataRange;
33
import net.sf.jasperreports.engine.JRCloneable;
34
import net.sf.jasperreports.engine.JRConstants;
35
import net.sf.jasperreports.engine.JRRuntimeException;
36
import net.sf.jasperreports.engine.base.JRBaseObjectFactory;
37
38
/**
39
 * Defines a subsection of a meter chart.  This section has its own range,
40
 * a label, and can shade a section of the meter face with its own color.
41
 * Common usages are to show "critical", "warning" and "good" ranges.
42
 *
43
 * @author Barry Klawans (barry@users.sourceforge.net)
44
 * @version $Id: JRMeterInterval.java 3715 2010-04-08 18:08:49Z teodord $
45
 */
46
47
48
public class JRMeterInterval implements JRCloneable, Serializable
49
{
50
	public static final double DEFAULT_TRANSPARENCY = 1.0;
51
	
52
	/**
53
	 * The range of this interval.  Must be inside the meter's range.
54
	 */
55
	protected JRDataRange dataRange = null;
56
57
	/**
58
	 * The label of this interval.  Only appears in the meter's legend.
59
	 */
60
	protected String label = null;
61
62
	/**
63
	 * Color to use to shade in this region on the meter's face.
64
	 */
65
	protected Color backgroundColor = null;
66
67
	/**
68
	 * Transparency of the interval's color.  1.0 is fully opaque, 0.0 is
69
	 * fully transparent.
70
	 */
71
	protected Double alphaDouble = null;
72
73
	private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
74
75
	/**
76
	 * Construct an empty interval.
77
	 */
78
	public JRMeterInterval()
79
	{
80
	}
81
82
	/**
83
	 * Construct a new interval by copying an existing one.
84
	 *
85
	 * @param meterInterval the interval to copy
86
	 * @param factory factory object to register expressions with
87
	 */
88
	public JRMeterInterval(JRMeterInterval meterInterval, JRBaseObjectFactory factory)
89
	{
90
		dataRange = new JRBaseDataRange(meterInterval.getDataRange(), factory);
91
		label = meterInterval.getLabel();
92
		backgroundColor = meterInterval.getBackgroundColor();
93
		alphaDouble = meterInterval.getAlphaDouble();
94
	}
95
96
	/**
97
	 * Returns the range this interval is for.
98
	 *
99
	 * @return the range of this interval
100
	 */
101
	public JRDataRange getDataRange()
102
	{
103
		return dataRange;
104
	}
105
106
	/**
107
	 * Sets the range for this interval.  The range must be inside the
108
	 * range of the meter we are going to add the interval to.
109
	 *
110
	 * @param dataRange the range of this interval
111
	 */
112
	public void setDataRange(JRDataRange dataRange)
113
	{
114
		this.dataRange = dataRange;
115
	}
116
117
	/**
118
	 * The text describing this range.  This text only appears in the
119
	 * meter's legend.
120
	 *
121
	 * @return the text describing this range
122
	 */
123
	public String getLabel()
124
	{
125
		return label;
126
	}
127
128
	/**
129
	 * Sets the textual description of this range.  This text only appears
130
	 * in the meter's legend.
131
	 *
132
	 * @param label the textual description of this range
133
	 */
134
	public void setLabel(String label)
135
	{
136
		this.label = label;
137
	}
138
139
	/**
140
	 * Returns the color used to shade this interval.
141
	 *
142
	 * @return the color used to shade this interval
143
	 */
144
	public Color getBackgroundColor()
145
	{
146
		return backgroundColor;
147
	}
148
149
	/**
150
	 * Specifies the color to use to shade this interval.
151
	 *
152
	 * @param backgroundColor the color to use to shade this interval
153
	 */
154
	public void setBackgroundColor(Color backgroundColor)
155
	{
156
		this.backgroundColor = backgroundColor;
157
	}
158
159
	/**
160
	 * @deprecated Replaced by {@link #getAlphaDouble()}
161
	 */
162
	public double getAlpha()
163
	{
164
		return alphaDouble == null ? DEFAULT_TRANSPARENCY : alphaDouble.doubleValue();
165
	}
166
167
	/**
168
	 * Returns the transparency of the interval color, with 0.0 being fully
169
	 * transparent and 1.0 being fully opaque.
170
	 *
171
	 * @return the transparency
172
	 */
173
	public Double getAlphaDouble()
174
	{
175
		return alphaDouble;
176
	}
177
178
	/**
179
	 * @deprecated Replaced by {@link #setAlpha(Double)}
180
	 */
181
	public void setAlpha(double alpha)
182
	{
183
		setAlpha(new Double(alpha));
184
	}
185
186
	/**
187
	 * Sets the transparency of the interval color, with 0.0 being fully
188
	 * transparent and 1.0 being fully opaque.
189
	 *
190
	 * @param alpha the transparency of the interval color
191
	 */
192
	public void setAlpha(Double alpha)
193
	{
194
		this.alphaDouble = alpha;
195
	}
196
197
	/**
198
	 *
199
	 */
200
	public Object clone() 
201
	{
202
		JRMeterInterval clone = null;
203
		
204
		try
205
		{
206
			clone = (JRMeterInterval)super.clone();
207
		}
208
		catch (CloneNotSupportedException e)
209
		{
210
			throw new JRRuntimeException(e);
211
		}
212
213
		if (dataRange != null)
214
		{
215
			clone.dataRange = (JRDataRange)dataRange.clone();
216
		}
217
		
218
		return clone;
219
	}
220
221
	/*
222
	 * These fields are only for serialization backward compatibility.
223
	 */
224
	private int PSEUDO_SERIAL_VERSION_UID = JRConstants.PSEUDO_SERIAL_VERSION_UID; //NOPMD
225
	/**
226
	 * @deprecated
227
	 */
228
	private double alpha = DEFAULT_TRANSPARENCY;
229
	
230
	private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
231
	{
232
		in.defaultReadObject();
233
		
234
		if (PSEUDO_SERIAL_VERSION_UID < JRConstants.PSEUDO_SERIAL_VERSION_UID_3_1_3)
235
		{
236
			alphaDouble = new Double(alpha);
237
		}
238
	}
239
	
240
}