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.Shape ; 50 import java.awt.Stroke ; 51 import java.awt.geom.Arc2D ; 52 import java.awt.geom.Area ; 53 import java.awt.geom.GeneralPath ; 54 import java.awt.geom.Point2D ; 55 import java.awt.geom.Rectangle2D ; 56 import java.io.IOException ; 57 import java.io.ObjectInputStream ; 58 import java.io.ObjectOutputStream ; 59 import java.io.Serializable ; 60 61 import org.jfree.chart.HashUtilities; 62 import org.jfree.io.SerialUtilities; 63 import org.jfree.util.PaintUtilities; 64 import org.jfree.util.PublicCloneable; 65 66 69 public class StandardDialFrame extends AbstractDialLayer implements DialFrame, 70 Cloneable , PublicCloneable, Serializable { 71 72 76 private transient Paint backgroundPaint; 77 78 82 private transient Paint foregroundPaint; 83 84 88 private transient Stroke stroke; 89 90 93 private double startAngle; 94 95 98 private double extent; 99 100 101 private double innerRadius; 102 103 104 private double outerRadius; 105 106 110 public StandardDialFrame() { 111 this(0, 180); 112 } 113 114 121 public StandardDialFrame(double startAngle, double extent) { 122 this.backgroundPaint = Color.gray; 123 this.foregroundPaint = new Color (100, 100, 150); 124 this.stroke = new BasicStroke (2.0f); 125 this.innerRadius = 0.25; 126 this.outerRadius = 0.75; 127 this.startAngle = startAngle; 128 this.extent = extent; 129 } 130 131 138 public Paint getBackgroundPaint() { 139 return this.backgroundPaint; 140 } 141 142 149 public void setBackgroundPaint(Paint paint) { 150 if (paint == null) { 151 throw new IllegalArgumentException ("Null 'paint' argument."); 152 } 153 this.backgroundPaint = paint; 154 notifyListeners(new DialLayerChangeEvent(this)); 155 } 156 157 164 public Paint getForegroundPaint() { 165 return this.foregroundPaint; 166 } 167 168 175 public void setForegroundPaint(Paint paint) { 176 if (paint == null) { 177 throw new IllegalArgumentException ("Null 'paint' argument."); 178 } 179 this.foregroundPaint = paint; 180 notifyListeners(new DialLayerChangeEvent(this)); 181 } 182 183 190 public Stroke getStroke() { 191 return this.stroke; 192 } 193 194 201 public void setStroke(Stroke stroke) { 202 if (stroke == null) { 203 throw new IllegalArgumentException ("Null 'stroke' argument."); 204 } 205 this.stroke = stroke; 206 notifyListeners(new DialLayerChangeEvent(this)); 207 } 208 209 216 public double getInnerRadius() { 217 return this.innerRadius; 218 } 219 220 227 public void setInnerRadius(double radius) { 228 this.innerRadius = radius; 230 notifyListeners(new DialLayerChangeEvent(this)); 231 } 232 233 240 public double getOuterRadius() { 241 return this.outerRadius; 242 } 243 244 251 public void setOuterRadius(double radius) { 252 this.outerRadius = radius; 254 notifyListeners(new DialLayerChangeEvent(this)); 255 } 256 257 264 public double getStartAngle() { 265 return this.startAngle; 266 } 267 268 275 public void setStartAngle(double angle) { 276 this.startAngle = angle; 277 notifyListeners(new DialLayerChangeEvent(this)); 278 } 279 280 287 public double getExtent() { 288 return this.extent; 289 } 290 291 298 public void setExtent(double extent) { 299 this.extent = extent; 300 notifyListeners(new DialLayerChangeEvent(this)); 301 } 302 303 311 public Shape getWindow(Rectangle2D frame) { 312 313 Rectangle2D innerFrame = DialPlot.rectangleByRadius(frame, 314 this.innerRadius, this.innerRadius); 315 Rectangle2D outerFrame = DialPlot.rectangleByRadius(frame, 316 this.outerRadius, this.outerRadius); 317 Arc2D inner = new Arc2D.Double (innerFrame, this.startAngle, this.extent, 318 Arc2D.OPEN); 319 Arc2D outer = new Arc2D.Double (outerFrame, this.startAngle 320 + this.extent, - this.extent, Arc2D.OPEN); 321 GeneralPath p = new GeneralPath (); 322 Point2D point1 = inner.getStartPoint(); 323 p.moveTo((float) point1.getX(), (float) point1.getY()); 324 p.append(inner, true); 325 p.append(outer, true); 326 p.closePath(); 327 return p; 328 329 } 330 331 protected Shape getOuterWindow(Rectangle2D frame) { 332 double radiusMargin = 0.02; 333 double angleMargin = 1.5; 334 Rectangle2D innerFrame = DialPlot.rectangleByRadius(frame, 335 this.innerRadius - radiusMargin, this.innerRadius 336 - radiusMargin); 337 Rectangle2D outerFrame = DialPlot.rectangleByRadius(frame, 338 this.outerRadius + radiusMargin, this.outerRadius 339 + radiusMargin); 340 Arc2D inner = new Arc2D.Double (innerFrame, this.startAngle 341 - angleMargin, this.extent + 2 * angleMargin, Arc2D.OPEN); 342 Arc2D outer = new Arc2D.Double (outerFrame, this.startAngle 343 + angleMargin + this.extent, - this.extent - 2 * angleMargin, 344 Arc2D.OPEN); 345 GeneralPath p = new GeneralPath (); 346 Point2D point1 = inner.getStartPoint(); 347 p.moveTo((float) point1.getX(), (float) point1.getY()); 348 p.append(inner, true); 349 p.append(outer, true); 350 p.closePath(); 351 return p; 352 353 } 354 355 363 public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 364 Rectangle2D view) { 365 366 Shape window = getWindow(frame); 367 Shape outerWindow = getOuterWindow(frame); 368 369 Area area1 = new Area (outerWindow); 370 Area area2 = new Area (window); 371 area1.subtract(area2); 372 g2.setPaint(Color.lightGray); 373 g2.fill(area1); 374 375 g2.setStroke(this.stroke); 376 g2.setPaint(this.foregroundPaint); 377 g2.draw(window); 378 g2.draw(outerWindow); 379 380 381 } 382 383 389 public boolean isClippedToWindow() { 390 return false; 391 } 392 393 400 public boolean equals(Object obj) { 401 if (obj == this) { 402 return true; 403 } 404 if (!(obj instanceof StandardDialFrame)) { 405 return false; 406 } 407 StandardDialFrame that = (StandardDialFrame) obj; 408 if (!PaintUtilities.equal(this.backgroundPaint, that.backgroundPaint)) { 409 return false; 410 } 411 if (!PaintUtilities.equal(this.foregroundPaint, that.foregroundPaint)) { 412 return false; 413 } 414 if (this.startAngle != that.startAngle) { 415 return false; 416 } 417 if (this.extent != that.extent) { 418 return false; 419 } 420 if (this.innerRadius != that.innerRadius) { 421 return false; 422 } 423 if (this.outerRadius != that.outerRadius) { 424 return false; 425 } 426 if (!this.stroke.equals(that.stroke)) { 427 return false; 428 } 429 return true; 430 } 431 432 437 public int hashCode() { 438 int result = 193; 439 long temp = Double.doubleToLongBits(this.startAngle); 440 result = (int) (temp ^ (temp >>> 32)); 441 temp = Double.doubleToLongBits(this.extent); 442 result = (int) (temp ^ (temp >>> 32)); 443 temp = Double.doubleToLongBits(this.innerRadius); 444 result = (int) (temp ^ (temp >>> 32)); 445 temp = Double.doubleToLongBits(this.outerRadius); 446 result = (int) (temp ^ (temp >>> 32)); 447 result = 37 * result + HashUtilities.hashCodeForPaint( 448 this.backgroundPaint); 449 result = 37 * result + HashUtilities.hashCodeForPaint( 450 this.foregroundPaint); 451 result = 37 * result + this.stroke.hashCode(); 452 return result; 453 } 454 455 463 public Object clone() throws CloneNotSupportedException { 464 return super.clone(); 465 } 466 467 474 private void writeObject(ObjectOutputStream stream) throws IOException { 475 stream.defaultWriteObject(); 476 SerialUtilities.writePaint(this.backgroundPaint, stream); 477 SerialUtilities.writePaint(this.foregroundPaint, stream); 478 SerialUtilities.writeStroke(this.stroke, stream); 479 } 480 481 489 private void readObject(ObjectInputStream stream) 490 throws IOException , ClassNotFoundException { 491 stream.defaultReadObject(); 492 this.backgroundPaint = SerialUtilities.readPaint(stream); 493 this.foregroundPaint = SerialUtilities.readPaint(stream); 494 this.stroke = SerialUtilities.readStroke(stream); 495 } 496 497 } 498 | Popular Tags |