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 implements DrawingSupplier, Cloneable,
76: 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 Paint[] DEFAULT_FILL_PAINT_SEQUENCE = new Paint[] {
91: Color.white};
92:
93:
94: public static final Stroke[] DEFAULT_STROKE_SEQUENCE = new Stroke[] {
95: new BasicStroke(1.0f, BasicStroke.CAP_SQUARE,
96: BasicStroke.JOIN_BEVEL)};
97:
98:
99: public static final Stroke[] DEFAULT_OUTLINE_STROKE_SEQUENCE
100: = new Stroke[] {new BasicStroke(1.0f, BasicStroke.CAP_SQUARE,
101: BasicStroke.JOIN_BEVEL)};
102:
103:
104: public static final Shape[] DEFAULT_SHAPE_SEQUENCE
105: = createStandardSeriesShapes();
106:
107:
108: private transient Paint[] paintSequence;
109:
110:
111: private int paintIndex;
112:
113:
114: private transient Paint[] outlinePaintSequence;
115:
116:
117: private int outlinePaintIndex;
118:
119:
120: private transient Paint[] fillPaintSequence;
121:
122:
123: private int fillPaintIndex;
124:
125:
126: private transient Stroke[] strokeSequence;
127:
128:
129: private int strokeIndex;
130:
131:
132: private transient Stroke[] outlineStrokeSequence;
133:
134:
135: private int outlineStrokeIndex;
136:
137:
138: private transient Shape[] shapeSequence;
139:
140:
141: private int shapeIndex;
142:
143:
147: public DefaultDrawingSupplier() {
148:
149: this(DEFAULT_PAINT_SEQUENCE, DEFAULT_FILL_PAINT_SEQUENCE,
150: DEFAULT_OUTLINE_PAINT_SEQUENCE,
151: DEFAULT_STROKE_SEQUENCE,
152: DEFAULT_OUTLINE_STROKE_SEQUENCE,
153: DEFAULT_SHAPE_SEQUENCE);
154:
155: }
156:
157:
166: public DefaultDrawingSupplier(Paint[] paintSequence,
167: Paint[] outlinePaintSequence,
168: Stroke[] strokeSequence,
169: Stroke[] outlineStrokeSequence,
170: Shape[] shapeSequence) {
171:
172: this.paintSequence = paintSequence;
173: this.fillPaintSequence = DEFAULT_FILL_PAINT_SEQUENCE;
174: this.outlinePaintSequence = outlinePaintSequence;
175: this.strokeSequence = strokeSequence;
176: this.outlineStrokeSequence = outlineStrokeSequence;
177: this.shapeSequence = shapeSequence;
178:
179: }
180:
181:
193: public DefaultDrawingSupplier(Paint[] paintSequence,
194: Paint[] fillPaintSequence, Paint[] outlinePaintSequence,
195: Stroke[] strokeSequence, Stroke[] outlineStrokeSequence,
196: Shape[] shapeSequence) {
197:
198: this.paintSequence = paintSequence;
199: this.fillPaintSequence = fillPaintSequence;
200: this.outlinePaintSequence = outlinePaintSequence;
201: this.strokeSequence = strokeSequence;
202: this.outlineStrokeSequence = outlineStrokeSequence;
203: this.shapeSequence = shapeSequence;
204: }
205:
206:
211: public Paint getNextPaint() {
212: Paint result
213: = this.paintSequence[this.paintIndex % this.paintSequence.length];
214: this.paintIndex++;
215: return result;
216: }
217:
218:
223: public Paint getNextOutlinePaint() {
224: Paint result = this.outlinePaintSequence[
225: this.outlinePaintIndex % this.outlinePaintSequence.length];
226: this.outlinePaintIndex++;
227: return result;
228: }
229:
230:
237: public Paint getNextFillPaint() {
238: Paint result = this.fillPaintSequence[this.fillPaintIndex
239: % this.fillPaintSequence.length];
240: this.fillPaintIndex++;
241: return result;
242: }
243:
244:
249: public Stroke getNextStroke() {
250: Stroke result = this.strokeSequence[
251: this.strokeIndex % this.strokeSequence.length];
252: this.strokeIndex++;
253: return result;
254: }
255:
256:
261: public Stroke getNextOutlineStroke() {
262: Stroke result = this.outlineStrokeSequence[
263: this.outlineStrokeIndex % this.outlineStrokeSequence.length];
264: this.outlineStrokeIndex++;
265: return result;
266: }
267:
268:
273: public Shape getNextShape() {
274: Shape result = this.shapeSequence[
275: this.shapeIndex % this.shapeSequence.length];
276: this.shapeIndex++;
277: return result;
278: }
279:
280:
286: public static Shape[] createStandardSeriesShapes() {
287:
288: Shape[] result = new Shape[10];
289:
290: double size = 6.0;
291: double delta = size / 2.0;
292: int[] xpoints = null;
293: int[] ypoints = null;
294:
295:
296: result[0] = new Rectangle2D.Double(-delta, -delta, size, size);
297:
298: result[1] = new Ellipse2D.Double(-delta, -delta, size, size);
299:
300:
301: xpoints = intArray(0.0, delta, -delta);
302: ypoints = intArray(-delta, delta, delta);
303: result[2] = new Polygon(xpoints, ypoints, 3);
304:
305:
306: xpoints = intArray(0.0, delta, 0.0, -delta);
307: ypoints = intArray(-delta, 0.0, delta, 0.0);
308: result[3] = new Polygon(xpoints, ypoints, 4);
309:
310:
311: result[4] = new Rectangle2D.Double(-delta, -delta / 2, size, size / 2);
312:
313:
314: xpoints = intArray(-delta, +delta, 0.0);
315: ypoints = intArray(-delta, -delta, delta);
316: result[5] = new Polygon(xpoints, ypoints, 3);
317:
318:
319: result[6] = new Ellipse2D.Double(-delta, -delta / 2, size, size / 2);
320:
321:
322: xpoints = intArray(-delta, delta, -delta);
323: ypoints = intArray(-delta, 0.0, delta);
324: result[7] = new Polygon(xpoints, ypoints, 3);
325:
326:
327: result[8] = new Rectangle2D.Double(-delta / 2, -delta, size / 2, size);
328:
329:
330: xpoints = intArray(-delta, delta, delta);
331: ypoints = intArray(0.0, -delta, +delta);
332: result[9] = new Polygon(xpoints, ypoints, 3);
333:
334: return result;
335:
336: }
337:
338:
345: public boolean equals(Object obj) {
346:
347: if (obj == this) {
348: return true;
349: }
350:
351: if (!(obj instanceof DefaultDrawingSupplier)) {
352: return false;
353: }
354:
355: DefaultDrawingSupplier that = (DefaultDrawingSupplier) obj;
356:
357: if (!Arrays.equals(this.paintSequence, that.paintSequence)) {
358: return false;
359: }
360: if (this.paintIndex != that.paintIndex) {
361: return false;
362: }
363: if (!Arrays.equals(this.outlinePaintSequence,
364: that.outlinePaintSequence)) {
365: return false;
366: }
367: if (this.outlinePaintIndex != that.outlinePaintIndex) {
368: return false;
369: }
370: if (!Arrays.equals(this.strokeSequence, that.strokeSequence)) {
371: return false;
372: }
373: if (this.strokeIndex != that.strokeIndex) {
374: return false;
375: }
376: if (!Arrays.equals(this.outlineStrokeSequence,
377: that.outlineStrokeSequence)) {
378: return false;
379: }
380: if (this.outlineStrokeIndex != that.outlineStrokeIndex) {
381: return false;
382: }
383: if (!equalShapes(this.shapeSequence, that.shapeSequence)) {
384: return false;
385: }
386: if (this.shapeIndex != that.shapeIndex) {
387: return false;
388: }
389: return true;
390:
391: }
392:
393:
401: private boolean equalShapes(Shape[] s1, Shape[] s2) {
402: if (s1 == null) {
403: return s2 == null;
404: }
405: if (s2 == null) {
406: return false;
407: }
408: if (s1.length != s2.length) {
409: return false;
410: }
411: for (int i = 0; i < s1.length; i++) {
412: if (!ShapeUtilities.equal(s1[i], s2[i])) {
413: return false;
414: }
415: }
416: return true;
417: }
418:
419:
426: private void writeObject(ObjectOutputStream stream) throws IOException {
427: stream.defaultWriteObject();
428:
429: int paintCount = this.paintSequence.length;
430: stream.writeInt(paintCount);
431: for (int i = 0; i < paintCount; i++) {
432: SerialUtilities.writePaint(this.paintSequence[i], stream);
433: }
434:
435: int outlinePaintCount = this.outlinePaintSequence.length;
436: stream.writeInt(outlinePaintCount);
437: for (int i = 0; i < outlinePaintCount; i++) {
438: SerialUtilities.writePaint(this.outlinePaintSequence[i], stream);
439: }
440:
441: int strokeCount = this.strokeSequence.length;
442: stream.writeInt(strokeCount);
443: for (int i = 0; i < strokeCount; i++) {
444: SerialUtilities.writeStroke(this.strokeSequence[i], stream);
445: }
446:
447: int outlineStrokeCount = this.outlineStrokeSequence.length;
448: stream.writeInt(outlineStrokeCount);
449: for (int i = 0; i < outlineStrokeCount; i++) {
450: SerialUtilities.writeStroke(this.outlineStrokeSequence[i], stream);
451: }
452:
453: int shapeCount = this.shapeSequence.length;
454: stream.writeInt(shapeCount);
455: for (int i = 0; i < shapeCount; i++) {
456: SerialUtilities.writeShape(this.shapeSequence[i], stream);
457: }
458:
459: }
460:
461:
469: private void readObject(ObjectInputStream stream)
470: throws IOException, ClassNotFoundException {
471: stream.defaultReadObject();
472:
473: int paintCount = stream.readInt();
474: this.paintSequence = new Paint[paintCount];
475: for (int i = 0; i < paintCount; i++) {
476: this.paintSequence[i] = SerialUtilities.readPaint(stream);
477: }
478:
479: int outlinePaintCount = stream.readInt();
480: this.outlinePaintSequence = new Paint[outlinePaintCount];
481: for (int i = 0; i < outlinePaintCount; i++) {
482: this.outlinePaintSequence[i] = SerialUtilities.readPaint(stream);
483: }
484:
485: int strokeCount = stream.readInt();
486: this.strokeSequence = new Stroke[strokeCount];
487: for (int i = 0; i < strokeCount; i++) {
488: this.strokeSequence[i] = SerialUtilities.readStroke(stream);
489: }
490:
491: int outlineStrokeCount = stream.readInt();
492: this.outlineStrokeSequence = new Stroke[outlineStrokeCount];
493: for (int i = 0; i < outlineStrokeCount; i++) {
494: this.outlineStrokeSequence[i] = SerialUtilities.readStroke(stream);
495: }
496:
497: int shapeCount = stream.readInt();
498: this.shapeSequence = new Shape[shapeCount];
499: for (int i = 0; i < shapeCount; i++) {
500: this.shapeSequence[i] = SerialUtilities.readShape(stream);
501: }
502:
503: }
504:
505:
515: private static int[] intArray(double a, double b, double c) {
516: return new int[] {(int) a, (int) b, (int) c};
517: }
518:
519:
530: private static int[] intArray(double a, double b, double c, double d) {
531: return new int[] {(int) a, (int) b, (int) c, (int) d};
532: }
533:
534:
542: public Object clone() throws CloneNotSupportedException {
543: DefaultDrawingSupplier clone = (DefaultDrawingSupplier) super.clone();
544: return clone;
545: }
546: }