001/* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2017, by Object Refinery Limited and Contributors. 006 * 007 * Project Info: http://www.jfree.org/jfreechart/index.html 008 * 009 * This library is free software; you can redistribute it and/or modify it 010 * under the terms of the GNU Lesser General Public License as published by 011 * the Free Software Foundation; either version 2.1 of the License, or 012 * (at your option) any later version. 013 * 014 * This library is distributed in the hope that it will be useful, but 015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 017 * License for more details. 018 * 019 * You should have received a copy of the GNU Lesser General Public 020 * License along with this library; if not, write to the Free Software 021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 022 * USA. 023 * 024 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 025 * Other names may be trademarks of their respective owners.] 026 * 027 * ----------------------- 028 * StandardChartTheme.java 029 * ----------------------- 030 * (C) Copyright 2008-2017, by Object Refinery Limited. 031 * 032 * Original Author: David Gilbert (for Object Refinery Limited); 033 * Contributor(s): -; 034 * 035 * Changes 036 * ------- 037 * 14-Aug-2008 : Version 1 (DG); 038 * 10-Apr-2009 : Added getter/setter for smallFont (DG); 039 * 10-Jul-2009 : Added shadowGenerator field (DG); 040 * 29-Oct-2011 : Fixed Eclipse warnings (DG); 041 * 02-Jul-2013 : Use ParamChecks class (DG); 042 * 043 */ 044 045package org.jfree.chart; 046 047import java.awt.BasicStroke; 048import java.awt.Color; 049import java.awt.Font; 050import java.awt.Paint; 051import java.awt.Stroke; 052import java.io.IOException; 053import java.io.ObjectInputStream; 054import java.io.ObjectOutputStream; 055import java.io.Serializable; 056import java.util.Iterator; 057import java.util.List; 058 059import org.jfree.chart.annotations.XYAnnotation; 060import org.jfree.chart.annotations.XYTextAnnotation; 061import org.jfree.chart.axis.CategoryAxis; 062import org.jfree.chart.axis.PeriodAxis; 063import org.jfree.chart.axis.PeriodAxisLabelInfo; 064import org.jfree.chart.axis.SubCategoryAxis; 065import org.jfree.chart.axis.SymbolAxis; 066import org.jfree.chart.axis.ValueAxis; 067import org.jfree.chart.block.Block; 068import org.jfree.chart.block.BlockContainer; 069import org.jfree.chart.block.LabelBlock; 070import org.jfree.chart.plot.CategoryPlot; 071import org.jfree.chart.plot.CombinedDomainCategoryPlot; 072import org.jfree.chart.plot.CombinedDomainXYPlot; 073import org.jfree.chart.plot.CombinedRangeCategoryPlot; 074import org.jfree.chart.plot.CombinedRangeXYPlot; 075import org.jfree.chart.plot.DefaultDrawingSupplier; 076import org.jfree.chart.plot.DrawingSupplier; 077import org.jfree.chart.plot.FastScatterPlot; 078import org.jfree.chart.plot.MeterPlot; 079import org.jfree.chart.plot.MultiplePiePlot; 080import org.jfree.chart.plot.PieLabelLinkStyle; 081import org.jfree.chart.plot.PiePlot; 082import org.jfree.chart.plot.Plot; 083import org.jfree.chart.plot.PolarPlot; 084import org.jfree.chart.plot.SpiderWebPlot; 085import org.jfree.chart.plot.ThermometerPlot; 086import org.jfree.chart.plot.XYPlot; 087import org.jfree.chart.renderer.AbstractRenderer; 088import org.jfree.chart.renderer.category.BarPainter; 089import org.jfree.chart.renderer.category.BarRenderer; 090import org.jfree.chart.renderer.category.CategoryItemRenderer; 091import org.jfree.chart.renderer.category.GradientBarPainter; 092import org.jfree.chart.renderer.category.MinMaxCategoryRenderer; 093import org.jfree.chart.renderer.category.StatisticalBarRenderer; 094import org.jfree.chart.renderer.xy.GradientXYBarPainter; 095import org.jfree.chart.renderer.xy.XYBarPainter; 096import org.jfree.chart.renderer.xy.XYBarRenderer; 097import org.jfree.chart.renderer.xy.XYItemRenderer; 098import org.jfree.chart.title.CompositeTitle; 099import org.jfree.chart.title.LegendTitle; 100import org.jfree.chart.title.PaintScaleLegend; 101import org.jfree.chart.title.TextTitle; 102import org.jfree.chart.title.Title; 103import org.jfree.chart.ui.RectangleInsets; 104import org.jfree.chart.util.DefaultShadowGenerator; 105import org.jfree.chart.util.PaintUtils; 106import org.jfree.chart.util.Args; 107import org.jfree.chart.util.PublicCloneable; 108import org.jfree.chart.util.SerialUtils; 109import org.jfree.chart.util.ShadowGenerator; 110 111/** 112 * A default implementation of the {@link ChartTheme} interface. This 113 * implementation just collects a whole bunch of chart attributes and mimics 114 * the manual process of applying each attribute to the right sub-object 115 * within the JFreeChart instance. It's not elegant code, but it works. 116 * 117 * @since 1.0.11 118 */ 119public class StandardChartTheme implements ChartTheme, Cloneable, 120 PublicCloneable, Serializable { 121 122 /** The name of this theme. */ 123 private String name; 124 125 /** 126 * The largest font size. Use for the main chart title. 127 */ 128 private Font extraLargeFont; 129 130 /** 131 * A large font. Used for subtitles. 132 */ 133 private Font largeFont; 134 135 /** 136 * The regular font size. Used for axis tick labels, legend items etc. 137 */ 138 private Font regularFont; 139 140 /** 141 * The small font size. 142 */ 143 private Font smallFont; 144 145 /** The paint used to display the main chart title. */ 146 private transient Paint titlePaint; 147 148 /** The paint used to display subtitles. */ 149 private transient Paint subtitlePaint; 150 151 /** The background paint for the chart. */ 152 private transient Paint chartBackgroundPaint; 153 154 /** The legend background paint. */ 155 private transient Paint legendBackgroundPaint; 156 157 /** The legend item paint. */ 158 private transient Paint legendItemPaint; 159 160 /** The drawing supplier. */ 161 private DrawingSupplier drawingSupplier; 162 163 /** The background paint for the plot. */ 164 private transient Paint plotBackgroundPaint; 165 166 /** The plot outline paint. */ 167 private transient Paint plotOutlinePaint; 168 169 /** The label link style for pie charts. */ 170 private PieLabelLinkStyle labelLinkStyle; 171 172 /** The label link paint for pie charts. */ 173 private transient Paint labelLinkPaint; 174 175 /** The domain grid line paint. */ 176 private transient Paint domainGridlinePaint; 177 178 /** The range grid line paint. */ 179 private transient Paint rangeGridlinePaint; 180 181 /** 182 * The baseline paint (used for domain and range zero baselines) 183 * 184 * @since 1.0.13 185 */ 186 private transient Paint baselinePaint; 187 188 /** The crosshair paint. */ 189 private transient Paint crosshairPaint; 190 191 /** The axis offsets. */ 192 private RectangleInsets axisOffset; 193 194 /** The axis label paint. */ 195 private transient Paint axisLabelPaint; 196 197 /** The tick label paint. */ 198 private transient Paint tickLabelPaint; 199 200 /** The item label paint. */ 201 private transient Paint itemLabelPaint; 202 203 /** 204 * A flag that controls whether or not shadows are visible (for example, 205 * in a bar renderer). 206 */ 207 private boolean shadowVisible; 208 209 /** The shadow paint. */ 210 private transient Paint shadowPaint; 211 212 /** The bar painter. */ 213 private BarPainter barPainter; 214 215 /** The XY bar painter. */ 216 private XYBarPainter xyBarPainter; 217 218 /** The thermometer paint. */ 219 private transient Paint thermometerPaint; 220 221 /** The error indicator paint for the {@link StatisticalBarRenderer}. */ 222 private transient Paint errorIndicatorPaint; 223 224 /** The grid band paint for a {@link SymbolAxis}. */ 225 private transient Paint gridBandPaint = SymbolAxis.DEFAULT_GRID_BAND_PAINT; 226 227 /** The grid band alternate paint for a {@link SymbolAxis}. */ 228 private transient Paint gridBandAlternatePaint 229 = SymbolAxis.DEFAULT_GRID_BAND_ALTERNATE_PAINT; 230 231 /** 232 * The shadow generator (can be null). 233 * 234 * @since 1.0.14 235 */ 236 private ShadowGenerator shadowGenerator; 237 238 /** 239 * Creates and returns the default 'JFree' chart theme. 240 * 241 * @return A chart theme. 242 */ 243 public static ChartTheme createJFreeTheme() { 244 return new StandardChartTheme("JFree"); 245 } 246 247 /** 248 * Creates and returns a theme called "Darkness". In this theme, the 249 * charts have a black background. 250 * 251 * @return The "Darkness" theme. 252 */ 253 public static ChartTheme createDarknessTheme() { 254 StandardChartTheme theme = new StandardChartTheme("Darkness"); 255 theme.titlePaint = Color.WHITE; 256 theme.subtitlePaint = Color.WHITE; 257 theme.legendBackgroundPaint = Color.BLACK; 258 theme.legendItemPaint = Color.WHITE; 259 theme.chartBackgroundPaint = Color.BLACK; 260 theme.plotBackgroundPaint = Color.BLACK; 261 theme.plotOutlinePaint = Color.YELLOW; 262 theme.baselinePaint = Color.WHITE; 263 theme.crosshairPaint = Color.RED; 264 theme.labelLinkPaint = Color.LIGHT_GRAY; 265 theme.tickLabelPaint = Color.WHITE; 266 theme.axisLabelPaint = Color.WHITE; 267 theme.shadowPaint = Color.DARK_GRAY; 268 theme.itemLabelPaint = Color.WHITE; 269 theme.drawingSupplier = new DefaultDrawingSupplier( 270 new Paint[] {Color.decode("0xFFFF00"), 271 Color.decode("0x0036CC"), Color.decode("0xFF0000"), 272 Color.decode("0xFFFF7F"), Color.decode("0x6681CC"), 273 Color.decode("0xFF7F7F"), Color.decode("0xFFFFBF"), 274 Color.decode("0x99A6CC"), Color.decode("0xFFBFBF"), 275 Color.decode("0xA9A938"), Color.decode("0x2D4587")}, 276 new Paint[] {Color.decode("0xFFFF00"), 277 Color.decode("0x0036CC")}, 278 new Stroke[] {new BasicStroke(2.0f)}, 279 new Stroke[] {new BasicStroke(0.5f)}, 280 DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE); 281 theme.errorIndicatorPaint = Color.LIGHT_GRAY; 282 theme.gridBandPaint = new Color(255, 255, 255, 20); 283 theme.gridBandAlternatePaint = new Color(255, 255, 255, 40); 284 theme.shadowGenerator = null; 285 return theme; 286 } 287 288 /** 289 * Creates and returns a {@link ChartTheme} that doesn't apply any changes 290 * to the JFreeChart defaults. This produces the "legacy" look for 291 * JFreeChart. 292 * 293 * @return A legacy theme. 294 */ 295 public static ChartTheme createLegacyTheme() { 296 StandardChartTheme theme = new StandardChartTheme("Legacy") { 297 @Override 298 public void apply(JFreeChart chart) { 299 // do nothing at all 300 } 301 }; 302 return theme; 303 } 304 305 /** 306 * Creates a new default instance. 307 * 308 * @param name the name of the theme ({@code null} not permitted). 309 */ 310 public StandardChartTheme(String name) { 311 this(name, false); 312 } 313 314 /** 315 * Creates a new default instance. 316 * 317 * @param name the name of the theme ({@code null} not permitted). 318 * @param shadow a flag that controls whether a shadow generator is 319 * included. 320 * 321 * @since 1.0.14 322 */ 323 public StandardChartTheme(String name, boolean shadow) { 324 Args.nullNotPermitted(name, "name"); 325 this.name = name; 326 this.extraLargeFont = new Font("Tahoma", Font.BOLD, 20); 327 this.largeFont = new Font("Tahoma", Font.BOLD, 14); 328 this.regularFont = new Font("Tahoma", Font.PLAIN, 12); 329 this.smallFont = new Font("Tahoma", Font.PLAIN, 10); 330 this.titlePaint = Color.BLACK; 331 this.subtitlePaint = Color.BLACK; 332 this.legendBackgroundPaint = Color.WHITE; 333 this.legendItemPaint = Color.DARK_GRAY; 334 this.chartBackgroundPaint = Color.WHITE; 335 this.drawingSupplier = new DefaultDrawingSupplier(); 336 this.plotBackgroundPaint = Color.LIGHT_GRAY; 337 this.plotOutlinePaint = Color.BLACK; 338 this.labelLinkPaint = Color.BLACK; 339 this.labelLinkStyle = PieLabelLinkStyle.CUBIC_CURVE; 340 this.axisOffset = new RectangleInsets(4, 4, 4, 4); 341 this.domainGridlinePaint = Color.WHITE; 342 this.rangeGridlinePaint = Color.WHITE; 343 this.baselinePaint = Color.BLACK; 344 this.crosshairPaint = Color.BLUE; 345 this.axisLabelPaint = Color.DARK_GRAY; 346 this.tickLabelPaint = Color.DARK_GRAY; 347 this.barPainter = new GradientBarPainter(); 348 this.xyBarPainter = new GradientXYBarPainter(); 349 this.shadowVisible = false; 350 this.shadowPaint = Color.GRAY; 351 this.itemLabelPaint = Color.BLACK; 352 this.thermometerPaint = Color.WHITE; 353 this.errorIndicatorPaint = Color.BLACK; 354 this.shadowGenerator = shadow ? new DefaultShadowGenerator() : null; 355 } 356 357 /** 358 * Returns the largest font for this theme. 359 * 360 * @return The largest font for this theme. 361 * 362 * @see #setExtraLargeFont(Font) 363 */ 364 public Font getExtraLargeFont() { 365 return this.extraLargeFont; 366 } 367 368 /** 369 * Sets the largest font for this theme. 370 * 371 * @param font the font ({@code null} not permitted). 372 * 373 * @see #getExtraLargeFont() 374 */ 375 public void setExtraLargeFont(Font font) { 376 Args.nullNotPermitted(font, "font"); 377 this.extraLargeFont = font; 378 } 379 380 /** 381 * Returns the large font for this theme. 382 * 383 * @return The large font (never {@code null}). 384 * 385 * @see #setLargeFont(Font) 386 */ 387 public Font getLargeFont() { 388 return this.largeFont; 389 } 390 391 /** 392 * Sets the large font for this theme. 393 * 394 * @param font the font ({@code null} not permitted). 395 * 396 * @see #getLargeFont() 397 */ 398 public void setLargeFont(Font font) { 399 Args.nullNotPermitted(font, "font"); 400 this.largeFont = font; 401 } 402 403 /** 404 * Returns the regular font. 405 * 406 * @return The regular font (never {@code null}). 407 * 408 * @see #setRegularFont(Font) 409 */ 410 public Font getRegularFont() { 411 return this.regularFont; 412 } 413 414 /** 415 * Sets the regular font for this theme. 416 * 417 * @param font the font ({@code null} not permitted). 418 * 419 * @see #getRegularFont() 420 */ 421 public void setRegularFont(Font font) { 422 Args.nullNotPermitted(font, "font"); 423 this.regularFont = font; 424 } 425 426 /** 427 * Returns the small font. 428 * 429 * @return The small font (never {@code null}). 430 * 431 * @see #setSmallFont(Font) 432 * 433 * @since 1.0.13 434 */ 435 public Font getSmallFont() { 436 return this.smallFont; 437 } 438 439 /** 440 * Sets the small font for this theme. 441 * 442 * @param font the font ({@code null} not permitted). 443 * 444 * @see #getSmallFont() 445 * 446 * @since 1.0.13 447 */ 448 public void setSmallFont(Font font) { 449 Args.nullNotPermitted(font, "font"); 450 this.smallFont = font; 451 } 452 453 /** 454 * Returns the title paint. 455 * 456 * @return The title paint (never {@code null}). 457 * 458 * @see #setTitlePaint(Paint) 459 */ 460 public Paint getTitlePaint() { 461 return this.titlePaint; 462 } 463 464 /** 465 * Sets the title paint. 466 * 467 * @param paint the paint ({@code null} not permitted). 468 * 469 * @see #getTitlePaint() 470 */ 471 public void setTitlePaint(Paint paint) { 472 Args.nullNotPermitted(paint, "paint"); 473 this.titlePaint = paint; 474 } 475 476 /** 477 * Returns the subtitle paint. 478 * 479 * @return The subtitle paint (never {@code null}). 480 * 481 * @see #setSubtitlePaint(Paint) 482 */ 483 public Paint getSubtitlePaint() { 484 return this.subtitlePaint; 485 } 486 487 /** 488 * Sets the subtitle paint. 489 * 490 * @param paint the paint ({@code null} not permitted). 491 * 492 * @see #getSubtitlePaint() 493 */ 494 public void setSubtitlePaint(Paint paint) { 495 Args.nullNotPermitted(paint, "paint"); 496 this.subtitlePaint = paint; 497 } 498 499 /** 500 * Returns the chart background paint. 501 * 502 * @return The chart background paint (never {@code null}). 503 * 504 * @see #setChartBackgroundPaint(Paint) 505 */ 506 public Paint getChartBackgroundPaint() { 507 return this.chartBackgroundPaint; 508 } 509 510 /** 511 * Sets the chart background paint. 512 * 513 * @param paint the paint ({@code null} not permitted). 514 * 515 * @see #getChartBackgroundPaint() 516 */ 517 public void setChartBackgroundPaint(Paint paint) { 518 Args.nullNotPermitted(paint, "paint"); 519 this.chartBackgroundPaint = paint; 520 } 521 522 /** 523 * Returns the legend background paint. 524 * 525 * @return The legend background paint (never {@code null}). 526 * 527 * @see #setLegendBackgroundPaint(Paint) 528 */ 529 public Paint getLegendBackgroundPaint() { 530 return this.legendBackgroundPaint; 531 } 532 533 /** 534 * Sets the legend background paint. 535 * 536 * @param paint the paint ({@code null} not permitted). 537 * 538 * @see #getLegendBackgroundPaint() 539 */ 540 public void setLegendBackgroundPaint(Paint paint) { 541 Args.nullNotPermitted(paint, "paint"); 542 this.legendBackgroundPaint = paint; 543 } 544 545 /** 546 * Returns the legend item paint. 547 * 548 * @return The legend item paint (never {@code null}). 549 * 550 * @see #setLegendItemPaint(Paint) 551 */ 552 public Paint getLegendItemPaint() { 553 return this.legendItemPaint; 554 } 555 556 /** 557 * Sets the legend item paint. 558 * 559 * @param paint the paint ({@code null} not permitted). 560 * 561 * @see #getLegendItemPaint() 562 */ 563 public void setLegendItemPaint(Paint paint) { 564 Args.nullNotPermitted(paint, "paint"); 565 this.legendItemPaint = paint; 566 } 567 568 /** 569 * Returns the plot background paint. 570 * 571 * @return The plot background paint (never {@code null}). 572 * 573 * @see #setPlotBackgroundPaint(Paint) 574 */ 575 public Paint getPlotBackgroundPaint() { 576 return this.plotBackgroundPaint; 577 } 578 579 /** 580 * Sets the plot background paint. 581 * 582 * @param paint the paint ({@code null} not permitted). 583 * 584 * @see #getPlotBackgroundPaint() 585 */ 586 public void setPlotBackgroundPaint(Paint paint) { 587 Args.nullNotPermitted(paint, "paint"); 588 this.plotBackgroundPaint = paint; 589 } 590 591 /** 592 * Returns the plot outline paint. 593 * 594 * @return The plot outline paint (never {@code null}). 595 * 596 * @see #setPlotOutlinePaint(Paint) 597 */ 598 public Paint getPlotOutlinePaint() { 599 return this.plotOutlinePaint; 600 } 601 602 /** 603 * Sets the plot outline paint. 604 * 605 * @param paint the paint ({@code null} not permitted). 606 * 607 * @see #getPlotOutlinePaint() 608 */ 609 public void setPlotOutlinePaint(Paint paint) { 610 Args.nullNotPermitted(paint, "paint"); 611 this.plotOutlinePaint = paint; 612 } 613 614 /** 615 * Returns the label link style for pie charts. 616 * 617 * @return The label link style (never {@code null}). 618 * 619 * @see #setLabelLinkStyle(PieLabelLinkStyle) 620 */ 621 public PieLabelLinkStyle getLabelLinkStyle() { 622 return this.labelLinkStyle; 623 } 624 625 /** 626 * Sets the label link style for pie charts. 627 * 628 * @param style the style ({@code null} not permitted). 629 * 630 * @see #getLabelLinkStyle() 631 */ 632 public void setLabelLinkStyle(PieLabelLinkStyle style) { 633 Args.nullNotPermitted(style, "style"); 634 this.labelLinkStyle = style; 635 } 636 637 /** 638 * Returns the label link paint for pie charts. 639 * 640 * @return The label link paint (never {@code null}). 641 * 642 * @see #setLabelLinkPaint(Paint) 643 */ 644 public Paint getLabelLinkPaint() { 645 return this.labelLinkPaint; 646 } 647 648 /** 649 * Sets the label link paint for pie charts. 650 * 651 * @param paint the paint ({@code null} not permitted). 652 * 653 * @see #getLabelLinkPaint() 654 */ 655 public void setLabelLinkPaint(Paint paint) { 656 Args.nullNotPermitted(paint, "paint"); 657 this.labelLinkPaint = paint; 658 } 659 660 /** 661 * Returns the domain grid line paint. 662 * 663 * @return The domain grid line paint (never {@code null}). 664 * 665 * @see #setDomainGridlinePaint(Paint) 666 */ 667 public Paint getDomainGridlinePaint() { 668 return this.domainGridlinePaint; 669 } 670 671 /** 672 * Sets the domain grid line paint. 673 * 674 * @param paint the paint ({@code null} not permitted). 675 * 676 * @see #getDomainGridlinePaint() 677 */ 678 public void setDomainGridlinePaint(Paint paint) { 679 Args.nullNotPermitted(paint, "paint"); 680 this.domainGridlinePaint = paint; 681 } 682 683 /** 684 * Returns the range grid line paint. 685 * 686 * @return The range grid line paint (never {@code null}). 687 * 688 * @see #setRangeGridlinePaint(Paint) 689 */ 690 public Paint getRangeGridlinePaint() { 691 return this.rangeGridlinePaint; 692 } 693 694 /** 695 * Sets the range grid line paint. 696 * 697 * @param paint the paint ({@code null} not permitted). 698 * 699 * @see #getRangeGridlinePaint() 700 */ 701 public void setRangeGridlinePaint(Paint paint) { 702 Args.nullNotPermitted(paint, "paint"); 703 this.rangeGridlinePaint = paint; 704 } 705 706 /** 707 * Returns the baseline paint. 708 * 709 * @return The baseline paint. 710 * 711 * @since 1.0.13 712 */ 713 public Paint getBaselinePaint() { 714 return this.baselinePaint; 715 } 716 717 /** 718 * Sets the baseline paint. 719 * 720 * @param paint the paint ({@code null} not permitted). 721 * 722 * @since 1.0.13 723 */ 724 public void setBaselinePaint(Paint paint) { 725 Args.nullNotPermitted(paint, "paint"); 726 this.baselinePaint = paint; 727 } 728 729 /** 730 * Returns the crosshair paint. 731 * 732 * @return The crosshair paint. 733 */ 734 public Paint getCrosshairPaint() { 735 return this.crosshairPaint; 736 } 737 738 /** 739 * Sets the crosshair paint. 740 * 741 * @param paint the paint ({@code null} not permitted). 742 */ 743 public void setCrosshairPaint(Paint paint) { 744 Args.nullNotPermitted(paint, "paint"); 745 this.crosshairPaint = paint; 746 } 747 748 /** 749 * Returns the axis offsets. 750 * 751 * @return The axis offsets (never {@code null}). 752 * 753 * @see #setAxisOffset(RectangleInsets) 754 */ 755 public RectangleInsets getAxisOffset() { 756 return this.axisOffset; 757 } 758 759 /** 760 * Sets the axis offset. 761 * 762 * @param offset the offset ({@code null} not permitted). 763 * 764 * @see #getAxisOffset() 765 */ 766 public void setAxisOffset(RectangleInsets offset) { 767 Args.nullNotPermitted(offset, "offset"); 768 this.axisOffset = offset; 769 } 770 771 /** 772 * Returns the axis label paint. 773 * 774 * @return The axis label paint (never {@code null}). 775 * 776 * @see #setAxisLabelPaint(Paint) 777 */ 778 public Paint getAxisLabelPaint() { 779 return this.axisLabelPaint; 780 } 781 782 /** 783 * Sets the axis label paint. 784 * 785 * @param paint the paint ({@code null} not permitted). 786 * 787 * @see #getAxisLabelPaint() 788 */ 789 public void setAxisLabelPaint(Paint paint) { 790 Args.nullNotPermitted(paint, "paint"); 791 this.axisLabelPaint = paint; 792 } 793 794 /** 795 * Returns the tick label paint. 796 * 797 * @return The tick label paint (never {@code null}). 798 * 799 * @see #setTickLabelPaint(Paint) 800 */ 801 public Paint getTickLabelPaint() { 802 return this.tickLabelPaint; 803 } 804 805 /** 806 * Sets the tick label paint. 807 * 808 * @param paint the paint ({@code null} not permitted). 809 * 810 * @see #getTickLabelPaint() 811 */ 812 public void setTickLabelPaint(Paint paint) { 813 Args.nullNotPermitted(paint, "paint"); 814 this.tickLabelPaint = paint; 815 } 816 817 /** 818 * Returns the item label paint. 819 * 820 * @return The item label paint (never {@code null}). 821 * 822 * @see #setItemLabelPaint(Paint) 823 */ 824 public Paint getItemLabelPaint() { 825 return this.itemLabelPaint; 826 } 827 828 /** 829 * Sets the item label paint. 830 * 831 * @param paint the paint ({@code null} not permitted). 832 * 833 * @see #getItemLabelPaint() 834 */ 835 public void setItemLabelPaint(Paint paint) { 836 Args.nullNotPermitted(paint, "paint"); 837 this.itemLabelPaint = paint; 838 } 839 840 /** 841 * Returns the shadow visibility flag. 842 * 843 * @return The shadow visibility flag. 844 * 845 * @see #setShadowVisible(boolean) 846 */ 847 public boolean isShadowVisible() { 848 return this.shadowVisible; 849 } 850 851 /** 852 * Sets the shadow visibility flag. 853 * 854 * @param visible the flag. 855 * 856 * @see #isShadowVisible() 857 */ 858 public void setShadowVisible(boolean visible) { 859 this.shadowVisible = visible; 860 } 861 862 /** 863 * Returns the shadow paint. 864 * 865 * @return The shadow paint (never {@code null}). 866 * 867 * @see #setShadowPaint(Paint) 868 */ 869 public Paint getShadowPaint() { 870 return this.shadowPaint; 871 } 872 873 /** 874 * Sets the shadow paint. 875 * 876 * @param paint the paint ({@code null} not permitted). 877 * 878 * @see #getShadowPaint() 879 */ 880 public void setShadowPaint(Paint paint) { 881 Args.nullNotPermitted(paint, "paint"); 882 this.shadowPaint = paint; 883 } 884 885 /** 886 * Returns the bar painter. 887 * 888 * @return The bar painter (never {@code null}). 889 * 890 * @see #setBarPainter(BarPainter) 891 */ 892 public BarPainter getBarPainter() { 893 return this.barPainter; 894 } 895 896 /** 897 * Sets the bar painter. 898 * 899 * @param painter the painter ({@code null} not permitted). 900 * 901 * @see #getBarPainter() 902 */ 903 public void setBarPainter(BarPainter painter) { 904 Args.nullNotPermitted(painter, "painter"); 905 this.barPainter = painter; 906 } 907 908 /** 909 * Returns the XY bar painter. 910 * 911 * @return The XY bar painter (never {@code null}). 912 * 913 * @see #setXYBarPainter(XYBarPainter) 914 */ 915 public XYBarPainter getXYBarPainter() { 916 return this.xyBarPainter; 917 } 918 919 /** 920 * Sets the XY bar painter. 921 * 922 * @param painter the painter ({@code null} not permitted). 923 * 924 * @see #getXYBarPainter() 925 */ 926 public void setXYBarPainter(XYBarPainter painter) { 927 Args.nullNotPermitted(painter, "painter"); 928 this.xyBarPainter = painter; 929 } 930 931 /** 932 * Returns the thermometer paint. 933 * 934 * @return The thermometer paint (never {@code null}). 935 * 936 * @see #setThermometerPaint(Paint) 937 */ 938 public Paint getThermometerPaint() { 939 return this.thermometerPaint; 940 } 941 942 /** 943 * Sets the thermometer paint. 944 * 945 * @param paint the paint ({@code null} not permitted). 946 * 947 * @see #getThermometerPaint() 948 */ 949 public void setThermometerPaint(Paint paint) { 950 Args.nullNotPermitted(paint, "paint"); 951 this.thermometerPaint = paint; 952 } 953 954 /** 955 * Returns the error indicator paint. 956 * 957 * @return The error indicator paint (never {@code null}). 958 * 959 * @see #setErrorIndicatorPaint(Paint) 960 */ 961 public Paint getErrorIndicatorPaint() { 962 return this.errorIndicatorPaint; 963 } 964 965 /** 966 * Sets the error indicator paint. 967 * 968 * @param paint the paint ({@code null} not permitted). 969 * 970 * @see #getErrorIndicatorPaint() 971 */ 972 public void setErrorIndicatorPaint(Paint paint) { 973 Args.nullNotPermitted(paint, "paint"); 974 this.errorIndicatorPaint = paint; 975 } 976 977 /** 978 * Returns the grid band paint. 979 * 980 * @return The grid band paint (never {@code null}). 981 * 982 * @see #setGridBandPaint(Paint) 983 */ 984 public Paint getGridBandPaint() { 985 return this.gridBandPaint; 986 } 987 988 /** 989 * Sets the grid band paint. 990 * 991 * @param paint the paint ({@code null} not permitted). 992 * 993 * @see #getGridBandPaint() 994 */ 995 public void setGridBandPaint(Paint paint) { 996 Args.nullNotPermitted(paint, "paint"); 997 this.gridBandPaint = paint; 998 } 999 1000 /** 1001 * Returns the grid band alternate paint (used for a {@link SymbolAxis}). 1002 * 1003 * @return The paint (never {@code null}). 1004 * 1005 * @see #setGridBandAlternatePaint(Paint) 1006 */ 1007 public Paint getGridBandAlternatePaint() { 1008 return this.gridBandAlternatePaint; 1009 } 1010 1011 /** 1012 * Sets the grid band alternate paint (used for a {@link SymbolAxis}). 1013 * 1014 * @param paint the paint ({@code null} not permitted). 1015 * 1016 * @see #getGridBandAlternatePaint() 1017 */ 1018 public void setGridBandAlternatePaint(Paint paint) { 1019 Args.nullNotPermitted(paint, "paint"); 1020 this.gridBandAlternatePaint = paint; 1021 } 1022 1023 /** 1024 * Returns the name of this theme. 1025 * 1026 * @return The name of this theme. 1027 */ 1028 public String getName() { 1029 return this.name; 1030 } 1031 1032 /** 1033 * Returns a clone of the drawing supplier for this theme. 1034 * 1035 * @return A clone of the drawing supplier. 1036 */ 1037 public DrawingSupplier getDrawingSupplier() { 1038 DrawingSupplier result = null; 1039 if (this.drawingSupplier instanceof PublicCloneable) { 1040 PublicCloneable pc = (PublicCloneable) this.drawingSupplier; 1041 try { 1042 result = (DrawingSupplier) pc.clone(); 1043 } 1044 catch (CloneNotSupportedException e) { 1045 throw new RuntimeException(e); 1046 } 1047 } 1048 return result; 1049 } 1050 1051 /** 1052 * Sets the drawing supplier for this theme. 1053 * 1054 * @param supplier the supplier ({@code null} not permitted). 1055 * 1056 * @see #getDrawingSupplier() 1057 */ 1058 public void setDrawingSupplier(DrawingSupplier supplier) { 1059 Args.nullNotPermitted(supplier, "supplier"); 1060 this.drawingSupplier = supplier; 1061 } 1062 1063 /** 1064 * Applies this theme to the supplied chart. 1065 * 1066 * @param chart the chart ({@code null} not permitted). 1067 */ 1068 @Override 1069 public void apply(JFreeChart chart) { 1070 Args.nullNotPermitted(chart, "chart"); 1071 TextTitle title = chart.getTitle(); 1072 if (title != null) { 1073 title.setFont(this.extraLargeFont); 1074 title.setPaint(this.titlePaint); 1075 } 1076 1077 int subtitleCount = chart.getSubtitleCount(); 1078 for (int i = 0; i < subtitleCount; i++) { 1079 applyToTitle(chart.getSubtitle(i)); 1080 } 1081 1082 chart.setBackgroundPaint(this.chartBackgroundPaint); 1083 1084 // now process the plot if there is one 1085 Plot plot = chart.getPlot(); 1086 if (plot != null) { 1087 applyToPlot(plot); 1088 } 1089 } 1090 1091 /** 1092 * Applies the attributes of this theme to the specified title. 1093 * 1094 * @param title the title. 1095 */ 1096 protected void applyToTitle(Title title) { 1097 if (title instanceof TextTitle) { 1098 TextTitle tt = (TextTitle) title; 1099 tt.setFont(this.largeFont); 1100 tt.setPaint(this.subtitlePaint); 1101 } 1102 else if (title instanceof LegendTitle) { 1103 LegendTitle lt = (LegendTitle) title; 1104 if (lt.getBackgroundPaint() != null) { 1105 lt.setBackgroundPaint(this.legendBackgroundPaint); 1106 } 1107 lt.setItemFont(this.regularFont); 1108 lt.setItemPaint(this.legendItemPaint); 1109 if (lt.getWrapper() != null) { 1110 applyToBlockContainer(lt.getWrapper()); 1111 } 1112 } 1113 else if (title instanceof PaintScaleLegend) { 1114 PaintScaleLegend psl = (PaintScaleLegend) title; 1115 psl.setBackgroundPaint(this.legendBackgroundPaint); 1116 ValueAxis axis = psl.getAxis(); 1117 if (axis != null) { 1118 applyToValueAxis(axis); 1119 } 1120 } 1121 else if (title instanceof CompositeTitle) { 1122 CompositeTitle ct = (CompositeTitle) title; 1123 BlockContainer bc = ct.getContainer(); 1124 List blocks = bc.getBlocks(); 1125 Iterator iterator = blocks.iterator(); 1126 while (iterator.hasNext()) { 1127 Block b = (Block) iterator.next(); 1128 if (b instanceof Title) { 1129 applyToTitle((Title) b); 1130 } 1131 } 1132 } 1133 } 1134 1135 /** 1136 * Applies the attributes of this theme to the specified container. 1137 * 1138 * @param bc a block container ({@code null} not permitted). 1139 */ 1140 protected void applyToBlockContainer(BlockContainer bc) { 1141 Iterator iterator = bc.getBlocks().iterator(); 1142 while (iterator.hasNext()) { 1143 Block b = (Block) iterator.next(); 1144 applyToBlock(b); 1145 } 1146 } 1147 1148 /** 1149 * Applies the attributes of this theme to the specified block. 1150 * 1151 * @param b the block. 1152 */ 1153 protected void applyToBlock(Block b) { 1154 if (b instanceof Title) { 1155 applyToTitle((Title) b); 1156 } 1157 else if (b instanceof LabelBlock) { 1158 LabelBlock lb = (LabelBlock) b; 1159 lb.setFont(this.regularFont); 1160 lb.setPaint(this.legendItemPaint); 1161 } 1162 } 1163 1164 /** 1165 * Applies the attributes of this theme to a plot. 1166 * 1167 * @param plot the plot ({@code null}). 1168 */ 1169 protected void applyToPlot(Plot plot) { 1170 Args.nullNotPermitted(plot, "plot"); 1171 if (plot.getDrawingSupplier() != null) { 1172 plot.setDrawingSupplier(getDrawingSupplier()); 1173 } 1174 if (plot.getBackgroundPaint() != null) { 1175 plot.setBackgroundPaint(this.plotBackgroundPaint); 1176 } 1177 plot.setOutlinePaint(this.plotOutlinePaint); 1178 1179 // now handle specific plot types (and yes, I know this is some 1180 // really ugly code that has to be manually updated any time a new 1181 // plot type is added - I should have written something much cooler, 1182 // but I didn't and neither did anyone else). 1183 if (plot instanceof PiePlot) { 1184 applyToPiePlot((PiePlot) plot); 1185 } 1186 else if (plot instanceof MultiplePiePlot) { 1187 applyToMultiplePiePlot((MultiplePiePlot) plot); 1188 } 1189 else if (plot instanceof CategoryPlot) { 1190 applyToCategoryPlot((CategoryPlot) plot); 1191 } 1192 else if (plot instanceof XYPlot) { 1193 applyToXYPlot((XYPlot) plot); 1194 } 1195 else if (plot instanceof FastScatterPlot) { 1196 applyToFastScatterPlot((FastScatterPlot) plot); 1197 } 1198 else if (plot instanceof MeterPlot) { 1199 applyToMeterPlot((MeterPlot) plot); 1200 } 1201 else if (plot instanceof ThermometerPlot) { 1202 applyToThermometerPlot((ThermometerPlot) plot); 1203 } 1204 else if (plot instanceof SpiderWebPlot) { 1205 applyToSpiderWebPlot((SpiderWebPlot) plot); 1206 } 1207 else if (plot instanceof PolarPlot) { 1208 applyToPolarPlot((PolarPlot) plot); 1209 } 1210 } 1211 1212 /** 1213 * Applies the attributes of this theme to a {@link PiePlot} instance. 1214 * This method also clears any set values for the section paint, outline 1215 * etc, so that the theme's {@link DrawingSupplier} will be used. 1216 * 1217 * @param plot the plot ({@code null} not permitted). 1218 */ 1219 protected void applyToPiePlot(PiePlot plot) { 1220 plot.setLabelLinkPaint(this.labelLinkPaint); 1221 plot.setLabelLinkStyle(this.labelLinkStyle); 1222 plot.setLabelFont(this.regularFont); 1223 plot.setShadowGenerator(this.shadowGenerator); 1224 1225 // clear the section attributes so that the theme's DrawingSupplier 1226 // will be used 1227 if (plot.getAutoPopulateSectionPaint()) { 1228 plot.clearSectionPaints(false); 1229 } 1230 if (plot.getAutoPopulateSectionOutlinePaint()) { 1231 plot.clearSectionOutlinePaints(false); 1232 } 1233 if (plot.getAutoPopulateSectionOutlineStroke()) { 1234 plot.clearSectionOutlineStrokes(false); 1235 } 1236 } 1237 1238 /** 1239 * Applies the attributes of this theme to a {@link MultiplePiePlot}. 1240 * 1241 * @param plot the plot ({@code null} not permitted). 1242 */ 1243 protected void applyToMultiplePiePlot(MultiplePiePlot plot) { 1244 apply(plot.getPieChart()); 1245 } 1246 1247 /** 1248 * Applies the attributes of this theme to a {@link CategoryPlot}. 1249 * 1250 * @param plot the plot ({@code null} not permitted). 1251 */ 1252 protected void applyToCategoryPlot(CategoryPlot plot) { 1253 plot.setAxisOffset(this.axisOffset); 1254 plot.setDomainGridlinePaint(this.domainGridlinePaint); 1255 plot.setRangeGridlinePaint(this.rangeGridlinePaint); 1256 plot.setRangeZeroBaselinePaint(this.baselinePaint); 1257 plot.setShadowGenerator(this.shadowGenerator); 1258 1259 // process all domain axes 1260 int domainAxisCount = plot.getDomainAxisCount(); 1261 for (int i = 0; i < domainAxisCount; i++) { 1262 CategoryAxis axis = plot.getDomainAxis(i); 1263 if (axis != null) { 1264 applyToCategoryAxis(axis); 1265 } 1266 } 1267 1268 // process all range axes 1269 int rangeAxisCount = plot.getRangeAxisCount(); 1270 for (int i = 0; i < rangeAxisCount; i++) { 1271 ValueAxis axis = plot.getRangeAxis(i); 1272 if (axis != null) { 1273 applyToValueAxis(axis); 1274 } 1275 } 1276 1277 // process all renderers 1278 int rendererCount = plot.getRendererCount(); 1279 for (int i = 0; i < rendererCount; i++) { 1280 CategoryItemRenderer r = plot.getRenderer(i); 1281 if (r != null) { 1282 applyToCategoryItemRenderer(r); 1283 } 1284 } 1285 1286 if (plot instanceof CombinedDomainCategoryPlot) { 1287 CombinedDomainCategoryPlot cp = (CombinedDomainCategoryPlot) plot; 1288 Iterator iterator = cp.getSubplots().iterator(); 1289 while (iterator.hasNext()) { 1290 CategoryPlot subplot = (CategoryPlot) iterator.next(); 1291 if (subplot != null) { 1292 applyToPlot(subplot); 1293 } 1294 } 1295 } 1296 if (plot instanceof CombinedRangeCategoryPlot) { 1297 CombinedRangeCategoryPlot cp = (CombinedRangeCategoryPlot) plot; 1298 Iterator iterator = cp.getSubplots().iterator(); 1299 while (iterator.hasNext()) { 1300 CategoryPlot subplot = (CategoryPlot) iterator.next(); 1301 if (subplot != null) { 1302 applyToPlot(subplot); 1303 } 1304 } 1305 } 1306 } 1307 1308 /** 1309 * Applies the attributes of this theme to a {@link XYPlot}. 1310 * 1311 * @param plot the plot ({@code null} not permitted). 1312 */ 1313 protected void applyToXYPlot(XYPlot plot) { 1314 plot.setAxisOffset(this.axisOffset); 1315 plot.setDomainZeroBaselinePaint(this.baselinePaint); 1316 plot.setRangeZeroBaselinePaint(this.baselinePaint); 1317 plot.setDomainGridlinePaint(this.domainGridlinePaint); 1318 plot.setRangeGridlinePaint(this.rangeGridlinePaint); 1319 plot.setDomainCrosshairPaint(this.crosshairPaint); 1320 plot.setRangeCrosshairPaint(this.crosshairPaint); 1321 plot.setShadowGenerator(this.shadowGenerator); 1322 1323 // process all domain axes 1324 int domainAxisCount = plot.getDomainAxisCount(); 1325 for (int i = 0; i < domainAxisCount; i++) { 1326 ValueAxis axis = plot.getDomainAxis(i); 1327 if (axis != null) { 1328 applyToValueAxis(axis); 1329 } 1330 } 1331 1332 // process all range axes 1333 int rangeAxisCount = plot.getRangeAxisCount(); 1334 for (int i = 0; i < rangeAxisCount; i++) { 1335 ValueAxis axis = plot.getRangeAxis(i); 1336 if (axis != null) { 1337 applyToValueAxis(axis); 1338 } 1339 } 1340 1341 // process all renderers 1342 int rendererCount = plot.getRendererCount(); 1343 for (int i = 0; i < rendererCount; i++) { 1344 XYItemRenderer r = plot.getRenderer(i); 1345 if (r != null) { 1346 applyToXYItemRenderer(r); 1347 } 1348 } 1349 1350 // process all annotations 1351 Iterator iter = plot.getAnnotations().iterator(); 1352 while (iter.hasNext()) { 1353 XYAnnotation a = (XYAnnotation) iter.next(); 1354 applyToXYAnnotation(a); 1355 } 1356 1357 if (plot instanceof CombinedDomainXYPlot) { 1358 CombinedDomainXYPlot cp = (CombinedDomainXYPlot) plot; 1359 Iterator iterator = cp.getSubplots().iterator(); 1360 while (iterator.hasNext()) { 1361 XYPlot subplot = (XYPlot) iterator.next(); 1362 if (subplot != null) { 1363 applyToPlot(subplot); 1364 } 1365 } 1366 } 1367 if (plot instanceof CombinedRangeXYPlot) { 1368 CombinedRangeXYPlot cp = (CombinedRangeXYPlot) plot; 1369 Iterator iterator = cp.getSubplots().iterator(); 1370 while (iterator.hasNext()) { 1371 XYPlot subplot = (XYPlot) iterator.next(); 1372 if (subplot != null) { 1373 applyToPlot(subplot); 1374 } 1375 } 1376 } 1377 } 1378 1379 /** 1380 * Applies the attributes of this theme to a {@link FastScatterPlot}. 1381 * 1382 * @param plot the plot ({@code null} not permitted). 1383 */ 1384 protected void applyToFastScatterPlot(FastScatterPlot plot) { 1385 plot.setDomainGridlinePaint(this.domainGridlinePaint); 1386 plot.setRangeGridlinePaint(this.rangeGridlinePaint); 1387 ValueAxis xAxis = plot.getDomainAxis(); 1388 if (xAxis != null) { 1389 applyToValueAxis(xAxis); 1390 } 1391 ValueAxis yAxis = plot.getRangeAxis(); 1392 if (yAxis != null) { 1393 applyToValueAxis(yAxis); 1394 } 1395 1396 } 1397 1398 /** 1399 * Applies the attributes of this theme to a {@link PolarPlot}. This 1400 * method is called from the {@link #applyToPlot(Plot)} method. 1401 * 1402 * @param plot the plot ({@code null} not permitted). 1403 */ 1404 protected void applyToPolarPlot(PolarPlot plot) { 1405 plot.setAngleLabelFont(this.regularFont); 1406 plot.setAngleLabelPaint(this.tickLabelPaint); 1407 plot.setAngleGridlinePaint(this.domainGridlinePaint); 1408 plot.setRadiusGridlinePaint(this.rangeGridlinePaint); 1409 ValueAxis axis = plot.getAxis(); 1410 if (axis != null) { 1411 applyToValueAxis(axis); 1412 } 1413 } 1414 1415 /** 1416 * Applies the attributes of this theme to a {@link SpiderWebPlot}. 1417 * 1418 * @param plot the plot ({@code null} not permitted). 1419 */ 1420 protected void applyToSpiderWebPlot(SpiderWebPlot plot) { 1421 plot.setLabelFont(this.regularFont); 1422 plot.setLabelPaint(this.axisLabelPaint); 1423 plot.setAxisLinePaint(this.axisLabelPaint); 1424 } 1425 1426 /** 1427 * Applies the attributes of this theme to a {@link MeterPlot}. 1428 * 1429 * @param plot the plot ({@code null} not permitted). 1430 */ 1431 protected void applyToMeterPlot(MeterPlot plot) { 1432 plot.setDialBackgroundPaint(this.plotBackgroundPaint); 1433 plot.setValueFont(this.largeFont); 1434 plot.setValuePaint(this.axisLabelPaint); 1435 plot.setDialOutlinePaint(this.plotOutlinePaint); 1436 plot.setNeedlePaint(this.thermometerPaint); 1437 plot.setTickLabelFont(this.regularFont); 1438 plot.setTickLabelPaint(this.tickLabelPaint); 1439 } 1440 1441 /** 1442 * Applies the attributes for this theme to a {@link ThermometerPlot}. 1443 * This method is called from the {@link #applyToPlot(Plot)} method. 1444 * 1445 * @param plot the plot. 1446 */ 1447 protected void applyToThermometerPlot(ThermometerPlot plot) { 1448 plot.setValueFont(this.largeFont); 1449 plot.setThermometerPaint(this.thermometerPaint); 1450 ValueAxis axis = plot.getRangeAxis(); 1451 if (axis != null) { 1452 applyToValueAxis(axis); 1453 } 1454 } 1455 1456 /** 1457 * Applies the attributes for this theme to a {@link CategoryAxis}. 1458 * 1459 * @param axis the axis ({@code null} not permitted). 1460 */ 1461 protected void applyToCategoryAxis(CategoryAxis axis) { 1462 axis.setLabelFont(this.largeFont); 1463 axis.setLabelPaint(this.axisLabelPaint); 1464 axis.setTickLabelFont(this.regularFont); 1465 axis.setTickLabelPaint(this.tickLabelPaint); 1466 if (axis instanceof SubCategoryAxis) { 1467 SubCategoryAxis sca = (SubCategoryAxis) axis; 1468 sca.setSubLabelFont(this.regularFont); 1469 sca.setSubLabelPaint(this.tickLabelPaint); 1470 } 1471 } 1472 1473 /** 1474 * Applies the attributes for this theme to a {@link ValueAxis}. 1475 * 1476 * @param axis the axis ({@code null} not permitted). 1477 */ 1478 protected void applyToValueAxis(ValueAxis axis) { 1479 axis.setLabelFont(this.largeFont); 1480 axis.setLabelPaint(this.axisLabelPaint); 1481 axis.setTickLabelFont(this.regularFont); 1482 axis.setTickLabelPaint(this.tickLabelPaint); 1483 if (axis instanceof SymbolAxis) { 1484 applyToSymbolAxis((SymbolAxis) axis); 1485 } 1486 if (axis instanceof PeriodAxis) { 1487 applyToPeriodAxis((PeriodAxis) axis); 1488 } 1489 } 1490 1491 /** 1492 * Applies the attributes for this theme to a {@link SymbolAxis}. 1493 * 1494 * @param axis the axis ({@code null} not permitted). 1495 */ 1496 protected void applyToSymbolAxis(SymbolAxis axis) { 1497 axis.setGridBandPaint(this.gridBandPaint); 1498 axis.setGridBandAlternatePaint(this.gridBandAlternatePaint); 1499 } 1500 1501 /** 1502 * Applies the attributes for this theme to a {@link PeriodAxis}. 1503 * 1504 * @param axis the axis ({@code null} not permitted). 1505 */ 1506 protected void applyToPeriodAxis(PeriodAxis axis) { 1507 PeriodAxisLabelInfo[] info = axis.getLabelInfo(); 1508 for (int i = 0; i < info.length; i++) { 1509 PeriodAxisLabelInfo e = info[i]; 1510 PeriodAxisLabelInfo n = new PeriodAxisLabelInfo(e.getPeriodClass(), 1511 e.getDateFormat(), e.getPadding(), this.regularFont, 1512 this.tickLabelPaint, e.getDrawDividers(), 1513 e.getDividerStroke(), e.getDividerPaint()); 1514 info[i] = n; 1515 } 1516 axis.setLabelInfo(info); 1517 } 1518 1519 /** 1520 * Applies the attributes for this theme to an {@link AbstractRenderer}. 1521 * 1522 * @param renderer the renderer ({@code null} not permitted). 1523 */ 1524 protected void applyToAbstractRenderer(AbstractRenderer renderer) { 1525 if (renderer.getAutoPopulateSeriesPaint()) { 1526 renderer.clearSeriesPaints(false); 1527 } 1528 if (renderer.getAutoPopulateSeriesStroke()) { 1529 renderer.clearSeriesStrokes(false); 1530 } 1531 } 1532 1533 /** 1534 * Applies the settings of this theme to the specified renderer. 1535 * 1536 * @param renderer the renderer ({@code null} not permitted). 1537 */ 1538 protected void applyToCategoryItemRenderer(CategoryItemRenderer renderer) { 1539 Args.nullNotPermitted(renderer, "renderer"); 1540 1541 if (renderer instanceof AbstractRenderer) { 1542 applyToAbstractRenderer((AbstractRenderer) renderer); 1543 } 1544 1545 renderer.setDefaultItemLabelFont(this.regularFont); 1546 renderer.setDefaultItemLabelPaint(this.itemLabelPaint); 1547 1548 // now we handle some special cases - yes, UGLY code alert! 1549 1550 // BarRenderer 1551 if (renderer instanceof BarRenderer) { 1552 BarRenderer br = (BarRenderer) renderer; 1553 br.setBarPainter(this.barPainter); 1554 br.setShadowVisible(this.shadowVisible); 1555 br.setShadowPaint(this.shadowPaint); 1556 } 1557 1558 1559 // StatisticalBarRenderer 1560 if (renderer instanceof StatisticalBarRenderer) { 1561 StatisticalBarRenderer sbr = (StatisticalBarRenderer) renderer; 1562 sbr.setErrorIndicatorPaint(this.errorIndicatorPaint); 1563 } 1564 1565 // MinMaxCategoryRenderer 1566 if (renderer instanceof MinMaxCategoryRenderer) { 1567 MinMaxCategoryRenderer mmcr = (MinMaxCategoryRenderer) renderer; 1568 mmcr.setGroupPaint(this.errorIndicatorPaint); 1569 } 1570 } 1571 1572 /** 1573 * Applies the settings of this theme to the specified renderer. 1574 * 1575 * @param renderer the renderer ({@code null} not permitted). 1576 */ 1577 protected void applyToXYItemRenderer(XYItemRenderer renderer) { 1578 Args.nullNotPermitted(renderer, "renderer"); 1579 if (renderer instanceof AbstractRenderer) { 1580 applyToAbstractRenderer((AbstractRenderer) renderer); 1581 } 1582 renderer.setDefaultItemLabelFont(this.regularFont); 1583 renderer.setDefaultItemLabelPaint(this.itemLabelPaint); 1584 if (renderer instanceof XYBarRenderer) { 1585 XYBarRenderer br = (XYBarRenderer) renderer; 1586 br.setBarPainter(this.xyBarPainter); 1587 br.setShadowVisible(this.shadowVisible); 1588 } 1589 } 1590 1591 /** 1592 * Applies the settings of this theme to the specified annotation. 1593 * 1594 * @param annotation the annotation. 1595 */ 1596 protected void applyToXYAnnotation(XYAnnotation annotation) { 1597 Args.nullNotPermitted(annotation, "annotation"); 1598 if (annotation instanceof XYTextAnnotation) { 1599 XYTextAnnotation xyta = (XYTextAnnotation) annotation; 1600 xyta.setFont(this.smallFont); 1601 xyta.setPaint(this.itemLabelPaint); 1602 } 1603 } 1604 1605 /** 1606 * Tests this theme for equality with an arbitrary object. 1607 * 1608 * @param obj the object ({@code null} permitted). 1609 * 1610 * @return A boolean. 1611 */ 1612 @Override 1613 public boolean equals(Object obj) { 1614 if (obj == this) { 1615 return true; 1616 } 1617 if (!(obj instanceof StandardChartTheme)) { 1618 return false; 1619 } 1620 StandardChartTheme that = (StandardChartTheme) obj; 1621 if (!this.name.equals(that.name)) { 1622 return false; 1623 } 1624 if (!this.extraLargeFont.equals(that.extraLargeFont)) { 1625 return false; 1626 } 1627 if (!this.largeFont.equals(that.largeFont)) { 1628 return false; 1629 } 1630 if (!this.regularFont.equals(that.regularFont)) { 1631 return false; 1632 } 1633 if (!this.smallFont.equals(that.smallFont)) { 1634 return false; 1635 } 1636 if (!PaintUtils.equal(this.titlePaint, that.titlePaint)) { 1637 return false; 1638 } 1639 if (!PaintUtils.equal(this.subtitlePaint, that.subtitlePaint)) { 1640 return false; 1641 } 1642 if (!PaintUtils.equal(this.chartBackgroundPaint, 1643 that.chartBackgroundPaint)) { 1644 return false; 1645 } 1646 if (!PaintUtils.equal(this.legendBackgroundPaint, 1647 that.legendBackgroundPaint)) { 1648 return false; 1649 } 1650 if (!PaintUtils.equal(this.legendItemPaint, that.legendItemPaint)) { 1651 return false; 1652 } 1653 if (!this.drawingSupplier.equals(that.drawingSupplier)) { 1654 return false; 1655 } 1656 if (!PaintUtils.equal(this.plotBackgroundPaint, 1657 that.plotBackgroundPaint)) { 1658 return false; 1659 } 1660 if (!PaintUtils.equal(this.plotOutlinePaint, 1661 that.plotOutlinePaint)) { 1662 return false; 1663 } 1664 if (!this.labelLinkStyle.equals(that.labelLinkStyle)) { 1665 return false; 1666 } 1667 if (!PaintUtils.equal(this.labelLinkPaint, that.labelLinkPaint)) { 1668 return false; 1669 } 1670 if (!PaintUtils.equal(this.domainGridlinePaint, 1671 that.domainGridlinePaint)) { 1672 return false; 1673 } 1674 if (!PaintUtils.equal(this.rangeGridlinePaint, 1675 that.rangeGridlinePaint)) { 1676 return false; 1677 } 1678 if (!PaintUtils.equal(this.crosshairPaint, that.crosshairPaint)) { 1679 return false; 1680 } 1681 if (!this.axisOffset.equals(that.axisOffset)) { 1682 return false; 1683 } 1684 if (!PaintUtils.equal(this.axisLabelPaint, that.axisLabelPaint)) { 1685 return false; 1686 } 1687 if (!PaintUtils.equal(this.tickLabelPaint, that.tickLabelPaint)) { 1688 return false; 1689 } 1690 if (!PaintUtils.equal(this.itemLabelPaint, that.itemLabelPaint)) { 1691 return false; 1692 } 1693 if (this.shadowVisible != that.shadowVisible) { 1694 return false; 1695 } 1696 if (!PaintUtils.equal(this.shadowPaint, that.shadowPaint)) { 1697 return false; 1698 } 1699 if (!this.barPainter.equals(that.barPainter)) { 1700 return false; 1701 } 1702 if (!this.xyBarPainter.equals(that.xyBarPainter)) { 1703 return false; 1704 } 1705 if (!PaintUtils.equal(this.thermometerPaint, 1706 that.thermometerPaint)) { 1707 return false; 1708 } 1709 if (!PaintUtils.equal(this.errorIndicatorPaint, 1710 that.errorIndicatorPaint)) { 1711 return false; 1712 } 1713 if (!PaintUtils.equal(this.gridBandPaint, that.gridBandPaint)) { 1714 return false; 1715 } 1716 if (!PaintUtils.equal(this.gridBandAlternatePaint, 1717 that.gridBandAlternatePaint)) { 1718 return false; 1719 } 1720 return true; 1721 } 1722 1723 /** 1724 * Returns a clone of this theme. 1725 * 1726 * @return A clone. 1727 * 1728 * @throws CloneNotSupportedException if the theme cannot be cloned. 1729 */ 1730 @Override 1731 public Object clone() throws CloneNotSupportedException { 1732 return super.clone(); 1733 } 1734 1735 /** 1736 * Provides serialization support. 1737 * 1738 * @param stream the output stream ({@code null} not permitted). 1739 * 1740 * @throws IOException if there is an I/O error. 1741 */ 1742 private void writeObject(ObjectOutputStream stream) throws IOException { 1743 stream.defaultWriteObject(); 1744 SerialUtils.writePaint(this.titlePaint, stream); 1745 SerialUtils.writePaint(this.subtitlePaint, stream); 1746 SerialUtils.writePaint(this.chartBackgroundPaint, stream); 1747 SerialUtils.writePaint(this.legendBackgroundPaint, stream); 1748 SerialUtils.writePaint(this.legendItemPaint, stream); 1749 SerialUtils.writePaint(this.plotBackgroundPaint, stream); 1750 SerialUtils.writePaint(this.plotOutlinePaint, stream); 1751 SerialUtils.writePaint(this.labelLinkPaint, stream); 1752 SerialUtils.writePaint(this.baselinePaint, stream); 1753 SerialUtils.writePaint(this.domainGridlinePaint, stream); 1754 SerialUtils.writePaint(this.rangeGridlinePaint, stream); 1755 SerialUtils.writePaint(this.crosshairPaint, stream); 1756 SerialUtils.writePaint(this.axisLabelPaint, stream); 1757 SerialUtils.writePaint(this.tickLabelPaint, stream); 1758 SerialUtils.writePaint(this.itemLabelPaint, stream); 1759 SerialUtils.writePaint(this.shadowPaint, stream); 1760 SerialUtils.writePaint(this.thermometerPaint, stream); 1761 SerialUtils.writePaint(this.errorIndicatorPaint, stream); 1762 SerialUtils.writePaint(this.gridBandPaint, stream); 1763 SerialUtils.writePaint(this.gridBandAlternatePaint, stream); 1764 } 1765 1766 /** 1767 * Provides serialization support. 1768 * 1769 * @param stream the input stream ({@code null} not permitted). 1770 * 1771 * @throws IOException if there is an I/O error. 1772 * @throws ClassNotFoundException if there is a classpath problem. 1773 */ 1774 private void readObject(ObjectInputStream stream) 1775 throws IOException, ClassNotFoundException { 1776 stream.defaultReadObject(); 1777 this.titlePaint = SerialUtils.readPaint(stream); 1778 this.subtitlePaint = SerialUtils.readPaint(stream); 1779 this.chartBackgroundPaint = SerialUtils.readPaint(stream); 1780 this.legendBackgroundPaint = SerialUtils.readPaint(stream); 1781 this.legendItemPaint = SerialUtils.readPaint(stream); 1782 this.plotBackgroundPaint = SerialUtils.readPaint(stream); 1783 this.plotOutlinePaint = SerialUtils.readPaint(stream); 1784 this.labelLinkPaint = SerialUtils.readPaint(stream); 1785 this.baselinePaint = SerialUtils.readPaint(stream); 1786 this.domainGridlinePaint = SerialUtils.readPaint(stream); 1787 this.rangeGridlinePaint = SerialUtils.readPaint(stream); 1788 this.crosshairPaint = SerialUtils.readPaint(stream); 1789 this.axisLabelPaint = SerialUtils.readPaint(stream); 1790 this.tickLabelPaint = SerialUtils.readPaint(stream); 1791 this.itemLabelPaint = SerialUtils.readPaint(stream); 1792 this.shadowPaint = SerialUtils.readPaint(stream); 1793 this.thermometerPaint = SerialUtils.readPaint(stream); 1794 this.errorIndicatorPaint = SerialUtils.readPaint(stream); 1795 this.gridBandPaint = SerialUtils.readPaint(stream); 1796 this.gridBandAlternatePaint = SerialUtils.readPaint(stream); 1797 } 1798 1799}