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.Area ; 52 import java.awt.geom.Ellipse2D ; 53 import java.awt.geom.Rectangle2D ; 54 import java.io.IOException ; 55 import java.io.ObjectInputStream ; 56 import java.io.ObjectOutputStream ; 57 import java.io.Serializable ; 58 59 import org.jfree.chart.HashUtilities; 60 import org.jfree.io.SerialUtilities; 61 import org.jfree.util.PaintUtilities; 62 import org.jfree.util.PublicCloneable; 63 64 67 public class SimpleDialFrame extends AbstractDialLayer implements DialFrame, 68 Cloneable , PublicCloneable, Serializable { 69 70 71 private double radius; 72 73 77 private transient Paint backgroundPaint; 78 79 83 private transient Paint foregroundPaint; 84 85 89 private transient Stroke stroke; 90 91 94 public SimpleDialFrame() { 95 this.backgroundPaint = Color.gray; 96 this.foregroundPaint = Color.black; 97 this.stroke = new BasicStroke (2.0f); 98 this.radius = 0.95; 99 } 100 101 106 public double getRadius() { 107 return this.radius; 108 } 109 110 115 public void setRadius(double radius) { 116 this.radius = radius; 118 notifyListeners(new DialLayerChangeEvent(this)); 119 } 120 121 128 public Paint getBackgroundPaint() { 129 return this.backgroundPaint; 130 } 131 132 139 public void setBackgroundPaint(Paint paint) { 140 if (paint == null) { 141 throw new IllegalArgumentException ("Null 'paint' argument."); 142 } 143 this.backgroundPaint = paint; 144 notifyListeners(new DialLayerChangeEvent(this)); 145 } 146 147 154 public Paint getForegroundPaint() { 155 return this.foregroundPaint; 156 } 157 158 165 public void setForegroundPaint(Paint paint) { 166 if (paint == null) { 167 throw new IllegalArgumentException ("Null 'paint' argument."); 168 } 169 this.foregroundPaint = paint; 170 notifyListeners(new DialLayerChangeEvent(this)); 171 } 172 173 180 public Stroke getStroke() { 181 return this.stroke; 182 } 183 184 191 public void setStroke(Stroke stroke) { 192 if (stroke == null) { 193 throw new IllegalArgumentException ("Null 'stroke' argument."); 194 } 195 this.stroke = stroke; 196 notifyListeners(new DialLayerChangeEvent(this)); 197 } 198 199 207 public Shape getWindow(Rectangle2D frame) { 208 Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius, 209 this.radius); 210 return new Ellipse2D.Double (f.getX(), f.getY(), f.getWidth(), 211 f.getHeight()); 212 } 213 214 220 public boolean isClippedToWindow() { 221 return false; 222 } 223 224 233 public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 234 Rectangle2D view) { 235 236 Shape window = getWindow(frame); 237 238 Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius + 0.02, 239 this.radius + 0.02); 240 Ellipse2D e = new Ellipse2D.Double (f.getX(), f.getY(), f.getWidth(), 241 f.getHeight()); 242 243 Area area = new Area (e); 244 Area area2 = new Area (window); 245 area.subtract(area2); 246 g2.setPaint(this.backgroundPaint); 247 g2.fill(area); 248 249 g2.setStroke(this.stroke); 250 g2.setPaint(this.foregroundPaint); 251 g2.draw(window); 252 g2.draw(e); 253 } 254 255 262 public boolean equals(Object obj) { 263 if (obj == this) { 264 return true; 265 } 266 if (!(obj instanceof SimpleDialFrame)) { 267 return false; 268 } 269 SimpleDialFrame that = (SimpleDialFrame) obj; 270 if (!PaintUtilities.equal(this.backgroundPaint, that.backgroundPaint)) { 271 return false; 272 } 273 if (!PaintUtilities.equal(this.foregroundPaint, that.foregroundPaint)) { 274 return false; 275 } 276 if (this.radius != that.radius) { 277 return false; 278 } 279 if (!this.stroke.equals(that.stroke)) { 280 return false; 281 } 282 return true; 283 } 284 285 290 public int hashCode() { 291 int result = 193; 292 long temp = Double.doubleToLongBits(this.radius); 293 result = (int) (temp ^ (temp >>> 32)); 294 result = 37 * result + HashUtilities.hashCodeForPaint( 295 this.backgroundPaint); 296 result = 37 * result + HashUtilities.hashCodeForPaint( 297 this.foregroundPaint); 298 result = 37 * result + this.stroke.hashCode(); 299 return result; 300 } 301 302 310 public Object clone() throws CloneNotSupportedException { 311 return super.clone(); 312 } 313 314 321 private void writeObject(ObjectOutputStream stream) throws IOException { 322 stream.defaultWriteObject(); 323 SerialUtilities.writePaint(this.backgroundPaint, stream); 324 SerialUtilities.writePaint(this.foregroundPaint, stream); 325 SerialUtilities.writeStroke(this.stroke, stream); 326 } 327 328 336 private void readObject(ObjectInputStream stream) 337 throws IOException , ClassNotFoundException { 338 stream.defaultReadObject(); 339 this.backgroundPaint = SerialUtilities.readPaint(stream); 340 this.foregroundPaint = SerialUtilities.readPaint(stream); 341 this.stroke = SerialUtilities.readStroke(stream); 342 } 343 344 } 345 | Popular Tags |