1 53 54 package org.jfree.chart; 55 56 import java.awt.BasicStroke ; 57 import java.awt.Color ; 58 import java.awt.Paint ; 59 import java.awt.Shape ; 60 import java.awt.Stroke ; 61 import java.awt.geom.Line2D ; 62 import java.io.IOException ; 63 import java.io.ObjectInputStream ; 64 import java.io.ObjectOutputStream ; 65 import java.io.Serializable ; 66 67 import org.jfree.io.SerialUtilities; 68 import org.jfree.util.ObjectUtilities; 69 import org.jfree.util.ShapeUtilities; 70 71 75 public class LegendItem implements Serializable { 76 77 80 81 private static final long serialVersionUID = -797214582948827144L; 82 83 84 private String label; 85 86 89 private String description; 90 91 92 private String toolTipText; 93 94 95 private String urlText; 96 97 98 private boolean shapeVisible; 99 100 101 private transient Shape shape; 102 103 104 private boolean shapeFilled; 105 106 107 private transient Paint fillPaint; 108 109 110 private boolean shapeOutlineVisible; 111 112 113 private transient Paint outlinePaint; 114 115 116 private transient Stroke outlineStroke; 117 118 119 private boolean lineVisible; 120 121 122 private transient Shape line; 123 124 125 private transient Stroke lineStroke; 126 127 128 private transient Paint linePaint; 129 130 134 private static final Shape UNUSED_SHAPE = new Line2D.Float (); 135 136 140 private static final Stroke UNUSED_STROKE = new BasicStroke (0.0f); 141 142 154 public LegendItem(String label, String description, 155 String toolTipText, String urlText, 156 Shape shape, Paint fillPaint) { 157 this( 158 label, 159 description, 160 toolTipText, 161 urlText, 162 true, shape, 164 true, fillPaint, 166 false, Color.black, 168 UNUSED_STROKE, 169 false, UNUSED_SHAPE, 171 UNUSED_STROKE, 172 Color.black 173 ); 174 } 175 176 191 public LegendItem(String label, String description, 192 String toolTipText, String urlText, 193 Shape shape, Paint fillPaint, 194 Stroke outlineStroke, Paint outlinePaint) { 195 this( 196 label, 197 description, 198 toolTipText, 199 urlText, 200 true, shape, 202 true, fillPaint, 204 true, outlinePaint, 206 outlineStroke, 207 false, UNUSED_SHAPE, 209 UNUSED_STROKE, 210 Color.black 211 ); 212 } 213 214 225 public LegendItem(String label, String description, 226 String toolTipText, String urlText, 227 Shape line, Stroke lineStroke, Paint linePaint) { 228 this( 229 label, 230 description, 231 toolTipText, 232 urlText, 233 false, UNUSED_SHAPE, 235 false, Color.black, 237 false, Color.black, 239 UNUSED_STROKE, 240 true, line, 242 lineStroke, 243 linePaint 244 ); 245 } 246 247 272 public LegendItem(String label, 273 String description, 274 String toolTipText, 275 String urlText, 276 boolean shapeVisible, 277 Shape shape, 278 boolean shapeFilled, 279 Paint fillPaint, 280 boolean shapeOutlineVisible, 281 Paint outlinePaint, 282 Stroke outlineStroke, 283 boolean lineVisible, 284 Shape line, 285 Stroke lineStroke, 286 Paint linePaint) { 287 288 if (label == null) { 289 throw new IllegalArgumentException ("Null 'label' argument."); 290 } 291 if (fillPaint == null) { 292 throw new IllegalArgumentException ("Null 'fillPaint' argument."); 293 } 294 if (lineStroke == null) { 295 throw new IllegalArgumentException ("Null 'lineStroke' argument."); 296 } 297 if (outlinePaint == null) { 298 throw new IllegalArgumentException ("Null 'outlinePaint' argument."); 299 } 300 if (outlineStroke == null) { 301 throw new IllegalArgumentException ( 302 "Null 'outlineStroke' argument." 303 ); 304 } 305 this.label = label; 306 this.description = description; 307 this.shapeVisible = shapeVisible; 308 this.shape = shape; 309 this.shapeFilled = shapeFilled; 310 this.fillPaint = fillPaint; 311 this.shapeOutlineVisible = shapeOutlineVisible; 312 this.outlinePaint = outlinePaint; 313 this.outlineStroke = outlineStroke; 314 this.lineVisible = lineVisible; 315 this.line = line; 316 this.lineStroke = lineStroke; 317 this.linePaint = linePaint; 318 this.toolTipText = toolTipText; 319 this.urlText = urlText; 320 } 321 322 327 public String getLabel() { 328 return this.label; 329 } 330 331 336 public String getDescription() { 337 return this.description; 338 } 339 340 345 public String getToolTipText() { 346 return this.toolTipText; 347 } 348 349 354 public String getURLText() { 355 return this.urlText; 356 } 357 358 363 public boolean isShapeVisible() { 364 return this.shapeVisible; 365 } 366 367 373 public Shape getShape() { 374 return this.shape; 375 } 376 377 382 public boolean isShapeFilled() { 383 return this.shapeFilled; 384 } 385 386 391 public Paint getFillPaint() { 392 return this.fillPaint; 393 } 394 395 401 public boolean isShapeOutlineVisible() { 402 return this.shapeOutlineVisible; 403 } 404 405 410 public Stroke getLineStroke() { 411 return this.lineStroke; 412 } 413 414 419 public Paint getLinePaint() { 420 return this.linePaint; 421 } 422 423 428 public Paint getOutlinePaint() { 429 return this.outlinePaint; 430 } 431 432 437 public Stroke getOutlineStroke() { 438 return this.outlineStroke; 439 } 440 441 446 public boolean isLineVisible() { 447 return this.lineVisible; 448 } 449 450 455 public Shape getLine() { 456 return this.line; 457 } 458 459 466 public boolean equals(Object obj) { 467 if (obj == this) { 468 return true; 469 } 470 if (!(obj instanceof LegendItem)) { 471 return false; 472 } 473 LegendItem that = (LegendItem) obj; 474 if (!this.label.equals(that.label)) { 475 return false; 476 } 477 if (!ObjectUtilities.equal(this.description, that.description)) { 478 return false; 479 } 480 if (this.shapeVisible != that.shapeVisible) { 481 return false; 482 } 483 if (!ShapeUtilities.equal(this.shape, that.shape)) { 484 return false; 485 } 486 if (this.shapeFilled != that.shapeFilled) { 487 return false; 488 } 489 if (!this.fillPaint.equals(that.fillPaint)) { 490 return false; 491 } 492 if (this.shapeOutlineVisible != that.shapeOutlineVisible) { 493 return false; 494 } 495 if (!this.outlineStroke.equals(that.outlineStroke)) { 496 return false; 497 } 498 if (!this.outlinePaint.equals(that.outlinePaint)) { 499 return false; 500 } 501 if (!this.lineVisible == that.lineVisible) { 502 return false; 503 } 504 if (!ShapeUtilities.equal(this.line, that.line)) { 505 return false; 506 } 507 if (!this.lineStroke.equals(that.lineStroke)) { 508 return false; 509 } 510 if (!this.linePaint.equals(that.linePaint)) { 511 return false; 512 } 513 return true; 514 } 515 516 523 private void writeObject(ObjectOutputStream stream) throws IOException { 524 stream.defaultWriteObject(); 525 SerialUtilities.writeShape(this.shape, stream); 526 SerialUtilities.writePaint(this.fillPaint, stream); 527 SerialUtilities.writeStroke(this.outlineStroke, stream); 528 SerialUtilities.writePaint(this.outlinePaint, stream); 529 SerialUtilities.writeShape(this.line, stream); 530 SerialUtilities.writeStroke(this.lineStroke, stream); 531 SerialUtilities.writePaint(this.linePaint, stream); 532 } 533 534 542 private void readObject(ObjectInputStream stream) 543 throws IOException , ClassNotFoundException { 544 stream.defaultReadObject(); 545 this.shape = SerialUtilities.readShape(stream); 546 this.fillPaint = SerialUtilities.readPaint(stream); 547 this.outlineStroke = SerialUtilities.readStroke(stream); 548 this.outlinePaint = SerialUtilities.readPaint(stream); 549 this.line = SerialUtilities.readShape(stream); 550 this.lineStroke = SerialUtilities.readStroke(stream); 551 this.linePaint = SerialUtilities.readPaint(stream); 552 } 553 554 } 555 | Popular Tags |