1 42 43 package org.jfree.experimental.chart.plot.dial; 44 45 import java.awt.Color ; 46 import java.awt.Font ; 47 import java.awt.Graphics2D ; 48 import java.awt.Paint ; 49 import java.awt.geom.Arc2D ; 50 import java.awt.geom.Point2D ; 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.text.TextUtilities; 60 import org.jfree.ui.TextAnchor; 61 import org.jfree.util.PaintUtilities; 62 import org.jfree.util.PublicCloneable; 63 64 67 public class DialTextAnnotation extends AbstractDialLayer implements DialLayer, 68 Cloneable , PublicCloneable, Serializable { 69 70 71 private double angle; 72 73 74 private double radius; 75 76 77 private Font font; 78 79 83 private transient Paint paint; 84 85 86 private String label; 87 88 89 private TextAnchor anchor; 90 91 96 public DialTextAnnotation(String label) { 97 if (label == null) { 98 throw new IllegalArgumentException ("Null 'label' argument."); 99 } 100 this.angle = -90.0; 101 this.radius = 0.3; 102 this.font = new Font ("Dialog", Font.BOLD, 14); 103 this.paint = Color.black; 104 this.label = label; 105 this.anchor = TextAnchor.TOP_CENTER; 106 } 107 108 116 public double getAngle() { 117 return this.angle; 118 } 119 120 128 public void setAngle(double angle) { 129 this.angle = angle; 130 notifyListeners(new DialLayerChangeEvent(this)); 131 } 132 133 141 public double getRadius() { 142 return this.radius; 143 } 144 145 153 public void setRadius(double radius) { 154 this.radius = radius; 156 notifyListeners(new DialLayerChangeEvent(this)); 157 } 158 159 166 public Font getFont() { 167 return this.font; 168 } 169 170 177 public void setFont(Font font) { 178 if (font == null) { 179 throw new IllegalArgumentException ("Null 'font' argument."); 180 } 181 this.font = font; 182 notifyListeners(new DialLayerChangeEvent(this)); 183 } 184 185 192 public Paint getPaint() { 193 return this.paint; 194 } 195 196 203 public void setPaint(Paint paint) { 204 if (paint == null) { 205 throw new IllegalArgumentException ("Null 'paint' argument."); 206 } 207 this.paint = paint; 208 notifyListeners(new DialLayerChangeEvent(this)); 209 } 210 211 218 public String getLabel() { 219 return this.label; 220 } 221 222 229 public void setLabel(String label) { 230 if (label == null) { 231 throw new IllegalArgumentException ("Null 'label' argument."); 232 } 233 this.label = label; 234 notifyListeners(new DialLayerChangeEvent(this)); 235 } 236 237 243 public boolean isClippedToWindow() { 244 return true; 245 } 246 247 257 public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 258 Rectangle2D view) { 259 260 Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius, 262 this.radius); 263 Arc2D arc = new Arc2D.Double (f, this.angle, 0.0, Arc2D.OPEN); 264 Point2D pt = arc.getStartPoint(); 265 g2.setPaint(this.paint); 266 g2.setFont(this.font); 267 TextUtilities.drawAlignedString(this.label, g2, (float) pt.getX(), 268 (float) pt.getY(), this.anchor); 269 270 } 271 272 279 public boolean equals(Object obj) { 280 if (obj == this) { 281 return true; 282 } 283 if (!(obj instanceof DialTextAnnotation)) { 284 return false; 285 } 286 DialTextAnnotation that = (DialTextAnnotation) obj; 287 if (!this.label.equals(that.label)) { 288 return false; 289 } 290 if (!this.font.equals(that.font)) { 291 return false; 292 } 293 if (!PaintUtilities.equal(this.paint, that.paint)) { 294 return false; 295 } 296 if (this.radius != that.radius) { 297 return false; 298 } 299 if (this.angle != that.angle) { 300 return false; 301 } 302 if (!this.anchor.equals(that.anchor)) { 303 return false; 304 } 305 return true; 306 } 307 308 313 public int hashCode() { 314 int result = 193; 315 result = 37 * result + HashUtilities.hashCodeForPaint(this.paint); 316 result = 37 * result + this.font.hashCode(); 317 result = 37 * result + this.label.hashCode(); 318 result = 37 * result + this.anchor.hashCode(); 319 long temp = Double.doubleToLongBits(this.angle); 320 result = (int) (temp ^ (temp >>> 32)); 321 temp = Double.doubleToLongBits(this.radius); 322 result = (int) (temp ^ (temp >>> 32)); 323 return result; 324 } 325 326 334 public Object clone() throws CloneNotSupportedException { 335 return super.clone(); 336 } 337 338 345 private void writeObject(ObjectOutputStream stream) throws IOException { 346 stream.defaultWriteObject(); 347 SerialUtilities.writePaint(this.paint, stream); 348 } 349 350 358 private void readObject(ObjectInputStream stream) 359 throws IOException , ClassNotFoundException { 360 stream.defaultReadObject(); 361 this.paint = SerialUtilities.readPaint(stream); 362 } 363 364 } 365 | Popular Tags |