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