~brian-thomason/+junk/jasperreports3.7

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*
 * JasperReports - Free Java Reporting Library.
 * Copyright (C) 2001 - 2009 Jaspersoft Corporation. All rights reserved.
 * http://www.jaspersoft.com
 *
 * Unless you have purchased a commercial license agreement from Jaspersoft,
 * the following license terms apply:
 *
 * This program is part of JasperReports.
 *
 * JasperReports is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * JasperReports is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with JasperReports. If not, see <http://www.gnu.org/licenses/>.
 */
package net.sf.jasperreports.charts.util;

import java.awt.Color;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;

import net.sf.jasperreports.charts.JRDataRange;
import net.sf.jasperreports.charts.base.JRBaseDataRange;
import net.sf.jasperreports.engine.JRCloneable;
import net.sf.jasperreports.engine.JRConstants;
import net.sf.jasperreports.engine.JRRuntimeException;
import net.sf.jasperreports.engine.base.JRBaseObjectFactory;

/**
 * Defines a subsection of a meter chart.  This section has its own range,
 * a label, and can shade a section of the meter face with its own color.
 * Common usages are to show "critical", "warning" and "good" ranges.
 *
 * @author Barry Klawans (barry@users.sourceforge.net)
 * @version $Id: JRMeterInterval.java 3715 2010-04-08 18:08:49Z teodord $
 */


public class JRMeterInterval implements JRCloneable, Serializable
{
	public static final double DEFAULT_TRANSPARENCY = 1.0;
	
	/**
	 * The range of this interval.  Must be inside the meter's range.
	 */
	protected JRDataRange dataRange = null;

	/**
	 * The label of this interval.  Only appears in the meter's legend.
	 */
	protected String label = null;

	/**
	 * Color to use to shade in this region on the meter's face.
	 */
	protected Color backgroundColor = null;

	/**
	 * Transparency of the interval's color.  1.0 is fully opaque, 0.0 is
	 * fully transparent.
	 */
	protected Double alphaDouble = null;

	private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;

	/**
	 * Construct an empty interval.
	 */
	public JRMeterInterval()
	{
	}

	/**
	 * Construct a new interval by copying an existing one.
	 *
	 * @param meterInterval the interval to copy
	 * @param factory factory object to register expressions with
	 */
	public JRMeterInterval(JRMeterInterval meterInterval, JRBaseObjectFactory factory)
	{
		dataRange = new JRBaseDataRange(meterInterval.getDataRange(), factory);
		label = meterInterval.getLabel();
		backgroundColor = meterInterval.getBackgroundColor();
		alphaDouble = meterInterval.getAlphaDouble();
	}

	/**
	 * Returns the range this interval is for.
	 *
	 * @return the range of this interval
	 */
	public JRDataRange getDataRange()
	{
		return dataRange;
	}

	/**
	 * Sets the range for this interval.  The range must be inside the
	 * range of the meter we are going to add the interval to.
	 *
	 * @param dataRange the range of this interval
	 */
	public void setDataRange(JRDataRange dataRange)
	{
		this.dataRange = dataRange;
	}

	/**
	 * The text describing this range.  This text only appears in the
	 * meter's legend.
	 *
	 * @return the text describing this range
	 */
	public String getLabel()
	{
		return label;
	}

	/**
	 * Sets the textual description of this range.  This text only appears
	 * in the meter's legend.
	 *
	 * @param label the textual description of this range
	 */
	public void setLabel(String label)
	{
		this.label = label;
	}

	/**
	 * Returns the color used to shade this interval.
	 *
	 * @return the color used to shade this interval
	 */
	public Color getBackgroundColor()
	{
		return backgroundColor;
	}

	/**
	 * Specifies the color to use to shade this interval.
	 *
	 * @param backgroundColor the color to use to shade this interval
	 */
	public void setBackgroundColor(Color backgroundColor)
	{
		this.backgroundColor = backgroundColor;
	}

	/**
	 * @deprecated Replaced by {@link #getAlphaDouble()}
	 */
	public double getAlpha()
	{
		return alphaDouble == null ? DEFAULT_TRANSPARENCY : alphaDouble.doubleValue();
	}

	/**
	 * Returns the transparency of the interval color, with 0.0 being fully
	 * transparent and 1.0 being fully opaque.
	 *
	 * @return the transparency
	 */
	public Double getAlphaDouble()
	{
		return alphaDouble;
	}

	/**
	 * @deprecated Replaced by {@link #setAlpha(Double)}
	 */
	public void setAlpha(double alpha)
	{
		setAlpha(new Double(alpha));
	}

	/**
	 * Sets the transparency of the interval color, with 0.0 being fully
	 * transparent and 1.0 being fully opaque.
	 *
	 * @param alpha the transparency of the interval color
	 */
	public void setAlpha(Double alpha)
	{
		this.alphaDouble = alpha;
	}

	/**
	 *
	 */
	public Object clone() 
	{
		JRMeterInterval clone = null;
		
		try
		{
			clone = (JRMeterInterval)super.clone();
		}
		catch (CloneNotSupportedException e)
		{
			throw new JRRuntimeException(e);
		}

		if (dataRange != null)
		{
			clone.dataRange = (JRDataRange)dataRange.clone();
		}
		
		return clone;
	}

	/*
	 * These fields are only for serialization backward compatibility.
	 */
	private int PSEUDO_SERIAL_VERSION_UID = JRConstants.PSEUDO_SERIAL_VERSION_UID; //NOPMD
	/**
	 * @deprecated
	 */
	private double alpha = DEFAULT_TRANSPARENCY;
	
	private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
	{
		in.defaultReadObject();
		
		if (PSEUDO_SERIAL_VERSION_UID < JRConstants.PSEUDO_SERIAL_VERSION_UID_3_1_3)
		{
			alphaDouble = new Double(alpha);
		}
	}
	
}