1 47 48 package org.jfree.chart.plot; 49 50 import java.awt.BasicStroke ; 51 import java.awt.Color ; 52 import java.awt.Paint ; 53 import java.awt.Polygon ; 54 import java.awt.Shape ; 55 import java.awt.Stroke ; 56 import java.awt.geom.Ellipse2D ; 57 import java.awt.geom.Rectangle2D ; 58 import java.io.IOException ; 59 import java.io.ObjectInputStream ; 60 import java.io.ObjectOutputStream ; 61 import java.io.Serializable ; 62 import java.util.Arrays ; 63 64 import org.jfree.chart.ChartColor; 65 import org.jfree.io.SerialUtilities; 66 import org.jfree.util.PublicCloneable; 67 import org.jfree.util.ShapeUtilities; 68 69 73 public class DefaultDrawingSupplier implements DrawingSupplier, 74 Cloneable , 75 PublicCloneable, 76 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 91 public static final Stroke [] DEFAULT_STROKE_SEQUENCE = new Stroke [] { 92 new BasicStroke (1.0f, 93 BasicStroke.CAP_SQUARE, 94 BasicStroke.JOIN_BEVEL) 95 }; 96 97 98 public static final Stroke [] DEFAULT_OUTLINE_STROKE_SEQUENCE 99 = new Stroke [] { 100 new BasicStroke ( 101 1.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL 102 ) 103 }; 104 105 106 public static final Shape [] DEFAULT_SHAPE_SEQUENCE 107 = createStandardSeriesShapes(); 108 109 110 private transient Paint [] paintSequence; 111 112 113 private int paintIndex; 114 115 116 private transient Paint [] outlinePaintSequence; 117 118 119 private int outlinePaintIndex; 120 121 122 private transient Stroke [] strokeSequence; 123 124 125 private int strokeIndex; 126 127 128 private transient Stroke [] outlineStrokeSequence; 129 130 131 private int outlineStrokeIndex; 132 133 134 private transient Shape [] shapeSequence; 135 136 137 private int shapeIndex; 138 139 143 public DefaultDrawingSupplier() { 144 145 this(DEFAULT_PAINT_SEQUENCE, 146 DEFAULT_OUTLINE_PAINT_SEQUENCE, 147 DEFAULT_STROKE_SEQUENCE, 148 DEFAULT_OUTLINE_STROKE_SEQUENCE, 149 DEFAULT_SHAPE_SEQUENCE); 150 151 } 152 153 162 public DefaultDrawingSupplier(Paint [] paintSequence, 163 Paint [] outlinePaintSequence, 164 Stroke [] strokeSequence, 165 Stroke [] outlineStrokeSequence, 166 Shape [] shapeSequence) { 167 168 this.paintSequence = paintSequence; 169 this.outlinePaintSequence = outlinePaintSequence; 170 this.strokeSequence = strokeSequence; 171 this.outlineStrokeSequence = outlineStrokeSequence; 172 this.shapeSequence = shapeSequence; 173 174 } 175 176 181 public Paint getNextPaint() { 182 Paint result 183 = this.paintSequence[this.paintIndex % this.paintSequence.length]; 184 this.paintIndex++; 185 return result; 186 } 187 188 193 public Paint getNextOutlinePaint() { 194 Paint result = this.outlinePaintSequence[ 195 this.outlinePaintIndex % this.outlinePaintSequence.length 196 ]; 197 this.outlinePaintIndex++; 198 return result; 199 } 200 201 206 public Stroke getNextStroke() { 207 Stroke result = this.strokeSequence[ 208 this.strokeIndex % this.strokeSequence.length 209 ]; 210 this.strokeIndex++; 211 return result; 212 } 213 214 219 public Stroke getNextOutlineStroke() { 220 Stroke result = this.outlineStrokeSequence[ 221 this.outlineStrokeIndex % this.outlineStrokeSequence.length 222 ]; 223 this.outlineStrokeIndex++; 224 return result; 225 } 226 227 232 public Shape getNextShape() { 233 Shape result = this.shapeSequence[ 234 this.shapeIndex % this.shapeSequence.length 235 ]; 236 this.shapeIndex++; 237 return result; 238 } 239 240 246 public static Shape [] createStandardSeriesShapes() { 247 248 Shape [] result = new Shape [10]; 249 250 double size = 6.0; 251 double delta = size / 2.0; 252 int[] xpoints = null; 253 int[] ypoints = null; 254 255 result[0] = new Rectangle2D.Double (-delta, -delta, size, size); 257 result[1] = new Ellipse2D.Double (-delta, -delta, size, size); 259 260 xpoints = intArray(0.0, delta, -delta); 262 ypoints = intArray(-delta, delta, delta); 263 result[2] = new Polygon (xpoints, ypoints, 3); 264 265 xpoints = intArray(0.0, delta, 0.0, -delta); 267 ypoints = intArray(-delta, 0.0, delta, 0.0); 268 result[3] = new Polygon (xpoints, ypoints, 4); 269 270 result[4] = new Rectangle2D.Double (-delta, -delta / 2, size, size / 2); 272 273 xpoints = intArray(-delta, +delta, 0.0); 275 ypoints = intArray(-delta, -delta, delta); 276 result[5] = new Polygon (xpoints, ypoints, 3); 277 278 result[6] = new Ellipse2D.Double (-delta, -delta / 2, size, size / 2); 280 281 xpoints = intArray(-delta, delta, -delta); 283 ypoints = intArray(-delta, 0.0, delta); 284 result[7] = new Polygon (xpoints, ypoints, 3); 285 286 result[8] = new Rectangle2D.Double (-delta / 2, -delta, size / 2, size); 288 289 xpoints = intArray(-delta, delta, delta); 291 ypoints = intArray(0.0, -delta, +delta); 292 result[9] = new Polygon (xpoints, ypoints, 3); 293 294 return result; 295 296 } 297 298 305 public boolean equals(Object obj) { 306 307 if (obj == this) { 308 return true; 309 } 310 311 if (!(obj instanceof DefaultDrawingSupplier)) { 312 return false; 313 } 314 315 DefaultDrawingSupplier that = (DefaultDrawingSupplier) obj; 316 317 if (!Arrays.equals(this.paintSequence, that.paintSequence)) { 318 return false; 319 } 320 if (this.paintIndex != that.paintIndex) { 321 return false; 322 } 323 if (!Arrays.equals(this.outlinePaintSequence, 324 that.outlinePaintSequence)) { 325 return false; 326 } 327 if (this.outlinePaintIndex != that.outlinePaintIndex) { 328 return false; 329 } 330 if (!Arrays.equals(this.strokeSequence, that.strokeSequence)) { 331 return false; 332 } 333 if (this.strokeIndex != that.strokeIndex) { 334 return false; 335 } 336 if (!Arrays.equals(this.outlineStrokeSequence, 337 that.outlineStrokeSequence)) { 338 return false; 339 } 340 if (this.outlineStrokeIndex != that.outlineStrokeIndex) { 341 return false; 342 } 343 if (!equalShapes(this.shapeSequence, that.shapeSequence)) { 344 return false; 345 } 346 if (this.shapeIndex != that.shapeIndex) { 347 return false; 348 } 349 return true; 350 351 } 352 353 361 private boolean equalShapes(Shape [] s1, Shape [] s2) { 362 if (s1 == null) { 363 return s2 == null; 364 } 365 if (s2 == null) { 366 return false; 367 } 368 if (s1.length != s2.length) { 369 return false; 370 } 371 for (int i = 0; i < s1.length; i++) { 372 if (!ShapeUtilities.equal(s1[i], s2[i])) { 373 return false; 374 } 375 } 376 return true; 377 } 378 379 386 private void writeObject(ObjectOutputStream stream) throws IOException { 387 stream.defaultWriteObject(); 388 389 int paintCount = this.paintSequence.length; 390 stream.writeInt(paintCount); 391 for (int i = 0; i < paintCount; i++) { 392 SerialUtilities.writePaint(this.paintSequence[i], stream); 393 } 394 395 int outlinePaintCount = this.outlinePaintSequence.length; 396 stream.writeInt(outlinePaintCount); 397 for (int i = 0; i < outlinePaintCount; i++) { 398 SerialUtilities.writePaint(this.outlinePaintSequence[i], stream); 399 } 400 401 int strokeCount = this.strokeSequence.length; 402 stream.writeInt(strokeCount); 403 for (int i = 0; i < strokeCount; i++) { 404 SerialUtilities.writeStroke(this.strokeSequence[i], stream); 405 } 406 407 int outlineStrokeCount = this.outlineStrokeSequence.length; 408 stream.writeInt(outlineStrokeCount); 409 for (int i = 0; i < outlineStrokeCount; i++) { 410 SerialUtilities.writeStroke(this.outlineStrokeSequence[i], stream); 411 } 412 413 int shapeCount = this.shapeSequence.length; 414 stream.writeInt(shapeCount); 415 for (int i = 0; i < shapeCount; i++) { 416 SerialUtilities.writeShape(this.shapeSequence[i], stream); 417 } 418 419 } 420 421 429 private void readObject(ObjectInputStream stream) 430 throws IOException , ClassNotFoundException { 431 stream.defaultReadObject(); 432 433 int paintCount = stream.readInt(); 434 this.paintSequence = new Paint [paintCount]; 435 for (int i = 0; i < paintCount; i++) { 436 this.paintSequence[i] = SerialUtilities.readPaint(stream); 437 } 438 439 int outlinePaintCount = stream.readInt(); 440 this.outlinePaintSequence = new Paint [outlinePaintCount]; 441 for (int i = 0; i < outlinePaintCount; i++) { 442 this.outlinePaintSequence[i] = SerialUtilities.readPaint(stream); 443 } 444 445 int strokeCount = stream.readInt(); 446 this.strokeSequence = new Stroke [strokeCount]; 447 for (int i = 0; i < strokeCount; i++) { 448 this.strokeSequence[i] = SerialUtilities.readStroke(stream); 449 } 450 451 int outlineStrokeCount = stream.readInt(); 452 this.outlineStrokeSequence = new Stroke [outlineStrokeCount]; 453 for (int i = 0; i < outlineStrokeCount; i++) { 454 this.outlineStrokeSequence[i] = SerialUtilities.readStroke(stream); 455 } 456 457 int shapeCount = stream.readInt(); 458 this.shapeSequence = new Shape [shapeCount]; 459 for (int i = 0; i < shapeCount; i++) { 460 this.shapeSequence[i] = SerialUtilities.readShape(stream); 461 } 462 463 } 464 465 475 private static int[] intArray(double a, double b, double c) { 476 return new int[] {(int) a, (int) b, (int) c}; 477 } 478 479 490 private static int[] intArray(double a, double b, double c, double d) { 491 return new int[] {(int) a, (int) b, (int) c, (int) d}; 492 } 493 494 502 public Object clone() throws CloneNotSupportedException { 503 DefaultDrawingSupplier clone = (DefaultDrawingSupplier) super.clone(); 504 return clone; 505 } 506 } 507 | Popular Tags |