1:
43:
44: package ;
45:
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56: import ;
57: import ;
58: import ;
59: import ;
60:
61: import ;
62: import ;
63: import ;
64: import ;
65:
66:
69: public abstract class DialPointer extends AbstractDialLayer
70: implements DialLayer, Cloneable, PublicCloneable, Serializable {
71:
72:
73: double radius;
74:
75:
78: int datasetIndex;
79:
80:
83: protected DialPointer() {
84: this(0);
85: }
86:
87:
92: protected DialPointer(int datasetIndex) {
93: this.radius = 0.9;
94: this.datasetIndex = datasetIndex;
95: }
96:
97:
104: public int getDatasetIndex() {
105: return this.datasetIndex;
106: }
107:
108:
116: public void setDatasetIndex(int index) {
117: this.datasetIndex = index;
118: notifyListeners(new DialLayerChangeEvent(this));
119: }
120:
121:
129: public double getRadius() {
130: return this.radius;
131: }
132:
133:
141: public void setRadius(double radius) {
142: this.radius = radius;
143: notifyListeners(new DialLayerChangeEvent(this));
144: }
145:
146:
152: public boolean isClippedToWindow() {
153: return true;
154: }
155:
156:
163: public boolean equals(Object obj) {
164: if (obj == this) {
165: return true;
166: }
167: if (!(obj instanceof DialPointer)) {
168: return false;
169: }
170: DialPointer that = (DialPointer) obj;
171: if (this.datasetIndex != that.datasetIndex) {
172: return false;
173: }
174: if (this.radius != that.radius) {
175: return false;
176: }
177: return super.equals(obj);
178: }
179:
180:
185: public int hashCode() {
186: int result = 23;
187: result = HashUtilities.hashCode(result, this.radius);
188: return result;
189: }
190:
191:
199: public Object clone() throws CloneNotSupportedException {
200: return super.clone();
201: }
202:
203:
206: public static class Pin extends DialPointer {
207:
208:
209: static final long serialVersionUID = -8445860485367689750L;
210:
211:
212: private transient Paint paint;
213:
214:
215: private transient Stroke stroke;
216:
217:
220: public Pin() {
221: this(0);
222: }
223:
224:
229: public Pin(int datasetIndex) {
230: super(datasetIndex);
231: this.paint = Color.red;
232: this.stroke = new BasicStroke(3.0f, BasicStroke.CAP_ROUND,
233: BasicStroke.JOIN_BEVEL);
234: }
235:
236:
243: public Paint getPaint() {
244: return this.paint;
245: }
246:
247:
255: public void setPaint(Paint paint) {
256: if (paint == null) {
257: throw new IllegalArgumentException("Null 'paint' argument.");
258: }
259: this.paint = paint;
260: notifyListeners(new DialLayerChangeEvent(this));
261: }
262:
263:
270: public Stroke getStroke() {
271: return this.stroke;
272: }
273:
274:
282: public void setStroke(Stroke stroke) {
283: if (stroke == null) {
284: throw new IllegalArgumentException("Null 'stroke' argument.");
285: }
286: this.stroke = stroke;
287: notifyListeners(new DialLayerChangeEvent(this));
288: }
289:
290:
298: public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
299: Rectangle2D view) {
300:
301: g2.setPaint(this.paint);
302: g2.setStroke(this.stroke);
303: Rectangle2D arcRect = DialPlot.rectangleByRadius(frame,
304: this.radius, this.radius);
305:
306: double value = plot.getValue(this.datasetIndex);
307: DialScale scale = plot.getScaleForDataset(this.datasetIndex);
308: double angle = scale.valueToAngle(value);
309:
310: Arc2D arc = new Arc2D.Double(arcRect, angle, 0, Arc2D.OPEN);
311: Point2D pt = arc.getEndPoint();
312:
313: Line2D line = new Line2D.Double(frame.getCenterX(),
314: frame.getCenterY(), pt.getX(), pt.getY());
315: g2.draw(line);
316: }
317:
318:
325: public boolean equals(Object obj) {
326: if (obj == this) {
327: return true;
328: }
329: if (!(obj instanceof DialPointer.Pin)) {
330: return false;
331: }
332: DialPointer.Pin that = (DialPointer.Pin) obj;
333: if (!PaintUtilities.equal(this.paint, that.paint)) {
334: return false;
335: }
336: if (!this.stroke.equals(that.stroke)) {
337: return false;
338: }
339: return super.equals(obj);
340: }
341:
342:
347: public int hashCode() {
348: int result = super.hashCode();
349: result = HashUtilities.hashCode(result, this.paint);
350: result = HashUtilities.hashCode(result, this.stroke);
351: return result;
352: }
353:
354:
361: private void writeObject(ObjectOutputStream stream) throws IOException {
362: stream.defaultWriteObject();
363: SerialUtilities.writePaint(this.paint, stream);
364: SerialUtilities.writeStroke(this.stroke, stream);
365: }
366:
367:
375: private void readObject(ObjectInputStream stream)
376: throws IOException, ClassNotFoundException {
377: stream.defaultReadObject();
378: this.paint = SerialUtilities.readPaint(stream);
379: this.stroke = SerialUtilities.readStroke(stream);
380: }
381:
382: }
383:
384:
387: public static class Pointer extends DialPointer {
388:
389:
390: static final long serialVersionUID = -4180500011963176960L;
391:
392:
395: private double widthRadius;
396:
397:
400: public Pointer() {
401: this(0);
402: }
403:
404:
409: public Pointer(int datasetIndex) {
410: super(datasetIndex);
411: this.widthRadius = 0.05;
412: }
413:
414:
421: public double getWidthRadius() {
422: return this.widthRadius;
423: }
424:
425:
433: public void setWidthRadius(double radius) {
434: this.widthRadius = radius;
435: notifyListeners(new DialLayerChangeEvent(this));
436: }
437:
438:
446: public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
447: Rectangle2D view) {
448:
449: g2.setPaint(Color.blue);
450: g2.setStroke(new BasicStroke(1.0f));
451: Rectangle2D lengthRect = DialPlot.rectangleByRadius(frame,
452: this.radius, this.radius);
453: Rectangle2D widthRect = DialPlot.rectangleByRadius(frame,
454: this.widthRadius, this.widthRadius);
455: double value = plot.getValue(this.datasetIndex);
456: DialScale scale = plot.getScaleForDataset(this.datasetIndex);
457: double angle = scale.valueToAngle(value);
458:
459: Arc2D arc1 = new Arc2D.Double(lengthRect, angle, 0, Arc2D.OPEN);
460: Point2D pt1 = arc1.getEndPoint();
461: Arc2D arc2 = new Arc2D.Double(widthRect, angle - 90.0, 180.0,
462: Arc2D.OPEN);
463: Point2D pt2 = arc2.getStartPoint();
464: Point2D pt3 = arc2.getEndPoint();
465: Arc2D arc3 = new Arc2D.Double(widthRect, angle - 180.0, 0.0,
466: Arc2D.OPEN);
467: Point2D pt4 = arc3.getStartPoint();
468:
469: GeneralPath gp = new GeneralPath();
470: gp.moveTo((float) pt1.getX(), (float) pt1.getY());
471: gp.lineTo((float) pt2.getX(), (float) pt2.getY());
472: gp.lineTo((float) pt4.getX(), (float) pt4.getY());
473: gp.lineTo((float) pt3.getX(), (float) pt3.getY());
474: gp.closePath();
475: g2.setPaint(Color.gray);
476: g2.fill(gp);
477:
478: g2.setPaint(Color.black);
479: Line2D line = new Line2D.Double(frame.getCenterX(),
480: frame.getCenterY(), pt1.getX(), pt1.getY());
481: g2.draw(line);
482:
483: line.setLine(pt2, pt3);
484: g2.draw(line);
485:
486: line.setLine(pt3, pt1);
487: g2.draw(line);
488:
489: line.setLine(pt2, pt1);
490: g2.draw(line);
491:
492: line.setLine(pt2, pt4);
493: g2.draw(line);
494:
495: line.setLine(pt3, pt4);
496: g2.draw(line);
497: }
498:
499:
506: public boolean equals(Object obj) {
507: if (obj == this) {
508: return true;
509: }
510: if (!(obj instanceof DialPointer.Pointer)) {
511: return false;
512: }
513: DialPointer.Pointer that = (DialPointer.Pointer) obj;
514:
515: if (this.widthRadius != that.widthRadius) {
516: return false;
517: }
518: return super.equals(obj);
519: }
520:
521:
526: public int hashCode() {
527: int result = super.hashCode();
528: result = HashUtilities.hashCode(result, this.widthRadius);
529: return result;
530: }
531:
532: }
533:
534: }