1:
44:
45: package ;
46:
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: import ;
61: import ;
62:
63: import ;
64: import ;
65: import ;
66: import ;
67:
68:
71: public class ArcDialFrame extends AbstractDialLayer implements DialFrame,
72: Cloneable, PublicCloneable, Serializable {
73:
74:
75: static final long serialVersionUID = -4089176959553523499L;
76:
77:
81: private transient Paint backgroundPaint;
82:
83:
87: private transient Paint foregroundPaint;
88:
89:
93: private transient Stroke stroke;
94:
95:
98: private double startAngle;
99:
100:
103: private double extent;
104:
105:
106: private double innerRadius;
107:
108:
109: private double outerRadius;
110:
111:
115: public ArcDialFrame() {
116: this(0, 180);
117: }
118:
119:
126: public ArcDialFrame(double startAngle, double extent) {
127: this.backgroundPaint = Color.gray;
128: this.foregroundPaint = new Color(100, 100, 150);
129: this.stroke = new BasicStroke(2.0f);
130: this.innerRadius = 0.25;
131: this.outerRadius = 0.75;
132: this.startAngle = startAngle;
133: this.extent = extent;
134: }
135:
136:
143: public Paint getBackgroundPaint() {
144: return this.backgroundPaint;
145: }
146:
147:
155: public void setBackgroundPaint(Paint paint) {
156: if (paint == null) {
157: throw new IllegalArgumentException("Null 'paint' argument.");
158: }
159: this.backgroundPaint = paint;
160: notifyListeners(new DialLayerChangeEvent(this));
161: }
162:
163:
170: public Paint getForegroundPaint() {
171: return this.foregroundPaint;
172: }
173:
174:
182: public void setForegroundPaint(Paint paint) {
183: if (paint == null) {
184: throw new IllegalArgumentException("Null 'paint' argument.");
185: }
186: this.foregroundPaint = paint;
187: notifyListeners(new DialLayerChangeEvent(this));
188: }
189:
190:
197: public Stroke getStroke() {
198: return this.stroke;
199: }
200:
201:
209: public void setStroke(Stroke stroke) {
210: if (stroke == null) {
211: throw new IllegalArgumentException("Null 'stroke' argument.");
212: }
213: this.stroke = stroke;
214: notifyListeners(new DialLayerChangeEvent(this));
215: }
216:
217:
224: public double getInnerRadius() {
225: return this.innerRadius;
226: }
227:
228:
236: public void setInnerRadius(double radius) {
237: if (radius < 0.0) {
238: throw new IllegalArgumentException("Negative 'radius' argument.");
239: }
240: this.innerRadius = radius;
241: notifyListeners(new DialLayerChangeEvent(this));
242: }
243:
244:
251: public double getOuterRadius() {
252: return this.outerRadius;
253: }
254:
255:
263: public void setOuterRadius(double radius) {
264: if (radius < 0.0) {
265: throw new IllegalArgumentException("Negative 'radius' argument.");
266: }
267: this.outerRadius = radius;
268: notifyListeners(new DialLayerChangeEvent(this));
269: }
270:
271:
278: public double getStartAngle() {
279: return this.startAngle;
280: }
281:
282:
290: public void setStartAngle(double angle) {
291: this.startAngle = angle;
292: notifyListeners(new DialLayerChangeEvent(this));
293: }
294:
295:
302: public double getExtent() {
303: return this.extent;
304: }
305:
306:
314: public void setExtent(double extent) {
315: this.extent = extent;
316: notifyListeners(new DialLayerChangeEvent(this));
317: }
318:
319:
327: public Shape getWindow(Rectangle2D frame) {
328:
329: Rectangle2D innerFrame = DialPlot.rectangleByRadius(frame,
330: this.innerRadius, this.innerRadius);
331: Rectangle2D outerFrame = DialPlot.rectangleByRadius(frame,
332: this.outerRadius, this.outerRadius);
333: Arc2D inner = new Arc2D.Double(innerFrame, this.startAngle,
334: this.extent, Arc2D.OPEN);
335: Arc2D outer = new Arc2D.Double(outerFrame, this.startAngle
336: + this.extent, -this.extent, Arc2D.OPEN);
337: GeneralPath p = new GeneralPath();
338: Point2D point1 = inner.getStartPoint();
339: p.moveTo((float) point1.getX(), (float) point1.getY());
340: p.append(inner, true);
341: p.append(outer, true);
342: p.closePath();
343: return p;
344:
345: }
346:
347:
354: protected Shape getOuterWindow(Rectangle2D frame) {
355: double radiusMargin = 0.02;
356: double angleMargin = 1.5;
357: Rectangle2D innerFrame = DialPlot.rectangleByRadius(frame,
358: this.innerRadius - radiusMargin, this.innerRadius
359: - radiusMargin);
360: Rectangle2D outerFrame = DialPlot.rectangleByRadius(frame,
361: this.outerRadius + radiusMargin, this.outerRadius
362: + radiusMargin);
363: Arc2D inner = new Arc2D.Double(innerFrame, this.startAngle
364: - angleMargin, this.extent + 2 * angleMargin, Arc2D.OPEN);
365: Arc2D outer = new Arc2D.Double(outerFrame, this.startAngle
366: + angleMargin + this.extent, -this.extent - 2 * angleMargin,
367: Arc2D.OPEN);
368: GeneralPath p = new GeneralPath();
369: Point2D point1 = inner.getStartPoint();
370: p.moveTo((float) point1.getX(), (float) point1.getY());
371: p.append(inner, true);
372: p.append(outer, true);
373: p.closePath();
374: return p;
375: }
376:
377:
385: public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
386: Rectangle2D view) {
387:
388: Shape window = getWindow(frame);
389: Shape outerWindow = getOuterWindow(frame);
390:
391: Area area1 = new Area(outerWindow);
392: Area area2 = new Area(window);
393: area1.subtract(area2);
394: g2.setPaint(Color.lightGray);
395: g2.fill(area1);
396:
397: g2.setStroke(this.stroke);
398: g2.setPaint(this.foregroundPaint);
399: g2.draw(window);
400: g2.draw(outerWindow);
401:
402:
403: }
404:
405:
411: public boolean isClippedToWindow() {
412: return false;
413: }
414:
415:
422: public boolean equals(Object obj) {
423: if (obj == this) {
424: return true;
425: }
426: if (!(obj instanceof ArcDialFrame)) {
427: return false;
428: }
429: ArcDialFrame that = (ArcDialFrame) obj;
430: if (!PaintUtilities.equal(this.backgroundPaint, that.backgroundPaint)) {
431: return false;
432: }
433: if (!PaintUtilities.equal(this.foregroundPaint, that.foregroundPaint)) {
434: return false;
435: }
436: if (this.startAngle != that.startAngle) {
437: return false;
438: }
439: if (this.extent != that.extent) {
440: return false;
441: }
442: if (this.innerRadius != that.innerRadius) {
443: return false;
444: }
445: if (this.outerRadius != that.outerRadius) {
446: return false;
447: }
448: if (!this.stroke.equals(that.stroke)) {
449: return false;
450: }
451: return super.equals(obj);
452: }
453:
454:
459: public int hashCode() {
460: int result = 193;
461: long temp = Double.doubleToLongBits(this.startAngle);
462: result = 37 * result + (int) (temp ^ (temp >>> 32));
463: temp = Double.doubleToLongBits(this.extent);
464: result = 37 * result + (int) (temp ^ (temp >>> 32));
465: temp = Double.doubleToLongBits(this.innerRadius);
466: result = 37 * result + (int) (temp ^ (temp >>> 32));
467: temp = Double.doubleToLongBits(this.outerRadius);
468: result = 37 * result + (int) (temp ^ (temp >>> 32));
469: result = 37 * result + HashUtilities.hashCodeForPaint(
470: this.backgroundPaint);
471: result = 37 * result + HashUtilities.hashCodeForPaint(
472: this.foregroundPaint);
473: result = 37 * result + this.stroke.hashCode();
474: return result;
475: }
476:
477:
485: public Object clone() throws CloneNotSupportedException {
486: return super.clone();
487: }
488:
489:
496: private void writeObject(ObjectOutputStream stream) throws IOException {
497: stream.defaultWriteObject();
498: SerialUtilities.writePaint(this.backgroundPaint, stream);
499: SerialUtilities.writePaint(this.foregroundPaint, stream);
500: SerialUtilities.writeStroke(this.stroke, stream);
501: }
502:
503:
511: private void readObject(ObjectInputStream stream)
512: throws IOException, ClassNotFoundException {
513: stream.defaultReadObject();
514: this.backgroundPaint = SerialUtilities.readPaint(stream);
515: this.foregroundPaint = SerialUtilities.readPaint(stream);
516: this.stroke = SerialUtilities.readStroke(stream);
517: }
518:
519: }