1 61 62 package org.jfree.chart.plot; 63 64 import java.awt.BasicStroke ; 65 import java.awt.Color ; 66 import java.awt.Font ; 67 import java.awt.Paint ; 68 import java.awt.Stroke ; 69 import java.io.IOException ; 70 import java.io.ObjectInputStream ; 71 import java.io.ObjectOutputStream ; 72 import java.io.Serializable ; 73 import java.util.EventListener ; 74 75 import javax.swing.event.EventListenerList ; 76 77 import org.jfree.chart.event.MarkerChangeEvent; 78 import org.jfree.chart.event.MarkerChangeListener; 79 import org.jfree.io.SerialUtilities; 80 import org.jfree.ui.LengthAdjustmentType; 81 import org.jfree.ui.RectangleAnchor; 82 import org.jfree.ui.RectangleInsets; 83 import org.jfree.ui.TextAnchor; 84 import org.jfree.util.ObjectUtilities; 85 import org.jfree.util.PaintUtilities; 86 87 94 public abstract class Marker implements Cloneable , Serializable { 95 96 97 private static final long serialVersionUID = -734389651405327166L; 98 99 100 private transient Paint paint; 101 102 103 private transient Stroke stroke; 104 105 106 private transient Paint outlinePaint; 107 108 109 private transient Stroke outlineStroke; 110 111 112 private float alpha; 113 114 115 private String label = null; 116 117 118 private Font labelFont; 119 120 121 private transient Paint labelPaint; 122 123 124 private RectangleAnchor labelAnchor; 125 126 127 private TextAnchor labelTextAnchor; 128 129 130 private RectangleInsets labelOffset; 131 132 135 private LengthAdjustmentType labelOffsetType; 136 137 138 private transient EventListenerList listenerList; 139 140 143 protected Marker() { 144 this(Color.gray); 145 } 146 147 152 protected Marker(Paint paint) { 153 this(paint, new BasicStroke (0.5f), Color.gray, new BasicStroke (0.5f), 154 0.80f); 155 } 156 157 171 protected Marker(Paint paint, Stroke stroke, 172 Paint outlinePaint, Stroke outlineStroke, 173 float alpha) { 174 175 if (paint == null) { 176 throw new IllegalArgumentException ("Null 'paint' argument."); 177 } 178 if (stroke == null) { 179 throw new IllegalArgumentException ("Null 'stroke' argument."); 180 } 181 if (alpha < 0.0f || alpha > 1.0f) 182 throw new IllegalArgumentException ( 183 "The 'alpha' value must be in the range 0.0f to 1.0f"); 184 185 this.paint = paint; 186 this.stroke = stroke; 187 this.outlinePaint = outlinePaint; 188 this.outlineStroke = outlineStroke; 189 this.alpha = alpha; 190 191 this.labelFont = new Font ("SansSerif", Font.PLAIN, 9); 192 this.labelPaint = Color.black; 193 this.labelAnchor = RectangleAnchor.TOP_LEFT; 194 this.labelOffset = new RectangleInsets(3.0, 3.0, 3.0, 3.0); 195 this.labelOffsetType = LengthAdjustmentType.CONTRACT; 196 this.labelTextAnchor = TextAnchor.CENTER; 197 198 this.listenerList = new EventListenerList (); 199 } 200 201 208 public Paint getPaint() { 209 return this.paint; 210 } 211 212 220 public void setPaint(Paint paint) { 221 if (paint == null) { 222 throw new IllegalArgumentException ("Null 'paint' argument."); 223 } 224 this.paint = paint; 225 notifyListeners(new MarkerChangeEvent(this)); 226 } 227 228 235 public Stroke getStroke() { 236 return this.stroke; 237 } 238 239 247 public void setStroke(Stroke stroke) { 248 if (stroke == null) { 249 throw new IllegalArgumentException ("Null 'stroke' argument."); 250 } 251 this.stroke = stroke; 252 notifyListeners(new MarkerChangeEvent(this)); 253 } 254 255 262 public Paint getOutlinePaint() { 263 return this.outlinePaint; 264 } 265 266 274 public void setOutlinePaint(Paint paint) { 275 this.outlinePaint = paint; 276 notifyListeners(new MarkerChangeEvent(this)); 277 } 278 279 286 public Stroke getOutlineStroke() { 287 return this.outlineStroke; 288 } 289 290 298 public void setOutlineStroke(Stroke stroke) { 299 this.outlineStroke = stroke; 300 notifyListeners(new MarkerChangeEvent(this)); 301 } 302 303 310 public float getAlpha() { 311 return this.alpha; 312 } 313 314 328 public void setAlpha(float alpha) { 329 if (alpha < 0.0f || alpha > 1.0f) 330 throw new IllegalArgumentException ( 331 "The 'alpha' value must be in the range 0.0f to 1.0f"); 332 this.alpha = alpha; 333 notifyListeners(new MarkerChangeEvent(this)); 334 } 335 336 343 public String getLabel() { 344 return this.label; 345 } 346 347 355 public void setLabel(String label) { 356 this.label = label; 357 notifyListeners(new MarkerChangeEvent(this)); 358 } 359 360 367 public Font getLabelFont() { 368 return this.labelFont; 369 } 370 371 379 public void setLabelFont(Font font) { 380 if (font == null) { 381 throw new IllegalArgumentException ("Null 'font' argument."); 382 } 383 this.labelFont = font; 384 notifyListeners(new MarkerChangeEvent(this)); 385 } 386 387 394 public Paint getLabelPaint() { 395 return this.labelPaint; 396 } 397 398 406 public void setLabelPaint(Paint paint) { 407 if (paint == null) { 408 throw new IllegalArgumentException ("Null 'paint' argument."); 409 } 410 this.labelPaint = paint; 411 notifyListeners(new MarkerChangeEvent(this)); 412 } 413 414 422 public RectangleAnchor getLabelAnchor() { 423 return this.labelAnchor; 424 } 425 426 435 public void setLabelAnchor(RectangleAnchor anchor) { 436 if (anchor == null) { 437 throw new IllegalArgumentException ("Null 'anchor' argument."); 438 } 439 this.labelAnchor = anchor; 440 notifyListeners(new MarkerChangeEvent(this)); 441 } 442 443 450 public RectangleInsets getLabelOffset() { 451 return this.labelOffset; 452 } 453 454 462 public void setLabelOffset(RectangleInsets offset) { 463 if (offset == null) { 464 throw new IllegalArgumentException ("Null 'offset' argument."); 465 } 466 this.labelOffset = offset; 467 notifyListeners(new MarkerChangeEvent(this)); 468 } 469 470 477 public LengthAdjustmentType getLabelOffsetType() { 478 return this.labelOffsetType; 479 } 480 481 489 public void setLabelOffsetType(LengthAdjustmentType adj) { 490 if (adj == null) { 491 throw new IllegalArgumentException ("Null 'adj' argument."); 492 } 493 this.labelOffsetType = adj; 494 notifyListeners(new MarkerChangeEvent(this)); 495 } 496 497 504 public TextAnchor getLabelTextAnchor() { 505 return this.labelTextAnchor; 506 } 507 508 516 public void setLabelTextAnchor(TextAnchor anchor) { 517 if (anchor == null) { 518 throw new IllegalArgumentException ("Null 'anchor' argument."); 519 } 520 this.labelTextAnchor = anchor; 521 notifyListeners(new MarkerChangeEvent(this)); 522 } 523 524 531 public void addChangeListener(MarkerChangeListener listener) { 532 this.listenerList.add(MarkerChangeListener.class, listener); 533 } 534 535 542 public void removeChangeListener(MarkerChangeListener listener) { 543 this.listenerList.remove(MarkerChangeListener.class, listener); 544 } 545 546 553 public void notifyListeners(MarkerChangeEvent event) { 554 555 Object [] listeners = this.listenerList.getListenerList(); 556 for (int i = listeners.length - 2; i >= 0; i -= 2) { 557 if (listeners[i] == MarkerChangeListener.class) { 558 ((MarkerChangeListener) listeners[i + 1]).markerChanged(event); 559 } 560 } 561 562 } 563 564 573 public EventListener [] getListeners(Class listenerType) { 574 return this.listenerList.getListeners(listenerType); 575 } 576 577 584 public boolean equals(Object obj) { 585 if (obj == this) { 586 return true; 587 } 588 if (!(obj instanceof Marker)) { 589 return false; 590 } 591 Marker that = (Marker) obj; 592 if (!PaintUtilities.equal(this.paint, that.paint)) { 593 return false; 594 } 595 if (!ObjectUtilities.equal(this.stroke, that.stroke)) { 596 return false; 597 } 598 if (!PaintUtilities.equal(this.outlinePaint, that.outlinePaint)) { 599 return false; 600 } 601 if (!ObjectUtilities.equal(this.outlineStroke, that.outlineStroke)) { 602 return false; 603 } 604 if (this.alpha != that.alpha) { 605 return false; 606 } 607 if (!ObjectUtilities.equal(this.label, that.label)) { 608 return false; 609 } 610 if (!ObjectUtilities.equal(this.labelFont, that.labelFont)) { 611 return false; 612 } 613 if (!PaintUtilities.equal(this.labelPaint, that.labelPaint)) { 614 return false; 615 } 616 if (this.labelAnchor != that.labelAnchor) { 617 return false; 618 } 619 if (this.labelTextAnchor != that.labelTextAnchor) { 620 return false; 621 } 622 if (!ObjectUtilities.equal(this.labelOffset, that.labelOffset)) { 623 return false; 624 } 625 if (!this.labelOffsetType.equals(that.labelOffsetType)) { 626 return false; 627 } 628 return true; 629 } 630 631 638 public Object clone() throws CloneNotSupportedException { 639 return super.clone(); 640 } 641 642 649 private void writeObject(ObjectOutputStream stream) throws IOException { 650 stream.defaultWriteObject(); 651 SerialUtilities.writePaint(this.paint, stream); 652 SerialUtilities.writeStroke(this.stroke, stream); 653 SerialUtilities.writePaint(this.outlinePaint, stream); 654 SerialUtilities.writeStroke(this.outlineStroke, stream); 655 SerialUtilities.writePaint(this.labelPaint, stream); 656 } 657 658 666 private void readObject(ObjectInputStream stream) 667 throws IOException , ClassNotFoundException { 668 stream.defaultReadObject(); 669 this.paint = SerialUtilities.readPaint(stream); 670 this.stroke = SerialUtilities.readStroke(stream); 671 this.outlinePaint = SerialUtilities.readPaint(stream); 672 this.outlineStroke = SerialUtilities.readStroke(stream); 673 this.labelPaint = SerialUtilities.readPaint(stream); 674 } 675 676 } 677 | Popular Tags |