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.Stroke ; 50 import java.awt.geom.Ellipse2D ; 51 import java.awt.geom.Rectangle2D ; 52 import java.io.IOException ; 53 import java.io.ObjectInputStream ; 54 import java.io.ObjectOutputStream ; 55 import java.io.Serializable ; 56 57 import org.jfree.chart.HashUtilities; 58 import org.jfree.io.SerialUtilities; 59 import org.jfree.util.PaintUtilities; 60 import org.jfree.util.PublicCloneable; 61 62 66 public class DialCap extends AbstractDialLayer implements DialLayer, Cloneable , 67 PublicCloneable, Serializable { 68 69 72 private double radius; 73 74 78 private transient Paint fillPaint; 79 80 85 private transient Paint outlinePaint; 86 87 92 private transient Stroke outlineStroke; 93 94 98 public DialCap() { 99 this.radius = 0.05; 100 this.fillPaint = Color.white; 101 this.outlinePaint = Color.black; 102 this.outlineStroke = new BasicStroke (2.0f); 103 } 104 105 113 public double getRadius() { 114 return this.radius; 115 } 116 117 125 public void setRadius(double radius) { 126 this.radius = radius; 128 notifyListeners(new DialLayerChangeEvent(this)); 129 } 130 131 138 public Paint getFillPaint() { 139 return this.fillPaint; 140 } 141 142 149 public void setFillPaint(Paint paint) { 150 if (paint == null) { 151 throw new IllegalArgumentException ("Null 'paint' argument."); 152 } 153 this.fillPaint = paint; 154 notifyListeners(new DialLayerChangeEvent(this)); 155 } 156 157 164 public Paint getOutlinePaint() { 165 return this.outlinePaint; 166 } 167 168 175 public void setOutlinePaint(Paint paint) { 176 if (paint == null) { 177 throw new IllegalArgumentException ("Null 'paint' argument."); 178 } 179 this.outlinePaint = paint; 180 notifyListeners(new DialLayerChangeEvent(this)); 181 } 182 183 190 public Stroke getOutlineStroke() { 191 return this.outlineStroke; 192 } 193 194 202 public void setOutlineStroke(Stroke stroke) { 203 if (stroke == null) { 204 throw new IllegalArgumentException ("Null 'stroke' argument."); 205 } 206 this.outlineStroke = stroke; 207 notifyListeners(new DialLayerChangeEvent(this)); 208 } 209 210 216 public boolean isClippedToWindow() { 217 return true; 218 } 219 220 230 public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 231 Rectangle2D view) { 232 233 g2.setPaint(this.fillPaint); 234 235 Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius, 236 this.radius); 237 Ellipse2D e = new Ellipse2D.Double (f.getX(), f.getY(), f.getWidth(), 238 f.getHeight()); 239 g2.fill(e); 240 g2.setPaint(this.outlinePaint); 241 g2.setStroke(this.outlineStroke); 242 g2.draw(e); 243 244 } 245 246 253 public boolean equals(Object obj) { 254 if (obj == this) { 255 return true; 256 } 257 if (!(obj instanceof DialCap)) { 258 return false; 259 } 260 DialCap that = (DialCap) obj; 261 if (this.radius != that.radius) { 262 return false; 263 } 264 if (!PaintUtilities.equal(this.fillPaint, that.fillPaint)) { 265 return false; 266 } 267 if (!PaintUtilities.equal(this.outlinePaint, that.outlinePaint)) { 268 return false; 269 } 270 if (!this.outlineStroke.equals(that.outlineStroke)) { 271 return false; 272 } 273 return true; 274 } 275 276 281 public int hashCode() { 282 int result = 193; 283 result = 37 * result + HashUtilities.hashCodeForPaint(this.fillPaint); 284 result = 37 * result + HashUtilities.hashCodeForPaint( 285 this.outlinePaint); 286 result = 37 * result + this.outlineStroke.hashCode(); 287 return result; 288 } 289 290 298 public Object clone() throws CloneNotSupportedException { 299 return super.clone(); 300 } 301 302 309 private void writeObject(ObjectOutputStream stream) throws IOException { 310 stream.defaultWriteObject(); 311 SerialUtilities.writePaint(this.fillPaint, stream); 312 SerialUtilities.writePaint(this.outlinePaint, stream); 313 SerialUtilities.writeStroke(this.outlineStroke, stream); 314 } 315 316 324 private void readObject(ObjectInputStream stream) 325 throws IOException , ClassNotFoundException { 326 stream.defaultReadObject(); 327 this.fillPaint = SerialUtilities.readPaint(stream); 328 this.outlinePaint = SerialUtilities.readPaint(stream); 329 this.outlineStroke = SerialUtilities.readStroke(stream); 330 } 331 332 } 333 334 | Popular Tags |