| 1 69 70 package org.jfree.chart.renderer; 71 72 import java.awt.BasicStroke ; 73 import java.awt.Color ; 74 import java.awt.Font ; 75 import java.awt.Paint ; 76 import java.awt.Shape ; 77 import java.awt.Stroke ; 78 import java.awt.geom.Point2D ; 79 import java.awt.geom.Rectangle2D ; 80 import java.io.IOException ; 81 import java.io.ObjectInputStream ; 82 import java.io.ObjectOutputStream ; 83 import java.io.Serializable ; 84 import java.util.Arrays ; 85 import java.util.EventListener ; 86 import java.util.List ; 87 88 import javax.swing.event.EventListenerList ; 89 90 import org.jfree.chart.event.RendererChangeEvent; 91 import org.jfree.chart.event.RendererChangeListener; 92 import org.jfree.chart.labels.ItemLabelAnchor; 93 import org.jfree.chart.labels.ItemLabelPosition; 94 import org.jfree.chart.plot.DrawingSupplier; 95 import org.jfree.chart.plot.PlotOrientation; 96 import org.jfree.io.SerialUtilities; 97 import org.jfree.ui.TextAnchor; 98 import org.jfree.util.BooleanList; 99 import org.jfree.util.BooleanUtilities; 100 import org.jfree.util.ObjectList; 101 import org.jfree.util.ObjectUtilities; 102 import org.jfree.util.PaintList; 103 import org.jfree.util.ShapeList; 104 import org.jfree.util.ShapeUtilities; 105 import org.jfree.util.StrokeList; 106 107 113 public abstract class AbstractRenderer implements Cloneable , Serializable { 114 115 116 private static final long serialVersionUID = -828267569428206075L; 117 118 119 public static final Double ZERO = new Double (0.0); 120 121 122 public static final Paint DEFAULT_PAINT = Color.blue; 123 124 125 public static final Paint DEFAULT_OUTLINE_PAINT = Color.gray; 126 127 128 public static final Stroke DEFAULT_STROKE = new BasicStroke (1.0f); 129 130 131 public static final Stroke DEFAULT_OUTLINE_STROKE = new BasicStroke (1.0f); 132 133 134 public static final Shape DEFAULT_SHAPE 135 = new Rectangle2D.Double (-3.0, -3.0, 6.0, 6.0); 136 137 138 public static final Font DEFAULT_VALUE_LABEL_FONT 139 = new Font ("SansSerif", Font.PLAIN, 10); 140 141 142 public static final Paint DEFAULT_VALUE_LABEL_PAINT = Color.black; 143 144 145 private Boolean seriesVisible; 146 147 148 private BooleanList seriesVisibleList; 149 150 151 private boolean baseSeriesVisible; 152 153 154 private Boolean seriesVisibleInLegend; 155 156 160 private BooleanList seriesVisibleInLegendList; 161 162 163 private boolean baseSeriesVisibleInLegend; 164 165 166 private transient Paint paint; 167 168 169 private PaintList paintList; 170 171 172 private transient Paint basePaint; 173 174 175 private transient Paint fillPaint; 176 177 178 private PaintList fillPaintList; 179 180 181 private transient Paint baseFillPaint; 182 183 184 private transient Paint outlinePaint; 185 186 187 private PaintList outlinePaintList; 188 189 190 private transient Paint baseOutlinePaint; 191 192 193 private transient Stroke stroke; 194 195 196 private StrokeList strokeList; 197 198 199 private transient Stroke baseStroke; 200 201 202 private transient Stroke outlineStroke; 203 204 205 private StrokeList outlineStrokeList; 206 207 208 private transient Stroke baseOutlineStroke; 209 210 211 private transient Shape shape; 212 213 214 private ShapeList shapeList; 215 216 217 private transient Shape baseShape; 218 219 220 private Boolean itemLabelsVisible; 221 222 223 private BooleanList itemLabelsVisibleList; 224 225 226 private Boolean baseItemLabelsVisible; 227 228 229 private Font itemLabelFont; 230 231 232 private ObjectList itemLabelFontList; 233 234 235 private Font baseItemLabelFont; 236 237 238 private transient Paint itemLabelPaint; 239 240 241 private PaintList itemLabelPaintList; 242 243 244 private transient Paint baseItemLabelPaint; 245 246 247 private ItemLabelPosition positiveItemLabelPosition; 248 249 250 private ObjectList positiveItemLabelPositionList; 251 252 253 private ItemLabelPosition basePositiveItemLabelPosition; 254 255 256 private ItemLabelPosition negativeItemLabelPosition; 257 258 259 private ObjectList negativeItemLabelPositionList; 260 261 262 private ItemLabelPosition baseNegativeItemLabelPosition; 263 264 265 private double itemLabelAnchorOffset = 2.0; 266 267 271 private Boolean createEntities; 272 273 277 private BooleanList createEntitiesList; 278 279 283 private boolean baseCreateEntities; 284 285 286 private transient EventListenerList listenerList; 287 288 291 public AbstractRenderer() { 292 293 this.seriesVisible = null; 294 this.seriesVisibleList = new BooleanList(); 295 this.baseSeriesVisible = true; 296 297 this.seriesVisibleInLegend = null; 298 this.seriesVisibleInLegendList = new BooleanList(); 299 this.baseSeriesVisibleInLegend = true; 300 301 this.paint = null; 302 this.paintList = new PaintList(); 303 this.basePaint = DEFAULT_PAINT; 304 305 this.fillPaint = null; 306 this.fillPaintList = new PaintList(); 307 this.baseFillPaint = Color.white; 308 309 this.outlinePaint = null; 310 this.outlinePaintList = new PaintList(); 311 this.baseOutlinePaint = DEFAULT_OUTLINE_PAINT; 312 313 this.stroke = null; 314 this.strokeList = new StrokeList(); 315 this.baseStroke = DEFAULT_STROKE; 316 317 this.outlineStroke = null; 318 this.outlineStrokeList = new StrokeList(); 319 this.baseOutlineStroke = DEFAULT_OUTLINE_STROKE; 320 321 this.shape = null; 322 this.shapeList = new ShapeList(); 323 this.baseShape = DEFAULT_SHAPE; 324 325 this.itemLabelsVisible = null; 326 this.itemLabelsVisibleList = new BooleanList(); 327 this.baseItemLabelsVisible = Boolean.FALSE; 328 329 this.itemLabelFont = null; 330 this.itemLabelFontList = new ObjectList(); 331 this.baseItemLabelFont = new Font ("SansSerif", Font.PLAIN, 10); 332 333 this.itemLabelPaint = null; 334 this.itemLabelPaintList = new PaintList(); 335 this.baseItemLabelPaint = Color.black; 336 337 this.positiveItemLabelPosition = null; 338 this.positiveItemLabelPositionList = new ObjectList(); 339 this.basePositiveItemLabelPosition = new ItemLabelPosition( 340 ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER 341 ); 342 343 this.negativeItemLabelPosition = null; 344 this.negativeItemLabelPositionList = new ObjectList(); 345 this.baseNegativeItemLabelPosition = new ItemLabelPosition( 346 ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER 347 ); 348 349 this.createEntities = null; 350 this.createEntitiesList = new BooleanList(); 351 this.baseCreateEntities = true; 352 353 this.listenerList = new EventListenerList (); 354 355 } 356 357 362 public abstract DrawingSupplier getDrawingSupplier(); 363 364 366 375 public boolean getItemVisible(int series, int item) { 376 return isSeriesVisible(series); 377 } 378 379 387 public boolean isSeriesVisible(int series) { 388 389 boolean result = this.baseSeriesVisible; 390 if (this.seriesVisible != null) { 391 result = this.seriesVisible.booleanValue(); 392 } 393 else { 394 Boolean b = this.seriesVisibleList.getBoolean(series); 395 if (b != null) { 396 result = b.booleanValue(); 397 } 398 } 399 return result; 400 } 401 402 409 public Boolean getSeriesVisible() { 410 return this.seriesVisible; 411 } 412 413 421 public void setSeriesVisible(Boolean visible) { 422 setSeriesVisible(visible, true); 423 } 424 425 434 public void setSeriesVisible(Boolean visible, boolean notify) { 435 this.seriesVisible = visible; 436 if (notify) { 437 notifyListeners(new RendererChangeEvent(this)); 438 } 439 } 440 441 448 public Boolean getSeriesVisible(int series) { 449 return this.seriesVisibleList.getBoolean(series); 450 } 451 452 459 public void setSeriesVisible(int series, Boolean visible) { 460 setSeriesVisible(series, visible, true); 461 } 462 463 472 public void setSeriesVisible(int series, Boolean visible, boolean notify) { 473 this.seriesVisibleList.setBoolean(series, visible); 474 if (notify) { 475 notifyListeners(new RendererChangeEvent(this)); 476 } 477 } 478 479 484 public boolean getBaseSeriesVisible() { 485 return this.baseSeriesVisible; 486 } 487 488 494 public void setBaseSeriesVisible(boolean visible) { 495 setBaseSeriesVisible(visible, true); 497 } 498 499 506 public void setBaseSeriesVisible(boolean visible, boolean notify) { 507 this.baseSeriesVisible = visible; 508 if (notify) { 509 notifyListeners(new RendererChangeEvent(this)); 510 } 511 } 512 513 515 523 public boolean isSeriesVisibleInLegend(int series) { 524 boolean result = this.baseSeriesVisibleInLegend; 525 if (this.seriesVisibleInLegend != null) { 526 result = this.seriesVisibleInLegend.booleanValue(); 527 } 528 else { 529 Boolean b = this.seriesVisibleInLegendList.getBoolean(series); 530 if (b != null) { 531 result = b.booleanValue(); 532 } 533 } 534 return result; 535 } 536 537 545 public Boolean getSeriesVisibleInLegend() { 546 return this.seriesVisibleInLegend; 547 } 548 549 557 public void setSeriesVisibleInLegend(Boolean visible) { 558 setSeriesVisibleInLegend(visible, true); 559 } 560 561 570 public void setSeriesVisibleInLegend(Boolean visible, boolean notify) { 571 this.seriesVisibleInLegend = visible; 572 if (notify) { 573 notifyListeners(new RendererChangeEvent(this)); 574 } 575 } 576 577 587 public Boolean getSeriesVisibleInLegend(int series) { 588 return this.seriesVisibleInLegendList.getBoolean(series); 589 } 590 591 598 public void setSeriesVisibleInLegend(int series, Boolean visible) { 599 setSeriesVisibleInLegend(series, visible, true); 600 } 601 602 611 public void setSeriesVisibleInLegend(int series, Boolean visible, 612 boolean notify) { 613 this.seriesVisibleInLegendList.setBoolean(series, visible); 614 if (notify) { 615 notifyListeners(new RendererChangeEvent(this)); 616 } 617 } 618 619 624 public boolean getBaseSeriesVisibleInLegend() { 625 return this.baseSeriesVisibleInLegend; 626 } 627 628 634 public void setBaseSeriesVisibleInLegend(boolean visible) { 635 setBaseSeriesVisibleInLegend(visible, true); 637 } 638 639 646 public void setBaseSeriesVisibleInLegend(boolean visible, boolean notify) { 647 this.baseSeriesVisibleInLegend = visible; 648 if (notify) { 649 notifyListeners(new RendererChangeEvent(this)); 650 } 651 } 652 653 655 667 public Paint getItemPaint(int row, int column) { 668 return getSeriesPaint(row); 669 } 670 671 678 public Paint getSeriesPaint(int series) { 679 680 if (this.paint != null) { 682 return this.paint; 683 } 684 685 Paint seriesPaint = this.paintList.getPaint(series); 687 if (seriesPaint == null) { 688 DrawingSupplier supplier = getDrawingSupplier(); 689 if (supplier != null) { 690 seriesPaint = supplier.getNextPaint(); 691 this.paintList.setPaint(series, seriesPaint); 692 } 693 else { 694 seriesPaint = this.basePaint; 695 } 696 } 697 return seriesPaint; 698 699 } 700 701 708 public void setPaint(Paint paint) { 709 setPaint(paint, true); 710 } 711 712 719 public void setPaint(Paint paint, boolean notify) { 720 this.paint = paint; 721 if (notify) { 722 notifyListeners(new RendererChangeEvent(this)); 723 } 724 } 725 726 733 public void setSeriesPaint(int series, Paint paint) { 734 setSeriesPaint(series, paint, true); 735 } 736 737 745 public void setSeriesPaint(int series, Paint paint, boolean notify) { 746 this.paintList.setPaint(series, paint); 747 if (notify) { 748 notifyListeners(new RendererChangeEvent(this)); 749 } 750 } 751 752 757 public Paint getBasePaint() { 758 return this.basePaint; 759 } 760 761 767 public void setBasePaint(Paint paint) { 768 setBasePaint(paint, true); 770 } 771 772 779 public void setBasePaint(Paint paint, boolean notify) { 780 this.basePaint = paint; 781 if (notify) { 782 notifyListeners(new RendererChangeEvent(this)); 783 } 784 } 785 786 788 799 public Paint getItemFillPaint(int row, int column) { 800 return getSeriesFillPaint(row); 801 } 802 803 810 public Paint getSeriesFillPaint(int series) { 811 812 if (this.fillPaint != null) { 814 return this.fillPaint; 815 } 816 817 Paint seriesFillPaint = this.fillPaintList.getPaint(series); 819 if (seriesFillPaint == null) { 820 seriesFillPaint = this.baseFillPaint; 821 } 822 return seriesFillPaint; 823 824 } 825 826 833 public void setSeriesFillPaint(int series, Paint paint) { 834 setSeriesFillPaint(series, paint, true); 835 } 836 837 845 public void setSeriesFillPaint(int series, Paint paint, boolean notify) { 846 this.fillPaintList.setPaint(series, paint); 847 if (notify) { 848 notifyListeners(new RendererChangeEvent(this)); 849 } 850 } 851 852 857 public void setFillPaint(Paint paint) { 858 setFillPaint(paint, true); 859 } 860 861 868 public void setFillPaint(Paint paint, boolean notify) { 869 this.fillPaint = paint; 870 if (notify) { 871 notifyListeners(new RendererChangeEvent(this)); 872 } 873 } 874 875 880 public Paint getBaseFillPaint() { 881 return this.baseFillPaint; 882 } 883 884 890 public void setBaseFillPaint(Paint paint) { 891 setBaseFillPaint(paint, true); 893 } 894 895 902 public void setBaseFillPaint(Paint paint, boolean notify) { 903 if (paint == null) { 904 throw new IllegalArgumentException ("Null 'paint' argument."); 905 } 906 this.baseFillPaint = paint; 907 if (notify) { 908 notifyListeners(new RendererChangeEvent(this)); 909 } 910 } 911 912 914 |