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.Arc2D ; 51 import java.awt.geom.GeneralPath ; 52 import java.awt.geom.Line2D ; 53 import java.awt.geom.Point2D ; 54 import java.awt.geom.Rectangle2D ; 55 import java.io.Serializable ; 56 57 import org.jfree.util.PublicCloneable; 58 59 62 public abstract class DialPointer extends AbstractDialLayer 63 implements DialLayer, Cloneable , Serializable { 64 65 66 double radius; 67 68 71 int datasetIndex; 72 73 76 public DialPointer() { 77 this(0); 78 } 79 80 85 public DialPointer(int datasetIndex) { 86 this.radius = 0.675; 87 this.datasetIndex = datasetIndex; 88 } 89 90 95 public int getDatasetIndex() { 96 return this.datasetIndex; 97 } 98 99 104 public void setDatasetIndex(int index) { 105 this.datasetIndex = index; 106 notifyListeners(new DialLayerChangeEvent(this)); 107 } 108 109 116 public double getRadius() { 117 return this.radius; 118 } 119 120 127 public void setRadius(double radius) { 128 this.radius = radius; 129 notifyListeners(new DialLayerChangeEvent(this)); 130 } 131 132 138 public boolean isClippedToWindow() { 139 return true; 140 } 141 142 145 public static class Pin extends DialPointer implements PublicCloneable { 146 147 148 private transient Paint paint; 149 150 151 private transient Stroke stroke; 152 153 156 public Pin() { 157 this(0); 158 } 159 160 165 public Pin(int datasetIndex) { 166 super(datasetIndex); 167 this.paint = Color.red; 168 this.stroke = new BasicStroke (3.0f, BasicStroke.CAP_ROUND, 169 BasicStroke.JOIN_BEVEL); 170 } 171 172 177 public Paint getPaint() { 178 return this.paint; 179 } 180 181 186 public void setPaint(Paint paint) { 187 this.paint = paint; 188 notifyListeners(new DialLayerChangeEvent(this)); 189 } 190 191 196 public Stroke getStroke() { 197 return this.stroke; 198 } 199 200 205 public void setStroke(Stroke stroke) { 206 this.stroke = stroke; 207 notifyListeners(new DialLayerChangeEvent(this)); 208 } 209 210 218 public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 219 Rectangle2D view) { 220 221 g2.setPaint(this.paint); 222 g2.setStroke(this.stroke); 223 Rectangle2D arcRect = DialPlot.rectangleByRadius(frame, 224 this.radius, this.radius); 225 226 double value = plot.getValue(this.datasetIndex); 227 DialScale scale = plot.getScaleForDataset(this.datasetIndex); 228 double angle = scale.valueToAngle(value); 229 230 Arc2D arc = new Arc2D.Double (arcRect, angle, 0, Arc2D.OPEN); 231 Point2D pt = arc.getEndPoint(); 232 233 Line2D line = new Line2D.Double (frame.getCenterX(), 234 frame.getCenterY(), pt.getX(), pt.getY()); 235 g2.draw(line); 236 } 237 238 246 public Object clone() throws CloneNotSupportedException { 247 return super.clone(); 248 } 249 250 } 251 252 255 public static class Pointer extends DialPointer implements PublicCloneable { 256 257 260 private double widthRadius; 261 262 265 public Pointer() { 266 this(0); 267 } 268 269 274 public Pointer(int datasetIndex) { 275 super(datasetIndex); 276 this.radius = 0.9; 277 this.widthRadius = 0.05; 278 } 279 280 285 public double getWidthRadius() { 286 return this.widthRadius; 287 } 288 289 294 public void setWidthRadius(double radius) { 295 this.widthRadius = radius; 296 notifyListeners(new DialLayerChangeEvent(this)); 297 } 298 299 307 public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 308 Rectangle2D view) { 309 310 g2.setPaint(Color.blue); 311 g2.setStroke(new BasicStroke (1.0f)); 312 Rectangle2D lengthRect = DialPlot.rectangleByRadius(frame, 313 this.radius, this.radius); 314 Rectangle2D widthRect = DialPlot.rectangleByRadius(frame, 315 this.widthRadius, this.widthRadius); 316 double value = plot.getValue(this.datasetIndex); 317 DialScale scale = plot.getScaleForDataset(this.datasetIndex); 318 double angle = scale.valueToAngle(value); 319 320 Arc2D arc1 = new Arc2D.Double (lengthRect, angle, 0, Arc2D.OPEN); 321 Point2D pt1 = arc1.getEndPoint(); 322 Arc2D arc2 = new Arc2D.Double (widthRect, angle - 90.0, 180.0, 323 Arc2D.OPEN); 324 Point2D pt2 = arc2.getStartPoint(); 325 Point2D pt3 = arc2.getEndPoint(); 326 Arc2D arc3 = new Arc2D.Double (widthRect, angle - 180.0, 0.0, 327 Arc2D.OPEN); 328 Point2D pt4 = arc3.getStartPoint(); 329 330 GeneralPath gp = new GeneralPath (); 331 gp.moveTo((float) pt1.getX(), (float) pt1.getY()); 332 gp.lineTo((float) pt2.getX(), (float) pt2.getY()); 333 gp.lineTo((float) pt4.getX(), (float) pt4.getY()); 334 gp.lineTo((float) pt3.getX(), (float) pt3.getY()); 335 gp.closePath(); 336 g2.setPaint(Color.gray); 337 g2.fill(gp); 338 339 g2.setPaint(Color.black); 340 Line2D line = new Line2D.Double (frame.getCenterX(), 341 frame.getCenterY(), pt1.getX(), pt1.getY()); 342 g2.draw(line); 343 344 line.setLine(pt2, pt3); 345 g2.draw(line); 346 347 line.setLine(pt3, pt1); 348 g2.draw(line); 349 350 line.setLine(pt2, pt1); 351 g2.draw(line); 352 353 line.setLine(pt2, pt4); 354 g2.draw(line); 355 356 line.setLine(pt3, pt4); 357 g2.draw(line); 358 } 359 360 public Object clone() throws CloneNotSupportedException { 361 return super.clone(); 362 } 363 364 } 365 366 } 367 | Popular Tags |