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