1:
48:
49: package ;
50:
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56: import ;
57: import ;
58: import ;
59: import ;
60: import ;
61: import ;
62: import ;
63: import ;
64:
65: import ;
66: import ;
67: import ;
68: import ;
69:
70:
75: public class DefaultDrawingSupplier
76: implements DrawingSupplier, Cloneable, PublicCloneable, Serializable {
77:
78:
79: private static final long serialVersionUID = -7339847061039422538L;
80:
81:
82: public static final Paint[] DEFAULT_PAINT_SEQUENCE
83: = ChartColor.createDefaultPaintArray();
84:
85:
86: public static final Paint[] DEFAULT_OUTLINE_PAINT_SEQUENCE = new Paint[] {
87: Color.lightGray};
88:
89:
90: public static final Stroke[] DEFAULT_STROKE_SEQUENCE = new Stroke[] {
91: new BasicStroke(1.0f, BasicStroke.CAP_SQUARE,
92: BasicStroke.JOIN_BEVEL)};
93:
94:
95: public static final Stroke[] DEFAULT_OUTLINE_STROKE_SEQUENCE
96: = new Stroke[] {new BasicStroke(1.0f, BasicStroke.CAP_SQUARE,
97: BasicStroke.JOIN_BEVEL)};
98:
99:
100: public static final Shape[] DEFAULT_SHAPE_SEQUENCE
101: = createStandardSeriesShapes();
102:
103:
104: private transient Paint[] paintSequence;
105:
106:
107: private int paintIndex;
108:
109:
110: private transient Paint[] outlinePaintSequence;
111:
112:
113: private int outlinePaintIndex;
114:
115:
116: private transient Stroke[] strokeSequence;
117:
118:
119: private int strokeIndex;
120:
121:
122: private transient Stroke[] outlineStrokeSequence;
123:
124:
125: private int outlineStrokeIndex;
126:
127:
128: private transient Shape[] shapeSequence;
129:
130:
131: private int shapeIndex;
132:
133:
137: public DefaultDrawingSupplier() {
138:
139: this(DEFAULT_PAINT_SEQUENCE,
140: DEFAULT_OUTLINE_PAINT_SEQUENCE,
141: DEFAULT_STROKE_SEQUENCE,
142: DEFAULT_OUTLINE_STROKE_SEQUENCE,
143: DEFAULT_SHAPE_SEQUENCE);
144:
145: }
146:
147:
156: public DefaultDrawingSupplier(Paint[] paintSequence,
157: Paint[] outlinePaintSequence,
158: Stroke[] strokeSequence,
159: Stroke[] outlineStrokeSequence,
160: Shape[] shapeSequence) {
161:
162: this.paintSequence = paintSequence;
163: this.outlinePaintSequence = outlinePaintSequence;
164: this.strokeSequence = strokeSequence;
165: this.outlineStrokeSequence = outlineStrokeSequence;
166: this.shapeSequence = shapeSequence;
167:
168: }
169:
170:
175: public Paint getNextPaint() {
176: Paint result
177: = this.paintSequence[this.paintIndex % this.paintSequence.length];
178: this.paintIndex++;
179: return result;
180: }
181:
182:
187: public Paint getNextOutlinePaint() {
188: Paint result = this.outlinePaintSequence[
189: this.outlinePaintIndex % this.outlinePaintSequence.length];
190: this.outlinePaintIndex++;
191: return result;
192: }
193:
194:
199: public Stroke getNextStroke() {
200: Stroke result = this.strokeSequence[
201: this.strokeIndex % this.strokeSequence.length];
202: this.strokeIndex++;
203: return result;
204: }
205:
206:
211: public Stroke getNextOutlineStroke() {
212: Stroke result = this.outlineStrokeSequence[
213: this.outlineStrokeIndex % this.outlineStrokeSequence.length];
214: this.outlineStrokeIndex++;
215: return result;
216: }
217:
218:
223: public Shape getNextShape() {
224: Shape result = this.shapeSequence[
225: this.shapeIndex % this.shapeSequence.length];
226: this.shapeIndex++;
227: return result;
228: }
229:
230:
236: public static Shape[] createStandardSeriesShapes() {
237:
238: Shape[] result = new Shape[10];
239:
240: double size = 6.0;
241: double delta = size / 2.0;
242: int[] xpoints = null;
243: int[] ypoints = null;
244:
245:
246: result[0] = new Rectangle2D.Double(-delta, -delta, size, size);
247:
248: result[1] = new Ellipse2D.Double(-delta, -delta, size, size);
249:
250:
251: xpoints = intArray(0.0, delta, -delta);
252: ypoints = intArray(-delta, delta, delta);
253: result[2] = new Polygon(xpoints, ypoints, 3);
254:
255:
256: xpoints = intArray(0.0, delta, 0.0, -delta);
257: ypoints = intArray(-delta, 0.0, delta, 0.0);
258: result[3] = new Polygon(xpoints, ypoints, 4);
259:
260:
261: result[4] = new Rectangle2D.Double(-delta, -delta / 2, size, size / 2);
262:
263:
264: xpoints = intArray(-delta, +delta, 0.0);
265: ypoints = intArray(-delta, -delta, delta);
266: result[5] = new Polygon(xpoints, ypoints, 3);
267:
268:
269: result[6] = new Ellipse2D.Double(-delta, -delta / 2, size, size / 2);
270:
271:
272: xpoints = intArray(-delta, delta, -delta);
273: ypoints = intArray(-delta, 0.0, delta);
274: result[7] = new Polygon(xpoints, ypoints, 3);
275:
276:
277: result[8] = new Rectangle2D.Double(-delta / 2, -delta, size / 2, size);
278:
279:
280: xpoints = intArray(-delta, delta, delta);
281: ypoints = intArray(0.0, -delta, +delta);
282: result[9] = new Polygon(xpoints, ypoints, 3);
283:
284: return result;
285:
286: }
287:
288:
295: public boolean equals(Object obj) {
296:
297: if (obj == this) {
298: return true;
299: }
300:
301: if (!(obj instanceof DefaultDrawingSupplier)) {
302: return false;
303: }
304:
305: DefaultDrawingSupplier that = (DefaultDrawingSupplier) obj;
306:
307: if (!Arrays.equals(this.paintSequence, that.paintSequence)) {
308: return false;
309: }
310: if (this.paintIndex != that.paintIndex) {
311: return false;
312: }
313: if (!Arrays.equals(this.outlinePaintSequence,
314: that.outlinePaintSequence)) {
315: return false;
316: }
317: if (this.outlinePaintIndex != that.outlinePaintIndex) {
318: return false;
319: }
320: if (!Arrays.equals(this.strokeSequence, that.strokeSequence)) {
321: return false;
322: }
323: if (this.strokeIndex != that.strokeIndex) {
324: return false;
325: }
326: if (!Arrays.equals(this.outlineStrokeSequence,
327: that.outlineStrokeSequence)) {
328: return false;
329: }
330: if (this.outlineStrokeIndex != that.outlineStrokeIndex) {
331: return false;
332: }
333: if (!equalShapes(this.shapeSequence, that.shapeSequence)) {
334: return false;
335: }
336: if (this.shapeIndex != that.shapeIndex) {
337: return false;
338: }
339: return true;
340:
341: }
342:
343:
351: private boolean equalShapes(Shape[] s1, Shape[] s2) {
352: if (s1 == null) {
353: return s2 == null;
354: }
355: if (s2 == null) {
356: return false;
357: }
358: if (s1.length != s2.length) {
359: return false;
360: }
361: for (int i = 0; i < s1.length; i++) {
362: if (!ShapeUtilities.equal(s1[i], s2[i])) {
363: return false;
364: }
365: }
366: return true;
367: }
368:
369:
376: private void writeObject(ObjectOutputStream stream) throws IOException {
377: stream.defaultWriteObject();
378:
379: int paintCount = this.paintSequence.length;
380: stream.writeInt(paintCount);
381: for (int i = 0; i < paintCount; i++) {
382: SerialUtilities.writePaint(this.paintSequence[i], stream);
383: }
384:
385: int outlinePaintCount = this.outlinePaintSequence.length;
386: stream.writeInt(outlinePaintCount);
387: for (int i = 0; i < outlinePaintCount; i++) {
388: SerialUtilities.writePaint(this.outlinePaintSequence[i], stream);
389: }
390:
391: int strokeCount = this.strokeSequence.length;
392: stream.writeInt(strokeCount);
393: for (int i = 0; i < strokeCount; i++) {
394: SerialUtilities.writeStroke(this.strokeSequence[i], stream);
395: }
396:
397: int outlineStrokeCount = this.outlineStrokeSequence.length;
398: stream.writeInt(outlineStrokeCount);
399: for (int i = 0; i < outlineStrokeCount; i++) {
400: SerialUtilities.writeStroke(this.outlineStrokeSequence[i], stream);
401: }
402:
403: int shapeCount = this.shapeSequence.length;
404: stream.writeInt(shapeCount);
405: for (int i = 0; i < shapeCount; i++) {
406: SerialUtilities.writeShape(this.shapeSequence[i], stream);
407: }
408:
409: }
410:
411:
419: private void readObject(ObjectInputStream stream)
420: throws IOException, ClassNotFoundException {
421: stream.defaultReadObject();
422:
423: int paintCount = stream.readInt();
424: this.paintSequence = new Paint[paintCount];
425: for (int i = 0; i < paintCount; i++) {
426: this.paintSequence[i] = SerialUtilities.readPaint(stream);
427: }
428:
429: int outlinePaintCount = stream.readInt();
430: this.outlinePaintSequence = new Paint[outlinePaintCount];
431: for (int i = 0; i < outlinePaintCount; i++) {
432: this.outlinePaintSequence[i] = SerialUtilities.readPaint(stream);
433: }
434:
435: int strokeCount = stream.readInt();
436: this.strokeSequence = new Stroke[strokeCount];
437: for (int i = 0; i < strokeCount; i++) {
438: this.strokeSequence[i] = SerialUtilities.readStroke(stream);
439: }
440:
441: int outlineStrokeCount = stream.readInt();
442: this.outlineStrokeSequence = new Stroke[outlineStrokeCount];
443: for (int i = 0; i < outlineStrokeCount; i++) {
444: this.outlineStrokeSequence[i] = SerialUtilities.readStroke(stream);
445: }
446:
447: int shapeCount = stream.readInt();
448: this.shapeSequence = new Shape[shapeCount];
449: for (int i = 0; i < shapeCount; i++) {
450: this.shapeSequence[i] = SerialUtilities.readShape(stream);
451: }
452:
453: }
454:
455:
465: private static int[] intArray(double a, double b, double c) {
466: return new int[] {(int) a, (int) b, (int) c};
467: }
468:
469:
480: private static int[] intArray(double a, double b, double c, double d) {
481: return new int[] {(int) a, (int) b, (int) c, (int) d};
482: }
483:
484:
492: public Object clone() throws CloneNotSupportedException {
493: DefaultDrawingSupplier clone = (DefaultDrawingSupplier) super.clone();
494: return clone;
495: }
496: }