2
* JasperReports - Free Java Reporting Library.
3
* Copyright (C) 2001 - 2009 Jaspersoft Corporation. All rights reserved.
4
* http://www.jaspersoft.com
6
* Unless you have purchased a commercial license agreement from Jaspersoft,
7
* the following license terms apply:
9
* This program is part of JasperReports.
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.
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.
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/>.
24
package net.sf.jasperreports.charts.util;
26
import java.awt.Color;
27
import java.io.IOException;
28
import java.io.ObjectInputStream;
29
import java.io.Serializable;
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;
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.
43
* @author Barry Klawans (barry@users.sourceforge.net)
44
* @version $Id: JRMeterInterval.java 3715 2010-04-08 18:08:49Z teodord $
48
public class JRMeterInterval implements JRCloneable, Serializable
50
public static final double DEFAULT_TRANSPARENCY = 1.0;
53
* The range of this interval. Must be inside the meter's range.
55
protected JRDataRange dataRange = null;
58
* The label of this interval. Only appears in the meter's legend.
60
protected String label = null;
63
* Color to use to shade in this region on the meter's face.
65
protected Color backgroundColor = null;
68
* Transparency of the interval's color. 1.0 is fully opaque, 0.0 is
71
protected Double alphaDouble = null;
73
private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
76
* Construct an empty interval.
78
public JRMeterInterval()
83
* Construct a new interval by copying an existing one.
85
* @param meterInterval the interval to copy
86
* @param factory factory object to register expressions with
88
public JRMeterInterval(JRMeterInterval meterInterval, JRBaseObjectFactory factory)
90
dataRange = new JRBaseDataRange(meterInterval.getDataRange(), factory);
91
label = meterInterval.getLabel();
92
backgroundColor = meterInterval.getBackgroundColor();
93
alphaDouble = meterInterval.getAlphaDouble();
97
* Returns the range this interval is for.
99
* @return the range of this interval
101
public JRDataRange getDataRange()
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.
110
* @param dataRange the range of this interval
112
public void setDataRange(JRDataRange dataRange)
114
this.dataRange = dataRange;
118
* The text describing this range. This text only appears in the
121
* @return the text describing this range
123
public String getLabel()
129
* Sets the textual description of this range. This text only appears
130
* in the meter's legend.
132
* @param label the textual description of this range
134
public void setLabel(String label)
140
* Returns the color used to shade this interval.
142
* @return the color used to shade this interval
144
public Color getBackgroundColor()
146
return backgroundColor;
150
* Specifies the color to use to shade this interval.
152
* @param backgroundColor the color to use to shade this interval
154
public void setBackgroundColor(Color backgroundColor)
156
this.backgroundColor = backgroundColor;
160
* @deprecated Replaced by {@link #getAlphaDouble()}
162
public double getAlpha()
164
return alphaDouble == null ? DEFAULT_TRANSPARENCY : alphaDouble.doubleValue();
168
* Returns the transparency of the interval color, with 0.0 being fully
169
* transparent and 1.0 being fully opaque.
171
* @return the transparency
173
public Double getAlphaDouble()
179
* @deprecated Replaced by {@link #setAlpha(Double)}
181
public void setAlpha(double alpha)
183
setAlpha(new Double(alpha));
187
* Sets the transparency of the interval color, with 0.0 being fully
188
* transparent and 1.0 being fully opaque.
190
* @param alpha the transparency of the interval color
192
public void setAlpha(Double alpha)
194
this.alphaDouble = alpha;
200
public Object clone()
202
JRMeterInterval clone = null;
206
clone = (JRMeterInterval)super.clone();
208
catch (CloneNotSupportedException e)
210
throw new JRRuntimeException(e);
213
if (dataRange != null)
215
clone.dataRange = (JRDataRange)dataRange.clone();
222
* These fields are only for serialization backward compatibility.
224
private int PSEUDO_SERIAL_VERSION_UID = JRConstants.PSEUDO_SERIAL_VERSION_UID; //NOPMD
228
private double alpha = DEFAULT_TRANSPARENCY;
230
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
232
in.defaultReadObject();
234
if (PSEUDO_SERIAL_VERSION_UID < JRConstants.PSEUDO_SERIAL_VERSION_UID_3_1_3)
236
alphaDouble = new Double(alpha);