1 42 43 package org.jfree.experimental.chart.plot.dial; 44 45 import java.awt.BasicStroke ; 46 import java.awt.Color ; 47 import java.awt.Graphics2D ; 48 import java.awt.Paint ; 49 import java.awt.geom.Arc2D ; 50 import java.awt.geom.Rectangle2D ; 51 import java.io.IOException ; 52 import java.io.ObjectInputStream ; 53 import java.io.ObjectOutputStream ; 54 import java.io.Serializable ; 55 56 import org.jfree.chart.HashUtilities; 57 import org.jfree.io.SerialUtilities; 58 import org.jfree.util.PaintUtilities; 59 import org.jfree.util.PublicCloneable; 60 61 64 public class StandardDialRange extends AbstractDialLayer implements DialLayer, 65 Cloneable , PublicCloneable, Serializable { 66 67 68 private double lowerBound; 69 70 71 private double upperBound; 72 73 76 private double increment; 77 78 82 private transient Paint paint; 83 84 88 private double innerRadius; 89 90 94 private double outerRadius; 95 96 99 public StandardDialRange() { 100 this(0.0, 100.0, Color.white); 101 } 102 103 110 public StandardDialRange(double lower, double upper, Paint paint) { 111 if (paint == null) { 112 throw new IllegalArgumentException ("Null 'paint' argument."); 113 } 114 this.lowerBound = lower; 115 this.upperBound = upper; 116 this.paint = paint; 117 } 118 119 126 public double getLowerBound() { 127 return this.lowerBound; 128 } 129 130 137 public void setLowerBound(double bound) { 138 this.lowerBound = bound; 140 notifyListeners(new DialLayerChangeEvent(this)); 141 } 142 143 150 public double getUpperBound() { 151 return this.upperBound; 152 } 153 154 161 public void setUpperBound(double bound) { 162 this.upperBound = bound; 164 notifyListeners(new DialLayerChangeEvent(this)); 165 } 166 167 174 public double getIncrement() { 175 return this.increment; 176 } 177 178 185 public void setIncrement(double increment) { 186 this.increment = increment; 188 notifyListeners(new DialLayerChangeEvent(this)); 189 } 190 191 198 public Paint getPaint() { 199 return this.paint; 200 } 201 202 209 public void setPaint(Paint paint) { 210 if (paint == null) { 211 throw new IllegalArgumentException ("Null 'paint' argument."); 212 } 213 this.paint = paint; 214 notifyListeners(new DialLayerChangeEvent(this)); 215 } 216 217 224 public double getInnerRadius() { 225 return this.innerRadius; 226 } 227 228 235 public void setInnerRadius(double radius) { 236 this.innerRadius = radius; 237 notifyListeners(new DialLayerChangeEvent(this)); 238 } 239 240 247 public double getOuterRadius() { 248 return this.outerRadius; 249 } 250 251 258 public void setOuterRadius(double radius) { 259 this.outerRadius = radius; 260 notifyListeners(new DialLayerChangeEvent(this)); 261 } 262 263 269 public boolean isClippedToWindow() { 270 return true; 271 } 272 273 281 public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 282 Rectangle2D view) { 283 284 Rectangle2D arcRectInner = DialPlot.rectangleByRadius(frame, 285 this.innerRadius, this.innerRadius); 286 Rectangle2D arcRectOuter = DialPlot.rectangleByRadius(frame, 287 this.outerRadius, this.outerRadius); 288 290 DialScale scale = plot.getScaleForDataset(0); 291 double angleMin = scale.valueToAngle(this.lowerBound); 292 double angleMax = scale.valueToAngle(this.upperBound); 293 294 Arc2D arcInner = new Arc2D.Double (arcRectInner, angleMin, 295 angleMax - angleMin, Arc2D.OPEN); 296 Arc2D arcOuter = new Arc2D.Double (arcRectOuter, angleMax, 297 angleMin - angleMax, Arc2D.OPEN); 298 299 g2.setPaint(this.paint); 300 g2.setStroke(new BasicStroke (2.0f)); 301 g2.draw(arcInner); 302 g2.draw(arcOuter); 303 } 304 305 312 public boolean equals(Object obj) { 313 if (obj == this) { 314 return true; 315 } 316 if (!(obj instanceof StandardDialRange)) { 317 return false; 318 } 319 StandardDialRange that = (StandardDialRange) obj; 320 if (this.lowerBound != that.lowerBound) { 321 return false; 322 } 323 if (this.upperBound != that.upperBound) { 324 return false; 325 } 326 if (this.increment != that.increment) { 327 return false; 328 } 329 if (!PaintUtilities.equal(this.paint, that.paint)) { 330 return false; 331 } 332 if (this.innerRadius != that.innerRadius) { 333 return false; 334 } 335 if (this.outerRadius != that.outerRadius) { 336 return false; 337 } 338 return true; 339 } 340 341 346 public int hashCode() { 347 int result = 193; 348 long temp = Double.doubleToLongBits(this.increment); 349 result = (int) (temp ^ (temp >>> 32)); 350 temp = Double.doubleToLongBits(this.lowerBound); 351 result = (int) (temp ^ (temp >>> 32)); 352 temp = Double.doubleToLongBits(this.upperBound); 353 result = (int) (temp ^ (temp >>> 32)); 354 temp = Double.doubleToLongBits(this.innerRadius); 355 result = (int) (temp ^ (temp >>> 32)); 356 temp = Double.doubleToLongBits(this.outerRadius); 357 result = (int) (temp ^ (temp >>> 32)); 358 result = 37 * result + HashUtilities.hashCodeForPaint(this.paint); 359 return result; 360 } 361 362 370 public Object clone() throws CloneNotSupportedException { 371 return super.clone(); 372 } 373 374 381 private void writeObject(ObjectOutputStream stream) throws IOException { 382 stream.defaultWriteObject(); 383 SerialUtilities.writePaint(this.paint, stream); 384 } 385 386 394 private void readObject(ObjectInputStream stream) 395 throws IOException , ClassNotFoundException { 396 stream.defaultReadObject(); 397 this.paint = SerialUtilities.readPaint(stream); 398 } 399 400 } 401 | Popular Tags |