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 * BarRenderer.java 029 * ---------------- 030 * (C) Copyright 2002-2017, by Object Refinery Limited. 031 * 032 * Original Author: David Gilbert (for Object Refinery Limited); 033 * Contributor(s): Christian W. Zuckschwerdt; 034 * Peter Kolb (patches 2497611, 2791407); 035 * 036 * Changes 037 * ------- 038 * 14-Mar-2002 : Version 1 (DG); 039 * 23-May-2002 : Added tooltip generator to renderer (DG); 040 * 29-May-2002 : Moved tooltip generator to abstract super-class (DG); 041 * 25-Jun-2002 : Changed constructor to protected and removed redundant 042 * code (DG); 043 * 26-Jun-2002 : Added axis to initialise method, and record upper and lower 044 * clip values (DG); 045 * 24-Sep-2002 : Added getLegendItem() method (DG); 046 * 09-Oct-2002 : Modified constructor to include URL generator (DG); 047 * 05-Nov-2002 : Base dataset is now TableDataset not CategoryDataset (DG); 048 * 10-Jan-2003 : Moved get/setItemMargin() method up from subclasses (DG); 049 * 17-Jan-2003 : Moved plot classes into a separate package (DG); 050 * 25-Mar-2003 : Implemented Serializable (DG); 051 * 01-May-2003 : Modified clipping to allow for dual axes and datasets (DG); 052 * 12-May-2003 : Merged horizontal and vertical bar renderers (DG); 053 * 12-Jun-2003 : Updates for item labels (DG); 054 * 30-Jul-2003 : Modified entity constructor (CZ); 055 * 02-Sep-2003 : Changed initialise method to fix bug 790407 (DG); 056 * 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG); 057 * 07-Oct-2003 : Added renderer state (DG); 058 * 27-Oct-2003 : Merged drawHorizontalItem() and drawVerticalItem() 059 * methods (DG); 060 * 28-Oct-2003 : Added support for gradient paint on bars (DG); 061 * 14-Nov-2003 : Added 'maxBarWidth' attribute (DG); 062 * 10-Feb-2004 : Small changes inside drawItem() method to ease cut-and-paste 063 * overriding (DG); 064 * 19-Mar-2004 : Fixed bug introduced with separation of tool tip and item 065 * label generators. Fixed equals() method (DG); 066 * 11-May-2004 : Fix for null pointer exception (bug id 951127) (DG); 067 * 05-Nov-2004 : Modified drawItem() signature (DG); 068 * 26-Jan-2005 : Provided override for getLegendItem() method (DG); 069 * 20-Apr-2005 : Generate legend labels, tooltips and URLs (DG); 070 * 18-May-2005 : Added configurable base value (DG); 071 * 09-Jun-2005 : Use addItemEntity() method from superclass (DG); 072 * 01-Dec-2005 : Update legend item to use/not use outline (DG); 073 * ------------: JFreeChart 1.0.x --------------------------------------------- 074 * 06-Dec-2005 : Fixed bug 1374222 (JDK 1.4 specific code) (DG); 075 * 11-Jan-2006 : Fixed bug 1401856 (bad rendering for non-zero base) (DG); 076 * 04-Aug-2006 : Fixed bug 1467706 (missing item labels for zero value 077 * bars) (DG); 078 * 04-Dec-2006 : Fixed bug in rendering to non-primary axis (DG); 079 * 13-Dec-2006 : Add support for GradientPaint display in legend items (DG); 080 * 20-Apr-2007 : Updated getLegendItem() for renderer change (DG); 081 * 11-May-2007 : Check for visibility in getLegendItem() (DG); 082 * 17-May-2007 : Set datasetIndex and seriesIndex in getLegendItem() (DG); 083 * 18-May-2007 : Set dataset and seriesKey for LegendItem (DG); 084 * 07-May-2008 : If minimumBarLength is > 0.0, extend the non-base end of the 085 * bar (DG); 086 * 17-Jun-2008 : Apply legend shape, font and paint attributes (DG); 087 * 24-Jun-2008 : Added barPainter mechanism (DG); 088 * 26-Jun-2008 : Added crosshair support (DG); 089 * 13-Aug-2008 : Added shadowPaint attribute (DG); 090 * 14-Jan-2009 : Added support for seriesVisible flags (PK); 091 * 03-Feb-2009 : Added defaultShadowsVisible flag - see patch 2511330 (PK); 092 * 03-Jul-2013 : Use ParamChecks (DG); 093 * 04-Aug-2014 : Add element hinting for JFreeSVG (DG); 094 * 095 */ 096 097package org.jfree.chart.renderer.category; 098 099import java.awt.BasicStroke; 100import java.awt.Color; 101import java.awt.Font; 102import java.awt.Graphics2D; 103import java.awt.Paint; 104import java.awt.Shape; 105import java.awt.Stroke; 106import java.awt.geom.Line2D; 107import java.awt.geom.Point2D; 108import java.awt.geom.Rectangle2D; 109import java.io.IOException; 110import java.io.ObjectInputStream; 111import java.io.ObjectOutputStream; 112import java.io.Serializable; 113 114import org.jfree.chart.LegendItem; 115import org.jfree.chart.axis.CategoryAxis; 116import org.jfree.chart.axis.ValueAxis; 117import org.jfree.chart.entity.EntityCollection; 118import org.jfree.chart.event.RendererChangeEvent; 119import org.jfree.chart.labels.CategoryItemLabelGenerator; 120import org.jfree.chart.labels.ItemLabelAnchor; 121import org.jfree.chart.labels.ItemLabelPosition; 122import org.jfree.chart.plot.CategoryPlot; 123import org.jfree.chart.plot.PlotOrientation; 124import org.jfree.chart.plot.PlotRenderingInfo; 125import org.jfree.chart.text.TextUtils; 126import org.jfree.chart.ui.GradientPaintTransformer; 127import org.jfree.chart.ui.RectangleEdge; 128import org.jfree.chart.ui.StandardGradientPaintTransformer; 129import org.jfree.chart.util.ObjectUtils; 130import org.jfree.chart.util.PaintUtils; 131import org.jfree.chart.util.Args; 132import org.jfree.chart.util.PublicCloneable; 133import org.jfree.chart.util.SerialUtils; 134import org.jfree.data.KeyedValues2DItemKey; 135import org.jfree.data.Range; 136import org.jfree.data.category.CategoryDataset; 137 138/** 139 * A {@link CategoryItemRenderer} that draws individual data items as bars. 140 * The example shown here is generated by the {@code BarChartDemo1.java} 141 * program included in the JFreeChart Demo Collection: 142 * <br><br> 143 * <img src="../../../../../images/BarRendererSample.png" 144 * alt="BarRendererSample.png"> 145 */ 146public class BarRenderer extends AbstractCategoryItemRenderer 147 implements Cloneable, PublicCloneable, Serializable { 148 149 /** For serialization. */ 150 private static final long serialVersionUID = 6000649414965887481L; 151 152 /** The default item margin percentage. */ 153 public static final double DEFAULT_ITEM_MARGIN = 0.20; 154 155 /** 156 * Constant that controls the minimum width before a bar has an outline 157 * drawn. 158 */ 159 public static final double BAR_OUTLINE_WIDTH_THRESHOLD = 3.0; 160 161 /** 162 * The default bar painter assigned to each new instance of this renderer. 163 * 164 * @since 1.0.11 165 */ 166 private static BarPainter defaultBarPainter = new GradientBarPainter(); 167 168 /** 169 * Returns the default bar painter. 170 * 171 * @return The default bar painter. 172 * 173 * @since 1.0.11 174 */ 175 public static BarPainter getDefaultBarPainter() { 176 return BarRenderer.defaultBarPainter; 177 } 178 179 /** 180 * Sets the default bar painter. 181 * 182 * @param painter the painter ({@code null} not permitted). 183 * 184 * @since 1.0.11 185 */ 186 public static void setDefaultBarPainter(BarPainter painter) { 187 Args.nullNotPermitted(painter, "painter"); 188 BarRenderer.defaultBarPainter = painter; 189 } 190 191 /** 192 * The default value for the initialisation of the shadowsVisible flag. 193 */ 194 private static boolean defaultShadowsVisible = true; 195 196 /** 197 * Returns the default value for the {@code shadowsVisible} flag. 198 * 199 * @return A boolean. 200 * 201 * @see #setDefaultShadowsVisible(boolean) 202 * 203 * @since 1.0.13 204 */ 205 public static boolean getDefaultShadowsVisible() { 206 return BarRenderer.defaultShadowsVisible; 207 } 208 209 /** 210 * Sets the default value for the shadows visible flag. 211 * 212 * @param visible the new value for the default. 213 * 214 * @see #getDefaultShadowsVisible() 215 * 216 * @since 1.0.13 217 */ 218 public static void setDefaultShadowsVisible(boolean visible) { 219 BarRenderer.defaultShadowsVisible = visible; 220 } 221 222 /** The margin between items (bars) within a category. */ 223 private double itemMargin; 224 225 /** A flag that controls whether or not bar outlines are drawn. */ 226 private boolean drawBarOutline; 227 228 /** The maximum bar width as a percentage of the available space. */ 229 private double maximumBarWidth; 230 231 /** The minimum bar length (in Java2D units). */ 232 private double minimumBarLength; 233 234 /** 235 * An optional class used to transform gradient paint objects to fit each 236 * bar. 237 */ 238 private GradientPaintTransformer gradientPaintTransformer; 239 240 /** 241 * The fallback position if a positive item label doesn't fit inside the 242 * bar. 243 */ 244 private ItemLabelPosition positiveItemLabelPositionFallback; 245 246 /** 247 * The fallback position if a negative item label doesn't fit inside the 248 * bar. 249 */ 250 private ItemLabelPosition negativeItemLabelPositionFallback; 251 252 /** The upper clip (axis) value for the axis. */ 253 private double upperClip; 254 // TODO: this needs to move into the renderer state 255 256 /** The lower clip (axis) value for the axis. */ 257 private double lowerClip; 258 // TODO: this needs to move into the renderer state 259 260 /** The base value for the bars (defaults to 0.0). */ 261 private double base; 262 263 /** 264 * A flag that controls whether the base value is included in the range 265 * returned by the findRangeBounds() method. 266 */ 267 private boolean includeBaseInRange; 268 269 /** 270 * The bar painter (never {@code null}). 271 * 272 * @since 1.0.11 273 */ 274 private BarPainter barPainter; 275 276 /** 277 * The flag that controls whether or not shadows are drawn for the bars. 278 * 279 * @since 1.0.11 280 */ 281 private boolean shadowsVisible; 282 283 /** 284 * The shadow paint. 285 * 286 * @since 1.0.11 287 */ 288 private transient Paint shadowPaint; 289 290 /** 291 * The x-offset for the shadow effect. 292 * 293 * @since 1.0.11 294 */ 295 private double shadowXOffset; 296 297 /** 298 * The y-offset for the shadow effect. 299 * 300 * @since 1.0.11 301 */ 302 private double shadowYOffset; 303 304 /** 305 * Creates a new bar renderer with default settings. 306 */ 307 public BarRenderer() { 308 super(); 309 this.base = 0.0; 310 this.includeBaseInRange = true; 311 this.itemMargin = DEFAULT_ITEM_MARGIN; 312 this.drawBarOutline = false; 313 this.maximumBarWidth = 1.0; 314 // 100 percent, so it will not apply unless changed 315 this.positiveItemLabelPositionFallback = null; 316 this.negativeItemLabelPositionFallback = null; 317 this.gradientPaintTransformer = new StandardGradientPaintTransformer(); 318 this.minimumBarLength = 0.0; 319 setDefaultLegendShape(new Rectangle2D.Double(-4.0, -4.0, 8.0, 8.0)); 320 this.barPainter = getDefaultBarPainter(); 321 this.shadowsVisible = getDefaultShadowsVisible(); 322 this.shadowPaint = Color.GRAY; 323 this.shadowXOffset = 4.0; 324 this.shadowYOffset = 4.0; 325 } 326 327 /** 328 * Returns the base value for the bars. The default value is 329 * {@code 0.0}. 330 * 331 * @return The base value for the bars. 332 * 333 * @see #setBase(double) 334 */ 335 public double getBase() { 336 return this.base; 337 } 338 339 /** 340 * Sets the base value for the bars and sends a {@link RendererChangeEvent} 341 * to all registered listeners. 342 * 343 * @param base the new base value. 344 * 345 * @see #getBase() 346 */ 347 public void setBase(double base) { 348 this.base = base; 349 fireChangeEvent(); 350 } 351 352 /** 353 * Returns the item margin as a percentage of the available space for all 354 * bars. 355 * 356 * @return The margin percentage (where 0.10 is ten percent). 357 * 358 * @see #setItemMargin(double) 359 */ 360 public double getItemMargin() { 361 return this.itemMargin; 362 } 363 364 /** 365 * Sets the item margin and sends a {@link RendererChangeEvent} to all 366 * registered listeners. The value is expressed as a percentage of the 367 * available width for plotting all the bars, with the resulting amount to 368 * be distributed between all the bars evenly. 369 * 370 * @param percent the margin (where 0.10 is ten percent). 371 * 372 * @see #getItemMargin() 373 */ 374 public void setItemMargin(double percent) { 375 this.itemMargin = percent; 376 fireChangeEvent(); 377 } 378 379 /** 380 * Returns a flag that controls whether or not bar outlines are drawn. 381 * 382 * @return A boolean. 383 * 384 * @see #setDrawBarOutline(boolean) 385 */ 386 public boolean isDrawBarOutline() { 387 return this.drawBarOutline; 388 } 389 390 /** 391 * Sets the flag that controls whether or not bar outlines are drawn and 392 * sends a {@link RendererChangeEvent} to all registered listeners. 393 * 394 * @param draw the flag. 395 * 396 * @see #isDrawBarOutline() 397 */ 398 public void setDrawBarOutline(boolean draw) { 399 this.drawBarOutline = draw; 400 fireChangeEvent(); 401 } 402 403 /** 404 * Returns the maximum bar width, as a percentage of the available drawing 405 * space. 406 * 407 * @return The maximum bar width. 408 * 409 * @see #setMaximumBarWidth(double) 410 */ 411 public double getMaximumBarWidth() { 412 return this.maximumBarWidth; 413 } 414 415 /** 416 * Sets the maximum bar width, which is specified as a percentage of the 417 * available space for all bars, and sends a {@link RendererChangeEvent} to 418 * all registered listeners. 419 * 420 * @param percent the percent (where 0.05 is five percent). 421 * 422 * @see #getMaximumBarWidth() 423 */ 424 public void setMaximumBarWidth(double percent) { 425 this.maximumBarWidth = percent; 426 fireChangeEvent(); 427 } 428 429 /** 430 * Returns the minimum bar length (in Java2D units). The default value is 431 * 0.0. 432 * 433 * @return The minimum bar length. 434 * 435 * @see #setMinimumBarLength(double) 436 */ 437 public double getMinimumBarLength() { 438 return this.minimumBarLength; 439 } 440 441 /** 442 * Sets the minimum bar length and sends a {@link RendererChangeEvent} to 443 * all registered listeners. The minimum bar length is specified in Java2D 444 * units, and can be used to prevent bars that represent very small data 445 * values from disappearing when drawn on the screen. Typically you would 446 * set this to (say) 0.5 or 1.0 Java 2D units. Use this attribute with 447 * caution, however, because setting it to a non-zero value will 448 * artificially increase the length of bars representing small values, 449 * which may misrepresent your data. 450 * 451 * @param min the minimum bar length (in Java2D units, must be >= 0.0). 452 * 453 * @see #getMinimumBarLength() 454 */ 455 public void setMinimumBarLength(double min) { 456 if (min < 0.0) { 457 throw new IllegalArgumentException("Requires 'min' >= 0.0"); 458 } 459 this.minimumBarLength = min; 460 fireChangeEvent(); 461 } 462 463 /** 464 * Returns the gradient paint transformer (an object used to transform 465 * gradient paint objects to fit each bar). 466 * 467 * @return A transformer ({@code null} possible). 468 * 469 * @see #setGradientPaintTransformer(GradientPaintTransformer) 470 */ 471 public GradientPaintTransformer getGradientPaintTransformer() { 472 return this.gradientPaintTransformer; 473 } 474 475 /** 476 * Sets the gradient paint transformer and sends a 477 * {@link RendererChangeEvent} to all registered listeners. 478 * 479 * @param transformer the transformer ({@code null} permitted). 480 * 481 * @see #getGradientPaintTransformer() 482 */ 483 public void setGradientPaintTransformer( 484 GradientPaintTransformer transformer) { 485 this.gradientPaintTransformer = transformer; 486 fireChangeEvent(); 487 } 488 489 /** 490 * Returns the fallback position for positive item labels that don't fit 491 * within a bar. 492 * 493 * @return The fallback position ({@code null} possible). 494 * 495 * @see #setPositiveItemLabelPositionFallback(ItemLabelPosition) 496 */ 497 public ItemLabelPosition getPositiveItemLabelPositionFallback() { 498 return this.positiveItemLabelPositionFallback; 499 } 500 501 /** 502 * Sets the fallback position for positive item labels that don't fit 503 * within a bar, and sends a {@link RendererChangeEvent} to all registered 504 * listeners. 505 * 506 * @param position the position ({@code null} permitted). 507 * 508 * @see #getPositiveItemLabelPositionFallback() 509 */ 510 public void setPositiveItemLabelPositionFallback( 511 ItemLabelPosition position) { 512 this.positiveItemLabelPositionFallback = position; 513 fireChangeEvent(); 514 } 515 516 /** 517 * Returns the fallback position for negative item labels that don't fit 518 * within a bar. 519 * 520 * @return The fallback position ({@code null} possible). 521 * 522 * @see #setPositiveItemLabelPositionFallback(ItemLabelPosition) 523 */ 524 public ItemLabelPosition getNegativeItemLabelPositionFallback() { 525 return this.negativeItemLabelPositionFallback; 526 } 527 528 /** 529 * Sets the fallback position for negative item labels that don't fit 530 * within a bar, and sends a {@link RendererChangeEvent} to all registered 531 * listeners. 532 * 533 * @param position the position ({@code null} permitted). 534 * 535 * @see #getNegativeItemLabelPositionFallback() 536 */ 537 public void setNegativeItemLabelPositionFallback( 538 ItemLabelPosition position) { 539 this.negativeItemLabelPositionFallback = position; 540 fireChangeEvent(); 541 } 542 543 /** 544 * Returns the flag that controls whether or not the base value for the 545 * bars is included in the range calculated by 546 * {@link #findRangeBounds(CategoryDataset)}. 547 * 548 * @return {@code true} if the base is included in the range, and 549 * {@code false} otherwise. 550 * 551 * @since 1.0.1 552 * 553 * @see #setIncludeBaseInRange(boolean) 554 */ 555 public boolean getIncludeBaseInRange() { 556 return this.includeBaseInRange; 557 } 558 559 /** 560 * Sets the flag that controls whether or not the base value for the bars 561 * is included in the range calculated by 562 * {@link #findRangeBounds(CategoryDataset)}. If the flag is changed, 563 * a {@link RendererChangeEvent} is sent to all registered listeners. 564 * 565 * @param include the new value for the flag. 566 * 567 * @since 1.0.1 568 * 569 * @see #getIncludeBaseInRange() 570 */ 571 public void setIncludeBaseInRange(boolean include) { 572 if (this.includeBaseInRange != include) { 573 this.includeBaseInRange = include; 574 fireChangeEvent(); 575 } 576 } 577 578 /** 579 * Returns the bar painter. 580 * 581 * @return The bar painter (never {@code null}). 582 * 583 * @see #setBarPainter(BarPainter) 584 * 585 * @since 1.0.11 586 */ 587 public BarPainter getBarPainter() { 588 return this.barPainter; 589 } 590 591 /** 592 * Sets the bar painter for this renderer and sends a 593 * {@link RendererChangeEvent} to all registered listeners. 594 * 595 * @param painter the painter ({@code null} not permitted). 596 * 597 * @see #getBarPainter() 598 * 599 * @since 1.0.11 600 */ 601 public void setBarPainter(BarPainter painter) { 602 Args.nullNotPermitted(painter, "painter"); 603 this.barPainter = painter; 604 fireChangeEvent(); 605 } 606 607 /** 608 * Returns the flag that controls whether or not shadows are drawn for 609 * the bars. 610 * 611 * @return A boolean. 612 * 613 * @since 1.0.11 614 */ 615 public boolean getShadowsVisible() { 616 return this.shadowsVisible; 617 } 618 619 /** 620 * Sets the flag that controls whether or not shadows are 621 * drawn by the renderer. 622 * 623 * @param visible the new flag value. 624 * 625 * @since 1.0.11 626 */ 627 public void setShadowVisible(boolean visible) { 628 this.shadowsVisible = visible; 629 fireChangeEvent(); 630 } 631 632 /** 633 * Returns the shadow paint. 634 * 635 * @return The shadow paint. 636 * 637 * @see #setShadowPaint(Paint) 638 * 639 * @since 1.0.11 640 */ 641 public Paint getShadowPaint() { 642 return this.shadowPaint; 643 } 644 645 /** 646 * Sets the shadow paint and sends a {@link RendererChangeEvent} to all 647 * registered listeners. 648 * 649 * @param paint the paint ({@code null} not permitted). 650 * 651 * @see #getShadowPaint() 652 * 653 * @since 1.0.11 654 */ 655 public void setShadowPaint(Paint paint) { 656 Args.nullNotPermitted(paint, "paint"); 657 this.shadowPaint = paint; 658 fireChangeEvent(); 659 } 660 661 /** 662 * Returns the shadow x-offset. 663 * 664 * @return The shadow x-offset. 665 * 666 * @since 1.0.11 667 */ 668 public double getShadowXOffset() { 669 return this.shadowXOffset; 670 } 671 672 /** 673 * Sets the x-offset for the bar shadow and sends a 674 * {@link RendererChangeEvent} to all registered listeners. 675 * 676 * @param offset the offset. 677 * 678 * @since 1.0.11 679 */ 680 public void setShadowXOffset(double offset) { 681 this.shadowXOffset = offset; 682 fireChangeEvent(); 683 } 684 685 /** 686 * Returns the shadow y-offset. 687 * 688 * @return The shadow y-offset. 689 * 690 * @since 1.0.11 691 */ 692 public double getShadowYOffset() { 693 return this.shadowYOffset; 694 } 695 696 /** 697 * Sets the y-offset for the bar shadow and sends a 698 * {@link RendererChangeEvent} to all registered listeners. 699 * 700 * @param offset the offset. 701 * 702 * @since 1.0.11 703 */ 704 public void setShadowYOffset(double offset) { 705 this.shadowYOffset = offset; 706 fireChangeEvent(); 707 } 708 709 /** 710 * Returns the lower clip value. This value is recalculated in the 711 * initialise() method. 712 * 713 * @return The value. 714 */ 715 public double getLowerClip() { 716 // TODO: this attribute should be transferred to the renderer state. 717 return this.lowerClip; 718 } 719 720 /** 721 * Returns the upper clip value. This value is recalculated in the 722 * initialise() method. 723 * 724 * @return The value. 725 */ 726 public double getUpperClip() { 727 // TODO: this attribute should be transferred to the renderer state. 728 return this.upperClip; 729 } 730 731 /** 732 * Initialises the renderer and returns a state object that will be passed 733 * to subsequent calls to the drawItem method. This method gets called 734 * once at the start of the process of drawing a chart. 735 * 736 * @param g2 the graphics device. 737 * @param dataArea the area in which the data is to be plotted. 738 * @param plot the plot. 739 * @param rendererIndex the renderer index. 740 * @param info collects chart rendering information for return to caller. 741 * 742 * @return The renderer state. 743 */ 744 @Override 745 public CategoryItemRendererState initialise(Graphics2D g2, 746 Rectangle2D dataArea, CategoryPlot plot, int rendererIndex, 747 PlotRenderingInfo info) { 748 749 CategoryItemRendererState state = super.initialise(g2, dataArea, plot, 750 rendererIndex, info); 751 752 // get the clipping values... 753 ValueAxis rangeAxis = plot.getRangeAxisForDataset(rendererIndex); 754 this.lowerClip = rangeAxis.getRange().getLowerBound(); 755 this.upperClip = rangeAxis.getRange().getUpperBound(); 756 757 // calculate the bar width 758 calculateBarWidth(plot, dataArea, rendererIndex, state); 759 760 return state; 761 762 } 763 764 /** 765 * Calculates the bar width and stores it in the renderer state. 766 * 767 * @param plot the plot. 768 * @param dataArea the data area. 769 * @param rendererIndex the renderer index. 770 * @param state the renderer state. 771 */ 772 protected void calculateBarWidth(CategoryPlot plot, 773 Rectangle2D dataArea, 774 int rendererIndex, 775 CategoryItemRendererState state) { 776 777 CategoryAxis domainAxis = getDomainAxis(plot, rendererIndex); 778 CategoryDataset dataset = plot.getDataset(rendererIndex); 779 if (dataset != null) { 780 int columns = dataset.getColumnCount(); 781 int rows = state.getVisibleSeriesCount() >= 0 782 ? state.getVisibleSeriesCount() : dataset.getRowCount(); 783 double space = 0.0; 784 PlotOrientation orientation = plot.getOrientation(); 785 if (orientation == PlotOrientation.HORIZONTAL) { 786 space = dataArea.getHeight(); 787 } 788 else if (orientation == PlotOrientation.VERTICAL) { 789 space = dataArea.getWidth(); 790 } 791 double maxWidth = space * getMaximumBarWidth(); 792 double categoryMargin = 0.0; 793 double currentItemMargin = 0.0; 794 if (columns > 1) { 795 categoryMargin = domainAxis.getCategoryMargin(); 796 } 797 if (rows > 1) { 798 currentItemMargin = getItemMargin(); 799 } 800 double used = space * (1 - domainAxis.getLowerMargin() 801 - domainAxis.getUpperMargin() 802 - categoryMargin - currentItemMargin); 803 if ((rows * columns) > 0) { 804 state.setBarWidth(Math.min(used / (rows * columns), maxWidth)); 805 } 806 else { 807 state.setBarWidth(Math.min(used, maxWidth)); 808 } 809 } 810 } 811 812 /** 813 * Calculates the coordinate of the first "side" of a bar. This will be 814 * the minimum x-coordinate for a vertical bar, and the minimum 815 * y-coordinate for a horizontal bar. 816 * 817 * @param plot the plot. 818 * @param orientation the plot orientation. 819 * @param dataArea the data area. 820 * @param domainAxis the domain axis. 821 * @param state the renderer state (has the bar width precalculated). 822 * @param row the row index. 823 * @param column the column index. 824 * 825 * @return The coordinate. 826 */ 827 protected double calculateBarW0(CategoryPlot plot, 828 PlotOrientation orientation, Rectangle2D dataArea, 829 CategoryAxis domainAxis, CategoryItemRendererState state, 830 int row, int column) { 831 // calculate bar width... 832 double space; 833 if (orientation == PlotOrientation.HORIZONTAL) { 834 space = dataArea.getHeight(); 835 } 836 else { 837 space = dataArea.getWidth(); 838 } 839 double barW0 = domainAxis.getCategoryStart(column, getColumnCount(), 840 dataArea, plot.getDomainAxisEdge()); 841 int seriesCount = state.getVisibleSeriesCount() >= 0 842 ? state.getVisibleSeriesCount() : getRowCount(); 843 int categoryCount = getColumnCount(); 844 if (seriesCount > 1) { 845 double seriesGap = space * getItemMargin() 846 / (categoryCount * (seriesCount - 1)); 847 double seriesW = calculateSeriesWidth(space, domainAxis, 848 categoryCount, seriesCount); 849 barW0 = barW0 + row * (seriesW + seriesGap) 850 + (seriesW / 2.0) - (state.getBarWidth() / 2.0); 851 } 852 else { 853 barW0 = domainAxis.getCategoryMiddle(column, getColumnCount(), 854 dataArea, plot.getDomainAxisEdge()) - state.getBarWidth() 855 / 2.0; 856 } 857 return barW0; 858 } 859 860 /** 861 * Calculates the coordinates for the length of a single bar. 862 * 863 * @param value the value represented by the bar. 864 * 865 * @return The coordinates for each end of the bar (or {@code null} if 866 * the bar is not visible for the current axis range). 867 */ 868 protected double[] calculateBarL0L1(double value) { 869 double lclip = getLowerClip(); 870 double uclip = getUpperClip(); 871 double barLow = Math.min(this.base, value); 872 double barHigh = Math.max(this.base, value); 873 if (barHigh < lclip) { // bar is not visible 874 return null; 875 } 876 if (barLow > uclip) { // bar is not visible 877 return null; 878 } 879 barLow = Math.max(barLow, lclip); 880 barHigh = Math.min(barHigh, uclip); 881 return new double[] {barLow, barHigh}; 882 } 883 884 /** 885 * Returns the range of values the renderer requires to display all the 886 * items from the specified dataset. This takes into account the range 887 * of values in the dataset, plus the flag that determines whether or not 888 * the base value for the bars should be included in the range. 889 * 890 * @param dataset the dataset ({@code null} permitted). 891 * @param includeInterval include the interval if the dataset has one? 892 * 893 * @return The range (or {@code null} if the dataset is 894 * {@code null} or empty). 895 */ 896 @Override 897 public Range findRangeBounds(CategoryDataset dataset, 898 boolean includeInterval) { 899 if (dataset == null) { 900 return null; 901 } 902 Range result = super.findRangeBounds(dataset, includeInterval); 903 if (result != null) { 904 if (this.includeBaseInRange) { 905 result = Range.expandToInclude(result, this.base); 906 } 907 } 908 return result; 909 } 910 911 /** 912 * Returns a legend item for a series. 913 * 914 * @param datasetIndex the dataset index (zero-based). 915 * @param series the series index (zero-based). 916 * 917 * @return The legend item (possibly {@code null}). 918 */ 919 @Override 920 public LegendItem getLegendItem(int datasetIndex, int series) { 921 922 CategoryPlot cp = getPlot(); 923 if (cp == null) { 924 return null; 925 } 926 927 // check that a legend item needs to be displayed... 928 if (!isSeriesVisible(series) || !isSeriesVisibleInLegend(series)) { 929 return null; 930 } 931 932 CategoryDataset dataset = cp.getDataset(datasetIndex); 933 String label = getLegendItemLabelGenerator().generateLabel(dataset, 934 series); 935 String description = label; 936 String toolTipText = null; 937 if (getLegendItemToolTipGenerator() != null) { 938 toolTipText = getLegendItemToolTipGenerator().generateLabel( 939 dataset, series); 940 } 941 String urlText = null; 942 if (getLegendItemURLGenerator() != null) { 943 urlText = getLegendItemURLGenerator().generateLabel(dataset, 944 series); 945 } 946 Shape shape = lookupLegendShape(series); 947 Paint paint = lookupSeriesPaint(series); 948 Paint outlinePaint = lookupSeriesOutlinePaint(series); 949 Stroke outlineStroke = lookupSeriesOutlineStroke(series); 950 951 LegendItem result = new LegendItem(label, description, toolTipText, 952 urlText, true, shape, true, paint, isDrawBarOutline(), 953 outlinePaint, outlineStroke, false, new Line2D.Float(), 954 new BasicStroke(1.0f), Color.BLACK); 955 result.setLabelFont(lookupLegendTextFont(series)); 956 Paint labelPaint = lookupLegendTextPaint(series); 957 if (labelPaint != null) { 958 result.setLabelPaint(labelPaint); 959 } 960 result.setDataset(dataset); 961 result.setDatasetIndex(datasetIndex); 962 result.setSeriesKey(dataset.getRowKey(series)); 963 result.setSeriesIndex(series); 964 if (this.gradientPaintTransformer != null) { 965 result.setFillPaintTransformer(this.gradientPaintTransformer); 966 } 967 return result; 968 } 969 970 /** 971 * Draws the bar for a single (series, category) data item. 972 * 973 * @param g2 the graphics device. 974 * @param state the renderer state. 975 * @param dataArea the data area. 976 * @param plot the plot. 977 * @param domainAxis the domain axis. 978 * @param rangeAxis the range axis. 979 * @param dataset the dataset. 980 * @param row the row index (zero-based). 981 * @param column the column index (zero-based). 982 * @param pass the pass index. 983 */ 984 @Override 985 public void drawItem(Graphics2D g2, CategoryItemRendererState state, 986 Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, 987 ValueAxis rangeAxis, CategoryDataset dataset, int row, 988 int column, int pass) { 989 990 // nothing is drawn if the row index is not included in the list with 991 // the indices of the visible rows... 992 int visibleRow = state.getVisibleSeriesIndex(row); 993 if (visibleRow < 0) { 994 return; 995 } 996 // nothing is drawn for null values... 997 Number dataValue = dataset.getValue(row, column); 998 if (dataValue == null) { 999 return; 1000 } 1001 1002 final double value = dataValue.doubleValue(); 1003 PlotOrientation orientation = plot.getOrientation(); 1004 double barW0 = calculateBarW0(plot, orientation, dataArea, domainAxis, 1005 state, visibleRow, column); 1006 double[] barL0L1 = calculateBarL0L1(value); 1007 if (barL0L1 == null) { 1008 return; // the bar is not visible 1009 } 1010 1011 RectangleEdge edge = plot.getRangeAxisEdge(); 1012 double transL0 = rangeAxis.valueToJava2D(barL0L1[0], dataArea, edge); 1013 double transL1 = rangeAxis.valueToJava2D(barL0L1[1], dataArea, edge); 1014 1015 // in the following code, barL0 is (in Java2D coordinates) the LEFT 1016 // end of the bar for a horizontal bar chart, and the TOP end of the 1017 // bar for a vertical bar chart. Whether this is the BASE of the bar 1018 // or not depends also on (a) whether the data value is 'negative' 1019 // relative to the base value and (b) whether or not the range axis is 1020 // inverted. This only matters if/when we apply the minimumBarLength 1021 // attribute, because we should extend the non-base end of the bar 1022 boolean positive = (value >= this.base); 1023 boolean inverted = rangeAxis.isInverted(); 1024 double barL0 = Math.min(transL0, transL1); 1025 double barLength = Math.abs(transL1 - transL0); 1026 double barLengthAdj = 0.0; 1027 if (barLength > 0.0 && barLength < getMinimumBarLength()) { 1028 barLengthAdj = getMinimumBarLength() - barLength; 1029 } 1030 double barL0Adj = 0.0; 1031 RectangleEdge barBase; 1032 if (orientation == PlotOrientation.HORIZONTAL) { 1033 if (positive && inverted || !positive && !inverted) { 1034 barL0Adj = barLengthAdj; 1035 barBase = RectangleEdge.RIGHT; 1036 } 1037 else { 1038 barBase = RectangleEdge.LEFT; 1039 } 1040 } 1041 else { 1042 if (positive && !inverted || !positive && inverted) { 1043 barL0Adj = barLengthAdj; 1044 barBase = RectangleEdge.BOTTOM; 1045 } 1046 else { 1047 barBase = RectangleEdge.TOP; 1048 } 1049 } 1050 1051 // draw the bar... 1052 Rectangle2D bar; 1053 if (orientation == PlotOrientation.HORIZONTAL) { 1054 bar = new Rectangle2D.Double(barL0 - barL0Adj, barW0, 1055 barLength + barLengthAdj, state.getBarWidth()); 1056 } 1057 else { 1058 bar = new Rectangle2D.Double(barW0, barL0 - barL0Adj, 1059 state.getBarWidth(), barLength + barLengthAdj); 1060 } 1061 if (state.getElementHinting()) { 1062 KeyedValues2DItemKey key = new KeyedValues2DItemKey( 1063 dataset.getRowKey(row), dataset.getColumnKey(column)); 1064 beginElementGroup(g2, key); 1065 } 1066 if (getShadowsVisible()) { 1067 this.barPainter.paintBarShadow(g2, this, row, column, bar, barBase, 1068 true); 1069 } 1070 this.barPainter.paintBar(g2, this, row, column, bar, barBase); 1071 if (state.getElementHinting()) { 1072 endElementGroup(g2); 1073 } 1074 1075 CategoryItemLabelGenerator generator = getItemLabelGenerator(row, 1076 column); 1077 if (generator != null && isItemLabelVisible(row, column)) { 1078 drawItemLabel(g2, dataset, row, column, plot, generator, bar, 1079 (value < 0.0)); 1080 } 1081 1082 // submit the current data point as a crosshair candidate 1083 int datasetIndex = plot.indexOf(dataset); 1084 updateCrosshairValues(state.getCrosshairState(), 1085 dataset.getRowKey(row), dataset.getColumnKey(column), value, 1086 datasetIndex, barW0, barL0, orientation); 1087 1088 // add an item entity, if this information is being collected 1089 EntityCollection entities = state.getEntityCollection(); 1090 if (entities != null) { 1091 addItemEntity(entities, dataset, row, column, bar); 1092 } 1093 1094 } 1095 1096 /** 1097 * Calculates the available space for each series. 1098 * 1099 * @param space the space along the entire axis (in Java2D units). 1100 * @param axis the category axis. 1101 * @param categories the number of categories. 1102 * @param series the number of series. 1103 * 1104 * @return The width of one series. 1105 */ 1106 protected double calculateSeriesWidth(double space, CategoryAxis axis, 1107 int categories, int series) { 1108 double factor = 1.0 - getItemMargin() - axis.getLowerMargin() 1109 - axis.getUpperMargin(); 1110 if (categories > 1) { 1111 factor = factor - axis.getCategoryMargin(); 1112 } 1113 return (space * factor) / (categories * series); 1114 } 1115 1116 /** 1117 * Draws an item label. This method is overridden so that the bar can be 1118 * used to calculate the label anchor point. 1119 * 1120 * @param g2 the graphics device. 1121 * @param data the dataset. 1122 * @param row the row. 1123 * @param column the column. 1124 * @param plot the plot. 1125 * @param generator the label generator. 1126 * @param bar the bar. 1127 * @param negative a flag indicating a negative value. 1128 */ 1129 protected void drawItemLabel(Graphics2D g2, 1130 CategoryDataset data, 1131 int row, 1132 int column, 1133 CategoryPlot plot, 1134 CategoryItemLabelGenerator generator, 1135 Rectangle2D bar, 1136 boolean negative) { 1137 1138 String label = generator.generateLabel(data, row, column); 1139 if (label == null) { 1140 return; // nothing to do 1141 } 1142 1143 Font labelFont = getItemLabelFont(row, column); 1144 g2.setFont(labelFont); 1145 Paint paint = getItemLabelPaint(row, column); 1146 g2.setPaint(paint); 1147 1148 // find out where to place the label... 1149 ItemLabelPosition position; 1150 if (!negative) { 1151 position = getPositiveItemLabelPosition(row, column); 1152 } 1153 else { 1154 position = getNegativeItemLabelPosition(row, column); 1155 } 1156 1157 // work out the label anchor point... 1158 Point2D anchorPoint = calculateLabelAnchorPoint( 1159 position.getItemLabelAnchor(), bar, plot.getOrientation()); 1160 1161 if (isInternalAnchor(position.getItemLabelAnchor())) { 1162 Shape bounds = TextUtils.calculateRotatedStringBounds(label, 1163 g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), 1164 position.getTextAnchor(), position.getAngle(), 1165 position.getRotationAnchor()); 1166 1167 if (bounds != null) { 1168 if (!bar.contains(bounds.getBounds2D())) { 1169 if (!negative) { 1170 position = getPositiveItemLabelPositionFallback(); 1171 } 1172 else { 1173 position = getNegativeItemLabelPositionFallback(); 1174 } 1175 if (position != null) { 1176 anchorPoint = calculateLabelAnchorPoint( 1177 position.getItemLabelAnchor(), bar, 1178 plot.getOrientation()); 1179 } 1180 } 1181 } 1182 1183 } 1184 1185 if (position != null) { 1186 TextUtils.drawRotatedString(label, g2, 1187 (float) anchorPoint.getX(), (float) anchorPoint.getY(), 1188 position.getTextAnchor(), position.getAngle(), 1189 position.getRotationAnchor()); 1190 } 1191 } 1192 1193 /** 1194 * Calculates the item label anchor point. 1195 * 1196 * @param anchor the anchor. 1197 * @param bar the bar. 1198 * @param orientation the plot orientation. 1199 * 1200 * @return The anchor point. 1201 */ 1202 private Point2D calculateLabelAnchorPoint(ItemLabelAnchor anchor, 1203 Rectangle2D bar, 1204 PlotOrientation orientation) { 1205 1206 Point2D result = null; 1207 double offset = getItemLabelAnchorOffset(); 1208 double x0 = bar.getX() - offset; 1209 double x1 = bar.getX(); 1210 double x2 = bar.getX() + offset; 1211 double x3 = bar.getCenterX(); 1212 double x4 = bar.getMaxX() - offset; 1213 double x5 = bar.getMaxX(); 1214 double x6 = bar.getMaxX() + offset; 1215 1216 double y0 = bar.getMaxY() + offset; 1217 double y1 = bar.getMaxY(); 1218 double y2 = bar.getMaxY() - offset; 1219 double y3 = bar.getCenterY(); 1220 double y4 = bar.getMinY() + offset; 1221 double y5 = bar.getMinY(); 1222 double y6 = bar.getMinY() - offset; 1223 1224 if (anchor == ItemLabelAnchor.CENTER) { 1225 result = new Point2D.Double(x3, y3); 1226 } 1227 else if (anchor == ItemLabelAnchor.INSIDE1) { 1228 result = new Point2D.Double(x4, y4); 1229 } 1230 else if (anchor == ItemLabelAnchor.INSIDE2) { 1231 result = new Point2D.Double(x4, y4); 1232 } 1233 else if (anchor == ItemLabelAnchor.INSIDE3) { 1234 result = new Point2D.Double(x4, y3); 1235 } 1236 else if (anchor == ItemLabelAnchor.INSIDE4) { 1237 result = new Point2D.Double(x4, y2); 1238 } 1239 else if (anchor == ItemLabelAnchor.INSIDE5) { 1240 result = new Point2D.Double(x4, y2); 1241 } 1242 else if (anchor == ItemLabelAnchor.INSIDE6) { 1243 result = new Point2D.Double(x3, y2); 1244 } 1245 else if (anchor == ItemLabelAnchor.INSIDE7) { 1246 result = new Point2D.Double(x2, y2); 1247 } 1248 else if (anchor == ItemLabelAnchor.INSIDE8) { 1249 result = new Point2D.Double(x2, y2); 1250 } 1251 else if (anchor == ItemLabelAnchor.INSIDE9) { 1252 result = new Point2D.Double(x2, y3); 1253 } 1254 else if (anchor == ItemLabelAnchor.INSIDE10) { 1255 result = new Point2D.Double(x2, y4); 1256 } 1257 else if (anchor == ItemLabelAnchor.INSIDE11) { 1258 result = new Point2D.Double(x2, y4); 1259 } 1260 else if (anchor == ItemLabelAnchor.INSIDE12) { 1261 result = new Point2D.Double(x3, y4); 1262 } 1263 else if (anchor == ItemLabelAnchor.OUTSIDE1) { 1264 result = new Point2D.Double(x5, y6); 1265 } 1266 else if (anchor == ItemLabelAnchor.OUTSIDE2) { 1267 result = new Point2D.Double(x6, y5); 1268 } 1269 else if (anchor == ItemLabelAnchor.OUTSIDE3) { 1270 result = new Point2D.Double(x6, y3); 1271 } 1272 else if (anchor == ItemLabelAnchor.OUTSIDE4) { 1273 result = new Point2D.Double(x6, y1); 1274 } 1275 else if (anchor == ItemLabelAnchor.OUTSIDE5) { 1276 result = new Point2D.Double(x5, y0); 1277 } 1278 else if (anchor == ItemLabelAnchor.OUTSIDE6) { 1279 result = new Point2D.Double(x3, y0); 1280 } 1281 else if (anchor == ItemLabelAnchor.OUTSIDE7) { 1282 result = new Point2D.Double(x1, y0); 1283 } 1284 else if (anchor == ItemLabelAnchor.OUTSIDE8) { 1285 result = new Point2D.Double(x0, y1); 1286 } 1287 else if (anchor == ItemLabelAnchor.OUTSIDE9) { 1288 result = new Point2D.Double(x0, y3); 1289 } 1290 else if (anchor == ItemLabelAnchor.OUTSIDE10) { 1291 result = new Point2D.Double(x0, y5); 1292 } 1293 else if (anchor == ItemLabelAnchor.OUTSIDE11) { 1294 result = new Point2D.Double(x1, y6); 1295 } 1296 else if (anchor == ItemLabelAnchor.OUTSIDE12) { 1297 result = new Point2D.Double(x3, y6); 1298 } 1299 1300 return result; 1301 1302 } 1303 1304 /** 1305 * Returns {@code true} if the specified anchor point is inside a bar. 1306 * 1307 * @param anchor the anchor point. 1308 * 1309 * @return A boolean. 1310 */ 1311 private boolean isInternalAnchor(ItemLabelAnchor anchor) { 1312 return anchor == ItemLabelAnchor.CENTER 1313 || anchor == ItemLabelAnchor.INSIDE1 1314 || anchor == ItemLabelAnchor.INSIDE2 1315 || anchor == ItemLabelAnchor.INSIDE3 1316 || anchor == ItemLabelAnchor.INSIDE4 1317 || anchor == ItemLabelAnchor.INSIDE5 1318 || anchor == ItemLabelAnchor.INSIDE6 1319 || anchor == ItemLabelAnchor.INSIDE7 1320 || anchor == ItemLabelAnchor.INSIDE8 1321 || anchor == ItemLabelAnchor.INSIDE9 1322 || anchor == ItemLabelAnchor.INSIDE10 1323 || anchor == ItemLabelAnchor.INSIDE11 1324 || anchor == ItemLabelAnchor.INSIDE12; 1325 } 1326 1327 /** 1328 * Tests this instance for equality with an arbitrary object. 1329 * 1330 * @param obj the object ({@code null} permitted). 1331 * 1332 * @return A boolean. 1333 */ 1334 @Override 1335 public boolean equals(Object obj) { 1336 if (obj == this) { 1337 return true; 1338 } 1339 if (!(obj instanceof BarRenderer)) { 1340 return false; 1341 } 1342 BarRenderer that = (BarRenderer) obj; 1343 if (this.base != that.base) { 1344 return false; 1345 } 1346 if (this.itemMargin != that.itemMargin) { 1347 return false; 1348 } 1349 if (this.drawBarOutline != that.drawBarOutline) { 1350 return false; 1351 } 1352 if (this.maximumBarWidth != that.maximumBarWidth) { 1353 return false; 1354 } 1355 if (this.minimumBarLength != that.minimumBarLength) { 1356 return false; 1357 } 1358 if (!ObjectUtils.equal(this.gradientPaintTransformer, 1359 that.gradientPaintTransformer)) { 1360 return false; 1361 } 1362 if (!ObjectUtils.equal(this.positiveItemLabelPositionFallback, 1363 that.positiveItemLabelPositionFallback)) { 1364 return false; 1365 } 1366 if (!ObjectUtils.equal(this.negativeItemLabelPositionFallback, 1367 that.negativeItemLabelPositionFallback)) { 1368 return false; 1369 } 1370 if (!this.barPainter.equals(that.barPainter)) { 1371 return false; 1372 } 1373 if (this.shadowsVisible != that.shadowsVisible) { 1374 return false; 1375 } 1376 if (!PaintUtils.equal(this.shadowPaint, that.shadowPaint)) { 1377 return false; 1378 } 1379 if (this.shadowXOffset != that.shadowXOffset) { 1380 return false; 1381 } 1382 if (this.shadowYOffset != that.shadowYOffset) { 1383 return false; 1384 } 1385 return super.equals(obj); 1386 } 1387 1388 /** 1389 * Provides serialization support. 1390 * 1391 * @param stream the output stream. 1392 * 1393 * @throws IOException if there is an I/O error. 1394 */ 1395 private void writeObject(ObjectOutputStream stream) throws IOException { 1396 stream.defaultWriteObject(); 1397 SerialUtils.writePaint(this.shadowPaint, stream); 1398 } 1399 1400 /** 1401 * Provides serialization support. 1402 * 1403 * @param stream the input stream. 1404 * 1405 * @throws IOException if there is an I/O error. 1406 * @throws ClassNotFoundException if there is a classpath problem. 1407 */ 1408 private void readObject(ObjectInputStream stream) 1409 throws IOException, ClassNotFoundException { 1410 stream.defaultReadObject(); 1411 this.shadowPaint = SerialUtils.readPaint(stream); 1412 } 1413 1414}