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 * XYPlot.java 029 * ----------- 030 * (C) Copyright 2000-2017, by Object Refinery Limited and Contributors. 031 * 032 * Original Author: David Gilbert (for Object Refinery Limited); 033 * Contributor(s): Craig MacFarlane; 034 * Mark Watson (www.markwatson.com); 035 * Jonathan Nash; 036 * Gideon Krause; 037 * Klaus Rheinwald; 038 * Xavier Poinsard; 039 * Richard Atkinson; 040 * Arnaud Lelievre; 041 * Nicolas Brodu; 042 * Eduardo Ramalho; 043 * Sergei Ivanov; 044 * Richard West, Advanced Micro Devices, Inc.; 045 * Ulrich Voigt - patches 1997549 and 2686040; 046 * Peter Kolb - patches 1934255, 2603321 and 2809117; 047 * Andrew Mickish - patch 1868749; 048 * 049 * Changes (from 21-Jun-2001) 050 * -------------------------- 051 * 21-Jun-2001 : Removed redundant JFreeChart parameter from constructors (DG); 052 * 18-Sep-2001 : Updated header and fixed DOS encoding problem (DG); 053 * 15-Oct-2001 : Data source classes moved to com.jrefinery.data.* (DG); 054 * 19-Oct-2001 : Removed the code for drawing the visual representation of each 055 * data point into a separate class StandardXYItemRenderer. 056 * This will make it easier to add variations to the way the 057 * charts are drawn. Based on code contributed by Mark 058 * Watson (DG); 059 * 22-Oct-2001 : Renamed DataSource.java --> Dataset.java etc. (DG); 060 * 20-Nov-2001 : Fixed clipping bug that shows up when chart is displayed 061 * inside JScrollPane (DG); 062 * 12-Dec-2001 : Removed unnecessary 'throws' clauses from constructor (DG); 063 * 13-Dec-2001 : Added skeleton code for tooltips. Added new constructor. (DG); 064 * 16-Jan-2002 : Renamed the tooltips class (DG); 065 * 22-Jan-2002 : Added DrawInfo class, incorporating tooltips and crosshairs. 066 * Crosshairs based on code by Jonathan Nash (DG); 067 * 05-Feb-2002 : Added alpha-transparency setting based on code by Sylvain 068 * Vieujot (DG); 069 * 26-Feb-2002 : Updated getMinimumXXX() and getMaximumXXX() methods to handle 070 * special case when chart is null (DG); 071 * 28-Feb-2002 : Renamed Datasets.java --> DatasetUtilities.java (DG); 072 * 28-Mar-2002 : The plot now registers with the renderer as a property change 073 * listener. Also added a new constructor (DG); 074 * 09-Apr-2002 : Removed the transRangeZero from the renderer.drawItem() 075 * method. Moved the tooltip generator into the renderer (DG); 076 * 23-Apr-2002 : Fixed bug in methods for drawing horizontal and vertical 077 * lines (DG); 078 * 13-May-2002 : Small change to the draw() method so that it works for 079 * OverlaidXYPlot also (DG); 080 * 25-Jun-2002 : Removed redundant import (DG); 081 * 20-Aug-2002 : Renamed getItemRenderer() --> getRenderer(), and 082 * setXYItemRenderer() --> setRenderer() (DG); 083 * 28-Aug-2002 : Added mechanism for (optional) plot annotations (DG); 084 * 02-Oct-2002 : Fixed errors reported by Checkstyle (DG); 085 * 18-Nov-2002 : Added grid settings for both domain and range axis (previously 086 * these were set in the axes) (DG); 087 * 09-Jan-2003 : Further additions to the grid settings, plus integrated plot 088 * border bug fix contributed by Gideon Krause (DG); 089 * 22-Jan-2003 : Removed monolithic constructor (DG); 090 * 04-Mar-2003 : Added 'no data' message, see bug report 691634. Added 091 * secondary range markers using code contributed by Klaus 092 * Rheinwald (DG); 093 * 26-Mar-2003 : Implemented Serializable (DG); 094 * 03-Apr-2003 : Added setDomainAxisLocation() method (DG); 095 * 30-Apr-2003 : Moved annotation drawing into a separate method (DG); 096 * 01-May-2003 : Added multi-pass mechanism for renderers (DG); 097 * 02-May-2003 : Changed axis locations from int to AxisLocation (DG); 098 * 15-May-2003 : Added an orientation attribute (DG); 099 * 02-Jun-2003 : Removed range axis compatibility test (DG); 100 * 05-Jun-2003 : Added domain and range grid bands (sponsored by Focus Computer 101 * Services Ltd) (DG); 102 * 26-Jun-2003 : Fixed bug (757303) in getDataRange() method (DG); 103 * 02-Jul-2003 : Added patch from bug report 698646 (secondary axes for 104 * overlaid plots) (DG); 105 * 23-Jul-2003 : Added support for multiple secondary datasets, axes and 106 * renderers (DG); 107 * 27-Jul-2003 : Added support for stacked XY area charts (RA); 108 * 19-Aug-2003 : Implemented Cloneable (DG); 109 * 01-Sep-2003 : Fixed bug where change to secondary datasets didn't generate 110 * change event (797466) (DG) 111 * 08-Sep-2003 : Added internationalization via use of properties 112 * resourceBundle (RFE 690236) (AL); 113 * 08-Sep-2003 : Changed ValueAxis API (DG); 114 * 08-Sep-2003 : Fixes for serialization (NB); 115 * 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG); 116 * 17-Sep-2003 : Fixed zooming to include secondary domain axes (DG); 117 * 18-Sep-2003 : Added getSecondaryDomainAxisCount() and 118 * getSecondaryRangeAxisCount() methods suggested by Eduardo 119 * Ramalho (RFE 808548) (DG); 120 * 23-Sep-2003 : Split domain and range markers into foreground and 121 * background (DG); 122 * 06-Oct-2003 : Fixed bug in clearDomainMarkers() and clearRangeMarkers() 123 * methods. Fixed bug (815876) in addSecondaryRangeMarker() 124 * method. Added new addSecondaryDomainMarker methods (see bug 125 * id 815869) (DG); 126 * 10-Nov-2003 : Added getSecondaryDomain/RangeAxisMappedToDataset() methods 127 * requested by Eduardo Ramalho (DG); 128 * 24-Nov-2003 : Removed unnecessary notification when updating axis anchor 129 * values (DG); 130 * 21-Jan-2004 : Update for renamed method in ValueAxis (DG); 131 * 25-Feb-2004 : Replaced CrosshairInfo with CrosshairState (DG); 132 * 12-Mar-2004 : Fixed bug where primary renderer is always used to determine 133 * range type (DG); 134 * 22-Mar-2004 : Fixed cloning bug (DG); 135 * 23-Mar-2004 : Fixed more cloning bugs (DG); 136 * 07-Apr-2004 : Fixed problem with axis range when the secondary renderer is 137 * stacked, see this post in the forum: 138 * http://www.jfree.org/phpBB2/viewtopic.php?t=8204 (DG); 139 * 07-Apr-2004 : Added get/setDatasetRenderingOrder() methods (DG); 140 * 26-Apr-2004 : Added option to fill quadrant areas in the background of the 141 * plot (DG); 142 * 27-Apr-2004 : Removed major distinction between primary and secondary 143 * datasets, renderers and axes (DG); 144 * 30-Apr-2004 : Modified to make use of the new getRangeExtent() method in the 145 * renderer interface (DG); 146 * 13-May-2004 : Added optional fixedLegendItems attribute (DG); 147 * 19-May-2004 : Added indexOf() method (DG); 148 * 03-Jun-2004 : Fixed zooming bug (DG); 149 * 18-Aug-2004 : Added removedAnnotation() method (by tkram01) (DG); 150 * 05-Oct-2004 : Modified storage type for dataset-to-axis maps (DG); 151 * 06-Oct-2004 : Modified getDataRange() method to use renderer to determine 152 * the x-value range (now matches behaviour for y-values). Added 153 * getDomainAxisIndex() method (DG); 154 * 12-Nov-2004 : Implemented new Zoomable interface (DG); 155 * 25-Nov-2004 : Small update to clone() implementation (DG); 156 * 22-Feb-2005 : Changed axis offsets from Spacer --> RectangleInsets (DG); 157 * 24-Feb-2005 : Added indexOf(XYItemRenderer) method (DG); 158 * 21-Mar-2005 : Register plot as change listener in setRenderer() method (DG); 159 * 21-Apr-2005 : Added get/setSeriesRenderingOrder() methods (ET); 160 * 26-Apr-2005 : Removed LOGGER (DG); 161 * 04-May-2005 : Fixed serialization of domain and range markers (DG); 162 * 05-May-2005 : Removed unused draw() method (DG); 163 * 20-May-2005 : Added setDomainAxes() and setRangeAxes() methods, as per 164 * RFE 1183100 (DG); 165 * 01-Jun-2005 : Upon deserialization, register plot as a listener with its 166 * axes, dataset(s) and renderer(s) - see patch 1209475 (DG); 167 * 01-Jun-2005 : Added clearDomainMarkers(int) method to match 168 * clearRangeMarkers(int) (DG); 169 * 06-Jun-2005 : Fixed equals() method to handle GradientPaint (DG); 170 * 09-Jun-2005 : Added setRenderers(), as per RFE 1183100 (DG); 171 * 06-Jul-2005 : Fixed crosshair bug (id = 1233336) (DG); 172 * ------------- JFREECHART 1.0.x --------------------------------------------- 173 * 26-Jan-2006 : Added getAnnotations() method (DG); 174 * 05-Sep-2006 : Added MarkerChangeEvent support (DG); 175 * 13-Oct-2006 : Fixed initialisation of CrosshairState - see bug report 176 * 1565168 (DG); 177 * 22-Nov-2006 : Fixed equals() and cloning() for quadrant attributes, plus 178 * API doc updates (DG); 179 * 29-Nov-2006 : Added argument checks (DG); 180 * 15-Jan-2007 : Fixed bug in drawRangeMarkers() (DG); 181 * 07-Feb-2007 : Fixed bug 1654215, renderer with no dataset (DG); 182 * 26-Feb-2007 : Added missing setDomainAxisLocation() and 183 * setRangeAxisLocation() methods (DG); 184 * 02-Mar-2007 : Fix for crosshair positioning with horizontal orientation 185 * (see patch 1671648 by Sergei Ivanov) (DG); 186 * 13-Mar-2007 : Added null argument checks for crosshair attributes (DG); 187 * 23-Mar-2007 : Added domain zero base line facility (DG); 188 * 04-May-2007 : Render only visible data items if possible (DG); 189 * 24-May-2007 : Fixed bug in render method for an empty series (DG); 190 * 07-Jun-2007 : Modified drawBackground() to pass orientation to 191 * fillBackground() for handling GradientPaint (DG); 192 * 24-Sep-2007 : Added new zoom methods (DG); 193 * 26-Sep-2007 : Include index value in IllegalArgumentExceptions (DG); 194 * 05-Nov-2007 : Applied patch 1823697, by Richard West, for removal of domain 195 * and range markers (DG); 196 * 12-Nov-2007 : Fixed bug in equals() method for domain and range tick 197 * band paint attributes (DG); 198 * 27-Nov-2007 : Added new setFixedDomain/RangeAxisSpace() methods (DG); 199 * 04-Jan-2008 : Fix for quadrant painting error - see patch 1849564 (DG); 200 * 25-Mar-2008 : Added new methods with optional notification - see patch 201 * 1913751 (DG); 202 * 07-Apr-2008 : Fixed NPE in removeDomainMarker() and 203 * removeRangeMarker() (DG); 204 * 22-May-2008 : Modified calculateAxisSpace() to process range axes first, 205 * then adjust the plot area before calculating the space 206 * for the domain axes (DG); 207 * 09-Jul-2008 : Added renderer state notification when series pass begins 208 * and ends - see patch 1997549 by Ulrich Voigt (DG); 209 * 25-Jul-2008 : Fixed NullPointerException for plots with no axes (DG); 210 * 15-Aug-2008 : Added getRendererCount() method (DG); 211 * 25-Sep-2008 : Added minor tick support, see patch 1934255 by Peter Kolb (DG); 212 * 25-Nov-2008 : Allow datasets to be mapped to multiple axes - based on patch 213 * 1868749 by Andrew Mickish (DG); 214 * 18-Dec-2008 : Use ResourceBundleWrapper - see patch 1607918 by 215 * Jess Thrysoee (DG); 216 * 10-Mar-2009 : Allow some annotations to contribute to axis autoRange (DG); 217 * 18-Mar-2009 : Modified anchored zoom behaviour and fixed bug in 218 * "process visible range" rendering (DG); 219 * 19-Mar-2009 : Added panning support based on patch 2686040 by Ulrich 220 * Voigt (DG); 221 * 19-Mar-2009 : Added entity support - see patch 2603321 by Peter Kolb (DG); 222 * 30-Mar-2009 : Delegate panning to axes (DG); 223 * 10-May-2009 : Added check for fixedLegendItems in equals(), and code to 224 * handle cloning (DG); 225 * 24-Jun-2009 : Added support for annotation events - see patch 2809117 226 * by PK (DG); 227 * 06-Jul-2009 : Fix for cloning of renderers - see bug 2817504 (DG) 228 * 10-Jul-2009 : Added optional drop shadow generator (DG); 229 * 18-Oct-2011 : Fix tooltip offset with shadow renderer (DG); 230 * 12-Sep-2013 : Check for KEY_SUPPRESS_SHADOW_GENERATION rendering hint (DG); 231 * 10-Mar-2014 : Updated Javadocs for issue #1123 (DG); 232 * 29-Jul-2014 : Add hints to normalise stroke for crosshairs (DG); 233 * 234 */ 235 236package org.jfree.chart.plot; 237 238import java.awt.AlphaComposite; 239import java.awt.BasicStroke; 240import java.awt.Color; 241import java.awt.Composite; 242import java.awt.Graphics2D; 243import java.awt.Paint; 244import java.awt.Rectangle; 245import java.awt.RenderingHints; 246import java.awt.Shape; 247import java.awt.Stroke; 248import java.awt.geom.Line2D; 249import java.awt.geom.Point2D; 250import java.awt.geom.Rectangle2D; 251import java.awt.image.BufferedImage; 252import java.io.IOException; 253import java.io.ObjectInputStream; 254import java.io.ObjectOutputStream; 255import java.io.Serializable; 256import java.util.ArrayList; 257import java.util.Collection; 258import java.util.Collections; 259import java.util.HashMap; 260import java.util.HashSet; 261import java.util.Iterator; 262import java.util.List; 263import java.util.Map; 264import java.util.Map.Entry; 265import java.util.ResourceBundle; 266import java.util.Set; 267import java.util.TreeMap; 268import org.jfree.chart.JFreeChart; 269 270import org.jfree.chart.LegendItem; 271import org.jfree.chart.LegendItemCollection; 272import org.jfree.chart.annotations.Annotation; 273import org.jfree.chart.annotations.XYAnnotation; 274import org.jfree.chart.annotations.XYAnnotationBoundsInfo; 275import org.jfree.chart.axis.Axis; 276import org.jfree.chart.axis.AxisCollection; 277import org.jfree.chart.axis.AxisLocation; 278import org.jfree.chart.axis.AxisSpace; 279import org.jfree.chart.axis.AxisState; 280import org.jfree.chart.axis.TickType; 281import org.jfree.chart.axis.ValueAxis; 282import org.jfree.chart.axis.ValueTick; 283import org.jfree.chart.event.AnnotationChangeEvent; 284import org.jfree.chart.event.ChartChangeEventType; 285import org.jfree.chart.event.PlotChangeEvent; 286import org.jfree.chart.event.RendererChangeEvent; 287import org.jfree.chart.event.RendererChangeListener; 288import org.jfree.chart.renderer.RendererUtils; 289import org.jfree.chart.renderer.xy.AbstractXYItemRenderer; 290import org.jfree.chart.renderer.xy.XYItemRenderer; 291import org.jfree.chart.renderer.xy.XYItemRendererState; 292import org.jfree.chart.ui.Layer; 293import org.jfree.chart.ui.RectangleEdge; 294import org.jfree.chart.ui.RectangleInsets; 295import org.jfree.chart.util.CloneUtils; 296import org.jfree.chart.util.ObjectUtils; 297import org.jfree.chart.util.PaintUtils; 298import org.jfree.chart.util.Args; 299import org.jfree.chart.util.PublicCloneable; 300import org.jfree.chart.util.ResourceBundleWrapper; 301import org.jfree.chart.util.SerialUtils; 302import org.jfree.chart.util.ShadowGenerator; 303import org.jfree.data.Range; 304import org.jfree.data.general.DatasetChangeEvent; 305import org.jfree.data.general.DatasetUtils; 306import org.jfree.data.xy.XYDataset; 307 308/** 309 * A general class for plotting data in the form of (x, y) pairs. This plot can 310 * use data from any class that implements the {@link XYDataset} interface. 311 * <P> 312 * {@code XYPlot} makes use of an {@link XYItemRenderer} to draw each point 313 * on the plot. By using different renderers, various chart types can be 314 * produced. 315 * <p> 316 * The {@link org.jfree.chart.ChartFactory} class contains static methods for 317 * creating pre-configured charts. 318 */ 319public class XYPlot extends Plot implements ValueAxisPlot, Pannable, Zoomable, 320 RendererChangeListener, Cloneable, PublicCloneable, Serializable { 321 322 /** For serialization. */ 323 private static final long serialVersionUID = 7044148245716569264L; 324 325 /** The default grid line stroke. */ 326 public static final Stroke DEFAULT_GRIDLINE_STROKE = new BasicStroke(0.5f, 327 BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.0f, 328 new float[] {2.0f, 2.0f}, 0.0f); 329 330 /** The default grid line paint. */ 331 public static final Paint DEFAULT_GRIDLINE_PAINT = Color.LIGHT_GRAY; 332 333 /** The default crosshair visibility. */ 334 public static final boolean DEFAULT_CROSSHAIR_VISIBLE = false; 335 336 /** The default crosshair stroke. */ 337 public static final Stroke DEFAULT_CROSSHAIR_STROKE 338 = DEFAULT_GRIDLINE_STROKE; 339 340 /** The default crosshair paint. */ 341 public static final Paint DEFAULT_CROSSHAIR_PAINT = Color.BLUE; 342 343 /** The resourceBundle for the localization. */ 344 protected static ResourceBundle localizationResources 345 = ResourceBundleWrapper.getBundle( 346 "org.jfree.chart.plot.LocalizationBundle"); 347 348 /** The plot orientation. */ 349 private PlotOrientation orientation; 350 351 /** The offset between the data area and the axes. */ 352 private RectangleInsets axisOffset; 353 354 /** The domain axis / axes (used for the x-values). */ 355 private Map<Integer, ValueAxis> domainAxes; 356 357 /** The domain axis locations. */ 358 private Map<Integer, AxisLocation> domainAxisLocations; 359 360 /** The range axis (used for the y-values). */ 361 private Map<Integer, ValueAxis> rangeAxes; 362 363 /** The range axis location. */ 364 private Map<Integer, AxisLocation> rangeAxisLocations; 365 366 /** Storage for the datasets. */ 367 private Map<Integer, XYDataset> datasets; 368 369 /** Storage for the renderers. */ 370 private Map<Integer, XYItemRenderer> renderers; 371 372 /** 373 * Storage for the mapping between datasets/renderers and domain axes. The 374 * keys in the map are Integer objects, corresponding to the dataset 375 * index. The values in the map are List objects containing Integer 376 * objects (corresponding to the axis indices). If the map contains no 377 * entry for a dataset, it is assumed to map to the primary domain axis 378 * (index = 0). 379 */ 380 private Map<Integer, List<Integer>> datasetToDomainAxesMap; 381 382 /** 383 * Storage for the mapping between datasets/renderers and range axes. The 384 * keys in the map are Integer objects, corresponding to the dataset 385 * index. The values in the map are List objects containing Integer 386 * objects (corresponding to the axis indices). If the map contains no 387 * entry for a dataset, it is assumed to map to the primary domain axis 388 * (index = 0). 389 */ 390 private Map<Integer, List<Integer>> datasetToRangeAxesMap; 391 392 /** The origin point for the quadrants (if drawn). */ 393 private transient Point2D quadrantOrigin = new Point2D.Double(0.0, 0.0); 394 395 /** The paint used for each quadrant. */ 396 private transient Paint[] quadrantPaint 397 = new Paint[] {null, null, null, null}; 398 399 /** A flag that controls whether the domain grid-lines are visible. */ 400 private boolean domainGridlinesVisible; 401 402 /** The stroke used to draw the domain grid-lines. */ 403 private transient Stroke domainGridlineStroke; 404 405 /** The paint used to draw the domain grid-lines. */ 406 private transient Paint domainGridlinePaint; 407 408 /** A flag that controls whether the range grid-lines are visible. */ 409 private boolean rangeGridlinesVisible; 410 411 /** The stroke used to draw the range grid-lines. */ 412 private transient Stroke rangeGridlineStroke; 413 414 /** The paint used to draw the range grid-lines. */ 415 private transient Paint rangeGridlinePaint; 416 417 /** 418 * A flag that controls whether the domain minor grid-lines are visible. 419 * 420 * @since 1.0.12 421 */ 422 private boolean domainMinorGridlinesVisible; 423 424 /** 425 * The stroke used to draw the domain minor grid-lines. 426 * 427 * @since 1.0.12 428 */ 429 private transient Stroke domainMinorGridlineStroke; 430 431 /** 432 * The paint used to draw the domain minor grid-lines. 433 * 434 * @since 1.0.12 435 */ 436 private transient Paint domainMinorGridlinePaint; 437 438 /** 439 * A flag that controls whether the range minor grid-lines are visible. 440 * 441 * @since 1.0.12 442 */ 443 private boolean rangeMinorGridlinesVisible; 444 445 /** 446 * The stroke used to draw the range minor grid-lines. 447 * 448 * @since 1.0.12 449 */ 450 private transient Stroke rangeMinorGridlineStroke; 451 452 /** 453 * The paint used to draw the range minor grid-lines. 454 * 455 * @since 1.0.12 456 */ 457 private transient Paint rangeMinorGridlinePaint; 458 459 /** 460 * A flag that controls whether or not the zero baseline against the domain 461 * axis is visible. 462 * 463 * @since 1.0.5 464 */ 465 private boolean domainZeroBaselineVisible; 466 467 /** 468 * The stroke used for the zero baseline against the domain axis. 469 * 470 * @since 1.0.5 471 */ 472 private transient Stroke domainZeroBaselineStroke; 473 474 /** 475 * The paint used for the zero baseline against the domain axis. 476 * 477 * @since 1.0.5 478 */ 479 private transient Paint domainZeroBaselinePaint; 480 481 /** 482 * A flag that controls whether or not the zero baseline against the range 483 * axis is visible. 484 */ 485 private boolean rangeZeroBaselineVisible; 486 487 /** The stroke used for the zero baseline against the range axis. */ 488 private transient Stroke rangeZeroBaselineStroke; 489 490 /** The paint used for the zero baseline against the range axis. */ 491 private transient Paint rangeZeroBaselinePaint; 492 493 /** A flag that controls whether or not a domain crosshair is drawn..*/ 494 private boolean domainCrosshairVisible; 495 496 /** The domain crosshair value. */ 497 private double domainCrosshairValue; 498 499 /** The pen/brush used to draw the crosshair (if any). */ 500 private transient Stroke domainCrosshairStroke; 501 502 /** The color used to draw the crosshair (if any). */ 503 private transient Paint domainCrosshairPaint; 504 505 /** 506 * A flag that controls whether or not the crosshair locks onto actual 507 * data points. 508 */ 509 private boolean domainCrosshairLockedOnData = true; 510 511 /** A flag that controls whether or not a range crosshair is drawn..*/ 512 private boolean rangeCrosshairVisible; 513 514 /** The range crosshair value. */ 515 private double rangeCrosshairValue; 516 517 /** The pen/brush used to draw the crosshair (if any). */ 518 private transient Stroke rangeCrosshairStroke; 519 520 /** The color used to draw the crosshair (if any). */ 521 private transient Paint rangeCrosshairPaint; 522 523 /** 524 * A flag that controls whether or not the crosshair locks onto actual 525 * data points. 526 */ 527 private boolean rangeCrosshairLockedOnData = true; 528 529 /** A map of lists of foreground markers (optional) for the domain axes. */ 530 private Map foregroundDomainMarkers; 531 532 /** A map of lists of background markers (optional) for the domain axes. */ 533 private Map backgroundDomainMarkers; 534 535 /** A map of lists of foreground markers (optional) for the range axes. */ 536 private Map foregroundRangeMarkers; 537 538 /** A map of lists of background markers (optional) for the range axes. */ 539 private Map backgroundRangeMarkers; 540 541 /** 542 * A (possibly empty) list of annotations for the plot. The list should 543 * be initialised in the constructor and never allowed to be 544 * {@code null}. 545 */ 546 private List<XYAnnotation> annotations; 547 548 /** The paint used for the domain tick bands (if any). */ 549 private transient Paint domainTickBandPaint; 550 551 /** The paint used for the range tick bands (if any). */ 552 private transient Paint rangeTickBandPaint; 553 554 /** The fixed domain axis space. */ 555 private AxisSpace fixedDomainAxisSpace; 556 557 /** The fixed range axis space. */ 558 private AxisSpace fixedRangeAxisSpace; 559 560 /** 561 * The order of the dataset rendering (REVERSE draws the primary dataset 562 * last so that it appears to be on top). 563 */ 564 private DatasetRenderingOrder datasetRenderingOrder 565 = DatasetRenderingOrder.REVERSE; 566 567 /** 568 * The order of the series rendering (REVERSE draws the primary series 569 * last so that it appears to be on top). 570 */ 571 private SeriesRenderingOrder seriesRenderingOrder 572 = SeriesRenderingOrder.REVERSE; 573 574 /** 575 * The weight for this plot (only relevant if this is a subplot in a 576 * combined plot). 577 */ 578 private int weight; 579 580 /** 581 * An optional collection of legend items that can be returned by the 582 * getLegendItems() method. 583 */ 584 private LegendItemCollection fixedLegendItems; 585 586 /** 587 * A flag that controls whether or not panning is enabled for the domain 588 * axis/axes. 589 * 590 * @since 1.0.13 591 */ 592 private boolean domainPannable; 593 594 /** 595 * A flag that controls whether or not panning is enabled for the range 596 * axis/axes. 597 * 598 * @since 1.0.13 599 */ 600 private boolean rangePannable; 601 602 /** 603 * The shadow generator ({@code null} permitted). 604 * 605 * @since 1.0.14 606 */ 607 private ShadowGenerator shadowGenerator; 608 609 /** 610 * Creates a new {@code XYPlot} instance with no dataset, no axes and 611 * no renderer. You should specify these items before using the plot. 612 */ 613 public XYPlot() { 614 this(null, null, null, null); 615 } 616 617 /** 618 * Creates a new plot with the specified dataset, axes and renderer. Any 619 * of the arguments can be {@code null}, but in that case you should 620 * take care to specify the value before using the plot (otherwise a 621 * {@code NullPointerException} may be thrown). 622 * 623 * @param dataset the dataset ({@code null} permitted). 624 * @param domainAxis the domain axis ({@code null} permitted). 625 * @param rangeAxis the range axis ({@code null} permitted). 626 * @param renderer the renderer ({@code null} permitted). 627 */ 628 public XYPlot(XYDataset dataset, ValueAxis domainAxis, ValueAxis rangeAxis, 629 XYItemRenderer renderer) { 630 super(); 631 this.orientation = PlotOrientation.VERTICAL; 632 this.weight = 1; // only relevant when this is a subplot 633 this.axisOffset = RectangleInsets.ZERO_INSETS; 634 635 // allocate storage for datasets, axes and renderers (all optional) 636 this.domainAxes = new HashMap<Integer, ValueAxis>(); 637 this.domainAxisLocations = new HashMap<Integer, AxisLocation>(); 638 this.foregroundDomainMarkers = new HashMap(); 639 this.backgroundDomainMarkers = new HashMap(); 640 641 this.rangeAxes = new HashMap<Integer, ValueAxis>(); 642 this.rangeAxisLocations = new HashMap<Integer, AxisLocation>(); 643 this.foregroundRangeMarkers = new HashMap(); 644 this.backgroundRangeMarkers = new HashMap(); 645 646 this.datasets = new HashMap<Integer, XYDataset>(); 647 this.renderers = new HashMap<Integer, XYItemRenderer>(); 648 649 this.datasetToDomainAxesMap = new TreeMap(); 650 this.datasetToRangeAxesMap = new TreeMap(); 651 652 this.annotations = new java.util.ArrayList(); 653 654 this.datasets.put(0, dataset); 655 if (dataset != null) { 656 dataset.addChangeListener(this); 657 } 658 659 this.renderers.put(0, renderer); 660 if (renderer != null) { 661 renderer.setPlot(this); 662 renderer.addChangeListener(this); 663 } 664 665 this.domainAxes.put(0, domainAxis); 666 mapDatasetToDomainAxis(0, 0); 667 if (domainAxis != null) { 668 domainAxis.setPlot(this); 669 domainAxis.addChangeListener(this); 670 } 671 this.domainAxisLocations.put(0, AxisLocation.BOTTOM_OR_LEFT); 672 673 this.rangeAxes.put(0, rangeAxis); 674 mapDatasetToRangeAxis(0, 0); 675 if (rangeAxis != null) { 676 rangeAxis.setPlot(this); 677 rangeAxis.addChangeListener(this); 678 } 679 this.rangeAxisLocations.put(0, AxisLocation.BOTTOM_OR_LEFT); 680 681 configureDomainAxes(); 682 configureRangeAxes(); 683 684 this.domainGridlinesVisible = true; 685 this.domainGridlineStroke = DEFAULT_GRIDLINE_STROKE; 686 this.domainGridlinePaint = DEFAULT_GRIDLINE_PAINT; 687 688 this.domainMinorGridlinesVisible = false; 689 this.domainMinorGridlineStroke = DEFAULT_GRIDLINE_STROKE; 690 this.domainMinorGridlinePaint = Color.WHITE; 691 692 this.domainZeroBaselineVisible = false; 693 this.domainZeroBaselinePaint = Color.BLACK; 694 this.domainZeroBaselineStroke = new BasicStroke(0.5f); 695 696 this.rangeGridlinesVisible = true; 697 this.rangeGridlineStroke = DEFAULT_GRIDLINE_STROKE; 698 this.rangeGridlinePaint = DEFAULT_GRIDLINE_PAINT; 699 700 this.rangeMinorGridlinesVisible = false; 701 this.rangeMinorGridlineStroke = DEFAULT_GRIDLINE_STROKE; 702 this.rangeMinorGridlinePaint = Color.WHITE; 703 704 this.rangeZeroBaselineVisible = false; 705 this.rangeZeroBaselinePaint = Color.BLACK; 706 this.rangeZeroBaselineStroke = new BasicStroke(0.5f); 707 708 this.domainCrosshairVisible = false; 709 this.domainCrosshairValue = 0.0; 710 this.domainCrosshairStroke = DEFAULT_CROSSHAIR_STROKE; 711 this.domainCrosshairPaint = DEFAULT_CROSSHAIR_PAINT; 712 713 this.rangeCrosshairVisible = false; 714 this.rangeCrosshairValue = 0.0; 715 this.rangeCrosshairStroke = DEFAULT_CROSSHAIR_STROKE; 716 this.rangeCrosshairPaint = DEFAULT_CROSSHAIR_PAINT; 717 this.shadowGenerator = null; 718 } 719 720 /** 721 * Returns the plot type as a string. 722 * 723 * @return A short string describing the type of plot. 724 */ 725 @Override 726 public String getPlotType() { 727 return localizationResources.getString("XY_Plot"); 728 } 729 730 /** 731 * Returns the orientation of the plot. 732 * 733 * @return The orientation (never {@code null}). 734 * 735 * @see #setOrientation(PlotOrientation) 736 */ 737 @Override 738 public PlotOrientation getOrientation() { 739 return this.orientation; 740 } 741 742 /** 743 * Sets the orientation for the plot and sends a {@link PlotChangeEvent} to 744 * all registered listeners. 745 * 746 * @param orientation the orientation ({@code null} not allowed). 747 * 748 * @see #getOrientation() 749 */ 750 public void setOrientation(PlotOrientation orientation) { 751 Args.nullNotPermitted(orientation, "orientation"); 752 if (orientation != this.orientation) { 753 this.orientation = orientation; 754 fireChangeEvent(); 755 } 756 } 757 758 /** 759 * Returns the axis offset. 760 * 761 * @return The axis offset (never {@code null}). 762 * 763 * @see #setAxisOffset(RectangleInsets) 764 */ 765 public RectangleInsets getAxisOffset() { 766 return this.axisOffset; 767 } 768 769 /** 770 * Sets the axis offsets (gap between the data area and the axes) and sends 771 * a {@link PlotChangeEvent} to all registered listeners. 772 * 773 * @param offset the offset ({@code null} not permitted). 774 * 775 * @see #getAxisOffset() 776 */ 777 public void setAxisOffset(RectangleInsets offset) { 778 Args.nullNotPermitted(offset, "offset"); 779 this.axisOffset = offset; 780 fireChangeEvent(); 781 } 782 783 /** 784 * Returns the domain axis with index 0. If the domain axis for this plot 785 * is {@code null}, then the method will return the parent plot's 786 * domain axis (if there is a parent plot). 787 * 788 * @return The domain axis (possibly {@code null}). 789 * 790 * @see #getDomainAxis(int) 791 * @see #setDomainAxis(ValueAxis) 792 */ 793 public ValueAxis getDomainAxis() { 794 return getDomainAxis(0); 795 } 796 797 /** 798 * Returns the domain axis with the specified index, or {@code null} if 799 * there is no axis with that index. 800 * 801 * @param index the axis index. 802 * 803 * @return The axis ({@code null} possible). 804 * 805 * @see #setDomainAxis(int, ValueAxis) 806 */ 807 public ValueAxis getDomainAxis(int index) { 808 ValueAxis result = this.domainAxes.get(index); 809 if (result == null) { 810 Plot parent = getParent(); 811 if (parent instanceof XYPlot) { 812 XYPlot xy = (XYPlot) parent; 813 result = xy.getDomainAxis(index); 814 } 815 } 816 return result; 817 } 818 819 /** 820 * Sets the domain axis for the plot and sends a {@link PlotChangeEvent} 821 * to all registered listeners. 822 * 823 * @param axis the new axis ({@code null} permitted). 824 * 825 * @see #getDomainAxis() 826 * @see #setDomainAxis(int, ValueAxis) 827 */ 828 public void setDomainAxis(ValueAxis axis) { 829 setDomainAxis(0, axis); 830 } 831 832 /** 833 * Sets a domain axis and sends a {@link PlotChangeEvent} to all 834 * registered listeners. 835 * 836 * @param index the axis index. 837 * @param axis the axis ({@code null} permitted). 838 * 839 * @see #getDomainAxis(int) 840 * @see #setRangeAxis(int, ValueAxis) 841 */ 842 public void setDomainAxis(int index, ValueAxis axis) { 843 setDomainAxis(index, axis, true); 844 } 845 846 /** 847 * Sets a domain axis and, if requested, sends a {@link PlotChangeEvent} to 848 * all registered listeners. 849 * 850 * @param index the axis index. 851 * @param axis the axis. 852 * @param notify notify listeners? 853 * 854 * @see #getDomainAxis(int) 855 */ 856 public void setDomainAxis(int index, ValueAxis axis, boolean notify) { 857 ValueAxis existing = getDomainAxis(index); 858 if (existing != null) { 859 existing.removeChangeListener(this); 860 } 861 if (axis != null) { 862 axis.setPlot(this); 863 } 864 this.domainAxes.put(index, axis); 865 if (axis != null) { 866 axis.configure(); 867 axis.addChangeListener(this); 868 } 869 if (notify) { 870 fireChangeEvent(); 871 } 872 } 873 874 /** 875 * Sets the domain axes for this plot and sends a {@link PlotChangeEvent} 876 * to all registered listeners. 877 * 878 * @param axes the axes ({@code null} not permitted). 879 * 880 * @see #setRangeAxes(ValueAxis[]) 881 */ 882 public void setDomainAxes(ValueAxis[] axes) { 883 for (int i = 0; i < axes.length; i++) { 884 setDomainAxis(i, axes[i], false); 885 } 886 fireChangeEvent(); 887 } 888 889 /** 890 * Returns the location of the primary domain axis. 891 * 892 * @return The location (never {@code null}). 893 * 894 * @see #setDomainAxisLocation(AxisLocation) 895 */ 896 public AxisLocation getDomainAxisLocation() { 897 return (AxisLocation) this.domainAxisLocations.get(0); 898 } 899 900 /** 901 * Sets the location of the primary domain axis and sends a 902 * {@link PlotChangeEvent} to all registered listeners. 903 * 904 * @param location the location ({@code null} not permitted). 905 * 906 * @see #getDomainAxisLocation() 907 */ 908 public void setDomainAxisLocation(AxisLocation location) { 909 // delegate... 910 setDomainAxisLocation(0, location, true); 911 } 912 913 /** 914 * Sets the location of the domain axis and, if requested, sends a 915 * {@link PlotChangeEvent} to all registered listeners. 916 * 917 * @param location the location ({@code null} not permitted). 918 * @param notify notify listeners? 919 * 920 * @see #getDomainAxisLocation() 921 */ 922 public void setDomainAxisLocation(AxisLocation location, boolean notify) { 923 // delegate... 924 setDomainAxisLocation(0, location, notify); 925 } 926 927 /** 928 * Returns the edge for the primary domain axis (taking into account the 929 * plot's orientation). 930 * 931 * @return The edge. 932 * 933 * @see #getDomainAxisLocation() 934 * @see #getOrientation() 935 */ 936 public RectangleEdge getDomainAxisEdge() { 937 return Plot.resolveDomainAxisLocation(getDomainAxisLocation(), 938 this.orientation); 939 } 940 941 /** 942 * Returns the number of domain axes. 943 * 944 * @return The axis count. 945 * 946 * @see #getRangeAxisCount() 947 */ 948 public int getDomainAxisCount() { 949 return this.domainAxes.size(); 950 } 951 952 /** 953 * Clears the domain axes from the plot and sends a {@link PlotChangeEvent} 954 * to all registered listeners. 955 * 956 * @see #clearRangeAxes() 957 */ 958 public void clearDomainAxes() { 959 for (ValueAxis axis: this.domainAxes.values()) { 960 if (axis != null) { 961 axis.removeChangeListener(this); 962 } 963 } 964 this.domainAxes.clear(); 965 fireChangeEvent(); 966 } 967 968 /** 969 * Configures the domain axes. 970 */ 971 public void configureDomainAxes() { 972 for (ValueAxis axis: this.domainAxes.values()) { 973 if (axis != null) { 974 axis.configure(); 975 } 976 } 977 } 978 979 /** 980 * Returns the location for a domain axis. If this hasn't been set 981 * explicitly, the method returns the location that is opposite to the 982 * primary domain axis location. 983 * 984 * @param index the axis index (must be >= 0). 985 * 986 * @return The location (never {@code null}). 987 * 988 * @see #setDomainAxisLocation(int, AxisLocation) 989 */ 990 public AxisLocation getDomainAxisLocation(int index) { 991 AxisLocation result = this.domainAxisLocations.get(index); 992 if (result == null) { 993 result = AxisLocation.getOpposite(getDomainAxisLocation()); 994 } 995 return result; 996 } 997 998 /** 999 * Sets the location for a domain axis and sends a {@link PlotChangeEvent} 1000 * to all registered listeners. 1001 * 1002 * @param index the axis index. 1003 * @param location the location ({@code null} not permitted for index 1004 * 0). 1005 * 1006 * @see #getDomainAxisLocation(int) 1007 */ 1008 public void setDomainAxisLocation(int index, AxisLocation location) { 1009 // delegate... 1010 setDomainAxisLocation(index, location, true); 1011 } 1012 1013 /** 1014 * Sets the axis location for a domain axis and, if requested, sends a 1015 * {@link PlotChangeEvent} to all registered listeners. 1016 * 1017 * @param index the axis index (must be >= 0). 1018 * @param location the location ({@code null} not permitted for 1019 * index 0). 1020 * @param notify notify listeners? 1021 * 1022 * @since 1.0.5 1023 * 1024 * @see #getDomainAxisLocation(int) 1025 * @see #setRangeAxisLocation(int, AxisLocation, boolean) 1026 */ 1027 public void setDomainAxisLocation(int index, AxisLocation location, 1028 boolean notify) { 1029 if (index == 0 && location == null) { 1030 throw new IllegalArgumentException( 1031 "Null 'location' for index 0 not permitted."); 1032 } 1033 this.domainAxisLocations.put(index, location); 1034 if (notify) { 1035 fireChangeEvent(); 1036 } 1037 } 1038 1039 /** 1040 * Returns the edge for a domain axis. 1041 * 1042 * @param index the axis index. 1043 * 1044 * @return The edge. 1045 * 1046 * @see #getRangeAxisEdge(int) 1047 */ 1048 public RectangleEdge getDomainAxisEdge(int index) { 1049 AxisLocation location = getDomainAxisLocation(index); 1050 return Plot.resolveDomainAxisLocation(location, this.orientation); 1051 } 1052 1053 /** 1054 * Returns the range axis for the plot. If the range axis for this plot is 1055 * {@code null}, then the method will return the parent plot's range 1056 * axis (if there is a parent plot). 1057 * 1058 * @return The range axis. 1059 * 1060 * @see #getRangeAxis(int) 1061 * @see #setRangeAxis(ValueAxis) 1062 */ 1063 public ValueAxis getRangeAxis() { 1064 return getRangeAxis(0); 1065 } 1066 1067 /** 1068 * Sets the range axis for the plot and sends a {@link PlotChangeEvent} to 1069 * all registered listeners. 1070 * 1071 * @param axis the axis ({@code null} permitted). 1072 * 1073 * @see #getRangeAxis() 1074 * @see #setRangeAxis(int, ValueAxis) 1075 */ 1076 public void setRangeAxis(ValueAxis axis) { 1077 if (axis != null) { 1078 axis.setPlot(this); 1079 } 1080 // plot is likely registered as a listener with the existing axis... 1081 ValueAxis existing = getRangeAxis(); 1082 if (existing != null) { 1083 existing.removeChangeListener(this); 1084 } 1085 this.rangeAxes.put(0, axis); 1086 if (axis != null) { 1087 axis.configure(); 1088 axis.addChangeListener(this); 1089 } 1090 fireChangeEvent(); 1091 } 1092 1093 /** 1094 * Returns the location of the primary range axis. 1095 * 1096 * @return The location (never {@code null}). 1097 * 1098 * @see #setRangeAxisLocation(AxisLocation) 1099 */ 1100 public AxisLocation getRangeAxisLocation() { 1101 return (AxisLocation) this.rangeAxisLocations.get(0); 1102 } 1103 1104 /** 1105 * Sets the location of the primary range axis and sends a 1106 * {@link PlotChangeEvent} to all registered listeners. 1107 * 1108 * @param location the location ({@code null} not permitted). 1109 * 1110 * @see #getRangeAxisLocation() 1111 */ 1112 public void setRangeAxisLocation(AxisLocation location) { 1113 // delegate... 1114 setRangeAxisLocation(0, location, true); 1115 } 1116 1117 /** 1118 * Sets the location of the primary range axis and, if requested, sends a 1119 * {@link PlotChangeEvent} to all registered listeners. 1120 * 1121 * @param location the location ({@code null} not permitted). 1122 * @param notify notify listeners? 1123 * 1124 * @see #getRangeAxisLocation() 1125 */ 1126 public void setRangeAxisLocation(AxisLocation location, boolean notify) { 1127 // delegate... 1128 setRangeAxisLocation(0, location, notify); 1129 } 1130 1131 /** 1132 * Returns the edge for the primary range axis. 1133 * 1134 * @return The range axis edge. 1135 * 1136 * @see #getRangeAxisLocation() 1137 * @see #getOrientation() 1138 */ 1139 public RectangleEdge getRangeAxisEdge() { 1140 return Plot.resolveRangeAxisLocation(getRangeAxisLocation(), 1141 this.orientation); 1142 } 1143 1144 /** 1145 * Returns the range axis with the specified index, or {@code null} if 1146 * there is no axis with that index. 1147 * 1148 * @param index the axis index (must be >= 0). 1149 * 1150 * @return The axis ({@code null} possible). 1151 * 1152 * @see #setRangeAxis(int, ValueAxis) 1153 */ 1154 public ValueAxis getRangeAxis(int index) { 1155 ValueAxis result = this.rangeAxes.get(index); 1156 if (result == null) { 1157 Plot parent = getParent(); 1158 if (parent instanceof XYPlot) { 1159 XYPlot xy = (XYPlot) parent; 1160 result = xy.getRangeAxis(index); 1161 } 1162 } 1163 return result; 1164 } 1165 1166 /** 1167 * Sets a range axis and sends a {@link PlotChangeEvent} to all registered 1168 * listeners. 1169 * 1170 * @param index the axis index. 1171 * @param axis the axis ({@code null} permitted). 1172 * 1173 * @see #getRangeAxis(int) 1174 */ 1175 public void setRangeAxis(int index, ValueAxis axis) { 1176 setRangeAxis(index, axis, true); 1177 } 1178 1179 /** 1180 * Sets a range axis and, if requested, sends a {@link PlotChangeEvent} to 1181 * all registered listeners. 1182 * 1183 * @param index the axis index. 1184 * @param axis the axis ({@code null} permitted). 1185 * @param notify notify listeners? 1186 * 1187 * @see #getRangeAxis(int) 1188 */ 1189 public void setRangeAxis(int index, ValueAxis axis, boolean notify) { 1190 ValueAxis existing = getRangeAxis(index); 1191 if (existing != null) { 1192 existing.removeChangeListener(this); 1193 } 1194 if (axis != null) { 1195 axis.setPlot(this); 1196 } 1197 this.rangeAxes.put(index, axis); 1198 if (axis != null) { 1199 axis.configure(); 1200 axis.addChangeListener(this); 1201 } 1202 if (notify) { 1203 fireChangeEvent(); 1204 } 1205 } 1206 1207 /** 1208 * Sets the range axes for this plot and sends a {@link PlotChangeEvent} 1209 * to all registered listeners. 1210 * 1211 * @param axes the axes ({@code null} not permitted). 1212 * 1213 * @see #setDomainAxes(ValueAxis[]) 1214 */ 1215 public void setRangeAxes(ValueAxis[] axes) { 1216 for (int i = 0; i < axes.length; i++) { 1217 setRangeAxis(i, axes[i], false); 1218 } 1219 fireChangeEvent(); 1220 } 1221 1222 /** 1223 * Returns the number of range axes. 1224 * 1225 * @return The axis count. 1226 * 1227 * @see #getDomainAxisCount() 1228 */ 1229 public int getRangeAxisCount() { 1230 return this.rangeAxes.size(); 1231 } 1232 1233 /** 1234 * Clears the range axes from the plot and sends a {@link PlotChangeEvent} 1235 * to all registered listeners. 1236 * 1237 * @see #clearDomainAxes() 1238 */ 1239 public void clearRangeAxes() { 1240 for (ValueAxis axis: this.rangeAxes.values()) { 1241 if (axis != null) { 1242 axis.removeChangeListener(this); 1243 } 1244 } 1245 this.rangeAxes.clear(); 1246 fireChangeEvent(); 1247 } 1248 1249 /** 1250 * Configures the range axes. 1251 * 1252 * @see #configureDomainAxes() 1253 */ 1254 public void configureRangeAxes() { 1255 for (ValueAxis axis: this.rangeAxes.values()) { 1256 if (axis != null) { 1257 axis.configure(); 1258 } 1259 } 1260 } 1261 1262 /** 1263 * Returns the location for a range axis. If this hasn't been set 1264 * explicitly, the method returns the location that is opposite to the 1265 * primary range axis location. 1266 * 1267 * @param index the axis index (must be >= 0). 1268 * 1269 * @return The location (never {@code null}). 1270 * 1271 * @see #setRangeAxisLocation(int, AxisLocation) 1272 */ 1273 public AxisLocation getRangeAxisLocation(int index) { 1274 AxisLocation result = this.rangeAxisLocations.get(index); 1275 if (result == null) { 1276 result = AxisLocation.getOpposite(getRangeAxisLocation()); 1277 } 1278 return result; 1279 } 1280 1281 /** 1282 * Sets the location for a range axis and sends a {@link PlotChangeEvent} 1283 * to all registered listeners. 1284 * 1285 * @param index the axis index. 1286 * @param location the location ({@code null} permitted). 1287 * 1288 * @see #getRangeAxisLocation(int) 1289 */ 1290 public void setRangeAxisLocation(int index, AxisLocation location) { 1291 // delegate... 1292 setRangeAxisLocation(index, location, true); 1293 } 1294 1295 /** 1296 * Sets the axis location for a domain axis and, if requested, sends a 1297 * {@link PlotChangeEvent} to all registered listeners. 1298 * 1299 * @param index the axis index. 1300 * @param location the location ({@code null} not permitted for 1301 * index 0). 1302 * @param notify notify listeners? 1303 * 1304 * @since 1.0.5 1305 * 1306 * @see #getRangeAxisLocation(int) 1307 * @see #setDomainAxisLocation(int, AxisLocation, boolean) 1308 */ 1309 public void setRangeAxisLocation(int index, AxisLocation location, 1310 boolean notify) { 1311 if (index == 0 && location == null) { 1312 throw new IllegalArgumentException( 1313 "Null 'location' for index 0 not permitted."); 1314 } 1315 this.rangeAxisLocations.put(index, location); 1316 if (notify) { 1317 fireChangeEvent(); 1318 } 1319 } 1320 1321 /** 1322 * Returns the edge for a range axis. 1323 * 1324 * @param index the axis index. 1325 * 1326 * @return The edge. 1327 * 1328 * @see #getRangeAxisLocation(int) 1329 * @see #getOrientation() 1330 */ 1331 public RectangleEdge getRangeAxisEdge(int index) { 1332 AxisLocation location = getRangeAxisLocation(index); 1333 return Plot.resolveRangeAxisLocation(location, this.orientation); 1334 } 1335 1336 /** 1337 * Returns the primary dataset for the plot. 1338 * 1339 * @return The primary dataset (possibly {@code null}). 1340 * 1341 * @see #getDataset(int) 1342 * @see #setDataset(XYDataset) 1343 */ 1344 public XYDataset getDataset() { 1345 return getDataset(0); 1346 } 1347 1348 /** 1349 * Returns the dataset with the specified index, or {@code null} if there 1350 * is no dataset with that index. 1351 * 1352 * @param index the dataset index (must be >= 0). 1353 * 1354 * @return The dataset (possibly {@code null}). 1355 * 1356 * @see #setDataset(int, XYDataset) 1357 */ 1358 public XYDataset getDataset(int index) { 1359 return (XYDataset) this.datasets.get(index); 1360 } 1361 1362 /** 1363 * Sets the primary dataset for the plot, replacing the existing dataset if 1364 * there is one. 1365 * 1366 * @param dataset the dataset ({@code null} permitted). 1367 * 1368 * @see #getDataset() 1369 * @see #setDataset(int, XYDataset) 1370 */ 1371 public void setDataset(XYDataset dataset) { 1372 setDataset(0, dataset); 1373 } 1374 1375 /** 1376 * Sets a dataset for the plot and sends a change event to all registered 1377 * listeners. 1378 * 1379 * @param index the dataset index (must be >= 0). 1380 * @param dataset the dataset ({@code null} permitted). 1381 * 1382 * @see #getDataset(int) 1383 */ 1384 public void setDataset(int index, XYDataset dataset) { 1385 XYDataset existing = getDataset(index); 1386 if (existing != null) { 1387 existing.removeChangeListener(this); 1388 } 1389 this.datasets.put(index, dataset); 1390 if (dataset != null) { 1391 dataset.addChangeListener(this); 1392 } 1393 1394 // send a dataset change event to self... 1395 DatasetChangeEvent event = new DatasetChangeEvent(this, dataset); 1396 datasetChanged(event); 1397 } 1398 1399 /** 1400 * Returns the number of datasets. 1401 * 1402 * @return The number of datasets. 1403 */ 1404 public int getDatasetCount() { 1405 return this.datasets.size(); 1406 } 1407 1408 /** 1409 * Returns the index of the specified dataset, or {@code -1} if the 1410 * dataset does not belong to the plot. 1411 * 1412 * @param dataset the dataset ({@code null} not permitted). 1413 * 1414 * @return The index or -1. 1415 */ 1416 public int indexOf(XYDataset dataset) { 1417 for (Map.Entry<Integer, XYDataset> entry: this.datasets.entrySet()) { 1418 if (dataset == entry.getValue()) { 1419 return entry.getKey(); 1420 } 1421 } 1422 return -1; 1423 } 1424 1425 /** 1426 * Maps a dataset to a particular domain axis. All data will be plotted 1427 * against axis zero by default, no mapping is required for this case. 1428 * 1429 * @param index the dataset index (zero-based). 1430 * @param axisIndex the axis index. 1431 * 1432 * @see #mapDatasetToRangeAxis(int, int) 1433 */ 1434 public void mapDatasetToDomainAxis(int index, int axisIndex) { 1435 List axisIndices = new java.util.ArrayList(1); 1436 axisIndices.add(axisIndex); 1437 mapDatasetToDomainAxes(index, axisIndices); 1438 } 1439 1440 /** 1441 * Maps the specified dataset to the axes in the list. Note that the 1442 * conversion of data values into Java2D space is always performed using 1443 * the first axis in the list. 1444 * 1445 * @param index the dataset index (zero-based). 1446 * @param axisIndices the axis indices ({@code null} permitted). 1447 * 1448 * @since 1.0.12 1449 */ 1450 public void mapDatasetToDomainAxes(int index, List axisIndices) { 1451 Args.requireNonNegative(index, "index"); 1452 checkAxisIndices(axisIndices); 1453 Integer key = index; 1454 this.datasetToDomainAxesMap.put(key, new ArrayList(axisIndices)); 1455 // fake a dataset change event to update axes... 1456 datasetChanged(new DatasetChangeEvent(this, getDataset(index))); 1457 } 1458 1459 /** 1460 * Maps a dataset to a particular range axis. All data will be plotted 1461 * against axis zero by default, no mapping is required for this case. 1462 * 1463 * @param index the dataset index (zero-based). 1464 * @param axisIndex the axis index. 1465 * 1466 * @see #mapDatasetToDomainAxis(int, int) 1467 */ 1468 public void mapDatasetToRangeAxis(int index, int axisIndex) { 1469 List axisIndices = new java.util.ArrayList(1); 1470 axisIndices.add(axisIndex); 1471 mapDatasetToRangeAxes(index, axisIndices); 1472 } 1473 1474 /** 1475 * Maps the specified dataset to the axes in the list. Note that the 1476 * conversion of data values into Java2D space is always performed using 1477 * the first axis in the list. 1478 * 1479 * @param index the dataset index (zero-based). 1480 * @param axisIndices the axis indices ({@code null} permitted). 1481 * 1482 * @since 1.0.12 1483 */ 1484 public void mapDatasetToRangeAxes(int index, List axisIndices) { 1485 Args.requireNonNegative(index, "index"); 1486 checkAxisIndices(axisIndices); 1487 Integer key = index; 1488 this.datasetToRangeAxesMap.put(key, new ArrayList(axisIndices)); 1489 // fake a dataset change event to update axes... 1490 datasetChanged(new DatasetChangeEvent(this, getDataset(index))); 1491 } 1492 1493 /** 1494 * This method is used to perform argument checking on the list of 1495 * axis indices passed to mapDatasetToDomainAxes() and 1496 * mapDatasetToRangeAxes(). 1497 * 1498 * @param indices the list of indices ({@code null} permitted). 1499 */ 1500 private void checkAxisIndices(List<Integer> indices) { 1501 // axisIndices can be: 1502 // 1. null; 1503 // 2. non-empty, containing only Integer objects that are unique. 1504 if (indices == null) { 1505 return; // OK 1506 } 1507 int count = indices.size(); 1508 if (count == 0) { 1509 throw new IllegalArgumentException("Empty list not permitted."); 1510 } 1511 Set<Integer> set = new HashSet<Integer>(); 1512 for (Integer item : indices) { 1513 if (set.contains(item)) { 1514 throw new IllegalArgumentException("Indices must be unique."); 1515 } 1516 set.add(item); 1517 } 1518 } 1519 1520 /** 1521 * Returns the number of renderer slots for this plot. 1522 * 1523 * @return The number of renderer slots. 1524 * 1525 * @since 1.0.11 1526 */ 1527 public int getRendererCount() { 1528 return this.renderers.size(); 1529 } 1530 1531 /** 1532 * Returns the renderer for the primary dataset. 1533 * 1534 * @return The item renderer (possibly {@code null}). 1535 * 1536 * @see #setRenderer(XYItemRenderer) 1537 */ 1538 public XYItemRenderer getRenderer() { 1539 return getRenderer(0); 1540 } 1541 1542 /** 1543 * Returns the renderer with the specified index, or {@code null}. 1544 * 1545 * @param index the renderer index (must be >= 0). 1546 * 1547 * @return The renderer (possibly {@code null}). 1548 * 1549 * @see #setRenderer(int, XYItemRenderer) 1550 */ 1551 public XYItemRenderer getRenderer(int index) { 1552 return this.renderers.get(index); 1553 } 1554 1555 /** 1556 * Sets the renderer for the primary dataset and sends a change event to 1557 * all registered listeners. If the renderer is set to {@code null}, 1558 * no data will be displayed. 1559 * 1560 * @param renderer the renderer ({@code null} permitted). 1561 * 1562 * @see #getRenderer() 1563 */ 1564 public void setRenderer(XYItemRenderer renderer) { 1565 setRenderer(0, renderer); 1566 } 1567 1568 /** 1569 * Sets the renderer for the dataset with the specified index and sends a 1570 * change event to all registered listeners. Note that each dataset should 1571 * have its own renderer, you should not use one renderer for multiple 1572 * datasets. 1573 * 1574 * @param index the index (must be >= 0). 1575 * @param renderer the renderer. 1576 * 1577 * @see #getRenderer(int) 1578 */ 1579 public void setRenderer(int index, XYItemRenderer renderer) { 1580 setRenderer(index, renderer, true); 1581 } 1582 1583 /** 1584 * Sets the renderer for the dataset with the specified index and, if 1585 * requested, sends a change event to all registered listeners. Note that 1586 * each dataset should have its own renderer, you should not use one 1587 * renderer for multiple datasets. 1588 * 1589 * @param index the index (must be >= 0). 1590 * @param renderer the renderer. 1591 * @param notify notify listeners? 1592 * 1593 * @see #getRenderer(int) 1594 */ 1595 public void setRenderer(int index, XYItemRenderer renderer, 1596 boolean notify) { 1597 XYItemRenderer existing = getRenderer(index); 1598 if (existing != null) { 1599 existing.removeChangeListener(this); 1600 } 1601 this.renderers.put(index, renderer); 1602 if (renderer != null) { 1603 renderer.setPlot(this); 1604 renderer.addChangeListener(this); 1605 } 1606 configureDomainAxes(); 1607 configureRangeAxes(); 1608 if (notify) { 1609 fireChangeEvent(); 1610 } 1611 } 1612 1613 /** 1614 * Sets the renderers for this plot and sends a {@link PlotChangeEvent} 1615 * to all registered listeners. 1616 * 1617 * @param renderers the renderers ({@code null} not permitted). 1618 */ 1619 public void setRenderers(XYItemRenderer[] renderers) { 1620 for (int i = 0; i < renderers.length; i++) { 1621 setRenderer(i, renderers[i], false); 1622 } 1623 fireChangeEvent(); 1624 } 1625 1626 /** 1627 * Returns the dataset rendering order. 1628 * 1629 * @return The order (never {@code null}). 1630 * 1631 * @see #setDatasetRenderingOrder(DatasetRenderingOrder) 1632 */ 1633 public DatasetRenderingOrder getDatasetRenderingOrder() { 1634 return this.datasetRenderingOrder; 1635 } 1636 1637 /** 1638 * Sets the rendering order and sends a {@link PlotChangeEvent} to all 1639 * registered listeners. By default, the plot renders the primary dataset 1640 * last (so that the primary dataset overlays the secondary datasets). 1641 * You can reverse this if you want to. 1642 * 1643 * @param order the rendering order ({@code null} not permitted). 1644 * 1645 * @see #getDatasetRenderingOrder() 1646 */ 1647 public void setDatasetRenderingOrder(DatasetRenderingOrder order) { 1648 Args.nullNotPermitted(order, "order"); 1649 this.datasetRenderingOrder = order; 1650 fireChangeEvent(); 1651 } 1652 1653 /** 1654 * Returns the series rendering order. 1655 * 1656 * @return the order (never {@code null}). 1657 * 1658 * @see #setSeriesRenderingOrder(SeriesRenderingOrder) 1659 */ 1660 public SeriesRenderingOrder getSeriesRenderingOrder() { 1661 return this.seriesRenderingOrder; 1662 } 1663 1664 /** 1665 * Sets the series order and sends a {@link PlotChangeEvent} to all 1666 * registered listeners. By default, the plot renders the primary series 1667 * last (so that the primary series appears to be on top). 1668 * You can reverse this if you want to. 1669 * 1670 * @param order the rendering order ({@code null} not permitted). 1671 * 1672 * @see #getSeriesRenderingOrder() 1673 */ 1674 public void setSeriesRenderingOrder(SeriesRenderingOrder order) { 1675 Args.nullNotPermitted(order, "order"); 1676 this.seriesRenderingOrder = order; 1677 fireChangeEvent(); 1678 } 1679 1680 /** 1681 * Returns the index of the specified renderer, or {@code -1} if the 1682 * renderer is not assigned to this plot. 1683 * 1684 * @param renderer the renderer ({@code null} permitted). 1685 * 1686 * @return The renderer index. 1687 */ 1688 public int getIndexOf(XYItemRenderer renderer) { 1689 for (Map.Entry<Integer, XYItemRenderer> entry 1690 : this.renderers.entrySet()) { 1691 if (entry.getValue() == renderer) { 1692 return entry.getKey(); 1693 } 1694 } 1695 return -1; 1696 } 1697 1698 /** 1699 * Returns the renderer for the specified dataset (this is either the 1700 * renderer with the same index as the dataset or, if there isn't a 1701 * renderer with the same index, the default renderer). If the dataset 1702 * does not belong to the plot, this method will return {@code null}. 1703 * 1704 * @param dataset the dataset ({@code null} permitted). 1705 * 1706 * @return The renderer (possibly {@code null}). 1707 */ 1708 public XYItemRenderer getRendererForDataset(XYDataset dataset) { 1709 int datasetIndex = indexOf(dataset); 1710 if (datasetIndex < 0) { 1711 return null; 1712 } 1713 XYItemRenderer result = this.renderers.get(datasetIndex); 1714 if (result == null) { 1715 result = getRenderer(); 1716 } 1717 return result; 1718 } 1719 1720 /** 1721 * Returns the weight for this plot when it is used as a subplot within a 1722 * combined plot. 1723 * 1724 * @return The weight. 1725 * 1726 * @see #setWeight(int) 1727 */ 1728 public int getWeight() { 1729 return this.weight; 1730 } 1731 1732 /** 1733 * Sets the weight for the plot and sends a {@link PlotChangeEvent} to all 1734 * registered listeners. 1735 * 1736 * @param weight the weight. 1737 * 1738 * @see #getWeight() 1739 */ 1740 public void setWeight(int weight) { 1741 this.weight = weight; 1742 fireChangeEvent(); 1743 } 1744 1745 /** 1746 * Returns {@code true} if the domain gridlines are visible, and 1747 * {@code false} otherwise. 1748 * 1749 * @return {@code true} or {@code false}. 1750 * 1751 * @see #setDomainGridlinesVisible(boolean) 1752 */ 1753 public boolean isDomainGridlinesVisible() { 1754 return this.domainGridlinesVisible; 1755 } 1756 1757 /** 1758 * Sets the flag that controls whether or not the domain grid-lines are 1759 * visible. 1760 * <p> 1761 * If the flag value is changed, a {@link PlotChangeEvent} is sent to all 1762 * registered listeners. 1763 * 1764 * @param visible the new value of the flag. 1765 * 1766 * @see #isDomainGridlinesVisible() 1767 */ 1768 public void setDomainGridlinesVisible(boolean visible) { 1769 if (this.domainGridlinesVisible != visible) { 1770 this.domainGridlinesVisible = visible; 1771 fireChangeEvent(); 1772 } 1773 } 1774 1775 /** 1776 * Returns {@code true} if the domain minor gridlines are visible, and 1777 * {@code false} otherwise. 1778 * 1779 * @return {@code true} or {@code false}. 1780 * 1781 * @see #setDomainMinorGridlinesVisible(boolean) 1782 * 1783 * @since 1.0.12 1784 */ 1785 public boolean isDomainMinorGridlinesVisible() { 1786 return this.domainMinorGridlinesVisible; 1787 } 1788 1789 /** 1790 * Sets the flag that controls whether or not the domain minor grid-lines 1791 * are visible. 1792 * <p> 1793 * If the flag value is changed, a {@link PlotChangeEvent} is sent to all 1794 * registered listeners. 1795 * 1796 * @param visible the new value of the flag. 1797 * 1798 * @see #isDomainMinorGridlinesVisible() 1799 * 1800 * @since 1.0.12 1801 */ 1802 public void setDomainMinorGridlinesVisible(boolean visible) { 1803 if (this.domainMinorGridlinesVisible != visible) { 1804 this.domainMinorGridlinesVisible = visible; 1805 fireChangeEvent(); 1806 } 1807 } 1808 1809 /** 1810 * Returns the stroke for the grid-lines (if any) plotted against the 1811 * domain axis. 1812 * 1813 * @return The stroke (never {@code null}). 1814 * 1815 * @see #setDomainGridlineStroke(Stroke) 1816 */ 1817 public Stroke getDomainGridlineStroke() { 1818 return this.domainGridlineStroke; 1819 } 1820 1821 /** 1822 * Sets the stroke for the grid lines plotted against the domain axis, and 1823 * sends a {@link PlotChangeEvent} to all registered listeners. 1824 * 1825 * @param stroke the stroke ({@code null} not permitted). 1826 * 1827 * @throws IllegalArgumentException if {@code stroke} is 1828 * {@code null}. 1829 * 1830 * @see #getDomainGridlineStroke() 1831 */ 1832 public void setDomainGridlineStroke(Stroke stroke) { 1833 Args.nullNotPermitted(stroke, "stroke"); 1834 this.domainGridlineStroke = stroke; 1835 fireChangeEvent(); 1836 } 1837 1838 /** 1839 * Returns the stroke for the minor grid-lines (if any) plotted against the 1840 * domain axis. 1841 * 1842 * @return The stroke (never {@code null}). 1843 * 1844 * @see #setDomainMinorGridlineStroke(Stroke) 1845 * 1846 * @since 1.0.12 1847 */ 1848 1849 public Stroke getDomainMinorGridlineStroke() { 1850 return this.domainMinorGridlineStroke; 1851 } 1852 1853 /** 1854 * Sets the stroke for the minor grid lines plotted against the domain 1855 * axis, and sends a {@link PlotChangeEvent} to all registered listeners. 1856 * 1857 * @param stroke the stroke ({@code null} not permitted). 1858 * 1859 * @throws IllegalArgumentException if {@code stroke} is 1860 * {@code null}. 1861 * 1862 * @see #getDomainMinorGridlineStroke() 1863 * 1864 * @since 1.0.12 1865 */ 1866 public void setDomainMinorGridlineStroke(Stroke stroke) { 1867 Args.nullNotPermitted(stroke, "stroke"); 1868 this.domainMinorGridlineStroke = stroke; 1869 fireChangeEvent(); 1870 } 1871 1872 /** 1873 * Returns the paint for the grid lines (if any) plotted against the domain 1874 * axis. 1875 * 1876 * @return The paint (never {@code null}). 1877 * 1878 * @see #setDomainGridlinePaint(Paint) 1879 */ 1880 public Paint getDomainGridlinePaint() { 1881 return this.domainGridlinePaint; 1882 } 1883 1884 /** 1885 * Sets the paint for the grid lines plotted against the domain axis, and 1886 * sends a {@link PlotChangeEvent} to all registered listeners. 1887 * 1888 * @param paint the paint ({@code null} not permitted). 1889 * 1890 * @throws IllegalArgumentException if {@code Paint} is 1891 * {@code null}. 1892 * 1893 * @see #getDomainGridlinePaint() 1894 */ 1895 public void setDomainGridlinePaint(Paint paint) { 1896 Args.nullNotPermitted(paint, "paint"); 1897 this.domainGridlinePaint = paint; 1898 fireChangeEvent(); 1899 } 1900 1901 /** 1902 * Returns the paint for the minor grid lines (if any) plotted against the 1903 * domain axis. 1904 * 1905 * @return The paint (never {@code null}). 1906 * 1907 * @see #setDomainMinorGridlinePaint(Paint) 1908 * 1909 * @since 1.0.12 1910 */ 1911 public Paint getDomainMinorGridlinePaint() { 1912 return this.domainMinorGridlinePaint; 1913 } 1914 1915 /** 1916 * Sets the paint for the minor grid lines plotted against the domain axis, 1917 * and sends a {@link PlotChangeEvent} to all registered listeners. 1918 * 1919 * @param paint the paint ({@code null} not permitted). 1920 * 1921 * @throws IllegalArgumentException if {@code Paint} is 1922 * {@code null}. 1923 * 1924 * @see #getDomainMinorGridlinePaint() 1925 * 1926 * @since 1.0.12 1927 */ 1928 public void setDomainMinorGridlinePaint(Paint paint) { 1929 Args.nullNotPermitted(paint, "paint"); 1930 this.domainMinorGridlinePaint = paint; 1931 fireChangeEvent(); 1932 } 1933 1934 /** 1935 * Returns {@code true} if the range axis grid is visible, and 1936 * {@code false} otherwise. 1937 * 1938 * @return A boolean. 1939 * 1940 * @see #setRangeGridlinesVisible(boolean) 1941 */ 1942 public boolean isRangeGridlinesVisible() { 1943 return this.rangeGridlinesVisible; 1944 } 1945 1946 /** 1947 * Sets the flag that controls whether or not the range axis grid lines 1948 * are visible. 1949 * <p> 1950 * If the flag value is changed, a {@link PlotChangeEvent} is sent to all 1951 * registered listeners. 1952 * 1953 * @param visible the new value of the flag. 1954 * 1955 * @see #isRangeGridlinesVisible() 1956 */ 1957 public void setRangeGridlinesVisible(boolean visible) { 1958 if (this.rangeGridlinesVisible != visible) { 1959 this.rangeGridlinesVisible = visible; 1960 fireChangeEvent(); 1961 } 1962 } 1963 1964 /** 1965 * Returns the stroke for the grid lines (if any) plotted against the 1966 * range axis. 1967 * 1968 * @return The stroke (never {@code null}). 1969 * 1970 * @see #setRangeGridlineStroke(Stroke) 1971 */ 1972 public Stroke getRangeGridlineStroke() { 1973 return this.rangeGridlineStroke; 1974 } 1975 1976 /** 1977 * Sets the stroke for the grid lines plotted against the range axis, 1978 * and sends a {@link PlotChangeEvent} to all registered listeners. 1979 * 1980 * @param stroke the stroke ({@code null} not permitted). 1981 * 1982 * @see #getRangeGridlineStroke() 1983 */ 1984 public void setRangeGridlineStroke(Stroke stroke) { 1985 Args.nullNotPermitted(stroke, "stroke"); 1986 this.rangeGridlineStroke = stroke; 1987 fireChangeEvent(); 1988 } 1989 1990 /** 1991 * Returns the paint for the grid lines (if any) plotted against the range 1992 * axis. 1993 * 1994 * @return The paint (never {@code null}). 1995 * 1996 * @see #setRangeGridlinePaint(Paint) 1997 */ 1998 public Paint getRangeGridlinePaint() { 1999 return this.rangeGridlinePaint; 2000 } 2001 2002 /** 2003 * Sets the paint for the grid lines plotted against the range axis and 2004 * sends a {@link PlotChangeEvent} to all registered listeners. 2005 * 2006 * @param paint the paint ({@code null} not permitted). 2007 * 2008 * @see #getRangeGridlinePaint() 2009 */ 2010 public void setRangeGridlinePaint(Paint paint) { 2011 Args.nullNotPermitted(paint, "paint"); 2012 this.rangeGridlinePaint = paint; 2013 fireChangeEvent(); 2014 } 2015 2016 /** 2017 * Returns {@code true} if the range axis minor grid is visible, and 2018 * {@code false} otherwise. 2019 * 2020 * @return A boolean. 2021 * 2022 * @see #setRangeMinorGridlinesVisible(boolean) 2023 * 2024 * @since 1.0.12 2025 */ 2026 public boolean isRangeMinorGridlinesVisible() { 2027 return this.rangeMinorGridlinesVisible; 2028 } 2029 2030 /** 2031 * Sets the flag that controls whether or not the range axis minor grid 2032 * lines are visible. 2033 * <p> 2034 * If the flag value is changed, a {@link PlotChangeEvent} is sent to all 2035 * registered listeners. 2036 * 2037 * @param visible the new value of the flag. 2038 * 2039 * @see #isRangeMinorGridlinesVisible() 2040 * 2041 * @since 1.0.12 2042 */ 2043 public void setRangeMinorGridlinesVisible(boolean visible) { 2044 if (this.rangeMinorGridlinesVisible != visible) { 2045 this.rangeMinorGridlinesVisible = visible; 2046 fireChangeEvent(); 2047 } 2048 } 2049 2050 /** 2051 * Returns the stroke for the minor grid lines (if any) plotted against the 2052 * range axis. 2053 * 2054 * @return The stroke (never {@code null}). 2055 * 2056 * @see #setRangeMinorGridlineStroke(Stroke) 2057 * 2058 * @since 1.0.12 2059 */ 2060 public Stroke getRangeMinorGridlineStroke() { 2061 return this.rangeMinorGridlineStroke; 2062 } 2063 2064 /** 2065 * Sets the stroke for the minor grid lines plotted against the range axis, 2066 * and sends a {@link PlotChangeEvent} to all registered listeners. 2067 * 2068 * @param stroke the stroke ({@code null} not permitted). 2069 * 2070 * @see #getRangeMinorGridlineStroke() 2071 * 2072 * @since 1.0.12 2073 */ 2074 public void setRangeMinorGridlineStroke(Stroke stroke) { 2075 Args.nullNotPermitted(stroke, "stroke"); 2076 this.rangeMinorGridlineStroke = stroke; 2077 fireChangeEvent(); 2078 } 2079 2080 /** 2081 * Returns the paint for the minor grid lines (if any) plotted against the 2082 * range axis. 2083 * 2084 * @return The paint (never {@code null}). 2085 * 2086 * @see #setRangeMinorGridlinePaint(Paint) 2087 * 2088 * @since 1.0.12 2089 */ 2090 public Paint getRangeMinorGridlinePaint() { 2091 return this.rangeMinorGridlinePaint; 2092 } 2093 2094 /** 2095 * Sets the paint for the minor grid lines plotted against the range axis 2096 * and sends a {@link PlotChangeEvent} to all registered listeners. 2097 * 2098 * @param paint the paint ({@code null} not permitted). 2099 * 2100 * @see #getRangeMinorGridlinePaint() 2101 * 2102 * @since 1.0.12 2103 */ 2104 public void setRangeMinorGridlinePaint(Paint paint) { 2105 Args.nullNotPermitted(paint, "paint"); 2106 this.rangeMinorGridlinePaint = paint; 2107 fireChangeEvent(); 2108 } 2109 2110 /** 2111 * Returns a flag that controls whether or not a zero baseline is 2112 * displayed for the domain axis. 2113 * 2114 * @return A boolean. 2115 * 2116 * @since 1.0.5 2117 * 2118 * @see #setDomainZeroBaselineVisible(boolean) 2119 */ 2120 public boolean isDomainZeroBaselineVisible() { 2121 return this.domainZeroBaselineVisible; 2122 } 2123 2124 /** 2125 * Sets the flag that controls whether or not the zero baseline is 2126 * displayed for the domain axis, and sends a {@link PlotChangeEvent} to 2127 * all registered listeners. 2128 * 2129 * @param visible the flag. 2130 * 2131 * @since 1.0.5 2132 * 2133 * @see #isDomainZeroBaselineVisible() 2134 */ 2135 public void setDomainZeroBaselineVisible(boolean visible) { 2136 this.domainZeroBaselineVisible = visible; 2137 fireChangeEvent(); 2138 } 2139 2140 /** 2141 * Returns the stroke used for the zero baseline against the domain axis. 2142 * 2143 * @return The stroke (never {@code null}). 2144 * 2145 * @since 1.0.5 2146 * 2147 * @see #setDomainZeroBaselineStroke(Stroke) 2148 */ 2149 public Stroke getDomainZeroBaselineStroke() { 2150 return this.domainZeroBaselineStroke; 2151 } 2152 2153 /** 2154 * Sets the stroke for the zero baseline for the domain axis, 2155 * and sends a {@link PlotChangeEvent} to all registered listeners. 2156 * 2157 * @param stroke the stroke ({@code null} not permitted). 2158 * 2159 * @since 1.0.5 2160 * 2161 * @see #getRangeZeroBaselineStroke() 2162 */ 2163 public void setDomainZeroBaselineStroke(Stroke stroke) { 2164 Args.nullNotPermitted(stroke, "stroke"); 2165 this.domainZeroBaselineStroke = stroke; 2166 fireChangeEvent(); 2167 } 2168 2169 /** 2170 * Returns the paint for the zero baseline (if any) plotted against the 2171 * domain axis. 2172 * 2173 * @since 1.0.5 2174 * 2175 * @return The paint (never {@code null}). 2176 * 2177 * @see #setDomainZeroBaselinePaint(Paint) 2178 */ 2179 public Paint getDomainZeroBaselinePaint() { 2180 return this.domainZeroBaselinePaint; 2181 } 2182 2183 /** 2184 * Sets the paint for the zero baseline plotted against the domain axis and 2185 * sends a {@link PlotChangeEvent} to all registered listeners. 2186 * 2187 * @param paint the paint ({@code null} not permitted). 2188 * 2189 * @since 1.0.5 2190 * 2191 * @see #getDomainZeroBaselinePaint() 2192 */ 2193 public void setDomainZeroBaselinePaint(Paint paint) { 2194 Args.nullNotPermitted(paint, "paint"); 2195 this.domainZeroBaselinePaint = paint; 2196 fireChangeEvent(); 2197 } 2198 2199 /** 2200 * Returns a flag that controls whether or not a zero baseline is 2201 * displayed for the range axis. 2202 * 2203 * @return A boolean. 2204 * 2205 * @see #setRangeZeroBaselineVisible(boolean) 2206 */ 2207 public boolean isRangeZeroBaselineVisible() { 2208 return this.rangeZeroBaselineVisible; 2209 } 2210 2211 /** 2212 * Sets the flag that controls whether or not the zero baseline is 2213 * displayed for the range axis, and sends a {@link PlotChangeEvent} to 2214 * all registered listeners. 2215 * 2216 * @param visible the flag. 2217 * 2218 * @see #isRangeZeroBaselineVisible() 2219 */ 2220 public void setRangeZeroBaselineVisible(boolean visible) { 2221 this.rangeZeroBaselineVisible = visible; 2222 fireChangeEvent(); 2223 } 2224 2225 /** 2226 * Returns the stroke used for the zero baseline against the range axis. 2227 * 2228 * @return The stroke (never {@code null}). 2229 * 2230 * @see #setRangeZeroBaselineStroke(Stroke) 2231 */ 2232 public Stroke getRangeZeroBaselineStroke() { 2233 return this.rangeZeroBaselineStroke; 2234 } 2235 2236 /** 2237 * Sets the stroke for the zero baseline for the range axis, 2238 * and sends a {@link PlotChangeEvent} to all registered listeners. 2239 * 2240 * @param stroke the stroke ({@code null} not permitted). 2241 * 2242 * @see #getRangeZeroBaselineStroke() 2243 */ 2244 public void setRangeZeroBaselineStroke(Stroke stroke) { 2245 Args.nullNotPermitted(stroke, "stroke"); 2246 this.rangeZeroBaselineStroke = stroke; 2247 fireChangeEvent(); 2248 } 2249 2250 /** 2251 * Returns the paint for the zero baseline (if any) plotted against the 2252 * range axis. 2253 * 2254 * @return The paint (never {@code null}). 2255 * 2256 * @see #setRangeZeroBaselinePaint(Paint) 2257 */ 2258 public Paint getRangeZeroBaselinePaint() { 2259 return this.rangeZeroBaselinePaint; 2260 } 2261 2262 /** 2263 * Sets the paint for the zero baseline plotted against the range axis and 2264 * sends a {@link PlotChangeEvent} to all registered listeners. 2265 * 2266 * @param paint the paint ({@code null} not permitted). 2267 * 2268 * @see #getRangeZeroBaselinePaint() 2269 */ 2270 public void setRangeZeroBaselinePaint(Paint paint) { 2271 Args.nullNotPermitted(paint, "paint"); 2272 this.rangeZeroBaselinePaint = paint; 2273 fireChangeEvent(); 2274 } 2275 2276 /** 2277 * Returns the paint used for the domain tick bands. If this is 2278 * {@code null}, no tick bands will be drawn. 2279 * 2280 * @return The paint (possibly {@code null}). 2281 * 2282 * @see #setDomainTickBandPaint(Paint) 2283 */ 2284 public Paint getDomainTickBandPaint() { 2285 return this.domainTickBandPaint; 2286 } 2287 2288 /** 2289 * Sets the paint for the domain tick bands. 2290 * 2291 * @param paint the paint ({@code null} permitted). 2292 * 2293 * @see #getDomainTickBandPaint() 2294 */ 2295 public void setDomainTickBandPaint(Paint paint) { 2296 this.domainTickBandPaint = paint; 2297 fireChangeEvent(); 2298 } 2299 2300 /** 2301 * Returns the paint used for the range tick bands. If this is 2302 * {@code null}, no tick bands will be drawn. 2303 * 2304 * @return The paint (possibly {@code null}). 2305 * 2306 * @see #setRangeTickBandPaint(Paint) 2307 */ 2308 public Paint getRangeTickBandPaint() { 2309 return this.rangeTickBandPaint; 2310 } 2311 2312 /** 2313 * Sets the paint for the range tick bands. 2314 * 2315 * @param paint the paint ({@code null} permitted). 2316 * 2317 * @see #getRangeTickBandPaint() 2318 */ 2319 public void setRangeTickBandPaint(Paint paint) { 2320 this.rangeTickBandPaint = paint; 2321 fireChangeEvent(); 2322 } 2323 2324 /** 2325 * Returns the origin for the quadrants that can be displayed on the plot. 2326 * This defaults to (0, 0). 2327 * 2328 * @return The origin point (never {@code null}). 2329 * 2330 * @see #setQuadrantOrigin(Point2D) 2331 */ 2332 public Point2D getQuadrantOrigin() { 2333 return this.quadrantOrigin; 2334 } 2335 2336 /** 2337 * Sets the quadrant origin and sends a {@link PlotChangeEvent} to all 2338 * registered listeners. 2339 * 2340 * @param origin the origin ({@code null} not permitted). 2341 * 2342 * @see #getQuadrantOrigin() 2343 */ 2344 public void setQuadrantOrigin(Point2D origin) { 2345 Args.nullNotPermitted(origin, "origin"); 2346 this.quadrantOrigin = origin; 2347 fireChangeEvent(); 2348 } 2349 2350 /** 2351 * Returns the paint used for the specified quadrant. 2352 * 2353 * @param index the quadrant index (0-3). 2354 * 2355 * @return The paint (possibly {@code null}). 2356 * 2357 * @see #setQuadrantPaint(int, Paint) 2358 */ 2359 public Paint getQuadrantPaint(int index) { 2360 if (index < 0 || index > 3) { 2361 throw new IllegalArgumentException("The index value (" + index 2362 + ") should be in the range 0 to 3."); 2363 } 2364 return this.quadrantPaint[index]; 2365 } 2366 2367 /** 2368 * Sets the paint used for the specified quadrant and sends a 2369 * {@link PlotChangeEvent} to all registered listeners. 2370 * 2371 * @param index the quadrant index (0-3). 2372 * @param paint the paint ({@code null} permitted). 2373 * 2374 * @see #getQuadrantPaint(int) 2375 */ 2376 public void setQuadrantPaint(int index, Paint paint) { 2377 if (index < 0 || index > 3) { 2378 throw new IllegalArgumentException("The index value (" + index 2379 + ") should be in the range 0 to 3."); 2380 } 2381 this.quadrantPaint[index] = paint; 2382 fireChangeEvent(); 2383 } 2384 2385 /** 2386 * Adds a marker for the domain axis and sends a {@link PlotChangeEvent} 2387 * to all registered listeners. 2388 * <P> 2389 * Typically a marker will be drawn by the renderer as a line perpendicular 2390 * to the domain axis, however this is entirely up to the renderer. 2391 * 2392 * @param marker the marker ({@code null} not permitted). 2393 * 2394 * @see #addDomainMarker(Marker, Layer) 2395 * @see #clearDomainMarkers() 2396 */ 2397 public void addDomainMarker(Marker marker) { 2398 // defer argument checking... 2399 addDomainMarker(marker, Layer.FOREGROUND); 2400 } 2401 2402 /** 2403 * Adds a marker for the domain axis in the specified layer and sends a 2404 * {@link PlotChangeEvent} to all registered listeners. 2405 * <P> 2406 * Typically a marker will be drawn by the renderer as a line perpendicular 2407 * to the domain axis, however this is entirely up to the renderer. 2408 * 2409 * @param marker the marker ({@code null} not permitted). 2410 * @param layer the layer (foreground or background). 2411 * 2412 * @see #addDomainMarker(int, Marker, Layer) 2413 */ 2414 public void addDomainMarker(Marker marker, Layer layer) { 2415 addDomainMarker(0, marker, layer); 2416 } 2417 2418 /** 2419 * Clears all the (foreground and background) domain markers and sends a 2420 * {@link PlotChangeEvent} to all registered listeners. 2421 * 2422 * @see #addDomainMarker(int, Marker, Layer) 2423 */ 2424 public void clearDomainMarkers() { 2425 if (this.backgroundDomainMarkers != null) { 2426 Set<Integer> keys = this.backgroundDomainMarkers.keySet(); 2427 for (Integer key : keys) { 2428 clearDomainMarkers(key); 2429 } 2430 this.backgroundDomainMarkers.clear(); 2431 } 2432 if (this.foregroundDomainMarkers != null) { 2433 Set<Integer> keys = this.foregroundDomainMarkers.keySet(); 2434 for (Integer key : keys) { 2435 clearDomainMarkers(key); 2436 } 2437 this.foregroundDomainMarkers.clear(); 2438 } 2439 fireChangeEvent(); 2440 } 2441 2442 /** 2443 * Clears the (foreground and background) domain markers for a particular 2444 * renderer and sends a {@link PlotChangeEvent} to all registered listeners. 2445 * 2446 * @param index the renderer index. 2447 * 2448 * @see #clearRangeMarkers(int) 2449 */ 2450 public void clearDomainMarkers(int index) { 2451 Integer key = index; 2452 if (this.backgroundDomainMarkers != null) { 2453 Collection markers 2454 = (Collection) this.backgroundDomainMarkers.get(key); 2455 if (markers != null) { 2456 Iterator iterator = markers.iterator(); 2457 while (iterator.hasNext()) { 2458 Marker m = (Marker) iterator.next(); 2459 m.removeChangeListener(this); 2460 } 2461 markers.clear(); 2462 } 2463 } 2464 if (this.foregroundRangeMarkers != null) { 2465 Collection markers 2466 = (Collection) this.foregroundDomainMarkers.get(key); 2467 if (markers != null) { 2468 Iterator iterator = markers.iterator(); 2469 while (iterator.hasNext()) { 2470 Marker m = (Marker) iterator.next(); 2471 m.removeChangeListener(this); 2472 } 2473 markers.clear(); 2474 } 2475 } 2476 fireChangeEvent(); 2477 } 2478 2479 /** 2480 * Adds a marker for a specific dataset/renderer and sends a 2481 * {@link PlotChangeEvent} to all registered listeners. 2482 * <P> 2483 * Typically a marker will be drawn by the renderer as a line perpendicular 2484 * to the domain axis (that the renderer is mapped to), however this is 2485 * entirely up to the renderer. 2486 * 2487 * @param index the dataset/renderer index. 2488 * @param marker the marker. 2489 * @param layer the layer (foreground or background). 2490 * 2491 * @see #clearDomainMarkers(int) 2492 * @see #addRangeMarker(int, Marker, Layer) 2493 */ 2494 public void addDomainMarker(int index, Marker marker, Layer layer) { 2495 addDomainMarker(index, marker, layer, true); 2496 } 2497 2498 /** 2499 * Adds a marker for a specific dataset/renderer and, if requested, sends a 2500 * {@link PlotChangeEvent} to all registered listeners. 2501 * <P> 2502 * Typically a marker will be drawn by the renderer as a line perpendicular 2503 * to the domain axis (that the renderer is mapped to), however this is 2504 * entirely up to the renderer. 2505 * 2506 * @param index the dataset/renderer index. 2507 * @param marker the marker. 2508 * @param layer the layer (foreground or background). 2509 * @param notify notify listeners? 2510 * 2511 * @since 1.0.10 2512 */ 2513 public void addDomainMarker(int index, Marker marker, Layer layer, 2514 boolean notify) { 2515 Args.nullNotPermitted(marker, "marker"); 2516 Args.nullNotPermitted(layer, "layer"); 2517 Collection markers; 2518 if (layer == Layer.FOREGROUND) { 2519 markers = (Collection) this.foregroundDomainMarkers.get(index); 2520 if (markers == null) { 2521 markers = new java.util.ArrayList(); 2522 this.foregroundDomainMarkers.put(index, markers); 2523 } 2524 markers.add(marker); 2525 } 2526 else if (layer == Layer.BACKGROUND) { 2527 markers = (Collection) this.backgroundDomainMarkers.get(index); 2528 if (markers == null) { 2529 markers = new java.util.ArrayList(); 2530 this.backgroundDomainMarkers.put(index, markers); 2531 } 2532 markers.add(marker); 2533 } 2534 marker.addChangeListener(this); 2535 if (notify) { 2536 fireChangeEvent(); 2537 } 2538 } 2539 2540 /** 2541 * Removes a marker for the domain axis and sends a {@link PlotChangeEvent} 2542 * to all registered listeners. 2543 * 2544 * @param marker the marker. 2545 * 2546 * @return A boolean indicating whether or not the marker was actually 2547 * removed. 2548 * 2549 * @since 1.0.7 2550 */ 2551 public boolean removeDomainMarker(Marker marker) { 2552 return removeDomainMarker(marker, Layer.FOREGROUND); 2553 } 2554 2555 /** 2556 * Removes a marker for the domain axis in the specified layer and sends a 2557 * {@link PlotChangeEvent} to all registered listeners. 2558 * 2559 * @param marker the marker ({@code null} not permitted). 2560 * @param layer the layer (foreground or background). 2561 * 2562 * @return A boolean indicating whether or not the marker was actually 2563 * removed. 2564 * 2565 * @since 1.0.7 2566 */ 2567 public boolean removeDomainMarker(Marker marker, Layer layer) { 2568 return removeDomainMarker(0, marker, layer); 2569 } 2570 2571 /** 2572 * Removes a marker for a specific dataset/renderer and sends a 2573 * {@link PlotChangeEvent} to all registered listeners. 2574 * 2575 * @param index the dataset/renderer index. 2576 * @param marker the marker. 2577 * @param layer the layer (foreground or background). 2578 * 2579 * @return A boolean indicating whether or not the marker was actually 2580 * removed. 2581 * 2582 * @since 1.0.7 2583 */ 2584 public boolean removeDomainMarker(int index, Marker marker, Layer layer) { 2585 return removeDomainMarker(index, marker, layer, true); 2586 } 2587 2588 /** 2589 * Removes a marker for a specific dataset/renderer and, if requested, 2590 * sends a {@link PlotChangeEvent} to all registered listeners. 2591 * 2592 * @param index the dataset/renderer index. 2593 * @param marker the marker. 2594 * @param layer the layer (foreground or background). 2595 * @param notify notify listeners? 2596 * 2597 * @return A boolean indicating whether or not the marker was actually 2598 * removed. 2599 * 2600 * @since 1.0.10 2601 */ 2602 public boolean removeDomainMarker(int index, Marker marker, Layer layer, 2603 boolean notify) { 2604 ArrayList markers; 2605 if (layer == Layer.FOREGROUND) { 2606 markers = (ArrayList) this.foregroundDomainMarkers.get(index); 2607 } 2608 else { 2609 markers = (ArrayList) this.backgroundDomainMarkers.get(index); 2610 } 2611 if (markers == null) { 2612 return false; 2613 } 2614 boolean removed = markers.remove(marker); 2615 if (removed && notify) { 2616 fireChangeEvent(); 2617 } 2618 return removed; 2619 } 2620 2621 /** 2622 * Adds a marker for the range axis and sends a {@link PlotChangeEvent} to 2623 * all registered listeners. 2624 * <P> 2625 * Typically a marker will be drawn by the renderer as a line perpendicular 2626 * to the range axis, however this is entirely up to the renderer. 2627 * 2628 * @param marker the marker ({@code null} not permitted). 2629 * 2630 * @see #addRangeMarker(Marker, Layer) 2631 */ 2632 public void addRangeMarker(Marker marker) { 2633 addRangeMarker(marker, Layer.FOREGROUND); 2634 } 2635 2636 /** 2637 * Adds a marker for the range axis in the specified layer and sends a 2638 * {@link PlotChangeEvent} to all registered listeners. 2639 * <P> 2640 * Typically a marker will be drawn by the renderer as a line perpendicular 2641 * to the range axis, however this is entirely up to the renderer. 2642 * 2643 * @param marker the marker ({@code null} not permitted). 2644 * @param layer the layer (foreground or background). 2645 * 2646 * @see #addRangeMarker(int, Marker, Layer) 2647 */ 2648 public void addRangeMarker(Marker marker, Layer layer) { 2649 addRangeMarker(0, marker, layer); 2650 } 2651 2652 /** 2653 * Clears all the range markers and sends a {@link PlotChangeEvent} to all 2654 * registered listeners. 2655 * 2656 * @see #clearRangeMarkers() 2657 */ 2658 public void clearRangeMarkers() { 2659 if (this.backgroundRangeMarkers != null) { 2660 Set<Integer> keys = this.backgroundRangeMarkers.keySet(); 2661 for (Integer key : keys) { 2662 clearRangeMarkers(key); 2663 } 2664 this.backgroundRangeMarkers.clear(); 2665 } 2666 if (this.foregroundRangeMarkers != null) { 2667 Set<Integer> keys = this.foregroundRangeMarkers.keySet(); 2668 for (Integer key : keys) { 2669 clearRangeMarkers(key); 2670 } 2671 this.foregroundRangeMarkers.clear(); 2672 } 2673 fireChangeEvent(); 2674 } 2675 2676 /** 2677 * Adds a marker for a specific dataset/renderer and sends a 2678 * {@link PlotChangeEvent} to all registered listeners. 2679 * <P> 2680 * Typically a marker will be drawn by the renderer as a line perpendicular 2681 * to the range axis, however this is entirely up to the renderer. 2682 * 2683 * @param index the dataset/renderer index. 2684 * @param marker the marker. 2685 * @param layer the layer (foreground or background). 2686 * 2687 * @see #clearRangeMarkers(int) 2688 * @see #addDomainMarker(int, Marker, Layer) 2689 */ 2690 public void addRangeMarker(int index, Marker marker, Layer layer) { 2691 addRangeMarker(index, marker, layer, true); 2692 } 2693 2694 /** 2695 * Adds a marker for a specific dataset/renderer and, if requested, sends a 2696 * {@link PlotChangeEvent} to all registered listeners. 2697 * <P> 2698 * Typically a marker will be drawn by the renderer as a line perpendicular 2699 * to the range axis, however this is entirely up to the renderer. 2700 * 2701 * @param index the dataset/renderer index. 2702 * @param marker the marker. 2703 * @param layer the layer (foreground or background). 2704 * @param notify notify listeners? 2705 * 2706 * @since 1.0.10 2707 */ 2708 public void addRangeMarker(int index, Marker marker, Layer layer, 2709 boolean notify) { 2710 Collection markers; 2711 if (layer == Layer.FOREGROUND) { 2712 markers = (Collection) this.foregroundRangeMarkers.get(index); 2713 if (markers == null) { 2714 markers = new java.util.ArrayList(); 2715 this.foregroundRangeMarkers.put(index, markers); 2716 } 2717 markers.add(marker); 2718 } 2719 else if (layer == Layer.BACKGROUND) { 2720 markers = (Collection) this.backgroundRangeMarkers.get(index); 2721 if (markers == null) { 2722 markers = new java.util.ArrayList(); 2723 this.backgroundRangeMarkers.put(index, markers); 2724 } 2725 markers.add(marker); 2726 } 2727 marker.addChangeListener(this); 2728 if (notify) { 2729 fireChangeEvent(); 2730 } 2731 } 2732 2733 /** 2734 * Clears the (foreground and background) range markers for a particular 2735 * renderer. 2736 * 2737 * @param index the renderer index. 2738 */ 2739 public void clearRangeMarkers(int index) { 2740 Integer key = index; 2741 if (this.backgroundRangeMarkers != null) { 2742 Collection markers 2743 = (Collection) this.backgroundRangeMarkers.get(key); 2744 if (markers != null) { 2745 Iterator iterator = markers.iterator(); 2746 while (iterator.hasNext()) { 2747 Marker m = (Marker) iterator.next(); 2748 m.removeChangeListener(this); 2749 } 2750 markers.clear(); 2751 } 2752 } 2753 if (this.foregroundRangeMarkers != null) { 2754 Collection markers 2755 = (Collection) this.foregroundRangeMarkers.get(key); 2756 if (markers != null) { 2757 Iterator iterator = markers.iterator(); 2758 while (iterator.hasNext()) { 2759 Marker m = (Marker) iterator.next(); 2760 m.removeChangeListener(this); 2761 } 2762 markers.clear(); 2763 } 2764 } 2765 fireChangeEvent(); 2766 } 2767 2768 /** 2769 * Removes a marker for the range axis and sends a {@link PlotChangeEvent} 2770 * to all registered listeners. 2771 * 2772 * @param marker the marker. 2773 * 2774 * @return A boolean indicating whether or not the marker was actually 2775 * removed. 2776 * 2777 * @since 1.0.7 2778 */ 2779 public boolean removeRangeMarker(Marker marker) { 2780 return removeRangeMarker(marker, Layer.FOREGROUND); 2781 } 2782 2783 /** 2784 * Removes a marker for the range axis in the specified layer and sends a 2785 * {@link PlotChangeEvent} to all registered listeners. 2786 * 2787 * @param marker the marker ({@code null} not permitted). 2788 * @param layer the layer (foreground or background). 2789 * 2790 * @return A boolean indicating whether or not the marker was actually 2791 * removed. 2792 * 2793 * @since 1.0.7 2794 */ 2795 public boolean removeRangeMarker(Marker marker, Layer layer) { 2796 return removeRangeMarker(0, marker, layer); 2797 } 2798 2799 /** 2800 * Removes a marker for a specific dataset/renderer and sends a 2801 * {@link PlotChangeEvent} to all registered listeners. 2802 * 2803 * @param index the dataset/renderer index. 2804 * @param marker the marker ({@code null} not permitted). 2805 * @param layer the layer (foreground or background). 2806 * 2807 * @return A boolean indicating whether or not the marker was actually 2808 * removed. 2809 * 2810 * @since 1.0.7 2811 */ 2812 public boolean removeRangeMarker(int index, Marker marker, Layer layer) { 2813 return removeRangeMarker(index, marker, layer, true); 2814 } 2815 2816 /** 2817 * Removes a marker for a specific dataset/renderer and sends a 2818 * {@link PlotChangeEvent} to all registered listeners. 2819 * 2820 * @param index the dataset/renderer index. 2821 * @param marker the marker ({@code null} not permitted). 2822 * @param layer the layer (foreground or background) ({@code null} not permitted). 2823 * @param notify notify listeners? 2824 * 2825 * @return A boolean indicating whether or not the marker was actually 2826 * removed. 2827 * 2828 * @since 1.0.10 2829 */ 2830 public boolean removeRangeMarker(int index, Marker marker, Layer layer, 2831 boolean notify) { 2832 Args.nullNotPermitted(marker, "marker"); 2833 Args.nullNotPermitted(layer, "layer"); 2834 List markers; 2835 if (layer == Layer.FOREGROUND) { 2836 markers = (List) this.foregroundRangeMarkers.get(index); 2837 } 2838 else { 2839 markers = (List) this.backgroundRangeMarkers.get(index); 2840 } 2841 if (markers == null) { 2842 return false; 2843 } 2844 boolean removed = markers.remove(marker); 2845 if (removed && notify) { 2846 fireChangeEvent(); 2847 } 2848 return removed; 2849 } 2850 2851 /** 2852 * Adds an annotation to the plot and sends a {@link PlotChangeEvent} to 2853 * all registered listeners. 2854 * 2855 * @param annotation the annotation ({@code null} not permitted). 2856 * 2857 * @see #getAnnotations() 2858 * @see #removeAnnotation(XYAnnotation) 2859 */ 2860 public void addAnnotation(XYAnnotation annotation) { 2861 addAnnotation(annotation, true); 2862 } 2863 2864 /** 2865 * Adds an annotation to the plot and, if requested, sends a 2866 * {@link PlotChangeEvent} to all registered listeners. 2867 * 2868 * @param annotation the annotation ({@code null} not permitted). 2869 * @param notify notify listeners? 2870 * 2871 * @since 1.0.10 2872 */ 2873 public void addAnnotation(XYAnnotation annotation, boolean notify) { 2874 Args.nullNotPermitted(annotation, "annotation"); 2875 this.annotations.add(annotation); 2876 annotation.addChangeListener(this); 2877 if (notify) { 2878 fireChangeEvent(); 2879 } 2880 } 2881 2882 /** 2883 * Removes an annotation from the plot and sends a {@link PlotChangeEvent} 2884 * to all registered listeners. 2885 * 2886 * @param annotation the annotation ({@code null} not permitted). 2887 * 2888 * @return A boolean (indicates whether or not the annotation was removed). 2889 * 2890 * @see #addAnnotation(XYAnnotation) 2891 * @see #getAnnotations() 2892 */ 2893 public boolean removeAnnotation(XYAnnotation annotation) { 2894 return removeAnnotation(annotation, true); 2895 } 2896 2897 /** 2898 * Removes an annotation from the plot and sends a {@link PlotChangeEvent} 2899 * to all registered listeners. 2900 * 2901 * @param annotation the annotation ({@code null} not permitted). 2902 * @param notify notify listeners? 2903 * 2904 * @return A boolean (indicates whether or not the annotation was removed). 2905 * 2906 * @since 1.0.10 2907 */ 2908 public boolean removeAnnotation(XYAnnotation annotation, boolean notify) { 2909 Args.nullNotPermitted(annotation, "annotation"); 2910 boolean removed = this.annotations.remove(annotation); 2911 annotation.removeChangeListener(this); 2912 if (removed && notify) { 2913 fireChangeEvent(); 2914 } 2915 return removed; 2916 } 2917 2918 /** 2919 * Returns the list of annotations. 2920 * 2921 * @return The list of annotations. 2922 * 2923 * @since 1.0.1 2924 * 2925 * @see #addAnnotation(XYAnnotation) 2926 */ 2927 public List getAnnotations() { 2928 return new ArrayList(this.annotations); 2929 } 2930 2931 /** 2932 * Clears all the annotations and sends a {@link PlotChangeEvent} to all 2933 * registered listeners. 2934 * 2935 * @see #addAnnotation(XYAnnotation) 2936 */ 2937 public void clearAnnotations() { 2938 for (XYAnnotation annotation : this.annotations) { 2939 annotation.removeChangeListener(this); 2940 } 2941 this.annotations.clear(); 2942 fireChangeEvent(); 2943 } 2944 2945 /** 2946 * Returns the shadow generator for the plot, if any. 2947 * 2948 * @return The shadow generator (possibly {@code null}). 2949 * 2950 * @since 1.0.14 2951 */ 2952 public ShadowGenerator getShadowGenerator() { 2953 return this.shadowGenerator; 2954 } 2955 2956 /** 2957 * Sets the shadow generator for the plot and sends a 2958 * {@link PlotChangeEvent} to all registered listeners. 2959 * 2960 * @param generator the generator ({@code null} permitted). 2961 * 2962 * @since 1.0.14 2963 */ 2964 public void setShadowGenerator(ShadowGenerator generator) { 2965 this.shadowGenerator = generator; 2966 fireChangeEvent(); 2967 } 2968 2969 /** 2970 * Calculates the space required for all the axes in the plot. 2971 * 2972 * @param g2 the graphics device. 2973 * @param plotArea the plot area. 2974 * 2975 * @return The required space. 2976 */ 2977 protected AxisSpace calculateAxisSpace(Graphics2D g2, 2978 Rectangle2D plotArea) { 2979 AxisSpace space = new AxisSpace(); 2980 space = calculateRangeAxisSpace(g2, plotArea, space); 2981 Rectangle2D revPlotArea = space.shrink(plotArea, null); 2982 space = calculateDomainAxisSpace(g2, revPlotArea, space); 2983 return space; 2984 } 2985 2986 /** 2987 * Calculates the space required for the domain axis/axes. 2988 * 2989 * @param g2 the graphics device. 2990 * @param plotArea the plot area. 2991 * @param space a carrier for the result ({@code null} permitted). 2992 * 2993 * @return The required space. 2994 */ 2995 protected AxisSpace calculateDomainAxisSpace(Graphics2D g2, 2996 Rectangle2D plotArea, AxisSpace space) { 2997 2998 if (space == null) { 2999 space = new AxisSpace(); 3000 } 3001 3002 // reserve some space for the domain axis... 3003 if (this.fixedDomainAxisSpace != null) { 3004 if (this.orientation == PlotOrientation.HORIZONTAL) { 3005 space.ensureAtLeast(this.fixedDomainAxisSpace.getLeft(), 3006 RectangleEdge.LEFT); 3007 space.ensureAtLeast(this.fixedDomainAxisSpace.getRight(), 3008 RectangleEdge.RIGHT); 3009 } 3010 else if (this.orientation == PlotOrientation.VERTICAL) { 3011 space.ensureAtLeast(this.fixedDomainAxisSpace.getTop(), 3012 RectangleEdge.TOP); 3013 space.ensureAtLeast(this.fixedDomainAxisSpace.getBottom(), 3014 RectangleEdge.BOTTOM); 3015 } 3016 } 3017 else { 3018 // reserve space for the domain axes... 3019 for (ValueAxis axis: this.domainAxes.values()) { 3020 if (axis != null) { 3021 RectangleEdge edge = getDomainAxisEdge( 3022 findDomainAxisIndex(axis)); 3023 space = axis.reserveSpace(g2, this, plotArea, edge, space); 3024 } 3025 } 3026 } 3027 3028 return space; 3029 3030 } 3031 3032 /** 3033 * Calculates the space required for the range axis/axes. 3034 * 3035 * @param g2 the graphics device. 3036 * @param plotArea the plot area. 3037 * @param space a carrier for the result ({@code null} permitted). 3038 * 3039 * @return The required space. 3040 */ 3041 protected AxisSpace calculateRangeAxisSpace(Graphics2D g2, 3042 Rectangle2D plotArea, AxisSpace space) { 3043 3044 if (space == null) { 3045 space = new AxisSpace(); 3046 } 3047 3048 // reserve some space for the range axis... 3049 if (this.fixedRangeAxisSpace != null) { 3050 if (this.orientation == PlotOrientation.HORIZONTAL) { 3051 space.ensureAtLeast(this.fixedRangeAxisSpace.getTop(), 3052 RectangleEdge.TOP); 3053 space.ensureAtLeast(this.fixedRangeAxisSpace.getBottom(), 3054 RectangleEdge.BOTTOM); 3055 } 3056 else if (this.orientation == PlotOrientation.VERTICAL) { 3057 space.ensureAtLeast(this.fixedRangeAxisSpace.getLeft(), 3058 RectangleEdge.LEFT); 3059 space.ensureAtLeast(this.fixedRangeAxisSpace.getRight(), 3060 RectangleEdge.RIGHT); 3061 } 3062 } 3063 else { 3064 // reserve space for the range axes... 3065 for (ValueAxis axis: this.rangeAxes.values()) { 3066 if (axis != null) { 3067 RectangleEdge edge = getRangeAxisEdge( 3068 findRangeAxisIndex(axis)); 3069 space = axis.reserveSpace(g2, this, plotArea, edge, space); 3070 } 3071 } 3072 } 3073 return space; 3074 3075 } 3076 3077 /** 3078 * Trims a rectangle to integer coordinates. 3079 * 3080 * @param rect the incoming rectangle. 3081 * 3082 * @return A rectangle with integer coordinates. 3083 */ 3084 private Rectangle integerise(Rectangle2D rect) { 3085 int x0 = (int) Math.ceil(rect.getMinX()); 3086 int y0 = (int) Math.ceil(rect.getMinY()); 3087 int x1 = (int) Math.floor(rect.getMaxX()); 3088 int y1 = (int) Math.floor(rect.getMaxY()); 3089 return new Rectangle(x0, y0, (x1 - x0), (y1 - y0)); 3090 } 3091 3092 /** 3093 * Draws the plot within the specified area on a graphics device. 3094 * 3095 * @param g2 the graphics device. 3096 * @param area the plot area (in Java2D space). 3097 * @param anchor an anchor point in Java2D space ({@code null} 3098 * permitted). 3099 * @param parentState the state from the parent plot, if there is one 3100 * ({@code null} permitted). 3101 * @param info collects chart drawing information ({@code null} 3102 * permitted). 3103 */ 3104 @Override 3105 public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, 3106 PlotState parentState, PlotRenderingInfo info) { 3107 3108 // if the plot area is too small, just return... 3109 boolean b1 = (area.getWidth() <= MINIMUM_WIDTH_TO_DRAW); 3110 boolean b2 = (area.getHeight() <= MINIMUM_HEIGHT_TO_DRAW); 3111 if (b1 || b2) { 3112 return; 3113 } 3114 3115 // record the plot area... 3116 if (info != null) { 3117 info.setPlotArea(area); 3118 } 3119 3120 // adjust the drawing area for the plot insets (if any)... 3121 RectangleInsets insets = getInsets(); 3122 insets.trim(area); 3123 3124 AxisSpace space = calculateAxisSpace(g2, area); 3125 Rectangle2D dataArea = space.shrink(area, null); 3126 this.axisOffset.trim(dataArea); 3127 3128 dataArea = integerise(dataArea); 3129 if (dataArea.isEmpty()) { 3130 return; 3131 } 3132 createAndAddEntity((Rectangle2D) dataArea.clone(), info, null, null); 3133 if (info != null) { 3134 info.setDataArea(dataArea); 3135 } 3136 3137 // draw the plot background and axes... 3138 drawBackground(g2, dataArea); 3139 Map axisStateMap = drawAxes(g2, area, dataArea, info); 3140 3141 PlotOrientation orient = getOrientation(); 3142 3143 // the anchor point is typically the point where the mouse last 3144 // clicked - the crosshairs will be driven off this point... 3145 if (anchor != null && !dataArea.contains(anchor)) { 3146 anchor = null; 3147 } 3148 CrosshairState crosshairState = new CrosshairState(); 3149 crosshairState.setCrosshairDistance(Double.POSITIVE_INFINITY); 3150 crosshairState.setAnchor(anchor); 3151 3152 crosshairState.setAnchorX(Double.NaN); 3153 crosshairState.setAnchorY(Double.NaN); 3154 if (anchor != null) { 3155 ValueAxis domainAxis = getDomainAxis(); 3156 if (domainAxis != null) { 3157 double x; 3158 if (orient == PlotOrientation.VERTICAL) { 3159 x = domainAxis.java2DToValue(anchor.getX(), dataArea, 3160 getDomainAxisEdge()); 3161 } 3162 else { 3163 x = domainAxis.java2DToValue(anchor.getY(), dataArea, 3164 getDomainAxisEdge()); 3165 } 3166 crosshairState.setAnchorX(x); 3167 } 3168 ValueAxis rangeAxis = getRangeAxis(); 3169 if (rangeAxis != null) { 3170 double y; 3171 if (orient == PlotOrientation.VERTICAL) { 3172 y = rangeAxis.java2DToValue(anchor.getY(), dataArea, 3173 getRangeAxisEdge()); 3174 } 3175 else { 3176 y = rangeAxis.java2DToValue(anchor.getX(), dataArea, 3177 getRangeAxisEdge()); 3178 } 3179 crosshairState.setAnchorY(y); 3180 } 3181 } 3182 crosshairState.setCrosshairX(getDomainCrosshairValue()); 3183 crosshairState.setCrosshairY(getRangeCrosshairValue()); 3184 Shape originalClip = g2.getClip(); 3185 Composite originalComposite = g2.getComposite(); 3186 3187 g2.clip(dataArea); 3188 g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 3189 getForegroundAlpha())); 3190 3191 AxisState domainAxisState = (AxisState) axisStateMap.get( 3192 getDomainAxis()); 3193 if (domainAxisState == null) { 3194 if (parentState != null) { 3195 domainAxisState = (AxisState) parentState.getSharedAxisStates() 3196 .get(getDomainAxis()); 3197 } 3198 } 3199 3200 AxisState rangeAxisState = (AxisState) axisStateMap.get(getRangeAxis()); 3201 if (rangeAxisState == null) { 3202 if (parentState != null) { 3203 rangeAxisState = (AxisState) parentState.getSharedAxisStates() 3204 .get(getRangeAxis()); 3205 } 3206 } 3207 if (domainAxisState != null) { 3208 drawDomainTickBands(g2, dataArea, domainAxisState.getTicks()); 3209 } 3210 if (rangeAxisState != null) { 3211 drawRangeTickBands(g2, dataArea, rangeAxisState.getTicks()); 3212 } 3213 if (domainAxisState != null) { 3214 drawDomainGridlines(g2, dataArea, domainAxisState.getTicks()); 3215 drawZeroDomainBaseline(g2, dataArea); 3216 } 3217 if (rangeAxisState != null) { 3218 drawRangeGridlines(g2, dataArea, rangeAxisState.getTicks()); 3219 drawZeroRangeBaseline(g2, dataArea); 3220 } 3221 3222 Graphics2D savedG2 = g2; 3223 BufferedImage dataImage = null; 3224 boolean suppressShadow = Boolean.TRUE.equals(g2.getRenderingHint( 3225 JFreeChart.KEY_SUPPRESS_SHADOW_GENERATION)); 3226 if (this.shadowGenerator != null && !suppressShadow) { 3227 dataImage = new BufferedImage((int) dataArea.getWidth(), 3228 (int)dataArea.getHeight(), BufferedImage.TYPE_INT_ARGB); 3229 g2 = dataImage.createGraphics(); 3230 g2.translate(-dataArea.getX(), -dataArea.getY()); 3231 g2.setRenderingHints(savedG2.getRenderingHints()); 3232 } 3233 3234 // draw the markers that are associated with a specific dataset... 3235 for (XYDataset dataset: this.datasets.values()) { 3236 int datasetIndex = indexOf(dataset); 3237 drawDomainMarkers(g2, dataArea, datasetIndex, Layer.BACKGROUND); 3238 } 3239 for (XYDataset dataset: this.datasets.values()) { 3240 int datasetIndex = indexOf(dataset); 3241 drawRangeMarkers(g2, dataArea, datasetIndex, Layer.BACKGROUND); 3242 } 3243 3244 // now draw annotations and render data items... 3245 boolean foundData = false; 3246 DatasetRenderingOrder order = getDatasetRenderingOrder(); 3247 List<Integer> rendererIndices = getRendererIndices(order); 3248 List<Integer> datasetIndices = getDatasetIndices(order); 3249 3250 // draw background annotations 3251 for (int i : rendererIndices) { 3252 XYItemRenderer renderer = getRenderer(i); 3253 if (renderer != null) { 3254 ValueAxis domainAxis = getDomainAxisForDataset(i); 3255 ValueAxis rangeAxis = getRangeAxisForDataset(i); 3256 renderer.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, 3257 Layer.BACKGROUND, info); 3258 } 3259 } 3260 3261 // render data items... 3262 for (int datasetIndex : datasetIndices) { 3263 XYDataset dataset = this.getDataset(datasetIndex); 3264 foundData = render(g2, dataArea, datasetIndex, info, 3265 crosshairState) || foundData; 3266 } 3267 3268 // draw foreground annotations 3269 for (int i : rendererIndices) { 3270 XYItemRenderer renderer = getRenderer(i); 3271 if (renderer != null) { 3272 ValueAxis domainAxis = getDomainAxisForDataset(i); 3273 ValueAxis rangeAxis = getRangeAxisForDataset(i); 3274 renderer.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, 3275 Layer.FOREGROUND, info); 3276 } 3277 } 3278 3279 // draw domain crosshair if required... 3280 int datasetIndex = crosshairState.getDatasetIndex(); 3281 ValueAxis xAxis = getDomainAxisForDataset(datasetIndex); 3282 RectangleEdge xAxisEdge = getDomainAxisEdge(getDomainAxisIndex(xAxis)); 3283 if (!this.domainCrosshairLockedOnData && anchor != null) { 3284 double xx; 3285 if (orient == PlotOrientation.VERTICAL) { 3286 xx = xAxis.java2DToValue(anchor.getX(), dataArea, xAxisEdge); 3287 } 3288 else { 3289 xx = xAxis.java2DToValue(anchor.getY(), dataArea, xAxisEdge); 3290 } 3291 crosshairState.setCrosshairX(xx); 3292 } 3293 setDomainCrosshairValue(crosshairState.getCrosshairX(), false); 3294 if (isDomainCrosshairVisible()) { 3295 double x = getDomainCrosshairValue(); 3296 Paint paint = getDomainCrosshairPaint(); 3297 Stroke stroke = getDomainCrosshairStroke(); 3298 drawDomainCrosshair(g2, dataArea, orient, x, xAxis, stroke, paint); 3299 } 3300 3301 // draw range crosshair if required... 3302 ValueAxis yAxis = getRangeAxisForDataset(datasetIndex); 3303 RectangleEdge yAxisEdge = getRangeAxisEdge(getRangeAxisIndex(yAxis)); 3304 if (!this.rangeCrosshairLockedOnData && anchor != null) { 3305 double yy; 3306 if (orient == PlotOrientation.VERTICAL) { 3307 yy = yAxis.java2DToValue(anchor.getY(), dataArea, yAxisEdge); 3308 } else { 3309 yy = yAxis.java2DToValue(anchor.getX(), dataArea, yAxisEdge); 3310 } 3311 crosshairState.setCrosshairY(yy); 3312 } 3313 setRangeCrosshairValue(crosshairState.getCrosshairY(), false); 3314 if (isRangeCrosshairVisible()) { 3315 double y = getRangeCrosshairValue(); 3316 Paint paint = getRangeCrosshairPaint(); 3317 Stroke stroke = getRangeCrosshairStroke(); 3318 drawRangeCrosshair(g2, dataArea, orient, y, yAxis, stroke, paint); 3319 } 3320 3321 if (!foundData) { 3322 drawNoDataMessage(g2, dataArea); 3323 } 3324 3325 for (int i : rendererIndices) { 3326 drawDomainMarkers(g2, dataArea, i, Layer.FOREGROUND); 3327 } 3328 for (int i : rendererIndices) { 3329 drawRangeMarkers(g2, dataArea, i, Layer.FOREGROUND); 3330 } 3331 3332 drawAnnotations(g2, dataArea, info); 3333 if (this.shadowGenerator != null && !suppressShadow) { 3334 BufferedImage shadowImage 3335 = this.shadowGenerator.createDropShadow(dataImage); 3336 g2 = savedG2; 3337 g2.drawImage(shadowImage, (int) dataArea.getX() 3338 + this.shadowGenerator.calculateOffsetX(), 3339 (int) dataArea.getY() 3340 + this.shadowGenerator.calculateOffsetY(), null); 3341 g2.drawImage(dataImage, (int) dataArea.getX(), 3342 (int) dataArea.getY(), null); 3343 } 3344 g2.setClip(originalClip); 3345 g2.setComposite(originalComposite); 3346 3347 drawOutline(g2, dataArea); 3348 3349 } 3350 3351 /** 3352 * Returns the indices of the non-null datasets in the specified order. 3353 * 3354 * @param order the order ({@code null} not permitted). 3355 * 3356 * @return The list of indices. 3357 */ 3358 private List<Integer> getDatasetIndices(DatasetRenderingOrder order) { 3359 List<Integer> result = new ArrayList<Integer>(); 3360 for (Entry<Integer, XYDataset> entry : this.datasets.entrySet()) { 3361 if (entry.getValue() != null) { 3362 result.add(entry.getKey()); 3363 } 3364 } 3365 Collections.sort(result); 3366 if (order == DatasetRenderingOrder.REVERSE) { 3367 Collections.reverse(result); 3368 } 3369 return result; 3370 } 3371 3372 private List<Integer> getRendererIndices(DatasetRenderingOrder order) { 3373 List<Integer> result = new ArrayList<Integer>(); 3374 for (Entry<Integer, XYItemRenderer> entry : this.renderers.entrySet()) { 3375 if (entry.getValue() != null) { 3376 result.add(entry.getKey()); 3377 } 3378 } 3379 Collections.sort(result); 3380 if (order == DatasetRenderingOrder.REVERSE) { 3381 Collections.reverse(result); 3382 } 3383 return result; 3384 } 3385 3386 /** 3387 * Draws the background for the plot. 3388 * 3389 * @param g2 the graphics device. 3390 * @param area the area. 3391 */ 3392 @Override 3393 public void drawBackground(Graphics2D g2, Rectangle2D area) { 3394 fillBackground(g2, area, this.orientation); 3395 drawQuadrants(g2, area); 3396 drawBackgroundImage(g2, area); 3397 } 3398 3399 /** 3400 * Draws the quadrants. 3401 * 3402 * @param g2 the graphics device. 3403 * @param area the area. 3404 * 3405 * @see #setQuadrantOrigin(Point2D) 3406 * @see #setQuadrantPaint(int, Paint) 3407 */ 3408 protected void drawQuadrants(Graphics2D g2, Rectangle2D area) { 3409 // 0 | 1 3410 // --+-- 3411 // 2 | 3 3412 boolean somethingToDraw = false; 3413 3414 ValueAxis xAxis = getDomainAxis(); 3415 if (xAxis == null) { // we can't draw quadrants without a valid x-axis 3416 return; 3417 } 3418 double x = xAxis.getRange().constrain(this.quadrantOrigin.getX()); 3419 double xx = xAxis.valueToJava2D(x, area, getDomainAxisEdge()); 3420 3421 ValueAxis yAxis = getRangeAxis(); 3422 if (yAxis == null) { // we can't draw quadrants without a valid y-axis 3423 return; 3424 } 3425 double y = yAxis.getRange().constrain(this.quadrantOrigin.getY()); 3426 double yy = yAxis.valueToJava2D(y, area, getRangeAxisEdge()); 3427 3428 double xmin = xAxis.getLowerBound(); 3429 double xxmin = xAxis.valueToJava2D(xmin, area, getDomainAxisEdge()); 3430 3431 double xmax = xAxis.getUpperBound(); 3432 double xxmax = xAxis.valueToJava2D(xmax, area, getDomainAxisEdge()); 3433 3434 double ymin = yAxis.getLowerBound(); 3435 double yymin = yAxis.valueToJava2D(ymin, area, getRangeAxisEdge()); 3436 3437 double ymax = yAxis.getUpperBound(); 3438 double yymax = yAxis.valueToJava2D(ymax, area, getRangeAxisEdge()); 3439 3440 Rectangle2D[] r = new Rectangle2D[] {null, null, null, null}; 3441 if (this.quadrantPaint[0] != null) { 3442 if (x > xmin && y < ymax) { 3443 if (this.orientation == PlotOrientation.HORIZONTAL) { 3444 r[0] = new Rectangle2D.Double(Math.min(yymax, yy), 3445 Math.min(xxmin, xx), Math.abs(yy - yymax), 3446 Math.abs(xx - xxmin)); 3447 } 3448 else { // PlotOrientation.VERTICAL 3449 r[0] = new Rectangle2D.Double(Math.min(xxmin, xx), 3450 Math.min(yymax, yy), Math.abs(xx - xxmin), 3451 Math.abs(yy - yymax)); 3452 } 3453 somethingToDraw = true; 3454 } 3455 } 3456 if (this.quadrantPaint[1] != null) { 3457 if (x < xmax && y < ymax) { 3458 if (this.orientation == PlotOrientation.HORIZONTAL) { 3459 r[1] = new Rectangle2D.Double(Math.min(yymax, yy), 3460 Math.min(xxmax, xx), Math.abs(yy - yymax), 3461 Math.abs(xx - xxmax)); 3462 } 3463 else { // PlotOrientation.VERTICAL 3464 r[1] = new Rectangle2D.Double(Math.min(xx, xxmax), 3465 Math.min(yymax, yy), Math.abs(xx - xxmax), 3466 Math.abs(yy - yymax)); 3467 } 3468 somethingToDraw = true; 3469 } 3470 } 3471 if (this.quadrantPaint[2] != null) { 3472 if (x > xmin && y > ymin) { 3473 if (this.orientation == PlotOrientation.HORIZONTAL) { 3474 r[2] = new Rectangle2D.Double(Math.min(yymin, yy), 3475 Math.min(xxmin, xx), Math.abs(yy - yymin), 3476 Math.abs(xx - xxmin)); 3477 } 3478 else { // PlotOrientation.VERTICAL 3479 r[2] = new Rectangle2D.Double(Math.min(xxmin, xx), 3480 Math.min(yymin, yy), Math.abs(xx - xxmin), 3481 Math.abs(yy - yymin)); 3482 } 3483 somethingToDraw = true; 3484 } 3485 } 3486 if (this.quadrantPaint[3] != null) { 3487 if (x < xmax && y > ymin) { 3488 if (this.orientation == PlotOrientation.HORIZONTAL) { 3489 r[3] = new Rectangle2D.Double(Math.min(yymin, yy), 3490 Math.min(xxmax, xx), Math.abs(yy - yymin), 3491 Math.abs(xx - xxmax)); 3492 } 3493 else { // PlotOrientation.VERTICAL 3494 r[3] = new Rectangle2D.Double(Math.min(xx, xxmax), 3495 Math.min(yymin, yy), Math.abs(xx - xxmax), 3496 Math.abs(yy - yymin)); 3497 } 3498 somethingToDraw = true; 3499 } 3500 } 3501 if (somethingToDraw) { 3502 Composite originalComposite = g2.getComposite(); 3503 g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 3504 getBackgroundAlpha())); 3505 for (int i = 0; i < 4; i++) { 3506 if (this.quadrantPaint[i] != null && r[i] != null) { 3507 g2.setPaint(this.quadrantPaint[i]); 3508 g2.fill(r[i]); 3509 } 3510 } 3511 g2.setComposite(originalComposite); 3512 } 3513 } 3514 3515 /** 3516 * Draws the domain tick bands, if any. 3517 * 3518 * @param g2 the graphics device. 3519 * @param dataArea the data area. 3520 * @param ticks the ticks. 3521 * 3522 * @see #setDomainTickBandPaint(Paint) 3523 */ 3524 public void drawDomainTickBands(Graphics2D g2, Rectangle2D dataArea, 3525 List ticks) { 3526 Paint bandPaint = getDomainTickBandPaint(); 3527 if (bandPaint != null) { 3528 boolean fillBand = false; 3529 ValueAxis xAxis = getDomainAxis(); 3530 double previous = xAxis.getLowerBound(); 3531 Iterator iterator = ticks.iterator(); 3532 while (iterator.hasNext()) { 3533 ValueTick tick = (ValueTick) iterator.next(); 3534 double current = tick.getValue(); 3535 if (fillBand) { 3536 getRenderer().fillDomainGridBand(g2, this, xAxis, dataArea, 3537 previous, current); 3538 } 3539 previous = current; 3540 fillBand = !fillBand; 3541 } 3542 double end = xAxis.getUpperBound(); 3543 if (fillBand) { 3544 getRenderer().fillDomainGridBand(g2, this, xAxis, dataArea, 3545 previous, end); 3546 } 3547 } 3548 } 3549 3550 /** 3551 * Draws the range tick bands, if any. 3552 * 3553 * @param g2 the graphics device. 3554 * @param dataArea the data area. 3555 * @param ticks the ticks. 3556 * 3557 * @see #setRangeTickBandPaint(Paint) 3558 */ 3559 public void drawRangeTickBands(Graphics2D g2, Rectangle2D dataArea, 3560 List ticks) { 3561 Paint bandPaint = getRangeTickBandPaint(); 3562 if (bandPaint != null) { 3563 boolean fillBand = false; 3564 ValueAxis axis = getRangeAxis(); 3565 double previous = axis.getLowerBound(); 3566 Iterator iterator = ticks.iterator(); 3567 while (iterator.hasNext()) { 3568 ValueTick tick = (ValueTick) iterator.next(); 3569 double current = tick.getValue(); 3570 if (fillBand) { 3571 getRenderer().fillRangeGridBand(g2, this, axis, dataArea, 3572 previous, current); 3573 } 3574 previous = current; 3575 fillBand = !fillBand; 3576 } 3577 double end = axis.getUpperBound(); 3578 if (fillBand) { 3579 getRenderer().fillRangeGridBand(g2, this, axis, dataArea, 3580 previous, end); 3581 } 3582 } 3583 } 3584 3585 /** 3586 * A utility method for drawing the axes. 3587 * 3588 * @param g2 the graphics device ({@code null} not permitted). 3589 * @param plotArea the plot area ({@code null} not permitted). 3590 * @param dataArea the data area ({@code null} not permitted). 3591 * @param plotState collects information about the plot ({@code null} 3592 * permitted). 3593 * 3594 * @return A map containing the state for each axis drawn. 3595 */ 3596 protected Map<Axis, AxisState> drawAxes(Graphics2D g2, Rectangle2D plotArea, 3597 Rectangle2D dataArea, PlotRenderingInfo plotState) { 3598 3599 AxisCollection axisCollection = new AxisCollection(); 3600 3601 // add domain axes to lists... 3602 for (ValueAxis axis : this.domainAxes.values()) { 3603 if (axis != null) { 3604 int axisIndex = findDomainAxisIndex(axis); 3605 axisCollection.add(axis, getDomainAxisEdge(axisIndex)); 3606 } 3607 } 3608 3609 // add range axes to lists... 3610 for (ValueAxis axis : this.rangeAxes.values()) { 3611 if (axis != null) { 3612 int axisIndex = findRangeAxisIndex(axis); 3613 axisCollection.add(axis, getRangeAxisEdge(axisIndex)); 3614 } 3615 } 3616 3617 Map axisStateMap = new HashMap(); 3618 3619 // draw the top axes 3620 double cursor = dataArea.getMinY() - this.axisOffset.calculateTopOutset( 3621 dataArea.getHeight()); 3622 Iterator iterator = axisCollection.getAxesAtTop().iterator(); 3623 while (iterator.hasNext()) { 3624 ValueAxis axis = (ValueAxis) iterator.next(); 3625 AxisState info = axis.draw(g2, cursor, plotArea, dataArea, 3626 RectangleEdge.TOP, plotState); 3627 cursor = info.getCursor(); 3628 axisStateMap.put(axis, info); 3629 } 3630 3631 // draw the bottom axes 3632 cursor = dataArea.getMaxY() 3633 + this.axisOffset.calculateBottomOutset(dataArea.getHeight()); 3634 iterator = axisCollection.getAxesAtBottom().iterator(); 3635 while (iterator.hasNext()) { 3636 ValueAxis axis = (ValueAxis) iterator.next(); 3637 AxisState info = axis.draw(g2, cursor, plotArea, dataArea, 3638 RectangleEdge.BOTTOM, plotState); 3639 cursor = info.getCursor(); 3640 axisStateMap.put(axis, info); 3641 } 3642 3643 // draw the left axes 3644 cursor = dataArea.getMinX() 3645 - this.axisOffset.calculateLeftOutset(dataArea.getWidth()); 3646 iterator = axisCollection.getAxesAtLeft().iterator(); 3647 while (iterator.hasNext()) { 3648 ValueAxis axis = (ValueAxis) iterator.next(); 3649 AxisState info = axis.draw(g2, cursor, plotArea, dataArea, 3650 RectangleEdge.LEFT, plotState); 3651 cursor = info.getCursor(); 3652 axisStateMap.put(axis, info); 3653 } 3654 3655 // draw the right axes 3656 cursor = dataArea.getMaxX() 3657 + this.axisOffset.calculateRightOutset(dataArea.getWidth()); 3658 iterator = axisCollection.getAxesAtRight().iterator(); 3659 while (iterator.hasNext()) { 3660 ValueAxis axis = (ValueAxis) iterator.next(); 3661 AxisState info = axis.draw(g2, cursor, plotArea, dataArea, 3662 RectangleEdge.RIGHT, plotState); 3663 cursor = info.getCursor(); 3664 axisStateMap.put(axis, info); 3665 } 3666 3667 return axisStateMap; 3668 } 3669 3670 /** 3671 * Draws a representation of the data within the dataArea region, using the 3672 * current renderer. 3673 * <P> 3674 * The {@code info} and {@code crosshairState} arguments may be 3675 * {@code null}. 3676 * 3677 * @param g2 the graphics device. 3678 * @param dataArea the region in which the data is to be drawn. 3679 * @param index the dataset index. 3680 * @param info an optional object for collection dimension information. 3681 * @param crosshairState collects crosshair information 3682 * ({@code null} permitted). 3683 * 3684 * @return A flag that indicates whether any data was actually rendered. 3685 */ 3686 public boolean render(Graphics2D g2, Rectangle2D dataArea, int index, 3687 PlotRenderingInfo info, CrosshairState crosshairState) { 3688 3689 boolean foundData = false; 3690 XYDataset dataset = getDataset(index); 3691 if (!DatasetUtils.isEmptyOrNull(dataset)) { 3692 foundData = true; 3693 ValueAxis xAxis = getDomainAxisForDataset(index); 3694 ValueAxis yAxis = getRangeAxisForDataset(index); 3695 if (xAxis == null || yAxis == null) { 3696 return foundData; // can't render anything without axes 3697 } 3698 XYItemRenderer renderer = getRenderer(index); 3699 if (renderer == null) { 3700 renderer = getRenderer(); 3701 if (renderer == null) { // no default renderer available 3702 return foundData; 3703 } 3704 } 3705 3706 XYItemRendererState state = renderer.initialise(g2, dataArea, this, 3707 dataset, info); 3708 int passCount = renderer.getPassCount(); 3709 3710 SeriesRenderingOrder seriesOrder = getSeriesRenderingOrder(); 3711 if (seriesOrder == SeriesRenderingOrder.REVERSE) { 3712 //render series in reverse order 3713 for (int pass = 0; pass < passCount; pass++) { 3714 int seriesCount = dataset.getSeriesCount(); 3715 for (int series = seriesCount - 1; series >= 0; series--) { 3716 int firstItem = 0; 3717 int lastItem = dataset.getItemCount(series) - 1; 3718 if (lastItem == -1) { 3719 continue; 3720 } 3721 if (state.getProcessVisibleItemsOnly()) { 3722 int[] itemBounds = RendererUtils.findLiveItems( 3723 dataset, series, xAxis.getLowerBound(), 3724 xAxis.getUpperBound()); 3725 firstItem = Math.max(itemBounds[0] - 1, 0); 3726 lastItem = Math.min(itemBounds[1] + 1, lastItem); 3727 } 3728 state.startSeriesPass(dataset, series, firstItem, 3729 lastItem, pass, passCount); 3730 for (int item = firstItem; item <= lastItem; item++) { 3731 renderer.drawItem(g2, state, dataArea, info, 3732 this, xAxis, yAxis, dataset, series, item, 3733 crosshairState, pass); 3734 } 3735 state.endSeriesPass(dataset, series, firstItem, 3736 lastItem, pass, passCount); 3737 } 3738 } 3739 } 3740 else { 3741 //render series in forward order 3742 for (int pass = 0; pass < passCount; pass++) { 3743 int seriesCount = dataset.getSeriesCount(); 3744 for (int series = 0; series < seriesCount; series++) { 3745 int firstItem = 0; 3746 int lastItem = dataset.getItemCount(series) - 1; 3747 if (state.getProcessVisibleItemsOnly()) { 3748 int[] itemBounds = RendererUtils.findLiveItems( 3749 dataset, series, xAxis.getLowerBound(), 3750 xAxis.getUpperBound()); 3751 firstItem = Math.max(itemBounds[0] - 1, 0); 3752 lastItem = Math.min(itemBounds[1] + 1, lastItem); 3753 } 3754 state.startSeriesPass(dataset, series, firstItem, 3755 lastItem, pass, passCount); 3756 for (int item = firstItem; item <= lastItem; item++) { 3757 renderer.drawItem(g2, state, dataArea, info, 3758 this, xAxis, yAxis, dataset, series, item, 3759 crosshairState, pass); 3760 } 3761 state.endSeriesPass(dataset, series, firstItem, 3762 lastItem, pass, passCount); 3763 } 3764 } 3765 } 3766 } 3767 return foundData; 3768 } 3769 3770 /** 3771 * Returns the domain axis for a dataset. 3772 * 3773 * @param index the dataset index (must be >= 0). 3774 * 3775 * @return The axis. 3776 */ 3777 public ValueAxis getDomainAxisForDataset(int index) { 3778 Args.requireNonNegative(index, "index"); 3779 ValueAxis valueAxis; 3780 List axisIndices = (List) this.datasetToDomainAxesMap.get(index); 3781 if (axisIndices != null) { 3782 // the first axis in the list is used for data <--> Java2D 3783 Integer axisIndex = (Integer) axisIndices.get(0); 3784 valueAxis = getDomainAxis(axisIndex); 3785 } 3786 else { 3787 valueAxis = getDomainAxis(0); 3788 } 3789 return valueAxis; 3790 } 3791 3792 /** 3793 * Returns the range axis for a dataset. 3794 * 3795 * @param index the dataset index (must be >= 0). 3796 * 3797 * @return The axis. 3798 */ 3799 public ValueAxis getRangeAxisForDataset(int index) { 3800 Args.requireNonNegative(index, "index"); 3801 ValueAxis valueAxis; 3802 List axisIndices = (List) this.datasetToRangeAxesMap.get(index); 3803 if (axisIndices != null) { 3804 // the first axis in the list is used for data <--> Java2D 3805 Integer axisIndex = (Integer) axisIndices.get(0); 3806 valueAxis = getRangeAxis(axisIndex); 3807 } 3808 else { 3809 valueAxis = getRangeAxis(0); 3810 } 3811 return valueAxis; 3812 } 3813 3814 /** 3815 * Draws the gridlines for the plot, if they are visible. 3816 * 3817 * @param g2 the graphics device. 3818 * @param dataArea the data area. 3819 * @param ticks the ticks. 3820 * 3821 * @see #drawRangeGridlines(Graphics2D, Rectangle2D, List) 3822 */ 3823 protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea, 3824 List ticks) { 3825 3826 // no renderer, no gridlines... 3827 if (getRenderer() == null) { 3828 return; 3829 } 3830 3831 // draw the domain grid lines, if any... 3832 if (isDomainGridlinesVisible() || isDomainMinorGridlinesVisible()) { 3833 Stroke gridStroke = null; 3834 Paint gridPaint = null; 3835 Iterator iterator = ticks.iterator(); 3836 boolean paintLine; 3837 while (iterator.hasNext()) { 3838 paintLine = false; 3839 ValueTick tick = (ValueTick) iterator.next(); 3840 if ((tick.getTickType() == TickType.MINOR) 3841 && isDomainMinorGridlinesVisible()) { 3842 gridStroke = getDomainMinorGridlineStroke(); 3843 gridPaint = getDomainMinorGridlinePaint(); 3844 paintLine = true; 3845 } else if ((tick.getTickType() == TickType.MAJOR) 3846 && isDomainGridlinesVisible()) { 3847 gridStroke = getDomainGridlineStroke(); 3848 gridPaint = getDomainGridlinePaint(); 3849 paintLine = true; 3850 } 3851 XYItemRenderer r = getRenderer(); 3852 if ((r instanceof AbstractXYItemRenderer) && paintLine) { 3853 ((AbstractXYItemRenderer) r).drawDomainLine(g2, this, 3854 getDomainAxis(), dataArea, tick.getValue(), 3855 gridPaint, gridStroke); 3856 } 3857 } 3858 } 3859 } 3860 3861 /** 3862 * Draws the gridlines for the plot's primary range axis, if they are 3863 * visible. 3864 * 3865 * @param g2 the graphics device. 3866 * @param area the data area. 3867 * @param ticks the ticks. 3868 * 3869 * @see #drawDomainGridlines(Graphics2D, Rectangle2D, List) 3870 */ 3871 protected void drawRangeGridlines(Graphics2D g2, Rectangle2D area, 3872 List ticks) { 3873 3874 // no renderer, no gridlines... 3875 if (getRenderer() == null) { 3876 return; 3877 } 3878 3879 // draw the range grid lines, if any... 3880 if (isRangeGridlinesVisible() || isRangeMinorGridlinesVisible()) { 3881 Stroke gridStroke = null; 3882 Paint gridPaint = null; 3883 ValueAxis axis = getRangeAxis(); 3884 if (axis != null) { 3885 Iterator iterator = ticks.iterator(); 3886 boolean paintLine; 3887 while (iterator.hasNext()) { 3888 paintLine = false; 3889 ValueTick tick = (ValueTick) iterator.next(); 3890 if ((tick.getTickType() == TickType.MINOR) 3891 && isRangeMinorGridlinesVisible()) { 3892 gridStroke = getRangeMinorGridlineStroke(); 3893 gridPaint = getRangeMinorGridlinePaint(); 3894 paintLine = true; 3895 } else if ((tick.getTickType() == TickType.MAJOR) 3896 && isRangeGridlinesVisible()) { 3897 gridStroke = getRangeGridlineStroke(); 3898 gridPaint = getRangeGridlinePaint(); 3899 paintLine = true; 3900 } 3901 if ((tick.getValue() != 0.0 3902 || !isRangeZeroBaselineVisible()) && paintLine) { 3903 getRenderer().drawRangeLine(g2, this, getRangeAxis(), 3904 area, tick.getValue(), gridPaint, gridStroke); 3905 } 3906 } 3907 } 3908 } 3909 } 3910 3911 /** 3912 * Draws a base line across the chart at value zero on the domain axis. 3913 * 3914 * @param g2 the graphics device. 3915 * @param area the data area. 3916 * 3917 * @see #setDomainZeroBaselineVisible(boolean) 3918 * 3919 * @since 1.0.5 3920 */ 3921 protected void drawZeroDomainBaseline(Graphics2D g2, Rectangle2D area) { 3922 if (isDomainZeroBaselineVisible() && getRenderer() != null) { 3923 getRenderer().drawDomainLine(g2, this, getDomainAxis(), area, 0.0, 3924 this.domainZeroBaselinePaint, 3925 this.domainZeroBaselineStroke); 3926 } 3927 } 3928 3929 /** 3930 * Draws a base line across the chart at value zero on the range axis. 3931 * 3932 * @param g2 the graphics device. 3933 * @param area the data area. 3934 * 3935 * @see #setRangeZeroBaselineVisible(boolean) 3936 */ 3937 protected void drawZeroRangeBaseline(Graphics2D g2, Rectangle2D area) { 3938 if (isRangeZeroBaselineVisible()) { 3939 getRenderer().drawRangeLine(g2, this, getRangeAxis(), area, 0.0, 3940 this.rangeZeroBaselinePaint, this.rangeZeroBaselineStroke); 3941 } 3942 } 3943 3944 /** 3945 * Draws the annotations for the plot. 3946 * 3947 * @param g2 the graphics device. 3948 * @param dataArea the data area. 3949 * @param info the chart rendering info. 3950 */ 3951 public void drawAnnotations(Graphics2D g2, Rectangle2D dataArea, 3952 PlotRenderingInfo info) { 3953 3954 Iterator iterator = this.annotations.iterator(); 3955 while (iterator.hasNext()) { 3956 XYAnnotation annotation = (XYAnnotation) iterator.next(); 3957 ValueAxis xAxis = getDomainAxis(); 3958 ValueAxis yAxis = getRangeAxis(); 3959 annotation.draw(g2, this, dataArea, xAxis, yAxis, 0, info); 3960 } 3961 3962 } 3963 3964 /** 3965 * Draws the domain markers (if any) for an axis and layer. This method is 3966 * typically called from within the draw() method. 3967 * 3968 * @param g2 the graphics device. 3969 * @param dataArea the data area. 3970 * @param index the dataset/renderer index. 3971 * @param layer the layer (foreground or background). 3972 */ 3973 protected void drawDomainMarkers(Graphics2D g2, Rectangle2D dataArea, 3974 int index, Layer layer) { 3975 3976 XYItemRenderer r = getRenderer(index); 3977 if (r == null) { 3978 return; 3979 } 3980 // check that the renderer has a corresponding dataset (it doesn't 3981 // matter if the dataset is null) 3982 if (index >= getDatasetCount()) { 3983 return; 3984 } 3985 Collection markers = getDomainMarkers(index, layer); 3986 ValueAxis axis = getDomainAxisForDataset(index); 3987 if (markers != null && axis != null) { 3988 Iterator iterator = markers.iterator(); 3989 while (iterator.hasNext()) { 3990 Marker marker = (Marker) iterator.next(); 3991 r.drawDomainMarker(g2, this, axis, marker, dataArea); 3992 } 3993 } 3994 3995 } 3996 3997 /** 3998 * Draws the range markers (if any) for a renderer and layer. This method 3999 * is typically called from within the draw() method. 4000 * 4001 * @param g2 the graphics device. 4002 * @param dataArea the data area. 4003 * @param index the renderer index. 4004 * @param layer the layer (foreground or background). 4005 */ 4006 protected void drawRangeMarkers(Graphics2D g2, Rectangle2D dataArea, 4007 int index, Layer layer) { 4008 4009 XYItemRenderer r = getRenderer(index); 4010 if (r == null) { 4011 return; 4012 } 4013 // check that the renderer has a corresponding dataset (it doesn't 4014 // matter if the dataset is null) 4015 if (index >= getDatasetCount()) { 4016 return; 4017 } 4018 Collection markers = getRangeMarkers(index, layer); 4019 ValueAxis axis = getRangeAxisForDataset(index); 4020 if (markers != null && axis != null) { 4021 Iterator iterator = markers.iterator(); 4022 while (iterator.hasNext()) { 4023 Marker marker = (Marker) iterator.next(); 4024 r.drawRangeMarker(g2, this, axis, marker, dataArea); 4025 } 4026 } 4027 } 4028 4029 /** 4030 * Returns the list of domain markers (read only) for the specified layer. 4031 * 4032 * @param layer the layer (foreground or background). 4033 * 4034 * @return The list of domain markers. 4035 * 4036 * @see #getRangeMarkers(Layer) 4037 */ 4038 public Collection getDomainMarkers(Layer layer) { 4039 return getDomainMarkers(0, layer); 4040 } 4041 4042 /** 4043 * Returns the list of range markers (read only) for the specified layer. 4044 * 4045 * @param layer the layer (foreground or background). 4046 * 4047 * @return The list of range markers. 4048 * 4049 * @see #getDomainMarkers(Layer) 4050 */ 4051 public Collection getRangeMarkers(Layer layer) { 4052 return getRangeMarkers(0, layer); 4053 } 4054 4055 /** 4056 * Returns a collection of domain markers for a particular renderer and 4057 * layer. 4058 * 4059 * @param index the renderer index. 4060 * @param layer the layer. 4061 * 4062 * @return A collection of markers (possibly {@code null}). 4063 * 4064 * @see #getRangeMarkers(int, Layer) 4065 */ 4066 public Collection getDomainMarkers(int index, Layer layer) { 4067 Collection result = null; 4068 Integer key = index; 4069 if (layer == Layer.FOREGROUND) { 4070 result = (Collection) this.foregroundDomainMarkers.get(key); 4071 } 4072 else if (layer == Layer.BACKGROUND) { 4073 result = (Collection) this.backgroundDomainMarkers.get(key); 4074 } 4075 if (result != null) { 4076 result = Collections.unmodifiableCollection(result); 4077 } 4078 return result; 4079 } 4080 4081 /** 4082 * Returns a collection of range markers for a particular renderer and 4083 * layer. 4084 * 4085 * @param index the renderer index. 4086 * @param layer the layer. 4087 * 4088 * @return A collection of markers (possibly {@code null}). 4089 * 4090 * @see #getDomainMarkers(int, Layer) 4091 */ 4092 public Collection getRangeMarkers(int index, Layer layer) { 4093 Collection result = null; 4094 Integer key = index; 4095 if (layer == Layer.FOREGROUND) { 4096 result = (Collection) this.foregroundRangeMarkers.get(key); 4097 } 4098 else if (layer == Layer.BACKGROUND) { 4099 result = (Collection) this.backgroundRangeMarkers.get(key); 4100 } 4101 if (result != null) { 4102 result = Collections.unmodifiableCollection(result); 4103 } 4104 return result; 4105 } 4106 4107 /** 4108 * Utility method for drawing a horizontal line across the data area of the 4109 * plot. 4110 * 4111 * @param g2 the graphics device. 4112 * @param dataArea the data area. 4113 * @param value the coordinate, where to draw the line. 4114 * @param stroke the stroke to use. 4115 * @param paint the paint to use. 4116 */ 4117 protected void drawHorizontalLine(Graphics2D g2, Rectangle2D dataArea, 4118 double value, Stroke stroke, 4119 Paint paint) { 4120 4121 ValueAxis axis = getRangeAxis(); 4122 if (getOrientation() == PlotOrientation.HORIZONTAL) { 4123 axis = getDomainAxis(); 4124 } 4125 if (axis.getRange().contains(value)) { 4126 double yy = axis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); 4127 Line2D line = new Line2D.Double(dataArea.getMinX(), yy, 4128 dataArea.getMaxX(), yy); 4129 g2.setStroke(stroke); 4130 g2.setPaint(paint); 4131 g2.draw(line); 4132 } 4133 4134 } 4135 4136 /** 4137 * Draws a domain crosshair. 4138 * 4139 * @param g2 the graphics target. 4140 * @param dataArea the data area. 4141 * @param orientation the plot orientation. 4142 * @param value the crosshair value. 4143 * @param axis the axis against which the value is measured. 4144 * @param stroke the stroke used to draw the crosshair line. 4145 * @param paint the paint used to draw the crosshair line. 4146 * 4147 * @since 1.0.4 4148 */ 4149 protected void drawDomainCrosshair(Graphics2D g2, Rectangle2D dataArea, 4150 PlotOrientation orientation, double value, ValueAxis axis, 4151 Stroke stroke, Paint paint) { 4152 4153 if (!axis.getRange().contains(value)) { 4154 return; 4155 } 4156 Line2D line; 4157 if (orientation == PlotOrientation.VERTICAL) { 4158 double xx = axis.valueToJava2D(value, dataArea, 4159 RectangleEdge.BOTTOM); 4160 line = new Line2D.Double(xx, dataArea.getMinY(), xx, 4161 dataArea.getMaxY()); 4162 } else { 4163 double yy = axis.valueToJava2D(value, dataArea, 4164 RectangleEdge.LEFT); 4165 line = new Line2D.Double(dataArea.getMinX(), yy, 4166 dataArea.getMaxX(), yy); 4167 } 4168 Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL); 4169 g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, 4170 RenderingHints.VALUE_STROKE_NORMALIZE); 4171 g2.setStroke(stroke); 4172 g2.setPaint(paint); 4173 g2.draw(line); 4174 g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, saved); 4175 } 4176 4177 /** 4178 * Utility method for drawing a vertical line on the data area of the plot. 4179 * 4180 * @param g2 the graphics device. 4181 * @param dataArea the data area. 4182 * @param value the coordinate, where to draw the line. 4183 * @param stroke the stroke to use. 4184 * @param paint the paint to use. 4185 */ 4186 protected void drawVerticalLine(Graphics2D g2, Rectangle2D dataArea, 4187 double value, Stroke stroke, Paint paint) { 4188 4189 ValueAxis axis = getDomainAxis(); 4190 if (getOrientation() == PlotOrientation.HORIZONTAL) { 4191 axis = getRangeAxis(); 4192 } 4193 if (axis.getRange().contains(value)) { 4194 double xx = axis.valueToJava2D(value, dataArea, 4195 RectangleEdge.BOTTOM); 4196 Line2D line = new Line2D.Double(xx, dataArea.getMinY(), xx, 4197 dataArea.getMaxY()); 4198 g2.setStroke(stroke); 4199 g2.setPaint(paint); 4200 g2.draw(line); 4201 } 4202 4203 } 4204 4205 /** 4206 * Draws a range crosshair. 4207 * 4208 * @param g2 the graphics target. 4209 * @param dataArea the data area. 4210 * @param orientation the plot orientation. 4211 * @param value the crosshair value. 4212 * @param axis the axis against which the value is measured. 4213 * @param stroke the stroke used to draw the crosshair line. 4214 * @param paint the paint used to draw the crosshair line. 4215 * 4216 * @since 1.0.4 4217 */ 4218 protected void drawRangeCrosshair(Graphics2D g2, Rectangle2D dataArea, 4219 PlotOrientation orientation, double value, ValueAxis axis, 4220 Stroke stroke, Paint paint) { 4221 4222 if (!axis.getRange().contains(value)) { 4223 return; 4224 } 4225 Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL); 4226 g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, 4227 RenderingHints.VALUE_STROKE_NORMALIZE); 4228 Line2D line; 4229 if (orientation == PlotOrientation.HORIZONTAL) { 4230 double xx = axis.valueToJava2D(value, dataArea, 4231 RectangleEdge.BOTTOM); 4232 line = new Line2D.Double(xx, dataArea.getMinY(), xx, 4233 dataArea.getMaxY()); 4234 } else { 4235 double yy = axis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); 4236 line = new Line2D.Double(dataArea.getMinX(), yy, 4237 dataArea.getMaxX(), yy); 4238 } 4239 g2.setStroke(stroke); 4240 g2.setPaint(paint); 4241 g2.draw(line); 4242 g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, saved); 4243 } 4244 4245 /** 4246 * Handles a 'click' on the plot by updating the anchor values. 4247 * 4248 * @param x the x-coordinate, where the click occurred, in Java2D space. 4249 * @param y the y-coordinate, where the click occurred, in Java2D space. 4250 * @param info object containing information about the plot dimensions. 4251 */ 4252 @Override 4253 public void handleClick(int x, int y, PlotRenderingInfo info) { 4254 4255 Rectangle2D dataArea = info.getDataArea(); 4256 if (dataArea.contains(x, y)) { 4257 // set the anchor value for the horizontal axis... 4258 ValueAxis xaxis = getDomainAxis(); 4259 if (xaxis != null) { 4260 double hvalue = xaxis.java2DToValue(x, info.getDataArea(), 4261 getDomainAxisEdge()); 4262 setDomainCrosshairValue(hvalue); 4263 } 4264 4265 // set the anchor value for the vertical axis... 4266 ValueAxis yaxis = getRangeAxis(); 4267 if (yaxis != null) { 4268 double vvalue = yaxis.java2DToValue(y, info.getDataArea(), 4269 getRangeAxisEdge()); 4270 setRangeCrosshairValue(vvalue); 4271 } 4272 } 4273 } 4274 4275 /** 4276 * A utility method that returns a list of datasets that are mapped to a 4277 * particular axis. 4278 * 4279 * @param axisIndex the axis index ({@code null} not permitted). 4280 * 4281 * @return A list of datasets. 4282 */ 4283 private List<XYDataset> getDatasetsMappedToDomainAxis(Integer axisIndex) { 4284 Args.nullNotPermitted(axisIndex, "axisIndex"); 4285 List<XYDataset> result = new ArrayList<XYDataset>(); 4286 for (Entry<Integer, XYDataset> entry : this.datasets.entrySet()) { 4287 int index = entry.getKey(); 4288 List<Integer> mappedAxes = this.datasetToDomainAxesMap.get(index); 4289 if (mappedAxes == null) { 4290 if (axisIndex.equals(ZERO)) { 4291 result.add(entry.getValue()); 4292 } 4293 } else { 4294 if (mappedAxes.contains(axisIndex)) { 4295 result.add(entry.getValue()); 4296 } 4297 } 4298 } 4299 return result; 4300 } 4301 4302 /** 4303 * A utility method that returns a list of datasets that are mapped to a 4304 * particular axis. 4305 * 4306 * @param axisIndex the axis index ({@code null} not permitted). 4307 * 4308 * @return A list of datasets. 4309 */ 4310 private List<XYDataset> getDatasetsMappedToRangeAxis(Integer axisIndex) { 4311 Args.nullNotPermitted(axisIndex, "axisIndex"); 4312 List<XYDataset> result = new ArrayList<XYDataset>(); 4313 for (Entry<Integer, XYDataset> entry : this.datasets.entrySet()) { 4314 int index = entry.getKey(); 4315 List<Integer> mappedAxes = this.datasetToRangeAxesMap.get(index); 4316 if (mappedAxes == null) { 4317 if (axisIndex.equals(ZERO)) { 4318 result.add(entry.getValue()); 4319 } 4320 } else { 4321 if (mappedAxes.contains(axisIndex)) { 4322 result.add(entry.getValue()); 4323 } 4324 } 4325 } 4326 return result; 4327 } 4328 4329 /** 4330 * Returns the index of the given domain axis. 4331 * 4332 * @param axis the axis. 4333 * 4334 * @return The axis index. 4335 * 4336 * @see #getRangeAxisIndex(ValueAxis) 4337 */ 4338 public int getDomainAxisIndex(ValueAxis axis) { 4339 int result = findDomainAxisIndex(axis); 4340 if (result < 0) { 4341 // try the parent plot 4342 Plot parent = getParent(); 4343 if (parent instanceof XYPlot) { 4344 XYPlot p = (XYPlot) parent; 4345 result = p.getDomainAxisIndex(axis); 4346 } 4347 } 4348 return result; 4349 } 4350 4351 private int findDomainAxisIndex(ValueAxis axis) { 4352 for (Map.Entry<Integer, ValueAxis> entry : this.domainAxes.entrySet()) { 4353 if (entry.getValue() == axis) { 4354 return entry.getKey(); 4355 } 4356 } 4357 return -1; 4358 } 4359 4360 /** 4361 * Returns the index of the given range axis. 4362 * 4363 * @param axis the axis. 4364 * 4365 * @return The axis index. 4366 * 4367 * @see #getDomainAxisIndex(ValueAxis) 4368 */ 4369 public int getRangeAxisIndex(ValueAxis axis) { 4370 int result = findRangeAxisIndex(axis); 4371 if (result < 0) { 4372 // try the parent plot 4373 Plot parent = getParent(); 4374 if (parent instanceof XYPlot) { 4375 XYPlot p = (XYPlot) parent; 4376 result = p.getRangeAxisIndex(axis); 4377 } 4378 } 4379 return result; 4380 } 4381 4382 private int findRangeAxisIndex(ValueAxis axis) { 4383 for (Map.Entry<Integer, ValueAxis> entry : this.rangeAxes.entrySet()) { 4384 if (entry.getValue() == axis) { 4385 return entry.getKey(); 4386 } 4387 } 4388 return -1; 4389 } 4390 4391 /** 4392 * Returns the range for the specified axis. 4393 * 4394 * @param axis the axis. 4395 * 4396 * @return The range. 4397 */ 4398 @Override 4399 public Range getDataRange(ValueAxis axis) { 4400 4401 Range result = null; 4402 List<XYDataset> mappedDatasets = new ArrayList<XYDataset>(); 4403 List<XYAnnotation> includedAnnotations = new ArrayList<XYAnnotation>(); 4404 boolean isDomainAxis = true; 4405 4406 // is it a domain axis? 4407 int domainIndex = getDomainAxisIndex(axis); 4408 if (domainIndex >= 0) { 4409 isDomainAxis = true; 4410 mappedDatasets.addAll(getDatasetsMappedToDomainAxis(domainIndex)); 4411 if (domainIndex == 0) { 4412 // grab the plot's annotations 4413 Iterator iterator = this.annotations.iterator(); 4414 while (iterator.hasNext()) { 4415 XYAnnotation annotation = (XYAnnotation) iterator.next(); 4416 if (annotation instanceof XYAnnotationBoundsInfo) { 4417 includedAnnotations.add(annotation); 4418 } 4419 } 4420 } 4421 } 4422 4423 // or is it a range axis? 4424 int rangeIndex = getRangeAxisIndex(axis); 4425 if (rangeIndex >= 0) { 4426 isDomainAxis = false; 4427 mappedDatasets.addAll(getDatasetsMappedToRangeAxis(rangeIndex)); 4428 if (rangeIndex == 0) { 4429 Iterator iterator = this.annotations.iterator(); 4430 while (iterator.hasNext()) { 4431 XYAnnotation annotation = (XYAnnotation) iterator.next(); 4432 if (annotation instanceof XYAnnotationBoundsInfo) { 4433 includedAnnotations.add(annotation); 4434 } 4435 } 4436 } 4437 } 4438 4439 // iterate through the datasets that map to the axis and get the union 4440 // of the ranges. 4441 for (XYDataset d : mappedDatasets) { 4442 if (d != null) { 4443 XYItemRenderer r = getRendererForDataset(d); 4444 if (isDomainAxis) { 4445 if (r != null) { 4446 result = Range.combine(result, r.findDomainBounds(d)); 4447 } 4448 else { 4449 result = Range.combine(result, 4450 DatasetUtils.findDomainBounds(d)); 4451 } 4452 } 4453 else { 4454 if (r != null) { 4455 result = Range.combine(result, r.findRangeBounds(d)); 4456 } 4457 else { 4458 result = Range.combine(result, 4459 DatasetUtils.findRangeBounds(d)); 4460 } 4461 } 4462 // FIXME: the XYItemRenderer interface doesn't specify the 4463 // getAnnotations() method but it should 4464 if (r instanceof AbstractXYItemRenderer) { 4465 AbstractXYItemRenderer rr = (AbstractXYItemRenderer) r; 4466 Collection c = rr.getAnnotations(); 4467 Iterator i = c.iterator(); 4468 while (i.hasNext()) { 4469 XYAnnotation a = (XYAnnotation) i.next(); 4470 if (a instanceof XYAnnotationBoundsInfo) { 4471 includedAnnotations.add(a); 4472 } 4473 } 4474 } 4475 } 4476 } 4477 4478 Iterator it = includedAnnotations.iterator(); 4479 while (it.hasNext()) { 4480 XYAnnotationBoundsInfo xyabi = (XYAnnotationBoundsInfo) it.next(); 4481 if (xyabi.getIncludeInDataBounds()) { 4482 if (isDomainAxis) { 4483 result = Range.combine(result, xyabi.getXRange()); 4484 } 4485 else { 4486 result = Range.combine(result, xyabi.getYRange()); 4487 } 4488 } 4489 } 4490 4491 return result; 4492 4493 } 4494 4495 /** 4496 * Receives notification of a change to an {@link Annotation} added to 4497 * this plot. 4498 * 4499 * @param event information about the event (not used here). 4500 * 4501 * @since 1.0.14 4502 */ 4503 @Override 4504 public void annotationChanged(AnnotationChangeEvent event) { 4505 if (getParent() != null) { 4506 getParent().annotationChanged(event); 4507 } 4508 else { 4509 PlotChangeEvent e = new PlotChangeEvent(this); 4510 notifyListeners(e); 4511 } 4512 } 4513 4514 /** 4515 * Receives notification of a change to the plot's dataset. 4516 * <P> 4517 * The axis ranges are updated if necessary. 4518 * 4519 * @param event information about the event (not used here). 4520 */ 4521 @Override 4522 public void datasetChanged(DatasetChangeEvent event) { 4523 configureDomainAxes(); 4524 configureRangeAxes(); 4525 if (getParent() != null) { 4526 getParent().datasetChanged(event); 4527 } 4528 else { 4529 PlotChangeEvent e = new PlotChangeEvent(this); 4530 e.setType(ChartChangeEventType.DATASET_UPDATED); 4531 notifyListeners(e); 4532 } 4533 } 4534 4535 /** 4536 * Receives notification of a renderer change event. 4537 * 4538 * @param event the event. 4539 */ 4540 @Override 4541 public void rendererChanged(RendererChangeEvent event) { 4542 // if the event was caused by a change to series visibility, then 4543 // the axis ranges might need updating... 4544 if (event.getSeriesVisibilityChanged()) { 4545 configureDomainAxes(); 4546 configureRangeAxes(); 4547 } 4548 fireChangeEvent(); 4549 } 4550 4551 /** 4552 * Returns a flag indicating whether or not the domain crosshair is visible. 4553 * 4554 * @return The flag. 4555 * 4556 * @see #setDomainCrosshairVisible(boolean) 4557 */ 4558 public boolean isDomainCrosshairVisible() { 4559 return this.domainCrosshairVisible; 4560 } 4561 4562 /** 4563 * Sets the flag indicating whether or not the domain crosshair is visible 4564 * and, if the flag changes, sends a {@link PlotChangeEvent} to all 4565 * registered listeners. 4566 * 4567 * @param flag the new value of the flag. 4568 * 4569 * @see #isDomainCrosshairVisible() 4570 */ 4571 public void setDomainCrosshairVisible(boolean flag) { 4572 if (this.domainCrosshairVisible != flag) { 4573 this.domainCrosshairVisible = flag; 4574 fireChangeEvent(); 4575 } 4576 } 4577 4578 /** 4579 * Returns a flag indicating whether or not the crosshair should "lock-on" 4580 * to actual data values. 4581 * 4582 * @return The flag. 4583 * 4584 * @see #setDomainCrosshairLockedOnData(boolean) 4585 */ 4586 public boolean isDomainCrosshairLockedOnData() { 4587 return this.domainCrosshairLockedOnData; 4588 } 4589 4590 /** 4591 * Sets the flag indicating whether or not the domain crosshair should 4592 * "lock-on" to actual data values. If the flag value changes, this 4593 * method sends a {@link PlotChangeEvent} to all registered listeners. 4594 * 4595 * @param flag the flag. 4596 * 4597 * @see #isDomainCrosshairLockedOnData() 4598 */ 4599 public void setDomainCrosshairLockedOnData(boolean flag) { 4600 if (this.domainCrosshairLockedOnData != flag) { 4601 this.domainCrosshairLockedOnData = flag; 4602 fireChangeEvent(); 4603 } 4604 } 4605 4606 /** 4607 * Returns the domain crosshair value. 4608 * 4609 * @return The value. 4610 * 4611 * @see #setDomainCrosshairValue(double) 4612 */ 4613 public double getDomainCrosshairValue() { 4614 return this.domainCrosshairValue; 4615 } 4616 4617 /** 4618 * Sets the domain crosshair value and sends a {@link PlotChangeEvent} to 4619 * all registered listeners (provided that the domain crosshair is visible). 4620 * 4621 * @param value the value. 4622 * 4623 * @see #getDomainCrosshairValue() 4624 */ 4625 public void setDomainCrosshairValue(double value) { 4626 setDomainCrosshairValue(value, true); 4627 } 4628 4629 /** 4630 * Sets the domain crosshair value and, if requested, sends a 4631 * {@link PlotChangeEvent} to all registered listeners (provided that the 4632 * domain crosshair is visible). 4633 * 4634 * @param value the new value. 4635 * @param notify notify listeners? 4636 * 4637 * @see #getDomainCrosshairValue() 4638 */ 4639 public void setDomainCrosshairValue(double value, boolean notify) { 4640 this.domainCrosshairValue = value; 4641 if (isDomainCrosshairVisible() && notify) { 4642 fireChangeEvent(); 4643 } 4644 } 4645 4646 /** 4647 * Returns the {@link Stroke} used to draw the crosshair (if visible). 4648 * 4649 * @return The crosshair stroke (never {@code null}). 4650 * 4651 * @see #setDomainCrosshairStroke(Stroke) 4652 * @see #isDomainCrosshairVisible() 4653 * @see #getDomainCrosshairPaint() 4654 */ 4655 public Stroke getDomainCrosshairStroke() { 4656 return this.domainCrosshairStroke; 4657 } 4658 4659 /** 4660 * Sets the Stroke used to draw the crosshairs (if visible) and notifies 4661 * registered listeners that the axis has been modified. 4662 * 4663 * @param stroke the new crosshair stroke ({@code null} not 4664 * permitted). 4665 * 4666 * @see #getDomainCrosshairStroke() 4667 */ 4668 public void setDomainCrosshairStroke(Stroke stroke) { 4669 Args.nullNotPermitted(stroke, "stroke"); 4670 this.domainCrosshairStroke = stroke; 4671 fireChangeEvent(); 4672 } 4673 4674 /** 4675 * Returns the domain crosshair paint. 4676 * 4677 * @return The crosshair paint (never {@code null}). 4678 * 4679 * @see #setDomainCrosshairPaint(Paint) 4680 * @see #isDomainCrosshairVisible() 4681 * @see #getDomainCrosshairStroke() 4682 */ 4683 public Paint getDomainCrosshairPaint() { 4684 return this.domainCrosshairPaint; 4685 } 4686 4687 /** 4688 * Sets the paint used to draw the crosshairs (if visible) and sends a 4689 * {@link PlotChangeEvent} to all registered listeners. 4690 * 4691 * @param paint the new crosshair paint ({@code null} not permitted). 4692 * 4693 * @see #getDomainCrosshairPaint() 4694 */ 4695 public void setDomainCrosshairPaint(Paint paint) { 4696 Args.nullNotPermitted(paint, "paint"); 4697 this.domainCrosshairPaint = paint; 4698 fireChangeEvent(); 4699 } 4700 4701 /** 4702 * Returns a flag indicating whether or not the range crosshair is visible. 4703 * 4704 * @return The flag. 4705 * 4706 * @see #setRangeCrosshairVisible(boolean) 4707 * @see #isDomainCrosshairVisible() 4708 */ 4709 public boolean isRangeCrosshairVisible() { 4710 return this.rangeCrosshairVisible; 4711 } 4712 4713 /** 4714 * Sets the flag indicating whether or not the range crosshair is visible. 4715 * If the flag value changes, this method sends a {@link PlotChangeEvent} 4716 * to all registered listeners. 4717 * 4718 * @param flag the new value of the flag. 4719 * 4720 * @see #isRangeCrosshairVisible() 4721 */ 4722 public void setRangeCrosshairVisible(boolean flag) { 4723 if (this.rangeCrosshairVisible != flag) { 4724 this.rangeCrosshairVisible = flag; 4725 fireChangeEvent(); 4726 } 4727 } 4728 4729 /** 4730 * Returns a flag indicating whether or not the crosshair should "lock-on" 4731 * to actual data values. 4732 * 4733 * @return The flag. 4734 * 4735 * @see #setRangeCrosshairLockedOnData(boolean) 4736 */ 4737 public boolean isRangeCrosshairLockedOnData() { 4738 return this.rangeCrosshairLockedOnData; 4739 } 4740 4741 /** 4742 * Sets the flag indicating whether or not the range crosshair should 4743 * "lock-on" to actual data values. If the flag value changes, this method 4744 * sends a {@link PlotChangeEvent} to all registered listeners. 4745 * 4746 * @param flag the flag. 4747 * 4748 * @see #isRangeCrosshairLockedOnData() 4749 */ 4750 public void setRangeCrosshairLockedOnData(boolean flag) { 4751 if (this.rangeCrosshairLockedOnData != flag) { 4752 this.rangeCrosshairLockedOnData = flag; 4753 fireChangeEvent(); 4754 } 4755 } 4756 4757 /** 4758 * Returns the range crosshair value. 4759 * 4760 * @return The value. 4761 * 4762 * @see #setRangeCrosshairValue(double) 4763 */ 4764 public double getRangeCrosshairValue() { 4765 return this.rangeCrosshairValue; 4766 } 4767 4768 /** 4769 * Sets the range crosshair value. 4770 * <P> 4771 * Registered listeners are notified that the plot has been modified, but 4772 * only if the crosshair is visible. 4773 * 4774 * @param value the new value. 4775 * 4776 * @see #getRangeCrosshairValue() 4777 */ 4778 public void setRangeCrosshairValue(double value) { 4779 setRangeCrosshairValue(value, true); 4780 } 4781 4782 /** 4783 * Sets the range crosshair value and sends a {@link PlotChangeEvent} to 4784 * all registered listeners, but only if the crosshair is visible. 4785 * 4786 * @param value the new value. 4787 * @param notify a flag that controls whether or not listeners are 4788 * notified. 4789 * 4790 * @see #getRangeCrosshairValue() 4791 */ 4792 public void setRangeCrosshairValue(double value, boolean notify) { 4793 this.rangeCrosshairValue = value; 4794 if (isRangeCrosshairVisible() && notify) { 4795 fireChangeEvent(); 4796 } 4797 } 4798 4799 /** 4800 * Returns the stroke used to draw the crosshair (if visible). 4801 * 4802 * @return The crosshair stroke (never {@code null}). 4803 * 4804 * @see #setRangeCrosshairStroke(Stroke) 4805 * @see #isRangeCrosshairVisible() 4806 * @see #getRangeCrosshairPaint() 4807 */ 4808 public Stroke getRangeCrosshairStroke() { 4809 return this.rangeCrosshairStroke; 4810 } 4811 4812 /** 4813 * Sets the stroke used to draw the crosshairs (if visible) and sends a 4814 * {@link PlotChangeEvent} to all registered listeners. 4815 * 4816 * @param stroke the new crosshair stroke ({@code null} not 4817 * permitted). 4818 * 4819 * @see #getRangeCrosshairStroke() 4820 */ 4821 public void setRangeCrosshairStroke(Stroke stroke) { 4822 Args.nullNotPermitted(stroke, "stroke"); 4823 this.rangeCrosshairStroke = stroke; 4824 fireChangeEvent(); 4825 } 4826 4827 /** 4828 * Returns the range crosshair paint. 4829 * 4830 * @return The crosshair paint (never {@code null}). 4831 * 4832 * @see #setRangeCrosshairPaint(Paint) 4833 * @see #isRangeCrosshairVisible() 4834 * @see #getRangeCrosshairStroke() 4835 */ 4836 public Paint getRangeCrosshairPaint() { 4837 return this.rangeCrosshairPaint; 4838 } 4839 4840 /** 4841 * Sets the paint used to color the crosshairs (if visible) and sends a 4842 * {@link PlotChangeEvent} to all registered listeners. 4843 * 4844 * @param paint the new crosshair paint ({@code null} not permitted). 4845 * 4846 * @see #getRangeCrosshairPaint() 4847 */ 4848 public void setRangeCrosshairPaint(Paint paint) { 4849 Args.nullNotPermitted(paint, "paint"); 4850 this.rangeCrosshairPaint = paint; 4851 fireChangeEvent(); 4852 } 4853 4854 /** 4855 * Returns the fixed domain axis space. 4856 * 4857 * @return The fixed domain axis space (possibly {@code null}). 4858 * 4859 * @see #setFixedDomainAxisSpace(AxisSpace) 4860 */ 4861 public AxisSpace getFixedDomainAxisSpace() { 4862 return this.fixedDomainAxisSpace; 4863 } 4864 4865 /** 4866 * Sets the fixed domain axis space and sends a {@link PlotChangeEvent} to 4867 * all registered listeners. 4868 * 4869 * @param space the space ({@code null} permitted). 4870 * 4871 * @see #getFixedDomainAxisSpace() 4872 */ 4873 public void setFixedDomainAxisSpace(AxisSpace space) { 4874 setFixedDomainAxisSpace(space, true); 4875 } 4876 4877 /** 4878 * Sets the fixed domain axis space and, if requested, sends a 4879 * {@link PlotChangeEvent} to all registered listeners. 4880 * 4881 * @param space the space ({@code null} permitted). 4882 * @param notify notify listeners? 4883 * 4884 * @see #getFixedDomainAxisSpace() 4885 * 4886 * @since 1.0.9 4887 */ 4888 public void setFixedDomainAxisSpace(AxisSpace space, boolean notify) { 4889 this.fixedDomainAxisSpace = space; 4890 if (notify) { 4891 fireChangeEvent(); 4892 } 4893 } 4894 4895 /** 4896 * Returns the fixed range axis space. 4897 * 4898 * @return The fixed range axis space (possibly {@code null}). 4899 * 4900 * @see #setFixedRangeAxisSpace(AxisSpace) 4901 */ 4902 public AxisSpace getFixedRangeAxisSpace() { 4903 return this.fixedRangeAxisSpace; 4904 } 4905 4906 /** 4907 * Sets the fixed range axis space and sends a {@link PlotChangeEvent} to 4908 * all registered listeners. 4909 * 4910 * @param space the space ({@code null} permitted). 4911 * 4912 * @see #getFixedRangeAxisSpace() 4913 */ 4914 public void setFixedRangeAxisSpace(AxisSpace space) { 4915 setFixedRangeAxisSpace(space, true); 4916 } 4917 4918 /** 4919 * Sets the fixed range axis space and, if requested, sends a 4920 * {@link PlotChangeEvent} to all registered listeners. 4921 * 4922 * @param space the space ({@code null} permitted). 4923 * @param notify notify listeners? 4924 * 4925 * @see #getFixedRangeAxisSpace() 4926 * 4927 * @since 1.0.9 4928 */ 4929 public void setFixedRangeAxisSpace(AxisSpace space, boolean notify) { 4930 this.fixedRangeAxisSpace = space; 4931 if (notify) { 4932 fireChangeEvent(); 4933 } 4934 } 4935 4936 /** 4937 * Returns {@code true} if panning is enabled for the domain axes, 4938 * and {@code false} otherwise. 4939 * 4940 * @return A boolean. 4941 * 4942 * @since 1.0.13 4943 */ 4944 @Override 4945 public boolean isDomainPannable() { 4946 return this.domainPannable; 4947 } 4948 4949 /** 4950 * Sets the flag that enables or disables panning of the plot along the 4951 * domain axes. 4952 * 4953 * @param pannable the new flag value. 4954 * 4955 * @since 1.0.13 4956 */ 4957 public void setDomainPannable(boolean pannable) { 4958 this.domainPannable = pannable; 4959 } 4960 4961 /** 4962 * Returns {@code true} if panning is enabled for the range axis/axes, 4963 * and {@code false} otherwise. The default value is {@code false}. 4964 * 4965 * @return A boolean. 4966 * 4967 * @since 1.0.13 4968 */ 4969 @Override 4970 public boolean isRangePannable() { 4971 return this.rangePannable; 4972 } 4973 4974 /** 4975 * Sets the flag that enables or disables panning of the plot along 4976 * the range axis/axes. 4977 * 4978 * @param pannable the new flag value. 4979 * 4980 * @since 1.0.13 4981 */ 4982 public void setRangePannable(boolean pannable) { 4983 this.rangePannable = pannable; 4984 } 4985 4986 /** 4987 * Pans the domain axes by the specified percentage. 4988 * 4989 * @param percent the distance to pan (as a percentage of the axis length). 4990 * @param info the plot info 4991 * @param source the source point where the pan action started. 4992 * 4993 * @since 1.0.13 4994 */ 4995 @Override 4996 public void panDomainAxes(double percent, PlotRenderingInfo info, 4997 Point2D source) { 4998 if (!isDomainPannable()) { 4999 return; 5000 } 5001 int domainAxisCount = getDomainAxisCount(); 5002 for (int i = 0; i < domainAxisCount; i++) { 5003 ValueAxis axis = getDomainAxis(i); 5004 if (axis == null) { 5005 continue; 5006 } 5007 5008 axis.pan(axis.isInverted() ? -percent : percent); 5009 } 5010 } 5011 5012 /** 5013 * Pans the range axes by the specified percentage. 5014 * 5015 * @param percent the distance to pan (as a percentage of the axis length). 5016 * @param info the plot info 5017 * @param source the source point where the pan action started. 5018 * 5019 * @since 1.0.13 5020 */ 5021 @Override 5022 public void panRangeAxes(double percent, PlotRenderingInfo info, 5023 Point2D source) { 5024 if (!isRangePannable()) { 5025 return; 5026 } 5027 int rangeAxisCount = getRangeAxisCount(); 5028 for (int i = 0; i < rangeAxisCount; i++) { 5029 ValueAxis axis = getRangeAxis(i); 5030 if (axis == null) { 5031 continue; 5032 } 5033 5034 axis.pan(axis.isInverted() ? -percent : percent); 5035 } 5036 } 5037 5038 /** 5039 * Multiplies the range on the domain axis/axes by the specified factor. 5040 * 5041 * @param factor the zoom factor. 5042 * @param info the plot rendering info. 5043 * @param source the source point (in Java2D space). 5044 * 5045 * @see #zoomRangeAxes(double, PlotRenderingInfo, Point2D) 5046 */ 5047 @Override 5048 public void zoomDomainAxes(double factor, PlotRenderingInfo info, 5049 Point2D source) { 5050 // delegate to other method 5051 zoomDomainAxes(factor, info, source, false); 5052 } 5053 5054 /** 5055 * Multiplies the range on the domain axis/axes by the specified factor. 5056 * 5057 * @param factor the zoom factor. 5058 * @param info the plot rendering info. 5059 * @param source the source point (in Java2D space). 5060 * @param useAnchor use source point as zoom anchor? 5061 * 5062 * @see #zoomRangeAxes(double, PlotRenderingInfo, Point2D, boolean) 5063 * 5064 * @since 1.0.7 5065 */ 5066 @Override 5067 public void zoomDomainAxes(double factor, PlotRenderingInfo info, 5068 Point2D source, boolean useAnchor) { 5069 5070 // perform the zoom on each domain axis 5071 for (ValueAxis xAxis : this.domainAxes.values()) { 5072 if (xAxis == null) { 5073 continue; 5074 } 5075 if (useAnchor) { 5076 // get the relevant source coordinate given the plot orientation 5077 double sourceX = source.getX(); 5078 if (this.orientation == PlotOrientation.HORIZONTAL) { 5079 sourceX = source.getY(); 5080 } 5081 double anchorX = xAxis.java2DToValue(sourceX, 5082 info.getDataArea(), getDomainAxisEdge()); 5083 xAxis.resizeRange2(factor, anchorX); 5084 } else { 5085 xAxis.resizeRange(factor); 5086 } 5087 } 5088 } 5089 5090 /** 5091 * Zooms in on the domain axis/axes. The new lower and upper bounds are 5092 * specified as percentages of the current axis range, where 0 percent is 5093 * the current lower bound and 100 percent is the current upper bound. 5094 * 5095 * @param lowerPercent a percentage that determines the new lower bound 5096 * for the axis (e.g. 0.20 is twenty percent). 5097 * @param upperPercent a percentage that determines the new upper bound 5098 * for the axis (e.g. 0.80 is eighty percent). 5099 * @param info the plot rendering info. 5100 * @param source the source point (ignored). 5101 * 5102 * @see #zoomRangeAxes(double, double, PlotRenderingInfo, Point2D) 5103 */ 5104 @Override 5105 public void zoomDomainAxes(double lowerPercent, double upperPercent, 5106 PlotRenderingInfo info, Point2D source) { 5107 for (ValueAxis xAxis : this.domainAxes.values()) { 5108 if (xAxis != null) { 5109 xAxis.zoomRange(lowerPercent, upperPercent); 5110 } 5111 } 5112 } 5113 5114 /** 5115 * Multiplies the range on the range axis/axes by the specified factor. 5116 * 5117 * @param factor the zoom factor. 5118 * @param info the plot rendering info. 5119 * @param source the source point. 5120 * 5121 * @see #zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean) 5122 */ 5123 @Override 5124 public void zoomRangeAxes(double factor, PlotRenderingInfo info, 5125 Point2D source) { 5126 // delegate to other method 5127 zoomRangeAxes(factor, info, source, false); 5128 } 5129 5130 /** 5131 * Multiplies the range on the range axis/axes by the specified factor. 5132 * 5133 * @param factor the zoom factor. 5134 * @param info the plot rendering info. 5135 * @param source the source point. 5136 * @param useAnchor a flag that controls whether or not the source point 5137 * is used for the zoom anchor. 5138 * 5139 * @see #zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean) 5140 * 5141 * @since 1.0.7 5142 */ 5143 @Override 5144 public void zoomRangeAxes(double factor, PlotRenderingInfo info, 5145 Point2D source, boolean useAnchor) { 5146 5147 // perform the zoom on each range axis 5148 for (ValueAxis yAxis : this.rangeAxes.values()) { 5149 if (yAxis == null) { 5150 continue; 5151 } 5152 if (useAnchor) { 5153 // get the relevant source coordinate given the plot orientation 5154 double sourceY = source.getY(); 5155 if (this.orientation == PlotOrientation.HORIZONTAL) { 5156 sourceY = source.getX(); 5157 } 5158 double anchorY = yAxis.java2DToValue(sourceY, 5159 info.getDataArea(), getRangeAxisEdge()); 5160 yAxis.resizeRange2(factor, anchorY); 5161 } else { 5162 yAxis.resizeRange(factor); 5163 } 5164 } 5165 } 5166 5167 /** 5168 * Zooms in on the range axes. 5169 * 5170 * @param lowerPercent the lower bound. 5171 * @param upperPercent the upper bound. 5172 * @param info the plot rendering info. 5173 * @param source the source point. 5174 * 5175 * @see #zoomDomainAxes(double, double, PlotRenderingInfo, Point2D) 5176 */ 5177 @Override 5178 public void zoomRangeAxes(double lowerPercent, double upperPercent, 5179 PlotRenderingInfo info, Point2D source) { 5180 for (ValueAxis yAxis : this.rangeAxes.values()) { 5181 if (yAxis != null) { 5182 yAxis.zoomRange(lowerPercent, upperPercent); 5183 } 5184 } 5185 } 5186 5187 /** 5188 * Returns {@code true}, indicating that the domain axis/axes for this 5189 * plot are zoomable. 5190 * 5191 * @return A boolean. 5192 * 5193 * @see #isRangeZoomable() 5194 */ 5195 @Override 5196 public boolean isDomainZoomable() { 5197 return true; 5198 } 5199 5200 /** 5201 * Returns {@code true}, indicating that the range axis/axes for this 5202 * plot are zoomable. 5203 * 5204 * @return A boolean. 5205 * 5206 * @see #isDomainZoomable() 5207 */ 5208 @Override 5209 public boolean isRangeZoomable() { 5210 return true; 5211 } 5212 5213 /** 5214 * Returns the number of series in the primary dataset for this plot. If 5215 * the dataset is {@code null}, the method returns 0. 5216 * 5217 * @return The series count. 5218 */ 5219 public int getSeriesCount() { 5220 int result = 0; 5221 XYDataset dataset = getDataset(); 5222 if (dataset != null) { 5223 result = dataset.getSeriesCount(); 5224 } 5225 return result; 5226 } 5227 5228 /** 5229 * Returns the fixed legend items, if any. 5230 * 5231 * @return The legend items (possibly {@code null}). 5232 * 5233 * @see #setFixedLegendItems(LegendItemCollection) 5234 */ 5235 public LegendItemCollection getFixedLegendItems() { 5236 return this.fixedLegendItems; 5237 } 5238 5239 /** 5240 * Sets the fixed legend items for the plot. Leave this set to 5241 * {@code null} if you prefer the legend items to be created 5242 * automatically. 5243 * 5244 * @param items the legend items ({@code null} permitted). 5245 * 5246 * @see #getFixedLegendItems() 5247 */ 5248 public void setFixedLegendItems(LegendItemCollection items) { 5249 this.fixedLegendItems = items; 5250 fireChangeEvent(); 5251 } 5252 5253 /** 5254 * Returns the legend items for the plot. Each legend item is generated by 5255 * the plot's renderer, since the renderer is responsible for the visual 5256 * representation of the data. 5257 * 5258 * @return The legend items. 5259 */ 5260 @Override 5261 public LegendItemCollection getLegendItems() { 5262 if (this.fixedLegendItems != null) { 5263 return this.fixedLegendItems; 5264 } 5265 LegendItemCollection result = new LegendItemCollection(); 5266 for (XYDataset dataset : this.datasets.values()) { 5267 if (dataset == null) { 5268 continue; 5269 } 5270 int datasetIndex = indexOf(dataset); 5271 XYItemRenderer renderer = getRenderer(datasetIndex); 5272 if (renderer == null) { 5273 renderer = getRenderer(0); 5274 } 5275 if (renderer != null) { 5276 int seriesCount = dataset.getSeriesCount(); 5277 for (int i = 0; i < seriesCount; i++) { 5278 if (renderer.isSeriesVisible(i) 5279 && renderer.isSeriesVisibleInLegend(i)) { 5280 LegendItem item = renderer.getLegendItem( 5281 datasetIndex, i); 5282 if (item != null) { 5283 result.add(item); 5284 } 5285 } 5286 } 5287 } 5288 } 5289 return result; 5290 } 5291 5292 /** 5293 * Tests this plot for equality with another object. 5294 * 5295 * @param obj the object ({@code null} permitted). 5296 * 5297 * @return {@code true} or {@code false}. 5298 */ 5299 @Override 5300 public boolean equals(Object obj) { 5301 if (obj == this) { 5302 return true; 5303 } 5304 if (!(obj instanceof XYPlot)) { 5305 return false; 5306 } 5307 XYPlot that = (XYPlot) obj; 5308 if (this.weight != that.weight) { 5309 return false; 5310 } 5311 if (this.orientation != that.orientation) { 5312 return false; 5313 } 5314 if (!this.domainAxes.equals(that.domainAxes)) { 5315 return false; 5316 } 5317 if (!this.domainAxisLocations.equals(that.domainAxisLocations)) { 5318 return false; 5319 } 5320 if (this.rangeCrosshairLockedOnData 5321 != that.rangeCrosshairLockedOnData) { 5322 return false; 5323 } 5324 if (this.domainGridlinesVisible != that.domainGridlinesVisible) { 5325 return false; 5326 } 5327 if (this.rangeGridlinesVisible != that.rangeGridlinesVisible) { 5328 return false; 5329 } 5330 if (this.domainMinorGridlinesVisible 5331 != that.domainMinorGridlinesVisible) { 5332 return false; 5333 } 5334 if (this.rangeMinorGridlinesVisible 5335 != that.rangeMinorGridlinesVisible) { 5336 return false; 5337 } 5338 if (this.domainZeroBaselineVisible != that.domainZeroBaselineVisible) { 5339 return false; 5340 } 5341 if (this.rangeZeroBaselineVisible != that.rangeZeroBaselineVisible) { 5342 return false; 5343 } 5344 if (this.domainCrosshairVisible != that.domainCrosshairVisible) { 5345 return false; 5346 } 5347 if (this.domainCrosshairValue != that.domainCrosshairValue) { 5348 return false; 5349 } 5350 if (this.domainCrosshairLockedOnData 5351 != that.domainCrosshairLockedOnData) { 5352 return false; 5353 } 5354 if (this.rangeCrosshairVisible != that.rangeCrosshairVisible) { 5355 return false; 5356 } 5357 if (this.rangeCrosshairValue != that.rangeCrosshairValue) { 5358 return false; 5359 } 5360 if (!ObjectUtils.equal(this.axisOffset, that.axisOffset)) { 5361 return false; 5362 } 5363 if (!ObjectUtils.equal(this.renderers, that.renderers)) { 5364 return false; 5365 } 5366 if (!ObjectUtils.equal(this.rangeAxes, that.rangeAxes)) { 5367 return false; 5368 } 5369 if (!this.rangeAxisLocations.equals(that.rangeAxisLocations)) { 5370 return false; 5371 } 5372 if (!ObjectUtils.equal(this.datasetToDomainAxesMap, 5373 that.datasetToDomainAxesMap)) { 5374 return false; 5375 } 5376 if (!ObjectUtils.equal(this.datasetToRangeAxesMap, 5377 that.datasetToRangeAxesMap)) { 5378 return false; 5379 } 5380 if (!ObjectUtils.equal(this.domainGridlineStroke, 5381 that.domainGridlineStroke)) { 5382 return false; 5383 } 5384 if (!PaintUtils.equal(this.domainGridlinePaint, 5385 that.domainGridlinePaint)) { 5386 return false; 5387 } 5388 if (!ObjectUtils.equal(this.rangeGridlineStroke, 5389 that.rangeGridlineStroke)) { 5390 return false; 5391 } 5392 if (!PaintUtils.equal(this.rangeGridlinePaint, 5393 that.rangeGridlinePaint)) { 5394 return false; 5395 } 5396 if (!ObjectUtils.equal(this.domainMinorGridlineStroke, 5397 that.domainMinorGridlineStroke)) { 5398 return false; 5399 } 5400 if (!PaintUtils.equal(this.domainMinorGridlinePaint, 5401 that.domainMinorGridlinePaint)) { 5402 return false; 5403 } 5404 if (!ObjectUtils.equal(this.rangeMinorGridlineStroke, 5405 that.rangeMinorGridlineStroke)) { 5406 return false; 5407 } 5408 if (!PaintUtils.equal(this.rangeMinorGridlinePaint, 5409 that.rangeMinorGridlinePaint)) { 5410 return false; 5411 } 5412 if (!PaintUtils.equal(this.domainZeroBaselinePaint, 5413 that.domainZeroBaselinePaint)) { 5414 return false; 5415 } 5416 if (!ObjectUtils.equal(this.domainZeroBaselineStroke, 5417 that.domainZeroBaselineStroke)) { 5418 return false; 5419 } 5420 if (!PaintUtils.equal(this.rangeZeroBaselinePaint, 5421 that.rangeZeroBaselinePaint)) { 5422 return false; 5423 } 5424 if (!ObjectUtils.equal(this.rangeZeroBaselineStroke, 5425 that.rangeZeroBaselineStroke)) { 5426 return false; 5427 } 5428 if (!ObjectUtils.equal(this.domainCrosshairStroke, 5429 that.domainCrosshairStroke)) { 5430 return false; 5431 } 5432 if (!PaintUtils.equal(this.domainCrosshairPaint, 5433 that.domainCrosshairPaint)) { 5434 return false; 5435 } 5436 if (!ObjectUtils.equal(this.rangeCrosshairStroke, 5437 that.rangeCrosshairStroke)) { 5438 return false; 5439 } 5440 if (!PaintUtils.equal(this.rangeCrosshairPaint, 5441 that.rangeCrosshairPaint)) { 5442 return false; 5443 } 5444 if (!ObjectUtils.equal(this.foregroundDomainMarkers, 5445 that.foregroundDomainMarkers)) { 5446 return false; 5447 } 5448 if (!ObjectUtils.equal(this.backgroundDomainMarkers, 5449 that.backgroundDomainMarkers)) { 5450 return false; 5451 } 5452 if (!ObjectUtils.equal(this.foregroundRangeMarkers, 5453 that.foregroundRangeMarkers)) { 5454 return false; 5455 } 5456 if (!ObjectUtils.equal(this.backgroundRangeMarkers, 5457 that.backgroundRangeMarkers)) { 5458 return false; 5459 } 5460 if (!ObjectUtils.equal(this.foregroundDomainMarkers, 5461 that.foregroundDomainMarkers)) { 5462 return false; 5463 } 5464 if (!ObjectUtils.equal(this.backgroundDomainMarkers, 5465 that.backgroundDomainMarkers)) { 5466 return false; 5467 } 5468 if (!ObjectUtils.equal(this.foregroundRangeMarkers, 5469 that.foregroundRangeMarkers)) { 5470 return false; 5471 } 5472 if (!ObjectUtils.equal(this.backgroundRangeMarkers, 5473 that.backgroundRangeMarkers)) { 5474 return false; 5475 } 5476 if (!ObjectUtils.equal(this.annotations, that.annotations)) { 5477 return false; 5478 } 5479 if (!ObjectUtils.equal(this.fixedLegendItems, 5480 that.fixedLegendItems)) { 5481 return false; 5482 } 5483 if (!PaintUtils.equal(this.domainTickBandPaint, 5484 that.domainTickBandPaint)) { 5485 return false; 5486 } 5487 if (!PaintUtils.equal(this.rangeTickBandPaint, 5488 that.rangeTickBandPaint)) { 5489 return false; 5490 } 5491 if (!this.quadrantOrigin.equals(that.quadrantOrigin)) { 5492 return false; 5493 } 5494 for (int i = 0; i < 4; i++) { 5495 if (!PaintUtils.equal(this.quadrantPaint[i], 5496 that.quadrantPaint[i])) { 5497 return false; 5498 } 5499 } 5500 if (!ObjectUtils.equal(this.shadowGenerator, 5501 that.shadowGenerator)) { 5502 return false; 5503 } 5504 return super.equals(obj); 5505 } 5506 5507 /** 5508 * Returns a clone of the plot. 5509 * 5510 * @return A clone. 5511 * 5512 * @throws CloneNotSupportedException this can occur if some component of 5513 * the plot cannot be cloned. 5514 */ 5515 @Override 5516 public Object clone() throws CloneNotSupportedException { 5517 XYPlot clone = (XYPlot) super.clone(); 5518 clone.domainAxes = CloneUtils.cloneMapValues(this.domainAxes); 5519 for (ValueAxis axis : clone.domainAxes.values()) { 5520 if (axis != null) { 5521 axis.setPlot(clone); 5522 axis.addChangeListener(clone); 5523 } 5524 } 5525 clone.rangeAxes = CloneUtils.cloneMapValues(this.rangeAxes); 5526 for (ValueAxis axis : clone.rangeAxes.values()) { 5527 if (axis != null) { 5528 axis.setPlot(clone); 5529 axis.addChangeListener(clone); 5530 } 5531 } 5532 clone.domainAxisLocations = new HashMap<Integer, AxisLocation>( 5533 this.domainAxisLocations); 5534 clone.rangeAxisLocations = new HashMap<Integer, AxisLocation>( 5535 this.rangeAxisLocations); 5536 5537 // the datasets are not cloned, but listeners need to be added... 5538 clone.datasets = new HashMap<Integer, XYDataset>(this.datasets); 5539 for (XYDataset dataset : clone.datasets.values()) { 5540 if (dataset != null) { 5541 dataset.addChangeListener(clone); 5542 } 5543 } 5544 5545 clone.datasetToDomainAxesMap = new TreeMap(); 5546 clone.datasetToDomainAxesMap.putAll(this.datasetToDomainAxesMap); 5547 clone.datasetToRangeAxesMap = new TreeMap(); 5548 clone.datasetToRangeAxesMap.putAll(this.datasetToRangeAxesMap); 5549 5550 clone.renderers = CloneUtils.cloneMapValues(this.renderers); 5551 for (XYItemRenderer renderer : clone.renderers.values()) { 5552 if (renderer != null) { 5553 renderer.setPlot(clone); 5554 renderer.addChangeListener(clone); 5555 } 5556 } 5557 clone.foregroundDomainMarkers = (Map) ObjectUtils.clone( 5558 this.foregroundDomainMarkers); 5559 clone.backgroundDomainMarkers = (Map) ObjectUtils.clone( 5560 this.backgroundDomainMarkers); 5561 clone.foregroundRangeMarkers = (Map) ObjectUtils.clone( 5562 this.foregroundRangeMarkers); 5563 clone.backgroundRangeMarkers = (Map) ObjectUtils.clone( 5564 this.backgroundRangeMarkers); 5565 clone.annotations = (List) ObjectUtils.deepClone(this.annotations); 5566 if (this.fixedDomainAxisSpace != null) { 5567 clone.fixedDomainAxisSpace = (AxisSpace) ObjectUtils.clone( 5568 this.fixedDomainAxisSpace); 5569 } 5570 if (this.fixedRangeAxisSpace != null) { 5571 clone.fixedRangeAxisSpace = (AxisSpace) ObjectUtils.clone( 5572 this.fixedRangeAxisSpace); 5573 } 5574 if (this.fixedLegendItems != null) { 5575 clone.fixedLegendItems 5576 = (LegendItemCollection) this.fixedLegendItems.clone(); 5577 } 5578 clone.quadrantOrigin = (Point2D) ObjectUtils.clone( 5579 this.quadrantOrigin); 5580 clone.quadrantPaint = this.quadrantPaint.clone(); 5581 return clone; 5582 5583 } 5584 5585 /** 5586 * Provides serialization support. 5587 * 5588 * @param stream the output stream. 5589 * 5590 * @throws IOException if there is an I/O error. 5591 */ 5592 private void writeObject(ObjectOutputStream stream) throws IOException { 5593 stream.defaultWriteObject(); 5594 SerialUtils.writeStroke(this.domainGridlineStroke, stream); 5595 SerialUtils.writePaint(this.domainGridlinePaint, stream); 5596 SerialUtils.writeStroke(this.rangeGridlineStroke, stream); 5597 SerialUtils.writePaint(this.rangeGridlinePaint, stream); 5598 SerialUtils.writeStroke(this.domainMinorGridlineStroke, stream); 5599 SerialUtils.writePaint(this.domainMinorGridlinePaint, stream); 5600 SerialUtils.writeStroke(this.rangeMinorGridlineStroke, stream); 5601 SerialUtils.writePaint(this.rangeMinorGridlinePaint, stream); 5602 SerialUtils.writeStroke(this.rangeZeroBaselineStroke, stream); 5603 SerialUtils.writePaint(this.rangeZeroBaselinePaint, stream); 5604 SerialUtils.writeStroke(this.domainCrosshairStroke, stream); 5605 SerialUtils.writePaint(this.domainCrosshairPaint, stream); 5606 SerialUtils.writeStroke(this.rangeCrosshairStroke, stream); 5607 SerialUtils.writePaint(this.rangeCrosshairPaint, stream); 5608 SerialUtils.writePaint(this.domainTickBandPaint, stream); 5609 SerialUtils.writePaint(this.rangeTickBandPaint, stream); 5610 SerialUtils.writePoint2D(this.quadrantOrigin, stream); 5611 for (int i = 0; i < 4; i++) { 5612 SerialUtils.writePaint(this.quadrantPaint[i], stream); 5613 } 5614 SerialUtils.writeStroke(this.domainZeroBaselineStroke, stream); 5615 SerialUtils.writePaint(this.domainZeroBaselinePaint, stream); 5616 } 5617 5618 /** 5619 * Provides serialization support. 5620 * 5621 * @param stream the input stream. 5622 * 5623 * @throws IOException if there is an I/O error. 5624 * @throws ClassNotFoundException if there is a classpath problem. 5625 */ 5626 private void readObject(ObjectInputStream stream) 5627 throws IOException, ClassNotFoundException { 5628 5629 stream.defaultReadObject(); 5630 this.domainGridlineStroke = SerialUtils.readStroke(stream); 5631 this.domainGridlinePaint = SerialUtils.readPaint(stream); 5632 this.rangeGridlineStroke = SerialUtils.readStroke(stream); 5633 this.rangeGridlinePaint = SerialUtils.readPaint(stream); 5634 this.domainMinorGridlineStroke = SerialUtils.readStroke(stream); 5635 this.domainMinorGridlinePaint = SerialUtils.readPaint(stream); 5636 this.rangeMinorGridlineStroke = SerialUtils.readStroke(stream); 5637 this.rangeMinorGridlinePaint = SerialUtils.readPaint(stream); 5638 this.rangeZeroBaselineStroke = SerialUtils.readStroke(stream); 5639 this.rangeZeroBaselinePaint = SerialUtils.readPaint(stream); 5640 this.domainCrosshairStroke = SerialUtils.readStroke(stream); 5641 this.domainCrosshairPaint = SerialUtils.readPaint(stream); 5642 this.rangeCrosshairStroke = SerialUtils.readStroke(stream); 5643 this.rangeCrosshairPaint = SerialUtils.readPaint(stream); 5644 this.domainTickBandPaint = SerialUtils.readPaint(stream); 5645 this.rangeTickBandPaint = SerialUtils.readPaint(stream); 5646 this.quadrantOrigin = SerialUtils.readPoint2D(stream); 5647 this.quadrantPaint = new Paint[4]; 5648 for (int i = 0; i < 4; i++) { 5649 this.quadrantPaint[i] = SerialUtils.readPaint(stream); 5650 } 5651 5652 this.domainZeroBaselineStroke = SerialUtils.readStroke(stream); 5653 this.domainZeroBaselinePaint = SerialUtils.readPaint(stream); 5654 5655 // register the plot as a listener with its axes, datasets, and 5656 // renderers... 5657 for (ValueAxis axis : this.domainAxes.values()) { 5658 if (axis != null) { 5659 axis.setPlot(this); 5660 axis.addChangeListener(this); 5661 } 5662 } 5663 for (ValueAxis axis : this.rangeAxes.values()) { 5664 if (axis != null) { 5665 axis.setPlot(this); 5666 axis.addChangeListener(this); 5667 } 5668 } 5669 for (XYDataset dataset : this.datasets.values()) { 5670 if (dataset != null) { 5671 dataset.addChangeListener(this); 5672 } 5673 } 5674 for (XYItemRenderer renderer : this.renderers.values()) { 5675 if (renderer != null) { 5676 renderer.addChangeListener(this); 5677 } 5678 } 5679 5680 } 5681 5682}