001/* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2013, by Object Refinery Limited and Contributors. 006 * 007 * Project Info: http://www.jfree.org/jfreechart/index.html 008 * 009 * This library is free software; you can redistribute it and/or modify it 010 * under the terms of the GNU Lesser General Public License as published by 011 * the Free Software Foundation; either version 2.1 of the License, or 012 * (at your option) any later version. 013 * 014 * This library is distributed in the hope that it will be useful, but 015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 017 * License for more details. 018 * 019 * You should have received a copy of the GNU Lesser General Public 020 * License along with this library; if not, write to the Free Software 021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 022 * USA. 023 * 024 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 025 * Other names may be trademarks of their respective owners.] 026 * 027 * ------------------ 028 * MeterInterval.java 029 * ------------------ 030 * (C) Copyright 2005-2013, by Object Refinery Limited and Contributors. 031 * 032 * Original Author: David Gilbert (for Object Refinery Limited); 033 * Contributor(s): -; 034 * 035 * Changes 036 * ------- 037 * 22-Mar-2005 : Version 1 (DG); 038 * 29-Mar-2005 : Fixed serialization (DG); 039 * 03-Jul-2013 : Use ParamChecks (DG); 040 * 041 */ 042 043package org.jfree.chart.plot; 044 045import java.awt.BasicStroke; 046import java.awt.Color; 047import java.awt.Paint; 048import java.awt.Stroke; 049import java.io.IOException; 050import java.io.ObjectInputStream; 051import java.io.ObjectOutputStream; 052import java.io.Serializable; 053import org.jfree.chart.util.ParamChecks; 054 055import org.jfree.data.Range; 056import org.jfree.io.SerialUtilities; 057import org.jfree.util.ObjectUtilities; 058import org.jfree.util.PaintUtilities; 059 060/** 061 * An interval to be highlighted on a {@link MeterPlot}. Instances of this 062 * class are immutable. 063 */ 064public class MeterInterval implements Serializable { 065 066 /** For serialization. */ 067 private static final long serialVersionUID = 1530982090622488257L; 068 069 /** The interval label. */ 070 private String label; 071 072 /** The interval range. */ 073 private Range range; 074 075 /** The outline paint (used for the arc marking the interval). */ 076 private transient Paint outlinePaint; 077 078 /** The outline stroke (used for the arc marking the interval). */ 079 private transient Stroke outlineStroke; 080 081 /** The background paint for the interval. */ 082 private transient Paint backgroundPaint; 083 084 /** 085 * Creates a new interval. 086 * 087 * @param label the label (<code>null</code> not permitted). 088 * @param range the range (<code>null</code> not permitted). 089 */ 090 public MeterInterval(String label, Range range) { 091 this(label, range, Color.yellow, new BasicStroke(2.0f), null); 092 } 093 094 /** 095 * Creates a new interval. 096 * 097 * @param label the label (<code>null</code> not permitted). 098 * @param range the range (<code>null</code> not permitted). 099 * @param outlinePaint the outline paint (<code>null</code> permitted). 100 * @param outlineStroke the outline stroke (<code>null</code> permitted). 101 * @param backgroundPaint the background paint (<code>null</code> 102 * permitted). 103 */ 104 public MeterInterval(String label, Range range, Paint outlinePaint, 105 Stroke outlineStroke, Paint backgroundPaint) { 106 ParamChecks.nullNotPermitted(label, "label"); 107 ParamChecks.nullNotPermitted(range, "range"); 108 this.label = label; 109 this.range = range; 110 this.outlinePaint = outlinePaint; 111 this.outlineStroke = outlineStroke; 112 this.backgroundPaint = backgroundPaint; 113 } 114 115 /** 116 * Returns the label. 117 * 118 * @return The label (never <code>null</code>). 119 */ 120 public String getLabel() { 121 return this.label; 122 } 123 124 /** 125 * Returns the range. 126 * 127 * @return The range (never <code>null</code>). 128 */ 129 public Range getRange() { 130 return this.range; 131 } 132 133 /** 134 * Returns the background paint. If <code>null</code>, the background 135 * should remain unfilled. 136 * 137 * @return The background paint (possibly <code>null</code>). 138 */ 139 public Paint getBackgroundPaint() { 140 return this.backgroundPaint; 141 } 142 143 /** 144 * Returns the outline paint. 145 * 146 * @return The outline paint (possibly <code>null</code>). 147 */ 148 public Paint getOutlinePaint() { 149 return this.outlinePaint; 150 } 151 152 /** 153 * Returns the outline stroke. 154 * 155 * @return The outline stroke (possibly <code>null</code>). 156 */ 157 public Stroke getOutlineStroke() { 158 return this.outlineStroke; 159 } 160 161 /** 162 * Checks this instance for equality with an arbitrary object. 163 * 164 * @param obj the object (<code>null</code> permitted). 165 * 166 * @return A boolean. 167 */ 168 @Override 169 public boolean equals(Object obj) { 170 if (obj == this) { 171 return true; 172 } 173 if (!(obj instanceof MeterInterval)) { 174 return false; 175 } 176 MeterInterval that = (MeterInterval) obj; 177 if (!this.label.equals(that.label)) { 178 return false; 179 } 180 if (!this.range.equals(that.range)) { 181 return false; 182 } 183 if (!PaintUtilities.equal(this.outlinePaint, that.outlinePaint)) { 184 return false; 185 } 186 if (!ObjectUtilities.equal(this.outlineStroke, that.outlineStroke)) { 187 return false; 188 } 189 if (!PaintUtilities.equal(this.backgroundPaint, that.backgroundPaint)) { 190 return false; 191 } 192 return true; 193 } 194 195 /** 196 * Provides serialization support. 197 * 198 * @param stream the output stream. 199 * 200 * @throws IOException if there is an I/O error. 201 */ 202 private void writeObject(ObjectOutputStream stream) throws IOException { 203 stream.defaultWriteObject(); 204 SerialUtilities.writePaint(this.outlinePaint, stream); 205 SerialUtilities.writeStroke(this.outlineStroke, stream); 206 SerialUtilities.writePaint(this.backgroundPaint, stream); 207 } 208 209 /** 210 * Provides serialization support. 211 * 212 * @param stream the input stream. 213 * 214 * @throws IOException if there is an I/O error. 215 * @throws ClassNotFoundException if there is a classpath problem. 216 */ 217 private void readObject(ObjectInputStream stream) 218 throws IOException, ClassNotFoundException { 219 stream.defaultReadObject(); 220 this.outlinePaint = SerialUtilities.readPaint(stream); 221 this.outlineStroke = SerialUtilities.readStroke(stream); 222 this.backgroundPaint = SerialUtilities.readPaint(stream); 223 } 224 225}