001/* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2022, by David Gilbert 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-2022, by David Gilbert and Contributors. 031 * 032 * Original Author: David Gilbert; 033 * Contributor(s): -; 034 * 035 */ 036 037package org.jfree.chart.plot; 038 039import java.awt.BasicStroke; 040import java.awt.Color; 041import java.awt.Paint; 042import java.awt.Stroke; 043import java.io.IOException; 044import java.io.ObjectInputStream; 045import java.io.ObjectOutputStream; 046import java.io.Serializable; 047import java.util.Objects; 048 049import org.jfree.chart.internal.PaintUtils; 050import org.jfree.chart.internal.Args; 051import org.jfree.chart.internal.SerialUtils; 052 053import org.jfree.data.Range; 054 055/** 056 * An interval to be highlighted on a {@link MeterPlot}. Instances of this 057 * class are immutable. 058 */ 059public class MeterInterval implements Serializable { 060 061 /** For serialization. */ 062 private static final long serialVersionUID = 1530982090622488257L; 063 064 /** The interval label. */ 065 private final String label; 066 067 /** The interval range. */ 068 private final Range range; 069 070 /** The outline paint (used for the arc marking the interval). */ 071 private transient Paint outlinePaint; 072 073 /** The outline stroke (used for the arc marking the interval). */ 074 private transient Stroke outlineStroke; 075 076 /** The background paint for the interval. */ 077 private transient Paint backgroundPaint; 078 079 /** 080 * Creates a new interval. 081 * 082 * @param label the label ({@code null} not permitted). 083 * @param range the range ({@code null} not permitted). 084 */ 085 public MeterInterval(String label, Range range) { 086 this(label, range, Color.YELLOW, new BasicStroke(2.0f), null); 087 } 088 089 /** 090 * Creates a new interval. 091 * 092 * @param label the label ({@code null} not permitted). 093 * @param range the range ({@code null} not permitted). 094 * @param outlinePaint the outline paint ({@code null} permitted). 095 * @param outlineStroke the outline stroke ({@code null} permitted). 096 * @param backgroundPaint the background paint ({@code null} 097 * permitted). 098 */ 099 public MeterInterval(String label, Range range, Paint outlinePaint, 100 Stroke outlineStroke, Paint backgroundPaint) { 101 Args.nullNotPermitted(label, "label"); 102 Args.nullNotPermitted(range, "range"); 103 this.label = label; 104 this.range = range; 105 this.outlinePaint = outlinePaint; 106 this.outlineStroke = outlineStroke; 107 this.backgroundPaint = backgroundPaint; 108 } 109 110 /** 111 * Returns the label. 112 * 113 * @return The label (never {@code null}). 114 */ 115 public String getLabel() { 116 return this.label; 117 } 118 119 /** 120 * Returns the range. 121 * 122 * @return The range (never {@code null}). 123 */ 124 public Range getRange() { 125 return this.range; 126 } 127 128 /** 129 * Returns the background paint. If {@code null}, the background 130 * should remain unfilled. 131 * 132 * @return The background paint (possibly {@code null}). 133 */ 134 public Paint getBackgroundPaint() { 135 return this.backgroundPaint; 136 } 137 138 /** 139 * Returns the outline paint. 140 * 141 * @return The outline paint (possibly {@code null}). 142 */ 143 public Paint getOutlinePaint() { 144 return this.outlinePaint; 145 } 146 147 /** 148 * Returns the outline stroke. 149 * 150 * @return The outline stroke (possibly {@code null}). 151 */ 152 public Stroke getOutlineStroke() { 153 return this.outlineStroke; 154 } 155 156 /** 157 * Checks this instance for equality with an arbitrary object. 158 * 159 * @param obj the object ({@code null} permitted). 160 * 161 * @return A boolean. 162 */ 163 @Override 164 public boolean equals(Object obj) { 165 if (obj == this) { 166 return true; 167 } 168 if (!(obj instanceof MeterInterval)) { 169 return false; 170 } 171 MeterInterval that = (MeterInterval) obj; 172 if (!this.label.equals(that.label)) { 173 return false; 174 } 175 if (!this.range.equals(that.range)) { 176 return false; 177 } 178 if (!PaintUtils.equal(this.outlinePaint, that.outlinePaint)) { 179 return false; 180 } 181 if (!Objects.equals(this.outlineStroke, that.outlineStroke)) { 182 return false; 183 } 184 if (!PaintUtils.equal(this.backgroundPaint, that.backgroundPaint)) { 185 return false; 186 } 187 return true; 188 } 189 190 /** 191 * Provides serialization support. 192 * 193 * @param stream the output stream. 194 * 195 * @throws IOException if there is an I/O error. 196 */ 197 private void writeObject(ObjectOutputStream stream) throws IOException { 198 stream.defaultWriteObject(); 199 SerialUtils.writePaint(this.outlinePaint, stream); 200 SerialUtils.writeStroke(this.outlineStroke, stream); 201 SerialUtils.writePaint(this.backgroundPaint, stream); 202 } 203 204 /** 205 * Provides serialization support. 206 * 207 * @param stream the input stream. 208 * 209 * @throws IOException if there is an I/O error. 210 * @throws ClassNotFoundException if there is a classpath problem. 211 */ 212 private void readObject(ObjectInputStream stream) 213 throws IOException, ClassNotFoundException { 214 stream.defaultReadObject(); 215 this.outlinePaint = SerialUtils.readPaint(stream); 216 this.outlineStroke = SerialUtils.readStroke(stream); 217 this.backgroundPaint = SerialUtils.readPaint(stream); 218 } 219 220}