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:
73: public class ArcDialFrame extends AbstractDialLayer implements DialFrame,
74: Cloneable, PublicCloneable, Serializable {
75:
76:
77: static final long serialVersionUID = -4089176959553523499L;
78:
79:
83: private transient Paint backgroundPaint;
84:
85:
89: private transient Paint foregroundPaint;
90:
91:
95: private transient Stroke stroke;
96:
97:
100: private double startAngle;
101:
102:
105: private double extent;
106:
107:
108: private double innerRadius;
109:
110:
111: private double outerRadius;
112:
113:
117: public ArcDialFrame() {
118: this(0, 180);
119: }
120:
121:
128: public ArcDialFrame(double startAngle, double extent) {
129: this.backgroundPaint = Color.gray;
130: this.foregroundPaint = new Color(100, 100, 150);
131: this.stroke = new BasicStroke(2.0f);
132: this.innerRadius = 0.25;
133: this.outerRadius = 0.75;
134: this.startAngle = startAngle;
135: this.extent = extent;
136: }
137:
138:
145: public Paint getBackgroundPaint() {
146: return this.backgroundPaint;
147: }
148:
149:
157: public void setBackgroundPaint(Paint paint) {
158: if (paint == null) {
159: throw new IllegalArgumentException("Null 'paint' argument.");
160: }
161: this.backgroundPaint = paint;
162: notifyListeners(new DialLayerChangeEvent(this));
163: }
164:
165:
172: public Paint getForegroundPaint() {
173: return this.foregroundPaint;
174: }
175:
176:
184: public void setForegroundPaint(Paint paint) {
185: if (paint == null) {
186: throw new IllegalArgumentException("Null 'paint' argument.");
187: }
188: this.foregroundPaint = paint;
189: notifyListeners(new DialLayerChangeEvent(this));
190: }
191:
192:
199: public Stroke getStroke() {
200: return this.stroke;
201: }
202:
203:
211: public void setStroke(Stroke stroke) {
212: if (stroke == null) {
213: throw new IllegalArgumentException("Null 'stroke' argument.");
214: }
215: this.stroke = stroke;
216: notifyListeners(new DialLayerChangeEvent(this));
217: }
218:
219:
226: public double getInnerRadius() {
227: return this.innerRadius;
228: }
229:
230:
238: public void setInnerRadius(double radius) {
239: if (radius < 0.0) {
240: throw new IllegalArgumentException("Negative 'radius' argument.");
241: }
242: this.innerRadius = radius;
243: notifyListeners(new DialLayerChangeEvent(this));
244: }
245:
246:
253: public double getOuterRadius() {
254: return this.outerRadius;
255: }
256:
257:
265: public void setOuterRadius(double radius) {
266: if (radius < 0.0) {
267: throw new IllegalArgumentException("Negative 'radius' argument.");
268: }
269: this.outerRadius = radius;
270: notifyListeners(new DialLayerChangeEvent(this));
271: }
272:
273:
280: public double getStartAngle() {
281: return this.startAngle;
282: }
283:
284:
292: public void setStartAngle(double angle) {
293: this.startAngle = angle;
294: notifyListeners(new DialLayerChangeEvent(this));
295: }
296:
297:
304: public double getExtent() {
305: return this.extent;
306: }
307:
308:
316: public void setExtent(double extent) {
317: this.extent = extent;
318: notifyListeners(new DialLayerChangeEvent(this));
319: }
320:
321:
329: public Shape getWindow(Rectangle2D frame) {
330:
331: Rectangle2D innerFrame = DialPlot.rectangleByRadius(frame,
332: this.innerRadius, this.innerRadius);
333: Rectangle2D outerFrame = DialPlot.rectangleByRadius(frame,
334: this.outerRadius, this.outerRadius);
335: Arc2D inner = new Arc2D.Double(innerFrame, this.startAngle,
336: this.extent, Arc2D.OPEN);
337: Arc2D outer = new Arc2D.Double(outerFrame, this.startAngle
338: + this.extent, -this.extent, Arc2D.OPEN);
339: GeneralPath p = new GeneralPath();
340: Point2D point1 = inner.getStartPoint();
341: p.moveTo((float) point1.getX(), (float) point1.getY());
342: p.append(inner, true);
343: p.append(outer, true);
344: p.closePath();
345: return p;
346:
347: }
348:
349:
356: protected Shape getOuterWindow(Rectangle2D frame) {
357: double radiusMargin = 0.02;
358: double angleMargin = 1.5;
359: Rectangle2D innerFrame = DialPlot.rectangleByRadius(frame,
360: this.innerRadius - radiusMargin, this.innerRadius
361: - radiusMargin);
362: Rectangle2D outerFrame = DialPlot.rectangleByRadius(frame,
363: this.outerRadius + radiusMargin, this.outerRadius
364: + radiusMargin);
365: Arc2D inner = new Arc2D.Double(innerFrame, this.startAngle
366: - angleMargin, this.extent + 2 * angleMargin, Arc2D.OPEN);
367: Arc2D outer = new Arc2D.Double(outerFrame, this.startAngle
368: + angleMargin + this.extent, -this.extent - 2 * angleMargin,
369: Arc2D.OPEN);
370: GeneralPath p = new GeneralPath();
371: Point2D point1 = inner.getStartPoint();
372: p.moveTo((float) point1.getX(), (float) point1.getY());
373: p.append(inner, true);
374: p.append(outer, true);
375: p.closePath();
376: return p;
377: }
378:
379:
387: public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
388: Rectangle2D view) {
389:
390: Shape window = getWindow(frame);
391: Shape outerWindow = getOuterWindow(frame);
392:
393: Area area1 = new Area(outerWindow);
394: Area area2 = new Area(window);
395: area1.subtract(area2);
396: g2.setPaint(Color.lightGray);
397: g2.fill(area1);
398:
399: g2.setStroke(this.stroke);
400: g2.setPaint(this.foregroundPaint);
401: g2.draw(window);
402: g2.draw(outerWindow);
403:
404: }
405:
406:
412: public boolean isClippedToWindow() {
413: return false;
414: }
415:
416:
423: public boolean equals(Object obj) {
424: if (obj == this) {
425: return true;
426: }
427: if (!(obj instanceof ArcDialFrame)) {
428: return false;
429: }
430: ArcDialFrame that = (ArcDialFrame) obj;
431: if (!PaintUtilities.equal(this.backgroundPaint, that.backgroundPaint)) {
432: return false;
433: }
434: if (!PaintUtilities.equal(this.foregroundPaint, that.foregroundPaint)) {
435: return false;
436: }
437: if (this.startAngle != that.startAngle) {
438: return false;
439: }
440: if (this.extent != that.extent) {
441: return false;
442: }
443: if (this.innerRadius != that.innerRadius) {
444: return false;
445: }
446: if (this.outerRadius != that.outerRadius) {
447: return false;
448: }
449: if (!this.stroke.equals(that.stroke)) {
450: return false;
451: }
452: return super.equals(obj);
453: }
454:
455:
460: public int hashCode() {
461: int result = 193;
462: long temp = Double.doubleToLongBits(this.startAngle);
463: result = 37 * result + (int) (temp ^ (temp >>> 32));
464: temp = Double.doubleToLongBits(this.extent);
465: result = 37 * result + (int) (temp ^ (temp >>> 32));
466: temp = Double.doubleToLongBits(this.innerRadius);
467: result = 37 * result + (int) (temp ^ (temp >>> 32));
468: temp = Double.doubleToLongBits(this.outerRadius);
469: result = 37 * result + (int) (temp ^ (temp >>> 32));
470: result = 37 * result + HashUtilities.hashCodeForPaint(
471: this.backgroundPaint);
472: result = 37 * result + HashUtilities.hashCodeForPaint(
473: this.foregroundPaint);
474: result = 37 * result + this.stroke.hashCode();
475: return result;
476: }
477:
478:
486: public Object clone() throws CloneNotSupportedException {
487: return super.clone();
488: }
489:
490:
497: private void writeObject(ObjectOutputStream stream) throws IOException {
498: stream.defaultWriteObject();
499: SerialUtilities.writePaint(this.backgroundPaint, stream);
500: SerialUtilities.writePaint(this.foregroundPaint, stream);
501: SerialUtilities.writeStroke(this.stroke, stream);
502: }
503:
504:
512: private void readObject(ObjectInputStream stream)
513: throws IOException, ClassNotFoundException {
514: stream.defaultReadObject();
515: this.backgroundPaint = SerialUtilities.readPaint(stream);
516: this.foregroundPaint = SerialUtilities.readPaint(stream);
517: this.stroke = SerialUtilities.readStroke(stream);
518: }
519:
520: }