1:
45:
46: package ;
47:
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: import ;
61: import ;
62:
63: import ;
64: import ;
65: import ;
66: import ;
67:
68:
73: public abstract class DialPointer extends AbstractDialLayer
74: implements DialLayer, Cloneable, PublicCloneable, Serializable {
75:
76:
77: double radius;
78:
79:
82: int datasetIndex;
83:
84:
87: protected DialPointer() {
88: this(0);
89: }
90:
91:
96: protected DialPointer(int datasetIndex) {
97: this.radius = 0.9;
98: this.datasetIndex = datasetIndex;
99: }
100:
101:
108: public int getDatasetIndex() {
109: return this.datasetIndex;
110: }
111:
112:
120: public void setDatasetIndex(int index) {
121: this.datasetIndex = index;
122: notifyListeners(new DialLayerChangeEvent(this));
123: }
124:
125:
133: public double getRadius() {
134: return this.radius;
135: }
136:
137:
145: public void setRadius(double radius) {
146: this.radius = radius;
147: notifyListeners(new DialLayerChangeEvent(this));
148: }
149:
150:
156: public boolean isClippedToWindow() {
157: return true;
158: }
159:
160:
167: public boolean equals(Object obj) {
168: if (obj == this) {
169: return true;
170: }
171: if (!(obj instanceof DialPointer)) {
172: return false;
173: }
174: DialPointer that = (DialPointer) obj;
175: if (this.datasetIndex != that.datasetIndex) {
176: return false;
177: }
178: if (this.radius != that.radius) {
179: return false;
180: }
181: return super.equals(obj);
182: }
183:
184:
189: public int hashCode() {
190: int result = 23;
191: result = HashUtilities.hashCode(result, this.radius);
192: return result;
193: }
194:
195:
203: public Object clone() throws CloneNotSupportedException {
204: return super.clone();
205: }
206:
207:
210: public static class Pin extends DialPointer {
211:
212:
213: static final long serialVersionUID = -8445860485367689750L;
214:
215:
216: private transient Paint paint;
217:
218:
219: private transient Stroke stroke;
220:
221:
224: public Pin() {
225: this(0);
226: }
227:
228:
233: public Pin(int datasetIndex) {
234: super(datasetIndex);
235: this.paint = Color.red;
236: this.stroke = new BasicStroke(3.0f, BasicStroke.CAP_ROUND,
237: BasicStroke.JOIN_BEVEL);
238: }
239:
240:
247: public Paint getPaint() {
248: return this.paint;
249: }
250:
251:
259: public void setPaint(Paint paint) {
260: if (paint == null) {
261: throw new IllegalArgumentException("Null 'paint' argument.");
262: }
263: this.paint = paint;
264: notifyListeners(new DialLayerChangeEvent(this));
265: }
266:
267:
274: public Stroke getStroke() {
275: return this.stroke;
276: }
277:
278:
286: public void setStroke(Stroke stroke) {
287: if (stroke == null) {
288: throw new IllegalArgumentException("Null 'stroke' argument.");
289: }
290: this.stroke = stroke;
291: notifyListeners(new DialLayerChangeEvent(this));
292: }
293:
294:
302: public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
303: Rectangle2D view) {
304:
305: g2.setPaint(this.paint);
306: g2.setStroke(this.stroke);
307: Rectangle2D arcRect = DialPlot.rectangleByRadius(frame,
308: this.radius, this.radius);
309:
310: double value = plot.getValue(this.datasetIndex);
311: DialScale scale = plot.getScaleForDataset(this.datasetIndex);
312: double angle = scale.valueToAngle(value);
313:
314: Arc2D arc = new Arc2D.Double(arcRect, angle, 0, Arc2D.OPEN);
315: Point2D pt = arc.getEndPoint();
316:
317: Line2D line = new Line2D.Double(frame.getCenterX(),
318: frame.getCenterY(), pt.getX(), pt.getY());
319: g2.draw(line);
320: }
321:
322:
329: public boolean equals(Object obj) {
330: if (obj == this) {
331: return true;
332: }
333: if (!(obj instanceof DialPointer.Pin)) {
334: return false;
335: }
336: DialPointer.Pin that = (DialPointer.Pin) obj;
337: if (!PaintUtilities.equal(this.paint, that.paint)) {
338: return false;
339: }
340: if (!this.stroke.equals(that.stroke)) {
341: return false;
342: }
343: return super.equals(obj);
344: }
345:
346:
351: public int hashCode() {
352: int result = super.hashCode();
353: result = HashUtilities.hashCode(result, this.paint);
354: result = HashUtilities.hashCode(result, this.stroke);
355: return result;
356: }
357:
358:
365: private void writeObject(ObjectOutputStream stream) throws IOException {
366: stream.defaultWriteObject();
367: SerialUtilities.writePaint(this.paint, stream);
368: SerialUtilities.writeStroke(this.stroke, stream);
369: }
370:
371:
379: private void readObject(ObjectInputStream stream)
380: throws IOException, ClassNotFoundException {
381: stream.defaultReadObject();
382: this.paint = SerialUtilities.readPaint(stream);
383: this.stroke = SerialUtilities.readStroke(stream);
384: }
385:
386: }
387:
388:
391: public static class Pointer extends DialPointer {
392:
393:
394: static final long serialVersionUID = -4180500011963176960L;
395:
396:
399: private double widthRadius;
400:
401:
406: private transient Paint fillPaint;
407:
408:
413: private transient Paint outlinePaint;
414:
415:
418: public Pointer() {
419: this(0);
420: }
421:
422:
427: public Pointer(int datasetIndex) {
428: super(datasetIndex);
429: this.widthRadius = 0.05;
430: this.fillPaint = Color.gray;
431: this.outlinePaint = Color.black;
432: }
433:
434:
441: public double getWidthRadius() {
442: return this.widthRadius;
443: }
444:
445:
453: public void setWidthRadius(double radius) {
454: this.widthRadius = radius;
455: notifyListeners(new DialLayerChangeEvent(this));
456: }
457:
458:
467: public Paint getFillPaint() {
468: return this.fillPaint;
469: }
470:
471:
481: public void setFillPaint(Paint paint) {
482: if (paint == null) {
483: throw new IllegalArgumentException("Null 'paint' argument.");
484: }
485: this.fillPaint = paint;
486: notifyListeners(new DialLayerChangeEvent(this));
487: }
488:
489:
498: public Paint getOutlinePaint() {
499: return this.outlinePaint;
500: }
501:
502:
512: public void setOutlinePaint(Paint paint) {
513: if (paint == null) {
514: throw new IllegalArgumentException("Null 'paint' argument.");
515: }
516: this.outlinePaint = paint;
517: notifyListeners(new DialLayerChangeEvent(this));
518: }
519:
520:
528: public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
529: Rectangle2D view) {
530:
531: g2.setPaint(Color.blue);
532: g2.setStroke(new BasicStroke(1.0f));
533: Rectangle2D lengthRect = DialPlot.rectangleByRadius(frame,
534: this.radius, this.radius);
535: Rectangle2D widthRect = DialPlot.rectangleByRadius(frame,
536: this.widthRadius, this.widthRadius);
537: double value = plot.getValue(this.datasetIndex);
538: DialScale scale = plot.getScaleForDataset(this.datasetIndex);
539: double angle = scale.valueToAngle(value);
540:
541: Arc2D arc1 = new Arc2D.Double(lengthRect, angle, 0, Arc2D.OPEN);
542: Point2D pt1 = arc1.getEndPoint();
543: Arc2D arc2 = new Arc2D.Double(widthRect, angle - 90.0, 180.0,
544: Arc2D.OPEN);
545: Point2D pt2 = arc2.getStartPoint();
546: Point2D pt3 = arc2.getEndPoint();
547: Arc2D arc3 = new Arc2D.Double(widthRect, angle - 180.0, 0.0,
548: Arc2D.OPEN);
549: Point2D pt4 = arc3.getStartPoint();
550:
551: GeneralPath gp = new GeneralPath();
552: gp.moveTo((float) pt1.getX(), (float) pt1.getY());
553: gp.lineTo((float) pt2.getX(), (float) pt2.getY());
554: gp.lineTo((float) pt4.getX(), (float) pt4.getY());
555: gp.lineTo((float) pt3.getX(), (float) pt3.getY());
556: gp.closePath();
557: g2.setPaint(this.fillPaint);
558: g2.fill(gp);
559:
560: g2.setPaint(this.outlinePaint);
561: Line2D line = new Line2D.Double(frame.getCenterX(),
562: frame.getCenterY(), pt1.getX(), pt1.getY());
563: g2.draw(line);
564:
565: line.setLine(pt2, pt3);
566: g2.draw(line);
567:
568: line.setLine(pt3, pt1);
569: g2.draw(line);
570:
571: line.setLine(pt2, pt1);
572: g2.draw(line);
573:
574: line.setLine(pt2, pt4);
575: g2.draw(line);
576:
577: line.setLine(pt3, pt4);
578: g2.draw(line);
579: }
580:
581:
588: public boolean equals(Object obj) {
589: if (obj == this) {
590: return true;
591: }
592: if (!(obj instanceof DialPointer.Pointer)) {
593: return false;
594: }
595: DialPointer.Pointer that = (DialPointer.Pointer) obj;
596:
597: if (this.widthRadius != that.widthRadius) {
598: return false;
599: }
600: if (!PaintUtilities.equal(this.fillPaint, that.fillPaint)) {
601: return false;
602: }
603: if (!PaintUtilities.equal(this.outlinePaint, that.outlinePaint)) {
604: return false;
605: }
606: return super.equals(obj);
607: }
608:
609:
614: public int hashCode() {
615: int result = super.hashCode();
616: result = HashUtilities.hashCode(result, this.widthRadius);
617: result = HashUtilities.hashCode(result, this.fillPaint);
618: result = HashUtilities.hashCode(result, this.outlinePaint);
619: return result;
620: }
621:
622:
629: private void writeObject(ObjectOutputStream stream) throws IOException {
630: stream.defaultWriteObject();
631: SerialUtilities.writePaint(this.fillPaint, stream);
632: SerialUtilities.writePaint(this.outlinePaint, stream);
633: }
634:
635:
643: private void readObject(ObjectInputStream stream)
644: throws IOException, ClassNotFoundException {
645: stream.defaultReadObject();
646: this.fillPaint = SerialUtilities.readPaint(stream);
647: this.outlinePaint = SerialUtilities.readPaint(stream);
648: }
649:
650: }
651:
652: }