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 * PiePlot.java
029 * ------------
030 * (C) Copyright 2000-2017, by Andrzej Porebski and Contributors.
031 *
032 * Original Author:  Andrzej Porebski;
033 * Contributor(s):   David Gilbert (for Object Refinery Limited);
034 *                   Martin Cordova (percentages in labels);
035 *                   Richard Atkinson (URL support for image maps);
036 *                   Christian W. Zuckschwerdt;
037 *                   Arnaud Lelievre;
038 *                   Martin Hilpert (patch 1891849);
039 *                   Andreas Schroeder (very minor);
040 *                   Christoph Beck (bug 2121818);
041 *
042 * Changes
043 * -------
044 * 21-Jun-2001 : Removed redundant JFreeChart parameter from constructors (DG);
045 * 18-Sep-2001 : Updated header (DG);
046 * 15-Oct-2001 : Data source classes moved to com.jrefinery.data.* (DG);
047 * 19-Oct-2001 : Moved series paint and stroke methods from JFreeChart.java to
048 *               Plot.java (DG);
049 * 22-Oct-2001 : Renamed DataSource.java --> Dataset.java etc. (DG);
050 * 13-Nov-2001 : Modified plot subclasses so that null axes are possible for
051 *               pie plot (DG);
052 * 17-Nov-2001 : Added PieDataset interface and amended this class accordingly,
053 *               and completed removal of BlankAxis class as it is no longer
054 *               required (DG);
055 * 19-Nov-2001 : Changed 'drawCircle' property to 'circular' property (DG);
056 * 21-Nov-2001 : Added options for exploding pie sections and filled out range
057 *               of properties (DG);
058 *               Added option for percentages in chart labels, based on code
059 *               by Martin Cordova (DG);
060 * 30-Nov-2001 : Changed default font from "Arial" --> "SansSerif" (DG);
061 * 12-Dec-2001 : Removed unnecessary 'throws' clause in constructor (DG);
062 * 13-Dec-2001 : Added tooltips (DG);
063 * 16-Jan-2002 : Renamed tooltips class (DG);
064 * 22-Jan-2002 : Fixed bug correlating legend labels with pie data (DG);
065 * 05-Feb-2002 : Added alpha-transparency to plot class, and updated
066 *               constructors accordingly (DG);
067 * 06-Feb-2002 : Added optional background image and alpha-transparency to Plot
068 *               and subclasses.  Clipped drawing within plot area (DG);
069 * 26-Mar-2002 : Added an empty zoom method (DG);
070 * 18-Apr-2002 : PieDataset is no longer sorted (oldman);
071 * 23-Apr-2002 : Moved dataset from JFreeChart to Plot.  Added
072 *               getLegendItemLabels() method (DG);
073 * 19-Jun-2002 : Added attributes to control starting angle and direction
074 *               (default is now clockwise) (DG);
075 * 25-Jun-2002 : Removed redundant imports (DG);
076 * 02-Jul-2002 : Fixed sign of percentage bug introduced in 0.9.2 (DG);
077 * 16-Jul-2002 : Added check for null dataset in getLegendItemLabels() (DG);
078 * 30-Jul-2002 : Moved summation code to DatasetUtilities (DG);
079 * 05-Aug-2002 : Added URL support for image maps - new member variable for
080 *               urlGenerator, modified constructor and minor change to the
081 *               draw method (RA);
082 * 18-Sep-2002 : Modified the percent label creation and added setters for the
083 *               formatters (AS);
084 * 24-Sep-2002 : Added getLegendItems() method (DG);
085 * 02-Oct-2002 : Fixed errors reported by Checkstyle (DG);
086 * 09-Oct-2002 : Added check for null entity collection (DG);
087 * 30-Oct-2002 : Changed PieDataset interface (DG);
088 * 18-Nov-2002 : Changed CategoryDataset to TableDataset (DG);
089 * 02-Jan-2003 : Fixed "no data" message (DG);
090 * 23-Jan-2003 : Modified to extract data from rows OR columns in
091 *               CategoryDataset (DG);
092 * 14-Feb-2003 : Fixed label drawing so that foreground alpha does not apply
093 *               (bug id 685536) (DG);
094 * 07-Mar-2003 : Modified to pass pieIndex on to PieSectionEntity and tooltip
095 *               and URL generators (DG);
096 * 21-Mar-2003 : Added a minimum angle for drawing arcs
097 *               (see bug id 620031) (DG);
098 * 24-Apr-2003 : Switched around PieDataset and KeyedValuesDataset (DG);
099 * 02-Jun-2003 : Fixed bug 721733 (DG);
100 * 30-Jul-2003 : Modified entity constructor (CZ);
101 * 19-Aug-2003 : Implemented Cloneable (DG);
102 * 29-Aug-2003 : Fixed bug 796936 (null pointer on setOutlinePaint()) (DG);
103 * 08-Sep-2003 : Added internationalization via use of properties
104 *               resourceBundle (RFE 690236) (AL);
105 * 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG);
106 * 29-Oct-2003 : Added workaround for font alignment in PDF output (DG);
107 * 05-Nov-2003 : Fixed missing legend bug (DG);
108 * 10-Nov-2003 : Re-added the DatasetChangeListener to constructors (CZ);
109 * 29-Jan-2004 : Fixed clipping bug in draw() method (DG);
110 * 11-Mar-2004 : Major overhaul to improve labelling (DG);
111 * 31-Mar-2004 : Made an adjustment for the plot area when the label generator
112 *               is null.  Fixed null pointer exception when the label
113 *               generator returns null for a label (DG);
114 * 06-Apr-2004 : Added getter, setter, serialization and draw support for
115 *               labelBackgroundPaint (AS);
116 * 08-Apr-2004 : Added flag to control whether null values are ignored or
117 *               not (DG);
118 * 15-Apr-2004 : Fixed some minor warnings from Eclipse (DG);
119 * 26-Apr-2004 : Added attributes for label outline and shadow (DG);
120 * 04-Oct-2004 : Renamed ShapeUtils --> ShapeUtilities (DG);
121 * 04-Nov-2004 : Fixed null pointer exception with new LegendTitle class (DG);
122 * 09-Nov-2004 : Added user definable legend item shape (DG);
123 * 25-Nov-2004 : Added new legend label generator (DG);
124 * 20-Apr-2005 : Added a tool tip generator for legend labels (DG);
125 * 26-Apr-2005 : Removed LOGGER (DG);
126 * 05-May-2005 : Updated draw() method parameters (DG);
127 * 10-May-2005 : Added flag to control visibility of label linking lines, plus
128 *               another flag to control the handling of zero values (DG);
129 * 08-Jun-2005 : Fixed bug in getLegendItems() method (not respecting flags
130 *               for ignoring null and zero values), and fixed equals() method
131 *               to handle GradientPaint (DG);
132 * 15-Jul-2005 : Added sectionOutlinesVisible attribute (DG);
133 * ------------- JFREECHART 1.0.x ---------------------------------------------
134 * 09-Jan-2006 : Fixed bug 1400442, inconsistent treatment of null and zero
135 *               values in dataset (DG);
136 * 28-Feb-2006 : Fixed bug 1440415, bad distribution of pie section
137 *               labels (DG);
138 * 27-Sep-2006 : Initialised baseSectionPaint correctly, added lookup methods
139 *               for section paint, outline paint and outline stroke (DG);
140 * 27-Sep-2006 : Refactored paint and stroke methods to use keys rather than
141 *               section indices (DG);
142 * 03-Oct-2006 : Replaced call to JRE 1.5 method (DG);
143 * 23-Nov-2006 : Added support for URLs for the legend items (DG);
144 * 24-Nov-2006 : Cloning fixes (DG);
145 * 17-Apr-2007 : Check for null label in legend items (DG);
146 * 19-Apr-2007 : Deprecated override settings (DG);
147 * 18-May-2007 : Set dataset for LegendItem (DG);
148 * 14-Jun-2007 : Added label distributor attribute (DG);
149 * 18-Jul-2007 : Added simple label option (DG);
150 * 21-Nov-2007 : Fixed labelling bugs, added debug code, restored default
151 *               white background (DG);
152 * 19-Mar-2008 : Fixed IllegalArgumentException when drawing with null
153 *               dataset (DG);
154 * 31-Mar-2008 : Adjust the label area for the interiorGap (DG);
155 * 31-Mar-2008 : Added quad and cubic curve label link lines - see patch
156 *               1891849 by Martin Hilpert (DG);
157 * 02-Jul-2008 : Added autoPopulate flags (DG);
158 * 15-Aug-2008 : Added methods to clear section attributes (DG);
159 * 15-Aug-2008 : Fixed bug 2051168 - problem with LegendItemEntity
160 *               generation (DG);
161 * 23-Sep-2008 : Added getLabelLinkDepth() method - see bug 2121818 reported
162 *               by Christoph Beck (DG);
163 * 18-Dec-2008 : Use ResourceBundleWrapper - see patch 1607918 by
164 *               Jess Thrysoee (DG);
165 * 10-Jul-2009 : Added optional drop shadow generator (DG);
166 * 03-Sep-2009 : Fixed bug where sinmpleLabelOffset is ignored (DG);
167 * 04-Nov-2009 : Add mouse wheel rotation support (DG);
168 * 18-Oct-2011 : Fixed tooltip offset with shadow generator (DG);
169 * 20-Nov-2011 : Initialise shadow generator as null (DG);
170 * 01-Jul-2012 : General label once only in drawSimpleLabels() (DG);
171 * 02-Jul-2013 : Use ParamChecks (DG);
172 * 12-Sep-2013 : Check for KEY_SUPPRESS_SHADOW_GENERATION rendering hint (DG);
173 * 
174 */
175
176package org.jfree.chart.plot;
177
178import java.awt.AlphaComposite;
179import java.awt.BasicStroke;
180import java.awt.Color;
181import java.awt.Composite;
182import java.awt.Font;
183import java.awt.FontMetrics;
184import java.awt.Graphics2D;
185import java.awt.Paint;
186import java.awt.RadialGradientPaint;
187import java.awt.Shape;
188import java.awt.Stroke;
189import java.awt.geom.Arc2D;
190import java.awt.geom.CubicCurve2D;
191import java.awt.geom.Ellipse2D;
192import java.awt.geom.Line2D;
193import java.awt.geom.Point2D;
194import java.awt.geom.QuadCurve2D;
195import java.awt.geom.Rectangle2D;
196import java.awt.image.BufferedImage;
197import java.io.IOException;
198import java.io.ObjectInputStream;
199import java.io.ObjectOutputStream;
200import java.io.Serializable;
201import java.util.Iterator;
202import java.util.List;
203import java.util.Map;
204import java.util.ResourceBundle;
205import java.util.TreeMap;
206import org.jfree.chart.JFreeChart;
207
208import org.jfree.chart.LegendItem;
209import org.jfree.chart.LegendItemCollection;
210import org.jfree.chart.PaintMap;
211import org.jfree.chart.StrokeMap;
212import org.jfree.chart.entity.EntityCollection;
213import org.jfree.chart.entity.PieSectionEntity;
214import org.jfree.chart.event.PlotChangeEvent;
215import org.jfree.chart.labels.PieSectionLabelGenerator;
216import org.jfree.chart.labels.PieToolTipGenerator;
217import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
218import org.jfree.chart.text.G2TextMeasurer;
219import org.jfree.chart.text.TextBlock;
220import org.jfree.chart.text.TextBox;
221import org.jfree.chart.text.TextUtils;
222import org.jfree.chart.ui.RectangleAnchor;
223import org.jfree.chart.ui.RectangleInsets;
224import org.jfree.chart.ui.TextAnchor;
225import org.jfree.chart.urls.PieURLGenerator;
226import org.jfree.chart.util.ObjectUtils;
227import org.jfree.chart.util.PaintUtils;
228import org.jfree.chart.util.Args;
229import org.jfree.chart.util.PublicCloneable;
230import org.jfree.chart.util.ResourceBundleWrapper;
231import org.jfree.chart.util.Rotation;
232import org.jfree.chart.util.SerialUtils;
233import org.jfree.chart.util.ShadowGenerator;
234import org.jfree.chart.util.ShapeUtils;
235import org.jfree.chart.util.UnitType;
236import org.jfree.data.DefaultKeyedValues;
237import org.jfree.data.KeyedValues;
238import org.jfree.data.general.DatasetChangeEvent;
239import org.jfree.data.general.DatasetUtils;
240import org.jfree.data.general.PieDataset;
241
242/**
243 * A plot that displays data in the form of a pie chart, using data from any
244 * class that implements the {@link PieDataset} interface.
245 * The example shown here is generated by the {@code PieChartDemo2.java}
246 * program included in the JFreeChart Demo Collection:
247 * <br><br>
248 * <img src="../../../../images/PiePlotSample.png" alt="PiePlotSample.png">
249 * <P>
250 * Special notes:
251 * <ol>
252 * <li>the default starting point is 12 o'clock and the pie sections proceed
253 * in a clockwise direction, but these settings can be changed;</li>
254 * <li>negative values in the dataset are ignored;</li>
255 * <li>there are utility methods for creating a {@link PieDataset} from a
256 * {@link org.jfree.data.category.CategoryDataset};</li>
257 * </ol>
258 *
259 * @see Plot
260 * @see PieDataset
261 */
262public class PiePlot extends Plot implements Cloneable, Serializable {
263
264    /** For serialization. */
265    private static final long serialVersionUID = -795612466005590431L;
266
267    /** The default interior gap. */
268    public static final double DEFAULT_INTERIOR_GAP = 0.08;
269
270    /** The maximum interior gap (currently 40%). */
271    public static final double MAX_INTERIOR_GAP = 0.40;
272
273    /** The default starting angle for the pie chart. */
274    public static final double DEFAULT_START_ANGLE = 90.0;
275
276    /** The default section label font. */
277    public static final Font DEFAULT_LABEL_FONT = new Font("SansSerif",
278            Font.PLAIN, 10);
279
280    /** The default section label paint. */
281    public static final Paint DEFAULT_LABEL_PAINT = Color.BLACK;
282
283    /** The default section label background paint. */
284    public static final Paint DEFAULT_LABEL_BACKGROUND_PAINT = new Color(255,
285            255, 192);
286
287    /** The default section label outline paint. */
288    public static final Paint DEFAULT_LABEL_OUTLINE_PAINT = Color.BLACK;
289
290    /** The default section label outline stroke. */
291    public static final Stroke DEFAULT_LABEL_OUTLINE_STROKE = new BasicStroke(
292            0.5f);
293
294    /** The default section label shadow paint. */
295    public static final Paint DEFAULT_LABEL_SHADOW_PAINT = new Color(151, 151,
296            151, 128);
297
298    /** The default minimum arc angle to draw. */
299    public static final double DEFAULT_MINIMUM_ARC_ANGLE_TO_DRAW = 0.00001;
300
301    /** The dataset for the pie chart. */
302    private PieDataset dataset;
303
304    /** The pie index (used by the {@link MultiplePiePlot} class). */
305    private int pieIndex;
306
307    /**
308     * The amount of space left around the outside of the pie plot, expressed
309     * as a percentage of the plot area width and height.
310     */
311    private double interiorGap;
312
313    /** Flag determining whether to draw an ellipse or a perfect circle. */
314    private boolean circular;
315
316    /** The starting angle. */
317    private double startAngle;
318
319    /** The direction for the pie segments. */
320    private Rotation direction;
321
322    /** The section paint map. */
323    private PaintMap sectionPaintMap;
324
325    /** The default section paint (fallback). */
326    private transient Paint defaultSectionPaint;
327
328    /**
329     * A flag that controls whether or not the section paint is auto-populated
330     * from the drawing supplier.
331     *
332     * @since 1.0.11
333     */
334    private boolean autoPopulateSectionPaint;
335
336    /**
337     * A flag that controls whether or not an outline is drawn for each
338     * section in the plot.
339     */
340    private boolean sectionOutlinesVisible;
341
342    /** The section outline paint map. */
343    private PaintMap sectionOutlinePaintMap;
344
345    /** The default section outline paint (fallback). */
346    private transient Paint defaultSectionOutlinePaint;
347
348    /**
349     * A flag that controls whether or not the section outline paint is
350     * auto-populated from the drawing supplier.
351     *
352     * @since 1.0.11
353     */
354    private boolean autoPopulateSectionOutlinePaint;
355
356    /** The section outline stroke map. */
357    private StrokeMap sectionOutlineStrokeMap;
358
359    /** The default section outline stroke (fallback). */
360    private transient Stroke defaultSectionOutlineStroke;
361
362    /**
363     * A flag that controls whether or not the section outline stroke is
364     * auto-populated from the drawing supplier.
365     *
366     * @since 1.0.11
367     */
368    private boolean autoPopulateSectionOutlineStroke;
369
370    /** The shadow paint. */
371    private transient Paint shadowPaint = Color.GRAY;
372
373    /** The x-offset for the shadow effect. */
374    private double shadowXOffset = 4.0f;
375
376    /** The y-offset for the shadow effect. */
377    private double shadowYOffset = 4.0f;
378
379    /** The percentage amount to explode each pie section. */
380    private Map<Comparable, Double> explodePercentages;
381
382    /** The section label generator. */
383    private PieSectionLabelGenerator labelGenerator;
384
385    /** The font used to display the section labels. */
386    private Font labelFont;
387
388    /** The color used to draw the section labels. */
389    private transient Paint labelPaint;
390
391    /**
392     * The color used to draw the background of the section labels.  If this
393     * is {@code null}, the background is not filled.
394     */
395    private transient Paint labelBackgroundPaint;
396
397    /**
398     * The paint used to draw the outline of the section labels
399     * ({@code null} permitted).
400     */
401    private transient Paint labelOutlinePaint;
402
403    /**
404     * The stroke used to draw the outline of the section labels
405     * ({@code null} permitted).
406     */
407    private transient Stroke labelOutlineStroke;
408
409    /**
410     * The paint used to draw the shadow for the section labels
411     * ({@code null} permitted).
412     */
413    private transient Paint labelShadowPaint;
414
415    /**
416     * A flag that controls whether simple or extended labels are used.
417     *
418     * @since 1.0.7
419     */
420    private boolean simpleLabels = true;
421
422    /**
423     * The padding between the labels and the label outlines.  This is not
424     * allowed to be {@code null}.
425     *
426     * @since 1.0.7
427     */
428    private RectangleInsets labelPadding;
429
430    /**
431     * The simple label offset.
432     *
433     * @since 1.0.7
434     */
435    private RectangleInsets simpleLabelOffset;
436
437    /** The maximum label width as a percentage of the plot width. */
438    private double maximumLabelWidth = 0.14;
439
440    /**
441     * The gap between the labels and the link corner, as a percentage of the
442     * plot width.
443     */
444    private double labelGap = 0.025;
445
446    /** A flag that controls whether or not the label links are drawn. */
447    private boolean labelLinksVisible;
448
449    /**
450     * The label link style.
451     *
452     * @since 1.0.10
453     */
454    private PieLabelLinkStyle labelLinkStyle = PieLabelLinkStyle.STANDARD;
455
456    /** The link margin. */
457    private double labelLinkMargin = 0.025;
458
459    /** The paint used for the label linking lines. */
460    private transient Paint labelLinkPaint = Color.BLACK;
461
462    /** The stroke used for the label linking lines. */
463    private transient Stroke labelLinkStroke = new BasicStroke(0.5f);
464
465    /**
466     * The pie section label distributor.
467     *
468     * @since 1.0.6
469     */
470    private AbstractPieLabelDistributor labelDistributor;
471
472    /** The tooltip generator. */
473    private PieToolTipGenerator toolTipGenerator;
474
475    /** The URL generator. */
476    private PieURLGenerator urlGenerator;
477
478    /** The legend label generator. */
479    private PieSectionLabelGenerator legendLabelGenerator;
480
481    /** A tool tip generator for the legend. */
482    private PieSectionLabelGenerator legendLabelToolTipGenerator;
483
484    /**
485     * A URL generator for the legend items (optional).
486     *
487     * @since 1.0.4.
488     */
489    private PieURLGenerator legendLabelURLGenerator;
490
491    /**
492     * A flag that controls whether {@code null} values are ignored.
493     */
494    private boolean ignoreNullValues;
495
496    /**
497     * A flag that controls whether zero values are ignored.
498     */
499    private boolean ignoreZeroValues;
500
501    /** The legend item shape. */
502    private transient Shape legendItemShape;
503
504    /**
505     * The smallest arc angle that will get drawn (this is to avoid a bug in
506     * various Java implementations that causes the JVM to crash).  See this
507     * link for details:
508     *
509     * http://www.jfree.org/phpBB2/viewtopic.php?t=2707
510     *
511     * ...and this bug report in the Java Bug Parade:
512     *
513     * http://developer.java.sun.com/developer/bugParade/bugs/4836495.html
514     */
515    private double minimumArcAngleToDraw;
516
517    /**
518     * The shadow generator for the plot ({@code null} permitted).
519     * 
520     * @since 1.0.14
521     */
522    private ShadowGenerator shadowGenerator;
523
524    /** The resourceBundle for the localization. */
525    protected static ResourceBundle localizationResources
526            = ResourceBundleWrapper.getBundle(
527                    "org.jfree.chart.plot.LocalizationBundle");
528
529    /**
530     * This debug flag controls whether or not an outline is drawn showing the
531     * interior of the plot region.  This is drawn as a lightGray rectangle
532     * showing the padding provided by the 'interiorGap' setting.
533     */
534    static final boolean DEBUG_DRAW_INTERIOR = false;
535
536    /**
537     * This debug flag controls whether or not an outline is drawn showing the
538     * link area (in blue) and link ellipse (in yellow).  This controls where
539     * the label links have 'elbow' points.
540     */
541    static final boolean DEBUG_DRAW_LINK_AREA = false;
542
543    /**
544     * This debug flag controls whether or not an outline is drawn showing
545     * the pie area (in green).
546     */
547    static final boolean DEBUG_DRAW_PIE_AREA = false;
548
549    /**
550     * Creates a new plot.  The dataset is initially set to {@code null}.
551     */
552    public PiePlot() {
553        this(null);
554    }
555
556    /**
557     * Creates a plot that will draw a pie chart for the specified dataset.
558     *
559     * @param dataset  the dataset ({@code null} permitted).
560     */
561    public PiePlot(PieDataset dataset) {
562        super();
563        this.dataset = dataset;
564        if (dataset != null) {
565            dataset.addChangeListener(this);
566        }
567        this.pieIndex = 0;
568
569        this.interiorGap = DEFAULT_INTERIOR_GAP;
570        this.circular = true;
571        this.startAngle = DEFAULT_START_ANGLE;
572        this.direction = Rotation.CLOCKWISE;
573        this.minimumArcAngleToDraw = DEFAULT_MINIMUM_ARC_ANGLE_TO_DRAW;
574
575        this.sectionPaintMap = new PaintMap();
576        this.defaultSectionPaint = Color.GRAY;
577        this.autoPopulateSectionPaint = true;
578
579        this.sectionOutlinesVisible = true;
580        this.sectionOutlinePaintMap = new PaintMap();
581        this.defaultSectionOutlinePaint = DEFAULT_OUTLINE_PAINT;
582        this.autoPopulateSectionOutlinePaint = false;
583
584        this.sectionOutlineStrokeMap = new StrokeMap();
585        this.defaultSectionOutlineStroke = DEFAULT_OUTLINE_STROKE;
586        this.autoPopulateSectionOutlineStroke = false;
587
588        this.explodePercentages = new TreeMap();
589
590        this.labelGenerator = new StandardPieSectionLabelGenerator();
591        this.labelFont = DEFAULT_LABEL_FONT;
592        this.labelPaint = DEFAULT_LABEL_PAINT;
593        this.labelBackgroundPaint = DEFAULT_LABEL_BACKGROUND_PAINT;
594        this.labelOutlinePaint = DEFAULT_LABEL_OUTLINE_PAINT;
595        this.labelOutlineStroke = DEFAULT_LABEL_OUTLINE_STROKE;
596        this.labelShadowPaint = DEFAULT_LABEL_SHADOW_PAINT;
597        this.labelLinksVisible = true;
598        this.labelDistributor = new PieLabelDistributor(0);
599
600        this.simpleLabels = false;
601        this.simpleLabelOffset = new RectangleInsets(UnitType.RELATIVE, 0.18,
602                0.18, 0.18, 0.18);
603        this.labelPadding = new RectangleInsets(2, 2, 2, 2);
604
605        this.toolTipGenerator = null;
606        this.urlGenerator = null;
607        this.legendLabelGenerator = new StandardPieSectionLabelGenerator();
608        this.legendLabelToolTipGenerator = null;
609        this.legendLabelURLGenerator = null;
610        this.legendItemShape = Plot.DEFAULT_LEGEND_ITEM_CIRCLE;
611
612        this.ignoreNullValues = false;
613        this.ignoreZeroValues = false;
614
615        this.shadowGenerator = null;
616    }
617
618    /**
619     * Returns the dataset.
620     *
621     * @return The dataset (possibly {@code null}).
622     *
623     * @see #setDataset(PieDataset)
624     */
625    public PieDataset getDataset() {
626        return this.dataset;
627    }
628
629    /**
630     * Sets the dataset and sends a {@link DatasetChangeEvent} to 'this'.
631     *
632     * @param dataset  the dataset ({@code null} permitted).
633     *
634     * @see #getDataset()
635     */
636    public void setDataset(PieDataset dataset) {
637        // if there is an existing dataset, remove the plot from the list of
638        // change listeners...
639        PieDataset existing = this.dataset;
640        if (existing != null) {
641            existing.removeChangeListener(this);
642        }
643
644        // set the new dataset, and register the chart as a change listener...
645        this.dataset = dataset;
646        if (dataset != null) {
647            setDatasetGroup(dataset.getGroup());
648            dataset.addChangeListener(this);
649        }
650
651        // send a dataset change event to self...
652        DatasetChangeEvent event = new DatasetChangeEvent(this, dataset);
653        datasetChanged(event);
654    }
655
656    /**
657     * Returns the pie index (this is used by the {@link MultiplePiePlot} class
658     * to track subplots).
659     *
660     * @return The pie index.
661     *
662     * @see #setPieIndex(int)
663     */
664    public int getPieIndex() {
665        return this.pieIndex;
666    }
667
668    /**
669     * Sets the pie index (this is used by the {@link MultiplePiePlot} class to
670     * track subplots).
671     *
672     * @param index  the index.
673     *
674     * @see #getPieIndex()
675     */
676    public void setPieIndex(int index) {
677        this.pieIndex = index;
678    }
679
680    /**
681     * Returns the start angle for the first pie section.  This is measured in
682     * degrees starting from 3 o'clock and measuring anti-clockwise.
683     *
684     * @return The start angle.
685     *
686     * @see #setStartAngle(double)
687     */
688    public double getStartAngle() {
689        return this.startAngle;
690    }
691
692    /**
693     * Sets the starting angle and sends a {@link PlotChangeEvent} to all
694     * registered listeners.  The initial default value is 90 degrees, which
695     * corresponds to 12 o'clock.  A value of zero corresponds to 3 o'clock...
696     * this is the encoding used by Java's Arc2D class.
697     *
698     * @param angle  the angle (in degrees).
699     *
700     * @see #getStartAngle()
701     */
702    public void setStartAngle(double angle) {
703        this.startAngle = angle;
704        fireChangeEvent();
705    }
706
707    /**
708     * Returns the direction in which the pie sections are drawn (clockwise or
709     * anti-clockwise).
710     *
711     * @return The direction (never {@code null}).
712     *
713     * @see #setDirection(Rotation)
714     */
715    public Rotation getDirection() {
716        return this.direction;
717    }
718
719    /**
720     * Sets the direction in which the pie sections are drawn and sends a
721     * {@link PlotChangeEvent} to all registered listeners.
722     *
723     * @param direction  the direction ({@code null} not permitted).
724     *
725     * @see #getDirection()
726     */
727    public void setDirection(Rotation direction) {
728        Args.nullNotPermitted(direction, "direction");
729        this.direction = direction;
730        fireChangeEvent();
731
732    }
733
734    /**
735     * Returns the interior gap, measured as a percentage of the available
736     * drawing space.
737     *
738     * @return The gap (as a percentage of the available drawing space).
739     *
740     * @see #setInteriorGap(double)
741     */
742    public double getInteriorGap() {
743        return this.interiorGap;
744    }
745
746    /**
747     * Sets the interior gap and sends a {@link PlotChangeEvent} to all
748     * registered listeners.  This controls the space between the edges of the
749     * pie plot and the plot area itself (the region where the section labels
750     * appear).
751     *
752     * @param percent  the gap (as a percentage of the available drawing space).
753     *
754     * @see #getInteriorGap()
755     */
756    public void setInteriorGap(double percent) {
757
758        if ((percent < 0.0) || (percent > MAX_INTERIOR_GAP)) {
759            throw new IllegalArgumentException(
760                "Invalid 'percent' (" + percent + ") argument.");
761        }
762
763        if (this.interiorGap != percent) {
764            this.interiorGap = percent;
765            fireChangeEvent();
766        }
767
768    }
769
770    /**
771     * Returns a flag indicating whether the pie chart is circular, or
772     * stretched into an elliptical shape.
773     *
774     * @return A flag indicating whether the pie chart is circular.
775     *
776     * @see #setCircular(boolean)
777     */
778    public boolean isCircular() {
779        return this.circular;
780    }
781
782    /**
783     * A flag indicating whether the pie chart is circular, or stretched into
784     * an elliptical shape.
785     *
786     * @param flag  the new value.
787     *
788     * @see #isCircular()
789     */
790    public void setCircular(boolean flag) {
791        setCircular(flag, true);
792    }
793
794    /**
795     * Sets the circular attribute and, if requested, sends a
796     * {@link PlotChangeEvent} to all registered listeners.
797     *
798     * @param circular  the new value of the flag.
799     * @param notify  notify listeners?
800     *
801     * @see #isCircular()
802     */
803    public void setCircular(boolean circular, boolean notify) {
804        this.circular = circular;
805        if (notify) {
806            fireChangeEvent();
807        }
808    }
809
810    /**
811     * Returns the flag that controls whether {@code null} values in the
812     * dataset are ignored.
813     *
814     * @return A boolean.
815     *
816     * @see #setIgnoreNullValues(boolean)
817     */
818    public boolean getIgnoreNullValues() {
819        return this.ignoreNullValues;
820    }
821
822    /**
823     * Sets a flag that controls whether {@code null} values are ignored,
824     * and sends a {@link PlotChangeEvent} to all registered listeners.  At
825     * present, this only affects whether or not the key is presented in the
826     * legend.
827     *
828     * @param flag  the flag.
829     *
830     * @see #getIgnoreNullValues()
831     * @see #setIgnoreZeroValues(boolean)
832     */
833    public void setIgnoreNullValues(boolean flag) {
834        this.ignoreNullValues = flag;
835        fireChangeEvent();
836    }
837
838    /**
839     * Returns the flag that controls whether zero values in the
840     * dataset are ignored.
841     *
842     * @return A boolean.
843     *
844     * @see #setIgnoreZeroValues(boolean)
845     */
846    public boolean getIgnoreZeroValues() {
847        return this.ignoreZeroValues;
848    }
849
850    /**
851     * Sets a flag that controls whether zero values are ignored,
852     * and sends a {@link PlotChangeEvent} to all registered listeners.  This
853     * only affects whether or not a label appears for the non-visible
854     * pie section.
855     *
856     * @param flag  the flag.
857     *
858     * @see #getIgnoreZeroValues()
859     * @see #setIgnoreNullValues(boolean)
860     */
861    public void setIgnoreZeroValues(boolean flag) {
862        this.ignoreZeroValues = flag;
863        fireChangeEvent();
864    }
865
866    //// SECTION PAINT ////////////////////////////////////////////////////////
867
868    /**
869     * Returns the paint for the specified section.  This is equivalent to
870     * {@code lookupSectionPaint(section, getAutoPopulateSectionPaint())}.
871     *
872     * @param key  the section key.
873     *
874     * @return The paint for the specified section.
875     *
876     * @since 1.0.3
877     *
878     * @see #lookupSectionPaint(Comparable, boolean)
879     */
880    protected Paint lookupSectionPaint(Comparable key) {
881        return lookupSectionPaint(key, getAutoPopulateSectionPaint());
882    }
883
884    /**
885     * Returns the paint for the specified section.  The lookup involves these
886     * steps:
887     * <ul>
888     * <li>if {@link #getSectionPaint(Comparable)} is non-{@code null} return
889     *         it;</li>
890     * <li>if {@link #getSectionPaint(Comparable)} is {@code null} but
891     *         {@code autoPopulate} is {@code true}, attempt to fetch
892     *         a new paint from the drawing supplier
893     *         ({@link #getDrawingSupplier()});
894     * <li>if all else fails, return {@link #getDefaultSectionPaint()}.
895     * </ul>
896     *
897     * @param key  the section key.
898     * @param autoPopulate  a flag that controls whether the drawing supplier
899     *     is used to auto-populate the section paint settings.
900     *
901     * @return The paint.
902     *
903     * @since 1.0.3
904     */
905    protected Paint lookupSectionPaint(Comparable key, boolean autoPopulate) { 
906
907        // if not, check if there is a paint defined for the specified key
908        Paint result = this.sectionPaintMap.getPaint(key);
909        if (result != null) {
910            return result;
911        }
912
913        // nothing defined - do we autoPopulate?
914        if (autoPopulate) {
915            DrawingSupplier ds = getDrawingSupplier();
916            if (ds != null) {
917                result = ds.getNextPaint();
918                this.sectionPaintMap.put(key, result);
919            }
920            else {
921                result = this.defaultSectionPaint;
922            }
923        }
924        else {
925            result = this.defaultSectionPaint;
926        }
927        return result;
928    }
929
930    /**
931     * Returns a key for the specified section.  If there is no such section
932     * in the dataset, we generate a key.  This is to provide some backward
933     * compatibility for the (now deprecated) methods that get/set attributes
934     * based on section indices.  The preferred way of doing this now is to
935     * link the attributes directly to the section key (there are new methods
936     * for this, starting from version 1.0.3).
937     *
938     * @param section  the section index.
939     *
940     * @return The key.
941     *
942     * @since 1.0.3
943     */
944    protected Comparable getSectionKey(int section) {
945        Comparable key = null;
946        if (this.dataset != null) {
947            if (section >= 0 && section < this.dataset.getItemCount()) {
948                key = this.dataset.getKey(section);
949            }
950        }
951        if (key == null) {
952            key = section;
953        }
954        return key;
955    }
956
957    /**
958     * Returns the paint associated with the specified key, or
959     * {@code null} if there is no paint associated with the key.
960     *
961     * @param key  the key ({@code null} not permitted).
962     *
963     * @return The paint associated with the specified key, or
964     *     {@code null}.
965     *
966     * @throws IllegalArgumentException if {@code key} is
967     *     {@code null}.
968     *
969     * @see #setSectionPaint(Comparable, Paint)
970     *
971     * @since 1.0.3
972     */
973    public Paint getSectionPaint(Comparable key) {
974        // null argument check delegated...
975        return this.sectionPaintMap.getPaint(key);
976    }
977
978    /**
979     * Sets the paint associated with the specified key, and sends a
980     * {@link PlotChangeEvent} to all registered listeners.
981     *
982     * @param key  the key ({@code null} not permitted).
983     * @param paint  the paint.
984     *
985     * @throws IllegalArgumentException if {@code key} is
986     *     {@code null}.
987     *
988     * @see #getSectionPaint(Comparable)
989     *
990     * @since 1.0.3
991     */
992    public void setSectionPaint(Comparable key, Paint paint) {
993        // null argument check delegated...
994        this.sectionPaintMap.put(key, paint);
995        fireChangeEvent();
996    }
997
998    /**
999     * Clears the section paint settings for this plot and, if requested, sends
1000     * a {@link PlotChangeEvent} to all registered listeners.  Be aware that
1001     * if the {@code autoPopulateSectionPaint} flag is set, the section
1002     * paints may be repopulated using the same colours as before.
1003     *
1004     * @param notify  notify listeners?
1005     *
1006     * @since 1.0.11
1007     *
1008     * @see #autoPopulateSectionPaint
1009     */
1010    public void clearSectionPaints(boolean notify) {
1011        this.sectionPaintMap.clear();
1012        if (notify) {
1013            fireChangeEvent();
1014        }
1015    }
1016
1017    /**
1018     * Returns the default section paint.  This is used when no other paint is
1019     * defined, which is rare.  The default value is {@code Color.GRAY}.
1020     *
1021     * @return The paint (never {@code null}).
1022     *
1023     * @see #setDefaultSectionPaint(Paint)
1024     */
1025    public Paint getDefaultSectionPaint() {
1026        return this.defaultSectionPaint;
1027    }
1028
1029    /**
1030     * Sets the default section paint and sends a {@link PlotChangeEvent} to all
1031     * registered listeners.
1032     *
1033     * @param paint  the paint ({@code null} not permitted).
1034     *
1035     * @see #getDefaultSectionPaint()
1036     */
1037    public void setDefaultSectionPaint(Paint paint) {
1038        Args.nullNotPermitted(paint, "paint");
1039        this.defaultSectionPaint = paint;
1040        fireChangeEvent();
1041    }
1042
1043    /**
1044     * Returns the flag that controls whether or not the section paint is
1045     * auto-populated by the {@link #lookupSectionPaint(Comparable)} method.
1046     *
1047     * @return A boolean.
1048     *
1049     * @since 1.0.11
1050     */
1051    public boolean getAutoPopulateSectionPaint() {
1052        return this.autoPopulateSectionPaint;
1053    }
1054
1055    /**
1056     * Sets the flag that controls whether or not the section paint is
1057     * auto-populated by the {@link #lookupSectionPaint(Comparable)} method,
1058     * and sends a {@link PlotChangeEvent} to all registered listeners.
1059     *
1060     * @param auto  auto-populate?
1061     *
1062     * @since 1.0.11
1063     */
1064    public void setAutoPopulateSectionPaint(boolean auto) {
1065        this.autoPopulateSectionPaint = auto;
1066        fireChangeEvent();
1067    }
1068
1069    //// SECTION OUTLINE PAINT ////////////////////////////////////////////////
1070
1071    /**
1072     * Returns the flag that controls whether or not the outline is drawn for
1073     * each pie section.
1074     *
1075     * @return The flag that controls whether or not the outline is drawn for
1076     *         each pie section.
1077     *
1078     * @see #setSectionOutlinesVisible(boolean)
1079     */
1080    public boolean getSectionOutlinesVisible() {
1081        return this.sectionOutlinesVisible;
1082    }
1083
1084    /**
1085     * Sets the flag that controls whether or not the outline is drawn for
1086     * each pie section, and sends a {@link PlotChangeEvent} to all registered
1087     * listeners.
1088     *
1089     * @param visible  the flag.
1090     *
1091     * @see #getSectionOutlinesVisible()
1092     */
1093    public void setSectionOutlinesVisible(boolean visible) {
1094        this.sectionOutlinesVisible = visible;
1095        fireChangeEvent();
1096    }
1097
1098    /**
1099     * Returns the outline paint for the specified section.  This is equivalent
1100     * to {@code lookupSectionPaint(section, 
1101     * getAutoPopulateSectionOutlinePaint())}.
1102     *
1103     * @param key  the section key.
1104     *
1105     * @return The paint for the specified section.
1106     *
1107     * @since 1.0.3
1108     *
1109     * @see #lookupSectionOutlinePaint(Comparable, boolean)
1110     */
1111    protected Paint lookupSectionOutlinePaint(Comparable key) {
1112        return lookupSectionOutlinePaint(key,
1113                getAutoPopulateSectionOutlinePaint());
1114    }
1115
1116    /**
1117     * Returns the outline paint for the specified section.  The lookup
1118     * involves these steps:
1119     * <ul>
1120     * <li>if {@link #getSectionOutlinePaint(Comparable)} is
1121     *         non-{@code null} return it;</li>
1122     * <li>if {@link #getSectionOutlinePaint(Comparable)} is {@code null} but
1123     *         {@code autoPopulate} is {@code true}, attempt to fetch
1124     *         a new outline paint from the drawing supplier
1125     *         ({@link #getDrawingSupplier()});
1126     * <li>if all else fails, return {@link #getDefaultSectionOutlinePaint()}.
1127     * </ul>
1128     *
1129     * @param key  the section key.
1130     * @param autoPopulate  a flag that controls whether the drawing supplier
1131     *     is used to auto-populate the section outline paint settings.
1132     *
1133     * @return The paint.
1134     *
1135     * @since 1.0.3
1136     */
1137    protected Paint lookupSectionOutlinePaint(Comparable key,
1138            boolean autoPopulate) {
1139
1140        // if not, check if there is a paint defined for the specified key
1141        Paint result = this.sectionOutlinePaintMap.getPaint(key);
1142        if (result != null) {
1143            return result;
1144        }
1145
1146        // nothing defined - do we autoPopulate?
1147        if (autoPopulate) {
1148            DrawingSupplier ds = getDrawingSupplier();
1149            if (ds != null) {
1150                result = ds.getNextOutlinePaint();
1151                this.sectionOutlinePaintMap.put(key, result);
1152            }
1153            else {
1154                result = this.defaultSectionOutlinePaint;
1155            }
1156        }
1157        else {
1158            result = this.defaultSectionOutlinePaint;
1159        }
1160        return result;
1161    }
1162
1163    /**
1164     * Returns the outline paint associated with the specified key, or
1165     * {@code null} if there is no paint associated with the key.
1166     *
1167     * @param key  the key ({@code null} not permitted).
1168     *
1169     * @return The paint associated with the specified key, or
1170     *     {@code null}.
1171     *
1172     * @throws IllegalArgumentException if {@code key} is
1173     *     {@code null}.
1174     *
1175     * @see #setSectionOutlinePaint(Comparable, Paint)
1176     *
1177     * @since 1.0.3
1178     */
1179    public Paint getSectionOutlinePaint(Comparable key) {
1180        // null argument check delegated...
1181        return this.sectionOutlinePaintMap.getPaint(key);
1182    }
1183
1184    /**
1185     * Sets the outline paint associated with the specified key, and sends a
1186     * {@link PlotChangeEvent} to all registered listeners.
1187     *
1188     * @param key  the key ({@code null} not permitted).
1189     * @param paint  the paint.
1190     *
1191     * @throws IllegalArgumentException if {@code key} is
1192     *     {@code null}.
1193     *
1194     * @see #getSectionOutlinePaint(Comparable)
1195     *
1196     * @since 1.0.3
1197     */
1198    public void setSectionOutlinePaint(Comparable key, Paint paint) {
1199        // null argument check delegated...
1200        this.sectionOutlinePaintMap.put(key, paint);
1201        fireChangeEvent();
1202    }
1203
1204    /**
1205     * Clears the section outline paint settings for this plot and, if
1206     * requested, sends a {@link PlotChangeEvent} to all registered listeners.
1207     * Be aware that if the {@code autoPopulateSectionPaint} flag is set,
1208     * the section paints may be repopulated using the same colours as before.
1209     *
1210     * @param notify  notify listeners?
1211     *
1212     * @since 1.0.11
1213     *
1214     * @see #autoPopulateSectionOutlinePaint
1215     */
1216    public void clearSectionOutlinePaints(boolean notify) {
1217        this.sectionOutlinePaintMap.clear();
1218        if (notify) {
1219            fireChangeEvent();
1220        }
1221    }
1222
1223    /**
1224     * Returns the default section paint.  This is used when no other paint is
1225     * available.
1226     *
1227     * @return The paint (never {@code null}).
1228     *
1229     * @see #setDefaultSectionOutlinePaint(Paint)
1230     */
1231    public Paint getDefaultSectionOutlinePaint() {
1232        return this.defaultSectionOutlinePaint;
1233    }
1234
1235    /**
1236     * Sets the default section paint.
1237     *
1238     * @param paint  the paint ({@code null} not permitted).
1239     *
1240     * @see #getDefaultSectionOutlinePaint()
1241     */
1242    public void setDefaultSectionOutlinePaint(Paint paint) {
1243        Args.nullNotPermitted(paint, "paint");
1244        this.defaultSectionOutlinePaint = paint;
1245        fireChangeEvent();
1246    }
1247
1248    /**
1249     * Returns the flag that controls whether or not the section outline paint
1250     * is auto-populated by the {@link #lookupSectionOutlinePaint(Comparable)}
1251     * method.
1252     *
1253     * @return A boolean.
1254     *
1255     * @since 1.0.11
1256     */
1257    public boolean getAutoPopulateSectionOutlinePaint() {
1258        return this.autoPopulateSectionOutlinePaint;
1259    }
1260
1261    /**
1262     * Sets the flag that controls whether or not the section outline paint is
1263     * auto-populated by the {@link #lookupSectionOutlinePaint(Comparable)}
1264     * method, and sends a {@link PlotChangeEvent} to all registered listeners.
1265     *
1266     * @param auto  auto-populate?
1267     *
1268     * @since 1.0.11
1269     */
1270    public void setAutoPopulateSectionOutlinePaint(boolean auto) {
1271        this.autoPopulateSectionOutlinePaint = auto;
1272        fireChangeEvent();
1273    }
1274
1275    //// SECTION OUTLINE STROKE ///////////////////////////////////////////////
1276
1277    /**
1278     * Returns the outline stroke for the specified section.  This is
1279     * equivalent to {@code lookupSectionOutlineStroke(section,
1280     * getAutoPopulateSectionOutlineStroke())}.
1281     *
1282     * @param key  the section key.
1283     *
1284     * @return The stroke for the specified section.
1285     *
1286     * @since 1.0.3
1287     *
1288     * @see #lookupSectionOutlineStroke(Comparable, boolean)
1289     */
1290    protected Stroke lookupSectionOutlineStroke(Comparable key) {
1291        return lookupSectionOutlineStroke(key,
1292                getAutoPopulateSectionOutlineStroke());
1293    }
1294
1295    /**
1296     * Returns the outline stroke for the specified section.  The lookup
1297     * involves these steps:
1298     * <ul>
1299     * <li>if {@link #getSectionOutlineStroke(Comparable)} is
1300     *         non-{@code null} return it;</li>
1301     * <li>if {@link #getSectionOutlineStroke(Comparable)} is {@code null} but
1302     *         {@code autoPopulate} is {@code true}, attempt to fetch
1303     *         a new outline stroke from the drawing supplier
1304     *         ({@link #getDrawingSupplier()});
1305     * <li>if all else fails, return {@link #getDefaultSectionOutlineStroke()}.
1306     * </ul>
1307     *
1308     * @param key  the section key.
1309     * @param autoPopulate  a flag that controls whether the drawing supplier
1310     *     is used to auto-populate the section outline stroke settings.
1311     *
1312     * @return The stroke.
1313     *
1314     * @since 1.0.3
1315     */
1316    protected Stroke lookupSectionOutlineStroke(Comparable key,
1317            boolean autoPopulate) {
1318
1319        // if not, check if there is a stroke defined for the specified key
1320        Stroke result = this.sectionOutlineStrokeMap.getStroke(key);
1321        if (result != null) {
1322            return result;
1323        }
1324
1325        // nothing defined - do we autoPopulate?
1326        if (autoPopulate) {
1327            DrawingSupplier ds = getDrawingSupplier();
1328            if (ds != null) {
1329                result = ds.getNextOutlineStroke();
1330                this.sectionOutlineStrokeMap.put(key, result);
1331            }
1332            else {
1333                result = this.defaultSectionOutlineStroke;
1334            }
1335        }
1336        else {
1337            result = this.defaultSectionOutlineStroke;
1338        }
1339        return result;
1340    }
1341
1342    /**
1343     * Returns the outline stroke associated with the specified key, or
1344     * {@code null} if there is no stroke associated with the key.
1345     *
1346     * @param key  the key ({@code null} not permitted).
1347     *
1348     * @return The stroke associated with the specified key, or
1349     *     {@code null}.
1350     *
1351     * @throws IllegalArgumentException if {@code key} is
1352     *     {@code null}.
1353     *
1354     * @see #setSectionOutlineStroke(Comparable, Stroke)
1355     *
1356     * @since 1.0.3
1357     */
1358    public Stroke getSectionOutlineStroke(Comparable key) {
1359        // null argument check delegated...
1360        return this.sectionOutlineStrokeMap.getStroke(key);
1361    }
1362
1363    /**
1364     * Sets the outline stroke associated with the specified key, and sends a
1365     * {@link PlotChangeEvent} to all registered listeners.
1366     *
1367     * @param key  the key ({@code null} not permitted).
1368     * @param stroke  the stroke.
1369     *
1370     * @throws IllegalArgumentException if {@code key} is
1371     *     {@code null}.
1372     *
1373     * @see #getSectionOutlineStroke(Comparable)
1374     *
1375     * @since 1.0.3
1376     */
1377    public void setSectionOutlineStroke(Comparable key, Stroke stroke) {
1378        // null argument check delegated...
1379        this.sectionOutlineStrokeMap.put(key, stroke);
1380        fireChangeEvent();
1381    }
1382
1383    /**
1384     * Clears the section outline stroke settings for this plot and, if
1385     * requested, sends a {@link PlotChangeEvent} to all registered listeners.
1386     * Be aware that if the {@code autoPopulateSectionPaint} flag is set,
1387     * the section paints may be repopulated using the same colours as before.
1388     *
1389     * @param notify  notify listeners?
1390     *
1391     * @since 1.0.11
1392     *
1393     * @see #autoPopulateSectionOutlineStroke
1394     */
1395    public void clearSectionOutlineStrokes(boolean notify) {
1396        this.sectionOutlineStrokeMap.clear();
1397        if (notify) {
1398            fireChangeEvent();
1399        }
1400    }
1401
1402    /**
1403     * Returns the default section stroke.  This is used when no other stroke is
1404     * available.
1405     *
1406     * @return The stroke (never {@code null}).
1407     *
1408     * @see #setDefaultSectionOutlineStroke(Stroke)
1409     */
1410    public Stroke getDefaultSectionOutlineStroke() {
1411        return this.defaultSectionOutlineStroke;
1412    }
1413
1414    /**
1415     * Sets the default section stroke.
1416     *
1417     * @param stroke  the stroke ({@code null} not permitted).
1418     *
1419     * @see #getDefaultSectionOutlineStroke()
1420     */
1421    public void setDefaultSectionOutlineStroke(Stroke stroke) {
1422        Args.nullNotPermitted(stroke, "stroke");
1423        this.defaultSectionOutlineStroke = stroke;
1424        fireChangeEvent();
1425    }
1426
1427    /**
1428     * Returns the flag that controls whether or not the section outline stroke
1429     * is auto-populated by the {@link #lookupSectionOutlinePaint(Comparable)}
1430     * method.
1431     *
1432     * @return A boolean.
1433     *
1434     * @since 1.0.11
1435     */
1436    public boolean getAutoPopulateSectionOutlineStroke() {
1437        return this.autoPopulateSectionOutlineStroke;
1438    }
1439
1440    /**
1441     * Sets the flag that controls whether or not the section outline stroke is
1442     * auto-populated by the {@link #lookupSectionOutlineStroke(Comparable)}
1443     * method, and sends a {@link PlotChangeEvent} to all registered listeners.
1444     *
1445     * @param auto  auto-populate?
1446     *
1447     * @since 1.0.11
1448     */
1449    public void setAutoPopulateSectionOutlineStroke(boolean auto) {
1450        this.autoPopulateSectionOutlineStroke = auto;
1451        fireChangeEvent();
1452    }
1453
1454    /**
1455     * Returns the shadow paint.
1456     *
1457     * @return The paint (possibly {@code null}).
1458     *
1459     * @see #setShadowPaint(Paint)
1460     */
1461    public Paint getShadowPaint() {
1462        return this.shadowPaint;
1463    }
1464
1465    /**
1466     * Sets the shadow paint and sends a {@link PlotChangeEvent} to all
1467     * registered listeners.
1468     *
1469     * @param paint  the paint ({@code null} permitted).
1470     *
1471     * @see #getShadowPaint()
1472     */
1473    public void setShadowPaint(Paint paint) {
1474        this.shadowPaint = paint;
1475        fireChangeEvent();
1476    }
1477
1478    /**
1479     * Returns the x-offset for the shadow effect.
1480     *
1481     * @return The offset (in Java2D units).
1482     *
1483     * @see #setShadowXOffset(double)
1484     */
1485    public double getShadowXOffset() {
1486        return this.shadowXOffset;
1487    }
1488
1489    /**
1490     * Sets the x-offset for the shadow effect and sends a
1491     * {@link PlotChangeEvent} to all registered listeners.
1492     *
1493     * @param offset  the offset (in Java2D units).
1494     *
1495     * @see #getShadowXOffset()
1496     */
1497    public void setShadowXOffset(double offset) {
1498        this.shadowXOffset = offset;
1499        fireChangeEvent();
1500    }
1501
1502    /**
1503     * Returns the y-offset for the shadow effect.
1504     *
1505     * @return The offset (in Java2D units).
1506     *
1507     * @see #setShadowYOffset(double)
1508     */
1509    public double getShadowYOffset() {
1510        return this.shadowYOffset;
1511    }
1512
1513    /**
1514     * Sets the y-offset for the shadow effect and sends a
1515     * {@link PlotChangeEvent} to all registered listeners.
1516     *
1517     * @param offset  the offset (in Java2D units).
1518     *
1519     * @see #getShadowYOffset()
1520     */
1521    public void setShadowYOffset(double offset) {
1522        this.shadowYOffset = offset;
1523        fireChangeEvent();
1524    }
1525
1526    /**
1527     * Returns the amount that the section with the specified key should be
1528     * exploded.
1529     *
1530     * @param key  the key ({@code null} not permitted).
1531     *
1532     * @return The amount that the section with the specified key should be
1533     *     exploded.
1534     *
1535     * @throws IllegalArgumentException if {@code key} is
1536     *     {@code null}.
1537     *
1538     * @since 1.0.3
1539     *
1540     * @see #setExplodePercent(Comparable, double)
1541     */
1542    public double getExplodePercent(Comparable key) {
1543        double result = 0.0;
1544        if (this.explodePercentages != null) {
1545            Number percent = (Number) this.explodePercentages.get(key);
1546            if (percent != null) {
1547                result = percent.doubleValue();
1548            }
1549        }
1550        return result;
1551    }
1552
1553    /**
1554     * Sets the amount that a pie section should be exploded and sends a
1555     * {@link PlotChangeEvent} to all registered listeners.
1556     *
1557     * @param key  the section key ({@code null} not permitted).
1558     * @param percent  the explode percentage (0.30 = 30 percent).
1559     *
1560     * @since 1.0.3
1561     *
1562     * @see #getExplodePercent(Comparable)
1563     */
1564    public void setExplodePercent(Comparable key, double percent) {
1565        Args.nullNotPermitted(key, "key");
1566        if (this.explodePercentages == null) {
1567            this.explodePercentages = new TreeMap();
1568        }
1569        this.explodePercentages.put(key, percent);
1570        fireChangeEvent();
1571    }
1572
1573    /**
1574     * Returns the maximum explode percent.
1575     *
1576     * @return The percent.
1577     */
1578    public double getMaximumExplodePercent() {
1579        if (this.dataset == null) {
1580            return 0.0;
1581        }
1582        double result = 0.0;
1583        Iterator iterator = this.dataset.getKeys().iterator();
1584        while (iterator.hasNext()) {
1585            Comparable key = (Comparable) iterator.next();
1586            Number explode = (Number) this.explodePercentages.get(key);
1587            if (explode != null) {
1588                result = Math.max(result, explode.doubleValue());
1589            }
1590        }
1591        return result;
1592    }
1593
1594    /**
1595     * Returns the section label generator.
1596     *
1597     * @return The generator (possibly {@code null}).
1598     *
1599     * @see #setLabelGenerator(PieSectionLabelGenerator)
1600     */
1601    public PieSectionLabelGenerator getLabelGenerator() {
1602        return this.labelGenerator;
1603    }
1604
1605    /**
1606     * Sets the section label generator and sends a {@link PlotChangeEvent} to
1607     * all registered listeners.
1608     *
1609     * @param generator  the generator ({@code null} permitted).
1610     *
1611     * @see #getLabelGenerator()
1612     */
1613    public void setLabelGenerator(PieSectionLabelGenerator generator) {
1614        this.labelGenerator = generator;
1615        fireChangeEvent();
1616    }
1617
1618    /**
1619     * Returns the gap between the edge of the pie and the labels, expressed as
1620     * a percentage of the plot width.
1621     *
1622     * @return The gap (a percentage, where 0.05 = five percent).
1623     *
1624     * @see #setLabelGap(double)
1625     */
1626    public double getLabelGap() {
1627        return this.labelGap;
1628    }
1629
1630    /**
1631     * Sets the gap between the edge of the pie and the labels (expressed as a
1632     * percentage of the plot width) and sends a {@link PlotChangeEvent} to all
1633     * registered listeners.
1634     *
1635     * @param gap  the gap (a percentage, where 0.05 = five percent).
1636     *
1637     * @see #getLabelGap()
1638     */
1639    public void setLabelGap(double gap) {
1640        this.labelGap = gap;
1641        fireChangeEvent();
1642    }
1643
1644    /**
1645     * Returns the maximum label width as a percentage of the plot width.
1646     *
1647     * @return The width (a percentage, where 0.20 = 20 percent).
1648     *
1649     * @see #setMaximumLabelWidth(double)
1650     */
1651    public double getMaximumLabelWidth() {
1652        return this.maximumLabelWidth;
1653    }
1654
1655    /**
1656     * Sets the maximum label width as a percentage of the plot width and sends
1657     * a {@link PlotChangeEvent} to all registered listeners.
1658     *
1659     * @param width  the width (a percentage, where 0.20 = 20 percent).
1660     *
1661     * @see #getMaximumLabelWidth()
1662     */
1663    public void setMaximumLabelWidth(double width) {
1664        this.maximumLabelWidth = width;
1665        fireChangeEvent();
1666    }
1667
1668    /**
1669     * Returns the flag that controls whether or not label linking lines are
1670     * visible.
1671     *
1672     * @return A boolean.
1673     *
1674     * @see #setLabelLinksVisible(boolean)
1675     */
1676    public boolean getLabelLinksVisible() {
1677        return this.labelLinksVisible;
1678    }
1679
1680    /**
1681     * Sets the flag that controls whether or not label linking lines are
1682     * visible and sends a {@link PlotChangeEvent} to all registered listeners.
1683     * Please take care when hiding the linking lines - depending on the data
1684     * values, the labels can be displayed some distance away from the
1685     * corresponding pie section.
1686     *
1687     * @param visible  the flag.
1688     *
1689     * @see #getLabelLinksVisible()
1690     */
1691    public void setLabelLinksVisible(boolean visible) {
1692        this.labelLinksVisible = visible;
1693        fireChangeEvent();
1694    }
1695
1696    /**
1697     * Returns the label link style.
1698     *
1699     * @return The label link style (never {@code null}).
1700     *
1701     * @see #setLabelLinkStyle(PieLabelLinkStyle)
1702     *
1703     * @since 1.0.10
1704     */
1705    public PieLabelLinkStyle getLabelLinkStyle() {
1706        return this.labelLinkStyle;
1707    }
1708
1709    /**
1710     * Sets the label link style and sends a {@link PlotChangeEvent} to all
1711     * registered listeners.
1712     *
1713     * @param style  the new style ({@code null} not permitted).
1714     *
1715     * @see #getLabelLinkStyle()
1716     *
1717     * @since 1.0.10
1718     */
1719    public void setLabelLinkStyle(PieLabelLinkStyle style) {
1720        Args.nullNotPermitted(style, "style");
1721        this.labelLinkStyle = style;
1722        fireChangeEvent();
1723    }
1724
1725    /**
1726     * Returns the margin (expressed as a percentage of the width or height)
1727     * between the edge of the pie and the link point.
1728     *
1729     * @return The link margin (as a percentage, where 0.05 is five percent).
1730     *
1731     * @see #setLabelLinkMargin(double)
1732     */
1733    public double getLabelLinkMargin() {
1734        return this.labelLinkMargin;
1735    }
1736
1737    /**
1738     * Sets the link margin and sends a {@link PlotChangeEvent} to all
1739     * registered listeners.
1740     *
1741     * @param margin  the margin.
1742     *
1743     * @see #getLabelLinkMargin()
1744     */
1745    public void setLabelLinkMargin(double margin) {
1746        this.labelLinkMargin = margin;
1747        fireChangeEvent();
1748    }
1749
1750    /**
1751     * Returns the paint used for the lines that connect pie sections to their
1752     * corresponding labels.
1753     *
1754     * @return The paint (never {@code null}).
1755     *
1756     * @see #setLabelLinkPaint(Paint)
1757     */
1758    public Paint getLabelLinkPaint() {
1759        return this.labelLinkPaint;
1760    }
1761
1762    /**
1763     * Sets the paint used for the lines that connect pie sections to their
1764     * corresponding labels, and sends a {@link PlotChangeEvent} to all
1765     * registered listeners.
1766     *
1767     * @param paint  the paint ({@code null} not permitted).
1768     *
1769     * @see #getLabelLinkPaint()
1770     */
1771    public void setLabelLinkPaint(Paint paint) {
1772        Args.nullNotPermitted(paint, "paint");
1773        this.labelLinkPaint = paint;
1774        fireChangeEvent();
1775    }
1776
1777    /**
1778     * Returns the stroke used for the label linking lines.
1779     *
1780     * @return The stroke.
1781     *
1782     * @see #setLabelLinkStroke(Stroke)
1783     */
1784    public Stroke getLabelLinkStroke() {
1785        return this.labelLinkStroke;
1786    }
1787
1788    /**
1789     * Sets the link stroke and sends a {@link PlotChangeEvent} to all
1790     * registered listeners.
1791     *
1792     * @param stroke  the stroke.
1793     *
1794     * @see #getLabelLinkStroke()
1795     */
1796    public void setLabelLinkStroke(Stroke stroke) {
1797        Args.nullNotPermitted(stroke, "stroke");
1798        this.labelLinkStroke = stroke;
1799        fireChangeEvent();
1800    }
1801
1802    /**
1803     * Returns the distance that the end of the label link is embedded into
1804     * the plot, expressed as a percentage of the plot's radius.
1805     * <br><br>
1806     * This method is overridden in the {@link RingPlot} class to resolve
1807     * bug 2121818.
1808     *
1809     * @return {@code 0.10}.
1810     *
1811     * @since 1.0.12
1812     */
1813    protected double getLabelLinkDepth() {
1814        return 0.1;
1815    }
1816
1817    /**
1818     * Returns the section label font.
1819     *
1820     * @return The font (never {@code null}).
1821     *
1822     * @see #setLabelFont(Font)
1823     */
1824    public Font getLabelFont() {
1825        return this.labelFont;
1826    }
1827
1828    /**
1829     * Sets the section label font and sends a {@link PlotChangeEvent} to all
1830     * registered listeners.
1831     *
1832     * @param font  the font ({@code null} not permitted).
1833     *
1834     * @see #getLabelFont()
1835     */
1836    public void setLabelFont(Font font) {
1837        Args.nullNotPermitted(font, "font");
1838        this.labelFont = font;
1839        fireChangeEvent();
1840    }
1841
1842    /**
1843     * Returns the section label paint.
1844     *
1845     * @return The paint (never {@code null}).
1846     *
1847     * @see #setLabelPaint(Paint)
1848     */
1849    public Paint getLabelPaint() {
1850        return this.labelPaint;
1851    }
1852
1853    /**
1854     * Sets the section label paint and sends a {@link PlotChangeEvent} to all
1855     * registered listeners.
1856     *
1857     * @param paint  the paint ({@code null} not permitted).
1858     *
1859     * @see #getLabelPaint()
1860     */
1861    public void setLabelPaint(Paint paint) {
1862        Args.nullNotPermitted(paint, "paint");
1863        this.labelPaint = paint;
1864        fireChangeEvent();
1865    }
1866
1867    /**
1868     * Returns the section label background paint.
1869     *
1870     * @return The paint (possibly {@code null}).
1871     *
1872     * @see #setLabelBackgroundPaint(Paint)
1873     */
1874    public Paint getLabelBackgroundPaint() {
1875        return this.labelBackgroundPaint;
1876    }
1877
1878    /**
1879     * Sets the section label background paint and sends a
1880     * {@link PlotChangeEvent} to all registered listeners.
1881     *
1882     * @param paint  the paint ({@code null} permitted).
1883     *
1884     * @see #getLabelBackgroundPaint()
1885     */
1886    public void setLabelBackgroundPaint(Paint paint) {
1887        this.labelBackgroundPaint = paint;
1888        fireChangeEvent();
1889    }
1890
1891    /**
1892     * Returns the section label outline paint.
1893     *
1894     * @return The paint (possibly {@code null}).
1895     *
1896     * @see #setLabelOutlinePaint(Paint)
1897     */
1898    public Paint getLabelOutlinePaint() {
1899        return this.labelOutlinePaint;
1900    }
1901
1902    /**
1903     * Sets the section label outline paint and sends a
1904     * {@link PlotChangeEvent} to all registered listeners.
1905     *
1906     * @param paint  the paint ({@code null} permitted).
1907     *
1908     * @see #getLabelOutlinePaint()
1909     */
1910    public void setLabelOutlinePaint(Paint paint) {
1911        this.labelOutlinePaint = paint;
1912        fireChangeEvent();
1913    }
1914
1915    /**
1916     * Returns the section label outline stroke.
1917     *
1918     * @return The stroke (possibly {@code null}).
1919     *
1920     * @see #setLabelOutlineStroke(Stroke)
1921     */
1922    public Stroke getLabelOutlineStroke() {
1923        return this.labelOutlineStroke;
1924    }
1925
1926    /**
1927     * Sets the section label outline stroke and sends a
1928     * {@link PlotChangeEvent} to all registered listeners.
1929     *
1930     * @param stroke  the stroke ({@code null} permitted).
1931     *
1932     * @see #getLabelOutlineStroke()
1933     */
1934    public void setLabelOutlineStroke(Stroke stroke) {
1935        this.labelOutlineStroke = stroke;
1936        fireChangeEvent();
1937    }
1938
1939    /**
1940     * Returns the section label shadow paint.
1941     *
1942     * @return The paint (possibly {@code null}).
1943     *
1944     * @see #setLabelShadowPaint(Paint)
1945     */
1946    public Paint getLabelShadowPaint() {
1947        return this.labelShadowPaint;
1948    }
1949
1950    /**
1951     * Sets the section label shadow paint and sends a {@link PlotChangeEvent}
1952     * to all registered listeners.
1953     *
1954     * @param paint  the paint ({@code null} permitted).
1955     *
1956     * @see #getLabelShadowPaint()
1957     */
1958    public void setLabelShadowPaint(Paint paint) {
1959        this.labelShadowPaint = paint;
1960        fireChangeEvent();
1961    }
1962
1963    /**
1964     * Returns the label padding.
1965     *
1966     * @return The label padding (never {@code null}).
1967     *
1968     * @since 1.0.7
1969     *
1970     * @see #setLabelPadding(RectangleInsets)
1971     */
1972    public RectangleInsets getLabelPadding() {
1973        return this.labelPadding;
1974    }
1975
1976    /**
1977     * Sets the padding between each label and its outline and sends a
1978     * {@link PlotChangeEvent} to all registered listeners.
1979     *
1980     * @param padding  the padding ({@code null} not permitted).
1981     *
1982     * @since 1.0.7
1983     *
1984     * @see #getLabelPadding()
1985     */
1986    public void setLabelPadding(RectangleInsets padding) {
1987        Args.nullNotPermitted(padding, "padding");
1988        this.labelPadding = padding;
1989        fireChangeEvent();
1990    }
1991
1992    /**
1993     * Returns the flag that controls whether simple or extended labels are
1994     * displayed on the plot.
1995     *
1996     * @return A boolean.
1997     *
1998     * @since 1.0.7
1999     */
2000    public boolean getSimpleLabels() {
2001        return this.simpleLabels;
2002    }
2003
2004    /**
2005     * Sets the flag that controls whether simple or extended labels are
2006     * displayed on the plot, and sends a {@link PlotChangeEvent} to all
2007     * registered listeners.
2008     *
2009     * @param simple  the new flag value.
2010     *
2011     * @since 1.0.7
2012     */
2013    public void setSimpleLabels(boolean simple) {
2014        this.simpleLabels = simple;
2015        fireChangeEvent();
2016    }
2017
2018    /**
2019     * Returns the offset used for the simple labels, if they are displayed.
2020     *
2021     * @return The offset (never {@code null}).
2022     *
2023     * @since 1.0.7
2024     *
2025     * @see #setSimpleLabelOffset(RectangleInsets)
2026     */
2027    public RectangleInsets getSimpleLabelOffset() {
2028        return this.simpleLabelOffset;
2029    }
2030
2031    /**
2032     * Sets the offset for the simple labels and sends a
2033     * {@link PlotChangeEvent} to all registered listeners.
2034     *
2035     * @param offset  the offset ({@code null} not permitted).
2036     *
2037     * @since 1.0.7
2038     *
2039     * @see #getSimpleLabelOffset()
2040     */
2041    public void setSimpleLabelOffset(RectangleInsets offset) {
2042        Args.nullNotPermitted(offset, "offset");
2043        this.simpleLabelOffset = offset;
2044        fireChangeEvent();
2045    }
2046
2047    /**
2048     * Returns the object responsible for the vertical layout of the pie
2049     * section labels.
2050     *
2051     * @return The label distributor (never {@code null}).
2052     *
2053     * @since 1.0.6
2054     */
2055    public AbstractPieLabelDistributor getLabelDistributor() {
2056        return this.labelDistributor;
2057    }
2058
2059    /**
2060     * Sets the label distributor and sends a {@link PlotChangeEvent} to all
2061     * registered listeners.
2062     *
2063     * @param distributor  the distributor ({@code null} not permitted).
2064     *
2065     * @since 1.0.6
2066     */
2067    public void setLabelDistributor(AbstractPieLabelDistributor distributor) {
2068        Args.nullNotPermitted(distributor, "distributor");
2069        this.labelDistributor = distributor;
2070        fireChangeEvent();
2071    }
2072
2073    /**
2074     * Returns the tool tip generator, an object that is responsible for
2075     * generating the text items used for tool tips by the plot.  If the
2076     * generator is {@code null}, no tool tips will be created.
2077     *
2078     * @return The generator (possibly {@code null}).
2079     *
2080     * @see #setToolTipGenerator(PieToolTipGenerator)
2081     */
2082    public PieToolTipGenerator getToolTipGenerator() {
2083        return this.toolTipGenerator;
2084    }
2085
2086    /**
2087     * Sets the tool tip generator and sends a {@link PlotChangeEvent} to all
2088     * registered listeners.  Set the generator to {@code null} if you
2089     * don't want any tool tips.
2090     *
2091     * @param generator  the generator ({@code null} permitted).
2092     *
2093     * @see #getToolTipGenerator()
2094     */
2095    public void setToolTipGenerator(PieToolTipGenerator generator) {
2096        this.toolTipGenerator = generator;
2097        fireChangeEvent();
2098    }
2099
2100    /**
2101     * Returns the URL generator.
2102     *
2103     * @return The generator (possibly {@code null}).
2104     *
2105     * @see #setURLGenerator(PieURLGenerator)
2106     */
2107    public PieURLGenerator getURLGenerator() {
2108        return this.urlGenerator;
2109    }
2110
2111    /**
2112     * Sets the URL generator and sends a {@link PlotChangeEvent} to all
2113     * registered listeners.
2114     *
2115     * @param generator  the generator ({@code null} permitted).
2116     *
2117     * @see #getURLGenerator()
2118     */
2119    public void setURLGenerator(PieURLGenerator generator) {
2120        this.urlGenerator = generator;
2121        fireChangeEvent();
2122    }
2123
2124    /**
2125     * Returns the minimum arc angle that will be drawn.  Pie sections for an
2126     * angle smaller than this are not drawn, to avoid a JDK bug.
2127     *
2128     * @return The minimum angle.
2129     *
2130     * @see #setMinimumArcAngleToDraw(double)
2131     */
2132    public double getMinimumArcAngleToDraw() {
2133        return this.minimumArcAngleToDraw;
2134    }
2135
2136    /**
2137     * Sets the minimum arc angle that will be drawn.  Pie sections for an
2138     * angle smaller than this are not drawn, to avoid a JDK bug.  See this
2139     * link for details:
2140     * <br><br>
2141     * <a href="http://www.jfree.org/phpBB2/viewtopic.php?t=2707">
2142     * http://www.jfree.org/phpBB2/viewtopic.php?t=2707</a>
2143     * <br><br>
2144     * ...and this bug report in the Java Bug Parade:
2145     * <br><br>
2146     * <a href=
2147     * "http://developer.java.sun.com/developer/bugParade/bugs/4836495.html">
2148     * http://developer.java.sun.com/developer/bugParade/bugs/4836495.html</a>
2149     *
2150     * @param angle  the minimum angle.
2151     *
2152     * @see #getMinimumArcAngleToDraw()
2153     */
2154    public void setMinimumArcAngleToDraw(double angle) {
2155        this.minimumArcAngleToDraw = angle;
2156    }
2157
2158    /**
2159     * Returns the shape used for legend items.
2160     *
2161     * @return The shape (never {@code null}).
2162     *
2163     * @see #setLegendItemShape(Shape)
2164     */
2165    public Shape getLegendItemShape() {
2166        return this.legendItemShape;
2167    }
2168
2169    /**
2170     * Sets the shape used for legend items and sends a {@link PlotChangeEvent}
2171     * to all registered listeners.
2172     *
2173     * @param shape  the shape ({@code null} not permitted).
2174     *
2175     * @see #getLegendItemShape()
2176     */
2177    public void setLegendItemShape(Shape shape) {
2178        Args.nullNotPermitted(shape, "shape");
2179        this.legendItemShape = shape;
2180        fireChangeEvent();
2181    }
2182
2183    /**
2184     * Returns the legend label generator.
2185     *
2186     * @return The legend label generator (never {@code null}).
2187     *
2188     * @see #setLegendLabelGenerator(PieSectionLabelGenerator)
2189     */
2190    public PieSectionLabelGenerator getLegendLabelGenerator() {
2191        return this.legendLabelGenerator;
2192    }
2193
2194    /**
2195     * Sets the legend label generator and sends a {@link PlotChangeEvent} to
2196     * all registered listeners.
2197     *
2198     * @param generator  the generator ({@code null} not permitted).
2199     *
2200     * @see #getLegendLabelGenerator()
2201     */
2202    public void setLegendLabelGenerator(PieSectionLabelGenerator generator) {
2203        Args.nullNotPermitted(generator, "generator");
2204        this.legendLabelGenerator = generator;
2205        fireChangeEvent();
2206    }
2207
2208    /**
2209     * Returns the legend label tool tip generator.
2210     *
2211     * @return The legend label tool tip generator (possibly {@code null}).
2212     *
2213     * @see #setLegendLabelToolTipGenerator(PieSectionLabelGenerator)
2214     */
2215    public PieSectionLabelGenerator getLegendLabelToolTipGenerator() {
2216        return this.legendLabelToolTipGenerator;
2217    }
2218
2219    /**
2220     * Sets the legend label tool tip generator and sends a
2221     * {@link PlotChangeEvent} to all registered listeners.
2222     *
2223     * @param generator  the generator ({@code null} permitted).
2224     *
2225     * @see #getLegendLabelToolTipGenerator()
2226     */
2227    public void setLegendLabelToolTipGenerator(
2228            PieSectionLabelGenerator generator) {
2229        this.legendLabelToolTipGenerator = generator;
2230        fireChangeEvent();
2231    }
2232
2233    /**
2234     * Returns the legend label URL generator.
2235     *
2236     * @return The legend label URL generator (possibly {@code null}).
2237     *
2238     * @see #setLegendLabelURLGenerator(PieURLGenerator)
2239     *
2240     * @since 1.0.4
2241     */
2242    public PieURLGenerator getLegendLabelURLGenerator() {
2243        return this.legendLabelURLGenerator;
2244    }
2245
2246    /**
2247     * Sets the legend label URL generator and sends a
2248     * {@link PlotChangeEvent} to all registered listeners.
2249     *
2250     * @param generator  the generator ({@code null} permitted).
2251     *
2252     * @see #getLegendLabelURLGenerator()
2253     *
2254     * @since 1.0.4
2255     */
2256    public void setLegendLabelURLGenerator(PieURLGenerator generator) {
2257        this.legendLabelURLGenerator = generator;
2258        fireChangeEvent();
2259    }
2260
2261    /**
2262     * Returns the shadow generator for the plot, if any.
2263     * 
2264     * @return The shadow generator (possibly {@code null}).
2265     * 
2266     * @since 1.0.14
2267     */
2268    public ShadowGenerator getShadowGenerator() {
2269        return this.shadowGenerator;
2270    }
2271
2272    /**
2273     * Sets the shadow generator for the plot and sends a
2274     * {@link PlotChangeEvent} to all registered listeners.  Note that this is
2275     * a bitmap drop-shadow generation facility and is separate from the
2276     * vector based show option that is controlled via the
2277     * {@link #setShadowPaint(java.awt.Paint)} method.
2278     *
2279     * @param generator  the generator ({@code null} permitted).
2280     *
2281     * @since 1.0.14
2282     */
2283    public void setShadowGenerator(ShadowGenerator generator) {
2284        this.shadowGenerator = generator;
2285        fireChangeEvent();
2286    }
2287
2288    /**
2289     * Handles a mouse wheel rotation (this method is intended for use by the
2290     * {@code MouseWheelHandler} class).
2291     *
2292     * @param rotateClicks  the number of rotate clicks on the the mouse wheel.
2293     *
2294     * @since 1.0.14
2295     */
2296    public void handleMouseWheelRotation(int rotateClicks) {
2297        setStartAngle(this.startAngle + rotateClicks * 4.0);
2298    }
2299
2300    /**
2301     * Initialises the drawing procedure.  This method will be called before
2302     * the first item is rendered, giving the plot an opportunity to initialise
2303     * any state information it wants to maintain.
2304     *
2305     * @param g2  the graphics device.
2306     * @param plotArea  the plot area ({@code null} not permitted).
2307     * @param plot  the plot.
2308     * @param index  the secondary index ({@code null} for primary
2309     *               renderer).
2310     * @param info  collects chart rendering information for return to caller.
2311     *
2312     * @return A state object (maintains state information relevant to one
2313     *         chart drawing).
2314     */
2315    public PiePlotState initialise(Graphics2D g2, Rectangle2D plotArea,
2316            PiePlot plot, Integer index, PlotRenderingInfo info) {
2317
2318        PiePlotState state = new PiePlotState(info);
2319        state.setPassesRequired(2);
2320        if (this.dataset != null) {
2321            state.setTotal(DatasetUtils.calculatePieDatasetTotal(
2322                    plot.getDataset()));
2323        }
2324        state.setLatestAngle(plot.getStartAngle());
2325        return state;
2326
2327    }
2328
2329    /**
2330     * Draws the plot on a Java 2D graphics device (such as the screen or a
2331     * printer).
2332     *
2333     * @param g2  the graphics device.
2334     * @param area  the area within which the plot should be drawn.
2335     * @param anchor  the anchor point ({@code null} permitted).
2336     * @param parentState  the state from the parent plot, if there is one.
2337     * @param info  collects info about the drawing
2338     *              ({@code null} permitted).
2339     */
2340    @Override
2341    public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor,
2342                     PlotState parentState, PlotRenderingInfo info) {
2343
2344        // adjust for insets...
2345        RectangleInsets insets = getInsets();
2346        insets.trim(area);
2347
2348        if (info != null) {
2349            info.setPlotArea(area);
2350            info.setDataArea(area);
2351        }
2352
2353        drawBackground(g2, area);
2354        drawOutline(g2, area);
2355
2356        Shape savedClip = g2.getClip();
2357        g2.clip(area);
2358
2359        Composite originalComposite = g2.getComposite();
2360        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
2361                getForegroundAlpha()));
2362
2363        if (!DatasetUtils.isEmptyOrNull(this.dataset)) {
2364            Graphics2D savedG2 = g2;
2365            boolean suppressShadow = Boolean.TRUE.equals(g2.getRenderingHint(
2366                    JFreeChart.KEY_SUPPRESS_SHADOW_GENERATION));
2367            BufferedImage dataImage = null;
2368            if (this.shadowGenerator != null && !suppressShadow) {
2369                dataImage = new BufferedImage((int) area.getWidth(),
2370                    (int) area.getHeight(), BufferedImage.TYPE_INT_ARGB);
2371                g2 = dataImage.createGraphics();
2372                g2.translate(-area.getX(), -area.getY());
2373                g2.setRenderingHints(savedG2.getRenderingHints());
2374            }
2375            drawPie(g2, area, info);
2376            if (this.shadowGenerator != null && !suppressShadow) {
2377                BufferedImage shadowImage 
2378                        = this.shadowGenerator.createDropShadow(dataImage);
2379                g2 = savedG2;
2380                g2.drawImage(shadowImage, (int) area.getX() 
2381                        + this.shadowGenerator.calculateOffsetX(), 
2382                        (int) area.getY()
2383                        + this.shadowGenerator.calculateOffsetY(), null);
2384                g2.drawImage(dataImage, (int) area.getX(), (int) area.getY(), 
2385                        null);
2386            }
2387        }
2388        else {
2389            drawNoDataMessage(g2, area);
2390        }
2391
2392        g2.setClip(savedClip);
2393        g2.setComposite(originalComposite);
2394
2395        drawOutline(g2, area);
2396
2397    }
2398
2399    /**
2400     * Draws the pie.
2401     *
2402     * @param g2  the graphics device.
2403     * @param plotArea  the plot area.
2404     * @param info  chart rendering info.
2405     */
2406    protected void drawPie(Graphics2D g2, Rectangle2D plotArea,
2407                           PlotRenderingInfo info) {
2408
2409        PiePlotState state = initialise(g2, plotArea, this, null, info);
2410
2411        // adjust the plot area for interior spacing and labels...
2412        double labelReserve = 0.0;
2413        if (this.labelGenerator != null && !this.simpleLabels) {
2414            labelReserve = this.labelGap + this.maximumLabelWidth;
2415        }
2416        double gapHorizontal = plotArea.getWidth() * labelReserve * 2.0;
2417        double gapVertical = plotArea.getHeight() * this.interiorGap * 2.0;
2418
2419
2420        if (DEBUG_DRAW_INTERIOR) {
2421            double hGap = plotArea.getWidth() * this.interiorGap;
2422            double vGap = plotArea.getHeight() * this.interiorGap;
2423
2424            double igx1 = plotArea.getX() + hGap;
2425            double igx2 = plotArea.getMaxX() - hGap;
2426            double igy1 = plotArea.getY() + vGap;
2427            double igy2 = plotArea.getMaxY() - vGap;
2428            g2.setPaint(Color.GRAY);
2429            g2.draw(new Rectangle2D.Double(igx1, igy1, igx2 - igx1,
2430                    igy2 - igy1));
2431        }
2432
2433        double linkX = plotArea.getX() + gapHorizontal / 2;
2434        double linkY = plotArea.getY() + gapVertical / 2;
2435        double linkW = plotArea.getWidth() - gapHorizontal;
2436        double linkH = plotArea.getHeight() - gapVertical;
2437
2438        // make the link area a square if the pie chart is to be circular...
2439        if (this.circular) {
2440            double min = Math.min(linkW, linkH) / 2;
2441            linkX = (linkX + linkX + linkW) / 2 - min;
2442            linkY = (linkY + linkY + linkH) / 2 - min;
2443            linkW = 2 * min;
2444            linkH = 2 * min;
2445        }
2446
2447        // the link area defines the dog leg points for the linking lines to
2448        // the labels
2449        Rectangle2D linkArea = new Rectangle2D.Double(linkX, linkY, linkW,
2450                linkH);
2451        state.setLinkArea(linkArea);
2452
2453        if (DEBUG_DRAW_LINK_AREA) {
2454            g2.setPaint(Color.BLUE);
2455            g2.draw(linkArea);
2456            g2.setPaint(Color.YELLOW);
2457            g2.draw(new Ellipse2D.Double(linkArea.getX(), linkArea.getY(),
2458                    linkArea.getWidth(), linkArea.getHeight()));
2459        }
2460
2461        // the explode area defines the max circle/ellipse for the exploded
2462        // pie sections.  it is defined by shrinking the linkArea by the
2463        // linkMargin factor.
2464        double lm = 0.0;
2465        if (!this.simpleLabels) {
2466            lm = this.labelLinkMargin;
2467        }
2468        double hh = linkArea.getWidth() * lm * 2.0;
2469        double vv = linkArea.getHeight() * lm * 2.0;
2470        Rectangle2D explodeArea = new Rectangle2D.Double(linkX + hh / 2.0,
2471                linkY + vv / 2.0, linkW - hh, linkH - vv);
2472
2473        state.setExplodedPieArea(explodeArea);
2474
2475        // the pie area defines the circle/ellipse for regular pie sections.
2476        // it is defined by shrinking the explodeArea by the explodeMargin
2477        // factor.
2478        double maximumExplodePercent = getMaximumExplodePercent();
2479        double percent = maximumExplodePercent / (1.0 + maximumExplodePercent);
2480
2481        double h1 = explodeArea.getWidth() * percent;
2482        double v1 = explodeArea.getHeight() * percent;
2483        Rectangle2D pieArea = new Rectangle2D.Double(explodeArea.getX()
2484                + h1 / 2.0, explodeArea.getY() + v1 / 2.0,
2485                explodeArea.getWidth() - h1, explodeArea.getHeight() - v1);
2486
2487        if (DEBUG_DRAW_PIE_AREA) {
2488            g2.setPaint(Color.GREEN);
2489            g2.draw(pieArea);
2490        }
2491        state.setPieArea(pieArea);
2492        state.setPieCenterX(pieArea.getCenterX());
2493        state.setPieCenterY(pieArea.getCenterY());
2494        state.setPieWRadius(pieArea.getWidth() / 2.0);
2495        state.setPieHRadius(pieArea.getHeight() / 2.0);
2496
2497        // plot the data (unless the dataset is null)...
2498        if ((this.dataset != null) && (this.dataset.getKeys().size() > 0)) {
2499
2500            List keys = this.dataset.getKeys();
2501            double totalValue = DatasetUtils.calculatePieDatasetTotal(
2502                    this.dataset);
2503
2504            int passesRequired = state.getPassesRequired();
2505            for (int pass = 0; pass < passesRequired; pass++) {
2506                double runningTotal = 0.0;
2507                for (int section = 0; section < keys.size(); section++) {
2508                    Number n = this.dataset.getValue(section);
2509                    if (n != null) {
2510                        double value = n.doubleValue();
2511                        if (value > 0.0) {
2512                            runningTotal += value;
2513                            drawItem(g2, section, explodeArea, state, pass);
2514                        }
2515                    }
2516                }
2517            }
2518            if (this.simpleLabels) {
2519                drawSimpleLabels(g2, keys, totalValue, plotArea, linkArea,
2520                        state);
2521            }
2522            else {
2523                drawLabels(g2, keys, totalValue, plotArea, linkArea, state);
2524            }
2525
2526        }
2527        else {
2528            drawNoDataMessage(g2, plotArea);
2529        }
2530    }
2531
2532    /**
2533     * Draws a single data item.
2534     *
2535     * @param g2  the graphics device ({@code null} not permitted).
2536     * @param section  the section index.
2537     * @param dataArea  the data plot area.
2538     * @param state  state information for one chart.
2539     * @param currentPass  the current pass index.
2540     */
2541    protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea,
2542                            PiePlotState state, int currentPass) {
2543
2544        Number n = this.dataset.getValue(section);
2545        if (n == null) {
2546            return;
2547        }
2548        double value = n.doubleValue();
2549        double angle1 = 0.0;
2550        double angle2 = 0.0;
2551
2552        if (this.direction == Rotation.CLOCKWISE) {
2553            angle1 = state.getLatestAngle();
2554            angle2 = angle1 - value / state.getTotal() * 360.0;
2555        }
2556        else if (this.direction == Rotation.ANTICLOCKWISE) {
2557            angle1 = state.getLatestAngle();
2558            angle2 = angle1 + value / state.getTotal() * 360.0;
2559        }
2560        else {
2561            throw new IllegalStateException("Rotation type not recognised.");
2562        }
2563
2564        double angle = (angle2 - angle1);
2565        if (Math.abs(angle) > getMinimumArcAngleToDraw()) {
2566            double ep = 0.0;
2567            double mep = getMaximumExplodePercent();
2568            if (mep > 0.0) {
2569                ep = getExplodePercent(dataset.getKey(section)) / mep;
2570            }
2571            Rectangle2D arcBounds = getArcBounds(state.getPieArea(),
2572                    state.getExplodedPieArea(), angle1, angle, ep);
2573            Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle,
2574                    Arc2D.PIE);
2575
2576            if (currentPass == 0) {
2577                if (this.shadowPaint != null && this.shadowGenerator == null) {
2578                    Shape shadowArc = ShapeUtils.createTranslatedShape(
2579                            arc, (float) this.shadowXOffset,
2580                            (float) this.shadowYOffset);
2581                    g2.setPaint(this.shadowPaint);
2582                    g2.fill(shadowArc);
2583                }
2584            }
2585            else if (currentPass == 1) {
2586                Comparable key = getSectionKey(section);
2587                Paint paint = lookupSectionPaint(key, state);
2588                g2.setPaint(paint);
2589                g2.fill(arc);
2590
2591                Paint outlinePaint = lookupSectionOutlinePaint(key);
2592                Stroke outlineStroke = lookupSectionOutlineStroke(key);
2593                if (this.sectionOutlinesVisible) {
2594                    g2.setPaint(outlinePaint);
2595                    g2.setStroke(outlineStroke);
2596                    g2.draw(arc);
2597                }
2598
2599                // update the linking line target for later
2600                // add an entity for the pie section
2601                if (state.getInfo() != null) {
2602                    EntityCollection entities = state.getEntityCollection();
2603                    if (entities != null) {
2604                        String tip = null;
2605                        if (this.toolTipGenerator != null) {
2606                            tip = this.toolTipGenerator.generateToolTip(
2607                                    this.dataset, key);
2608                        }
2609                        String url = null;
2610                        if (this.urlGenerator != null) {
2611                            url = this.urlGenerator.generateURL(this.dataset,
2612                                    key, this.pieIndex);
2613                        }
2614                        PieSectionEntity entity = new PieSectionEntity(
2615                                arc, this.dataset, this.pieIndex, section, key,
2616                                tip, url);
2617                        entities.add(entity);
2618                    }
2619                }
2620            }
2621        }
2622        state.setLatestAngle(angle2);
2623    }
2624
2625    /**
2626     * Draws the pie section labels in the simple form.
2627     *
2628     * @param g2  the graphics device.
2629     * @param keys  the section keys.
2630     * @param totalValue  the total value for all sections in the pie.
2631     * @param plotArea  the plot area.
2632     * @param pieArea  the area containing the pie.
2633     * @param state  the plot state.
2634     *
2635     * @since 1.0.7
2636     */
2637    protected void drawSimpleLabels(Graphics2D g2, List keys,
2638            double totalValue, Rectangle2D plotArea, Rectangle2D pieArea,
2639            PiePlotState state) {
2640
2641        Composite originalComposite = g2.getComposite();
2642        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
2643                1.0f));
2644
2645        Rectangle2D labelsArea = this.simpleLabelOffset.createInsetRectangle(
2646                pieArea);
2647        double runningTotal = 0.0;
2648        Iterator iterator = keys.iterator();
2649        while (iterator.hasNext()) {
2650            Comparable key = (Comparable) iterator.next();
2651            boolean include;
2652            double v = 0.0;
2653            Number n = getDataset().getValue(key);
2654            if (n == null) {
2655                include = !getIgnoreNullValues();
2656            }
2657            else {
2658                v = n.doubleValue();
2659                include = getIgnoreZeroValues() ? v > 0.0 : v >= 0.0;
2660            }
2661
2662            if (include) {
2663                runningTotal = runningTotal + v;
2664                // work out the mid angle (0 - 90 and 270 - 360) = right,
2665                // otherwise left
2666                double mid = getStartAngle() + (getDirection().getFactor()
2667                        * ((runningTotal - v / 2.0) * 360) / totalValue);
2668
2669                Arc2D arc = new Arc2D.Double(labelsArea, getStartAngle(),
2670                        mid - getStartAngle(), Arc2D.OPEN);
2671                int x = (int) arc.getEndPoint().getX();
2672                int y = (int) arc.getEndPoint().getY();
2673
2674                PieSectionLabelGenerator myLabelGenerator = getLabelGenerator();
2675                if (myLabelGenerator == null) {
2676                    continue;
2677                }
2678                String label = myLabelGenerator.generateSectionLabel(
2679                        this.dataset, key);
2680                if (label == null) {
2681                    continue;
2682                }
2683                g2.setFont(this.labelFont);
2684                FontMetrics fm = g2.getFontMetrics();
2685                Rectangle2D bounds = TextUtils.getTextBounds(label, g2, fm);
2686                Rectangle2D out = this.labelPadding.createOutsetRectangle(
2687                        bounds);
2688                Shape bg = ShapeUtils.createTranslatedShape(out,
2689                        x - bounds.getCenterX(), y - bounds.getCenterY());
2690                if (this.labelShadowPaint != null
2691                        && this.shadowGenerator == null) {
2692                    Shape shadow = ShapeUtils.createTranslatedShape(bg,
2693                            this.shadowXOffset, this.shadowYOffset);
2694                    g2.setPaint(this.labelShadowPaint);
2695                    g2.fill(shadow);
2696                }
2697                if (this.labelBackgroundPaint != null) {
2698                    g2.setPaint(this.labelBackgroundPaint);
2699                    g2.fill(bg);
2700                }
2701                if (this.labelOutlinePaint != null
2702                        && this.labelOutlineStroke != null) {
2703                    g2.setPaint(this.labelOutlinePaint);
2704                    g2.setStroke(this.labelOutlineStroke);
2705                    g2.draw(bg);
2706                }
2707
2708                g2.setPaint(this.labelPaint);
2709                g2.setFont(this.labelFont);
2710                TextUtils.drawAlignedString(label, g2, x, y,
2711                        TextAnchor.CENTER);
2712
2713            }
2714        }
2715
2716        g2.setComposite(originalComposite);
2717
2718    }
2719
2720    /**
2721     * Draws the labels for the pie sections.
2722     *
2723     * @param g2  the graphics device.
2724     * @param keys  the keys.
2725     * @param totalValue  the total value.
2726     * @param plotArea  the plot area.
2727     * @param linkArea  the link area.
2728     * @param state  the state.
2729     */
2730    protected void drawLabels(Graphics2D g2, List keys, double totalValue,
2731                              Rectangle2D plotArea, Rectangle2D linkArea,
2732                              PiePlotState state) {
2733
2734        Composite originalComposite = g2.getComposite();
2735        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
2736                1.0f));
2737
2738        // classify the keys according to which side the label will appear...
2739        DefaultKeyedValues leftKeys = new DefaultKeyedValues();
2740        DefaultKeyedValues rightKeys = new DefaultKeyedValues();
2741
2742        double runningTotal = 0.0;
2743        Iterator iterator = keys.iterator();
2744        while (iterator.hasNext()) {
2745            Comparable key = (Comparable) iterator.next();
2746            boolean include;
2747            double v = 0.0;
2748            Number n = this.dataset.getValue(key);
2749            if (n == null) {
2750                include = !this.ignoreNullValues;
2751            }
2752            else {
2753                v = n.doubleValue();
2754                include = this.ignoreZeroValues ? v > 0.0 : v >= 0.0;
2755            }
2756
2757            if (include) {
2758                runningTotal = runningTotal + v;
2759                // work out the mid angle (0 - 90 and 270 - 360) = right,
2760                // otherwise left
2761                double mid = this.startAngle + (this.direction.getFactor()
2762                        * ((runningTotal - v / 2.0) * 360) / totalValue);
2763                if (Math.cos(Math.toRadians(mid)) < 0.0) {
2764                    leftKeys.addValue(key, mid);
2765                }
2766                else {
2767                    rightKeys.addValue(key, mid);
2768                }
2769            }
2770        }
2771
2772        g2.setFont(getLabelFont());
2773
2774        // calculate the max label width from the plot dimensions, because
2775        // a circular pie can leave a lot more room for labels...
2776        double marginX = plotArea.getX();
2777        double gap = plotArea.getWidth() * this.labelGap;
2778        double ww = linkArea.getX() - gap - marginX;
2779        float labelWidth = (float) this.labelPadding.trimWidth(ww);
2780
2781        // draw the labels...
2782        if (this.labelGenerator != null) {
2783            drawLeftLabels(leftKeys, g2, plotArea, linkArea, labelWidth,
2784                    state);
2785            drawRightLabels(rightKeys, g2, plotArea, linkArea, labelWidth,
2786                    state);
2787        }
2788        g2.setComposite(originalComposite);
2789
2790    }
2791
2792    /**
2793     * Draws the left labels.
2794     *
2795     * @param leftKeys  a collection of keys and angles (to the middle of the
2796     *         section, in degrees) for the sections on the left side of the
2797     *         plot.
2798     * @param g2  the graphics device.
2799     * @param plotArea  the plot area.
2800     * @param linkArea  the link area.
2801     * @param maxLabelWidth  the maximum label width.
2802     * @param state  the state.
2803     */
2804    protected void drawLeftLabels(KeyedValues leftKeys, Graphics2D g2,
2805                                  Rectangle2D plotArea, Rectangle2D linkArea,
2806                                  float maxLabelWidth, PiePlotState state) {
2807
2808        this.labelDistributor.clear();
2809        double lGap = plotArea.getWidth() * this.labelGap;
2810        double verticalLinkRadius = state.getLinkArea().getHeight() / 2.0;
2811        for (int i = 0; i < leftKeys.getItemCount(); i++) {
2812            String label = this.labelGenerator.generateSectionLabel(
2813                    this.dataset, leftKeys.getKey(i));
2814            if (label != null) {
2815                TextBlock block = TextUtils.createTextBlock(label,
2816                        this.labelFont, this.labelPaint, maxLabelWidth,
2817                        new G2TextMeasurer(g2));
2818                TextBox labelBox = new TextBox(block);
2819                labelBox.setBackgroundPaint(this.labelBackgroundPaint);
2820                labelBox.setOutlinePaint(this.labelOutlinePaint);
2821                labelBox.setOutlineStroke(this.labelOutlineStroke);
2822                if (this.shadowGenerator == null) {
2823                    labelBox.setShadowPaint(this.labelShadowPaint);
2824                }
2825                else {
2826                    labelBox.setShadowPaint(null);
2827                }
2828                labelBox.setInteriorGap(this.labelPadding);
2829                double theta = Math.toRadians(
2830                        leftKeys.getValue(i).doubleValue());
2831                double baseY = state.getPieCenterY() - Math.sin(theta)
2832                               * verticalLinkRadius;
2833                double hh = labelBox.getHeight(g2);
2834
2835                this.labelDistributor.addPieLabelRecord(new PieLabelRecord(
2836                        leftKeys.getKey(i), theta, baseY, labelBox, hh,
2837                        lGap / 2.0 + lGap / 2.0 * -Math.cos(theta), 1.0
2838                        - getLabelLinkDepth()
2839                        + getExplodePercent(leftKeys.getKey(i))));
2840            }
2841        }
2842        double hh = plotArea.getHeight();
2843        double gap = hh * getInteriorGap();
2844        this.labelDistributor.distributeLabels(plotArea.getMinY() + gap,
2845                hh - 2 * gap);
2846        for (int i = 0; i < this.labelDistributor.getItemCount(); i++) {
2847            drawLeftLabel(g2, state,
2848                    this.labelDistributor.getPieLabelRecord(i));
2849        }
2850    }
2851
2852    /**
2853     * Draws the right labels.
2854     *
2855     * @param keys  the keys.
2856     * @param g2  the graphics device.
2857     * @param plotArea  the plot area.
2858     * @param linkArea  the link area.
2859     * @param maxLabelWidth  the maximum label width.
2860     * @param state  the state.
2861     */
2862    protected void drawRightLabels(KeyedValues keys, Graphics2D g2,
2863                                   Rectangle2D plotArea, Rectangle2D linkArea,
2864                                   float maxLabelWidth, PiePlotState state) {
2865
2866        // draw the right labels...
2867        this.labelDistributor.clear();
2868        double lGap = plotArea.getWidth() * this.labelGap;
2869        double verticalLinkRadius = state.getLinkArea().getHeight() / 2.0;
2870
2871        for (int i = 0; i < keys.getItemCount(); i++) {
2872            String label = this.labelGenerator.generateSectionLabel(
2873                    this.dataset, keys.getKey(i));
2874
2875            if (label != null) {
2876                TextBlock block = TextUtils.createTextBlock(label,
2877                        this.labelFont, this.labelPaint, maxLabelWidth,
2878                        new G2TextMeasurer(g2));
2879                TextBox labelBox = new TextBox(block);
2880                labelBox.setBackgroundPaint(this.labelBackgroundPaint);
2881                labelBox.setOutlinePaint(this.labelOutlinePaint);
2882                labelBox.setOutlineStroke(this.labelOutlineStroke);
2883                if (this.shadowGenerator == null) {
2884                    labelBox.setShadowPaint(this.labelShadowPaint);
2885                }
2886                else {
2887                    labelBox.setShadowPaint(null);
2888                }
2889                labelBox.setInteriorGap(this.labelPadding);
2890                double theta = Math.toRadians(keys.getValue(i).doubleValue());
2891                double baseY = state.getPieCenterY()
2892                              - Math.sin(theta) * verticalLinkRadius;
2893                double hh = labelBox.getHeight(g2);
2894                this.labelDistributor.addPieLabelRecord(new PieLabelRecord(
2895                        keys.getKey(i), theta, baseY, labelBox, hh,
2896                        lGap / 2.0 + lGap / 2.0 * Math.cos(theta),
2897                        1.0 - getLabelLinkDepth()
2898                        + getExplodePercent(keys.getKey(i))));
2899            }
2900        }
2901        double hh = plotArea.getHeight();
2902        double gap = 0.00; //hh * getInteriorGap();
2903        this.labelDistributor.distributeLabels(plotArea.getMinY() + gap,
2904                hh - 2 * gap);
2905        for (int i = 0; i < this.labelDistributor.getItemCount(); i++) {
2906            drawRightLabel(g2, state,
2907                    this.labelDistributor.getPieLabelRecord(i));
2908        }
2909
2910    }
2911
2912    /**
2913     * Returns a collection of legend items for the pie chart.
2914     *
2915     * @return The legend items (never {@code null}).
2916     */
2917    @Override
2918    public LegendItemCollection getLegendItems() {
2919
2920        LegendItemCollection result = new LegendItemCollection();
2921        if (this.dataset == null) {
2922            return result;
2923        }
2924        List keys = this.dataset.getKeys();
2925        int section = 0;
2926        Shape shape = getLegendItemShape();
2927        Iterator iterator = keys.iterator();
2928        while (iterator.hasNext()) {
2929            Comparable key = (Comparable) iterator.next();
2930            Number n = this.dataset.getValue(key);
2931            boolean include;
2932            if (n == null) {
2933                include = !this.ignoreNullValues;
2934            }
2935            else {
2936                double v = n.doubleValue();
2937                if (v == 0.0) {
2938                    include = !this.ignoreZeroValues;
2939                }
2940                else {
2941                    include = v > 0.0;
2942                }
2943            }
2944            if (include) {
2945                String label = this.legendLabelGenerator.generateSectionLabel(
2946                        this.dataset, key);
2947                if (label != null) {
2948                    String description = label;
2949                    String toolTipText = null;
2950                    if (this.legendLabelToolTipGenerator != null) {
2951                        toolTipText = this.legendLabelToolTipGenerator
2952                                .generateSectionLabel(this.dataset, key);
2953                    }
2954                    String urlText = null;
2955                    if (this.legendLabelURLGenerator != null) {
2956                        urlText = this.legendLabelURLGenerator.generateURL(
2957                                this.dataset, key, this.pieIndex);
2958                    }
2959                    Paint paint = lookupSectionPaint(key);
2960                    Paint outlinePaint = lookupSectionOutlinePaint(key);
2961                    Stroke outlineStroke = lookupSectionOutlineStroke(key);
2962                    LegendItem item = new LegendItem(label, description,
2963                            toolTipText, urlText, true, shape, true, paint,
2964                            true, outlinePaint, outlineStroke,
2965                            false,          // line not visible
2966                            new Line2D.Float(), new BasicStroke(), Color.BLACK);
2967                    item.setDataset(getDataset());
2968                    item.setSeriesIndex(this.dataset.getIndex(key));
2969                    item.setSeriesKey(key);
2970                    result.add(item);
2971                }
2972                section++;
2973            }
2974            else {
2975                section++;
2976            }
2977        }
2978        return result;
2979    }
2980
2981    /**
2982     * Returns a short string describing the type of plot.
2983     *
2984     * @return The plot type.
2985     */
2986    @Override
2987    public String getPlotType() {
2988        return localizationResources.getString("Pie_Plot");
2989    }
2990
2991    /**
2992     * Returns a rectangle that can be used to create a pie section (taking
2993     * into account the amount by which the pie section is 'exploded').
2994     *
2995     * @param unexploded  the area inside which the unexploded pie sections are
2996     *                    drawn.
2997     * @param exploded  the area inside which the exploded pie sections are
2998     *                  drawn.
2999     * @param angle  the start angle.
3000     * @param extent  the extent of the arc.
3001     * @param explodePercent  the amount by which the pie section is exploded.
3002     *
3003     * @return A rectangle that can be used to create a pie section.
3004     */
3005    protected Rectangle2D getArcBounds(Rectangle2D unexploded,
3006                                       Rectangle2D exploded,
3007                                       double angle, double extent,
3008                                       double explodePercent) {
3009
3010        if (explodePercent == 0.0) {
3011            return unexploded;
3012        }
3013        Arc2D arc1 = new Arc2D.Double(unexploded, angle, extent / 2,
3014                Arc2D.OPEN);
3015        Point2D point1 = arc1.getEndPoint();
3016        Arc2D.Double arc2 = new Arc2D.Double(exploded, angle, extent / 2,
3017                Arc2D.OPEN);
3018        Point2D point2 = arc2.getEndPoint();
3019        double deltaX = (point1.getX() - point2.getX()) * explodePercent;
3020        double deltaY = (point1.getY() - point2.getY()) * explodePercent;
3021        return new Rectangle2D.Double(unexploded.getX() - deltaX,
3022                unexploded.getY() - deltaY, unexploded.getWidth(),
3023                unexploded.getHeight());
3024    }
3025
3026    /**
3027     * Draws a section label on the left side of the pie chart.
3028     *
3029     * @param g2  the graphics device.
3030     * @param state  the state.
3031     * @param record  the label record.
3032     */
3033    protected void drawLeftLabel(Graphics2D g2, PiePlotState state,
3034                                 PieLabelRecord record) {
3035
3036        double anchorX = state.getLinkArea().getMinX();
3037        double targetX = anchorX - record.getGap();
3038        double targetY = record.getAllocatedY();
3039
3040        if (this.labelLinksVisible) {
3041            double theta = record.getAngle();
3042            double linkX = state.getPieCenterX() + Math.cos(theta)
3043                    * state.getPieWRadius() * record.getLinkPercent();
3044            double linkY = state.getPieCenterY() - Math.sin(theta)
3045                    * state.getPieHRadius() * record.getLinkPercent();
3046            double elbowX = state.getPieCenterX() + Math.cos(theta)
3047                    * state.getLinkArea().getWidth() / 2.0;
3048            double elbowY = state.getPieCenterY() - Math.sin(theta)
3049                    * state.getLinkArea().getHeight() / 2.0;
3050            double anchorY = elbowY;
3051            g2.setPaint(this.labelLinkPaint);
3052            g2.setStroke(this.labelLinkStroke);
3053            PieLabelLinkStyle style = getLabelLinkStyle();
3054            if (style.equals(PieLabelLinkStyle.STANDARD)) {
3055                g2.draw(new Line2D.Double(linkX, linkY, elbowX, elbowY));
3056                g2.draw(new Line2D.Double(anchorX, anchorY, elbowX, elbowY));
3057                g2.draw(new Line2D.Double(anchorX, anchorY, targetX, targetY));
3058            }
3059            else if (style.equals(PieLabelLinkStyle.QUAD_CURVE)) {
3060                QuadCurve2D q = new QuadCurve2D.Float();
3061                q.setCurve(targetX, targetY, anchorX, anchorY, elbowX, elbowY);
3062                g2.draw(q);
3063                g2.draw(new Line2D.Double(elbowX, elbowY, linkX, linkY));
3064            }
3065            else if (style.equals(PieLabelLinkStyle.CUBIC_CURVE)) {
3066                CubicCurve2D c = new CubicCurve2D .Float();
3067                c.setCurve(targetX, targetY, anchorX, anchorY, elbowX, elbowY,
3068                        linkX, linkY);
3069                g2.draw(c);
3070            }
3071        }
3072        TextBox tb = record.getLabel();
3073        tb.draw(g2, (float) targetX, (float) targetY, RectangleAnchor.RIGHT);
3074
3075    }
3076
3077    /**
3078     * Draws a section label on the right side of the pie chart.
3079     *
3080     * @param g2  the graphics device.
3081     * @param state  the state.
3082     * @param record  the label record.
3083     */
3084    protected void drawRightLabel(Graphics2D g2, PiePlotState state,
3085                                  PieLabelRecord record) {
3086
3087        double anchorX = state.getLinkArea().getMaxX();
3088        double targetX = anchorX + record.getGap();
3089        double targetY = record.getAllocatedY();
3090
3091        if (this.labelLinksVisible) {
3092            double theta = record.getAngle();
3093            double linkX = state.getPieCenterX() + Math.cos(theta)
3094                    * state.getPieWRadius() * record.getLinkPercent();
3095            double linkY = state.getPieCenterY() - Math.sin(theta)
3096                    * state.getPieHRadius() * record.getLinkPercent();
3097            double elbowX = state.getPieCenterX() + Math.cos(theta)
3098                    * state.getLinkArea().getWidth() / 2.0;
3099            double elbowY = state.getPieCenterY() - Math.sin(theta)
3100                    * state.getLinkArea().getHeight() / 2.0;
3101            double anchorY = elbowY;
3102            g2.setPaint(this.labelLinkPaint);
3103            g2.setStroke(this.labelLinkStroke);
3104            PieLabelLinkStyle style = getLabelLinkStyle();
3105            if (style.equals(PieLabelLinkStyle.STANDARD)) {
3106                g2.draw(new Line2D.Double(linkX, linkY, elbowX, elbowY));
3107                g2.draw(new Line2D.Double(anchorX, anchorY, elbowX, elbowY));
3108                g2.draw(new Line2D.Double(anchorX, anchorY, targetX, targetY));
3109            }
3110            else if (style.equals(PieLabelLinkStyle.QUAD_CURVE)) {
3111                QuadCurve2D q = new QuadCurve2D.Float();
3112                q.setCurve(targetX, targetY, anchorX, anchorY, elbowX, elbowY);
3113                g2.draw(q);
3114                g2.draw(new Line2D.Double(elbowX, elbowY, linkX, linkY));
3115            }
3116            else if (style.equals(PieLabelLinkStyle.CUBIC_CURVE)) {
3117                CubicCurve2D c = new CubicCurve2D .Float();
3118                c.setCurve(targetX, targetY, anchorX, anchorY, elbowX, elbowY,
3119                        linkX, linkY);
3120                g2.draw(c);
3121            }
3122        }
3123
3124        TextBox tb = record.getLabel();
3125        tb.draw(g2, (float) targetX, (float) targetY, RectangleAnchor.LEFT);
3126
3127    }
3128
3129    /**
3130     * Returns the center for the specified section.
3131     * Checks to see if the section is exploded and recalculates the
3132     * new center if so.
3133     *
3134     * @param state  PiePlotState
3135     * @param key  section key.
3136     *
3137     * @return The center for the specified section.
3138     *
3139     * @since 1.0.14
3140     */
3141    protected Point2D getArcCenter(PiePlotState state, Comparable key) {
3142        Point2D center = new Point2D.Double(state.getPieCenterX(), state
3143            .getPieCenterY());
3144
3145        double ep = getExplodePercent(key);
3146        double mep = getMaximumExplodePercent();
3147        if (mep > 0.0) {
3148            ep = ep / mep;
3149        }
3150        if (ep != 0) {
3151            Rectangle2D pieArea = state.getPieArea();
3152            Rectangle2D expPieArea = state.getExplodedPieArea();
3153            double angle1, angle2;
3154            Number n = this.dataset.getValue(key);
3155            double value = n.doubleValue();
3156
3157            if (this.direction == Rotation.CLOCKWISE) {
3158                angle1 = state.getLatestAngle();
3159                angle2 = angle1 - value / state.getTotal() * 360.0;
3160            } else if (this.direction == Rotation.ANTICLOCKWISE) {
3161                angle1 = state.getLatestAngle();
3162                angle2 = angle1 + value / state.getTotal() * 360.0;
3163            } else {
3164                throw new IllegalStateException("Rotation type not recognised.");
3165            }
3166            double angle = (angle2 - angle1);
3167
3168            Arc2D arc1 = new Arc2D.Double(pieArea, angle1, angle / 2,
3169                    Arc2D.OPEN);
3170            Point2D point1 = arc1.getEndPoint();
3171            Arc2D.Double arc2 = new Arc2D.Double(expPieArea, angle1, angle / 2,
3172                    Arc2D.OPEN);
3173            Point2D point2 = arc2.getEndPoint();
3174            double deltaX = (point1.getX() - point2.getX()) * ep;
3175            double deltaY = (point1.getY() - point2.getY()) * ep;
3176
3177            center = new Point2D.Double(state.getPieCenterX() - deltaX,
3178                     state.getPieCenterY() - deltaY);
3179
3180        }
3181        return center;
3182    }
3183
3184    /**
3185     * Returns the paint for the specified section. This is equivalent to
3186     * {@code lookupSectionPaint(section)}.  Checks to see if the user set the 
3187     * {@code Paint} to be of type {@code RadialGradientPaint} and if so it 
3188     * adjusts the center and radius to match the Pie.
3189     *
3190     * @param key  the section key.
3191     * @param state  PiePlotState.
3192     *
3193     * @return The paint for the specified section.
3194     *
3195     * @since 1.0.14
3196     */
3197    protected Paint lookupSectionPaint(Comparable key, PiePlotState state) {
3198        Paint paint = lookupSectionPaint(key, getAutoPopulateSectionPaint());
3199        // for a RadialGradientPaint we adjust the center and radius to match
3200        // the current pie segment...
3201        if (paint instanceof RadialGradientPaint) {
3202            RadialGradientPaint rgp = (RadialGradientPaint) paint;
3203            Point2D center = getArcCenter(state, key);
3204            float radius = (float) Math.max(state.getPieHRadius(), 
3205                    state.getPieWRadius());
3206            float[] fractions = rgp.getFractions();
3207            Color[] colors = rgp.getColors();
3208            paint = new RadialGradientPaint(center, radius, fractions, colors);
3209        }
3210        return paint;
3211    }
3212
3213    /**
3214     * Tests this plot for equality with an arbitrary object.  Note that the
3215     * plot's dataset is NOT included in the test for equality.
3216     *
3217     * @param obj  the object to test against ({@code null} permitted).
3218     *
3219     * @return {@code true} or {@code false}.
3220     */
3221    @Override
3222    public boolean equals(Object obj) {
3223        if (obj == this) {
3224            return true;
3225        }
3226        if (!(obj instanceof PiePlot)) {
3227            return false;
3228        }
3229        if (!super.equals(obj)) {
3230            return false;
3231        }
3232        PiePlot that = (PiePlot) obj;
3233        if (this.pieIndex != that.pieIndex) {
3234            return false;
3235        }
3236        if (this.interiorGap != that.interiorGap) {
3237            return false;
3238        }
3239        if (this.circular != that.circular) {
3240            return false;
3241        }
3242        if (this.startAngle != that.startAngle) {
3243            return false;
3244        }
3245        if (this.direction != that.direction) {
3246            return false;
3247        }
3248        if (this.ignoreZeroValues != that.ignoreZeroValues) {
3249            return false;
3250        }
3251        if (this.ignoreNullValues != that.ignoreNullValues) {
3252            return false;
3253        }
3254        if (!ObjectUtils.equal(this.sectionPaintMap,
3255                that.sectionPaintMap)) {
3256            return false;
3257        }
3258        if (!PaintUtils.equal(this.defaultSectionPaint,
3259                that.defaultSectionPaint)) {
3260            return false;
3261        }
3262        if (this.sectionOutlinesVisible != that.sectionOutlinesVisible) {
3263            return false;
3264        }
3265        if (!ObjectUtils.equal(this.sectionOutlinePaintMap,
3266                that.sectionOutlinePaintMap)) {
3267            return false;
3268        }
3269        if (!PaintUtils.equal(this.defaultSectionOutlinePaint,
3270                that.defaultSectionOutlinePaint)) {
3271            return false;
3272        }
3273        if (!ObjectUtils.equal(this.sectionOutlineStrokeMap,
3274                that.sectionOutlineStrokeMap)) {
3275            return false;
3276        }
3277        if (!ObjectUtils.equal(this.defaultSectionOutlineStroke,
3278                that.defaultSectionOutlineStroke)) {
3279            return false;
3280        }
3281        if (!PaintUtils.equal(this.shadowPaint, that.shadowPaint)) {
3282            return false;
3283        }
3284        if (!(this.shadowXOffset == that.shadowXOffset)) {
3285            return false;
3286        }
3287        if (!(this.shadowYOffset == that.shadowYOffset)) {
3288            return false;
3289        }
3290        if (!ObjectUtils.equal(this.explodePercentages,
3291                that.explodePercentages)) {
3292            return false;
3293        }
3294        if (!ObjectUtils.equal(this.labelGenerator,
3295                that.labelGenerator)) {
3296            return false;
3297        }
3298        if (!ObjectUtils.equal(this.labelFont, that.labelFont)) {
3299            return false;
3300        }
3301        if (!PaintUtils.equal(this.labelPaint, that.labelPaint)) {
3302            return false;
3303        }
3304        if (!PaintUtils.equal(this.labelBackgroundPaint,
3305                that.labelBackgroundPaint)) {
3306            return false;
3307        }
3308        if (!PaintUtils.equal(this.labelOutlinePaint,
3309                that.labelOutlinePaint)) {
3310            return false;
3311        }
3312        if (!ObjectUtils.equal(this.labelOutlineStroke,
3313                that.labelOutlineStroke)) {
3314            return false;
3315        }
3316        if (!PaintUtils.equal(this.labelShadowPaint,
3317                that.labelShadowPaint)) {
3318            return false;
3319        }
3320        if (this.simpleLabels != that.simpleLabels) {
3321            return false;
3322        }
3323        if (!this.simpleLabelOffset.equals(that.simpleLabelOffset)) {
3324            return false;
3325        }
3326        if (!this.labelPadding.equals(that.labelPadding)) {
3327            return false;
3328        }
3329        if (!(this.maximumLabelWidth == that.maximumLabelWidth)) {
3330            return false;
3331        }
3332        if (!(this.labelGap == that.labelGap)) {
3333            return false;
3334        }
3335        if (!(this.labelLinkMargin == that.labelLinkMargin)) {
3336            return false;
3337        }
3338        if (this.labelLinksVisible != that.labelLinksVisible) {
3339            return false;
3340        }
3341        if (!this.labelLinkStyle.equals(that.labelLinkStyle)) {
3342            return false;
3343        }
3344        if (!PaintUtils.equal(this.labelLinkPaint, that.labelLinkPaint)) {
3345            return false;
3346        }
3347        if (!ObjectUtils.equal(this.labelLinkStroke,
3348                that.labelLinkStroke)) {
3349            return false;
3350        }
3351        if (!ObjectUtils.equal(this.toolTipGenerator,
3352                that.toolTipGenerator)) {
3353            return false;
3354        }
3355        if (!ObjectUtils.equal(this.urlGenerator, that.urlGenerator)) {
3356            return false;
3357        }
3358        if (!(this.minimumArcAngleToDraw == that.minimumArcAngleToDraw)) {
3359            return false;
3360        }
3361        if (!ShapeUtils.equal(this.legendItemShape, that.legendItemShape)) {
3362            return false;
3363        }
3364        if (!ObjectUtils.equal(this.legendLabelGenerator,
3365                that.legendLabelGenerator)) {
3366            return false;
3367        }
3368        if (!ObjectUtils.equal(this.legendLabelToolTipGenerator,
3369                that.legendLabelToolTipGenerator)) {
3370            return false;
3371        }
3372        if (!ObjectUtils.equal(this.legendLabelURLGenerator,
3373                that.legendLabelURLGenerator)) {
3374            return false;
3375        }
3376        if (this.autoPopulateSectionPaint != that.autoPopulateSectionPaint) {
3377            return false;
3378        }
3379        if (this.autoPopulateSectionOutlinePaint
3380                != that.autoPopulateSectionOutlinePaint) {
3381            return false;
3382        }
3383        if (this.autoPopulateSectionOutlineStroke
3384                != that.autoPopulateSectionOutlineStroke) {
3385            return false;
3386        }
3387        if (!ObjectUtils.equal(this.shadowGenerator,
3388                that.shadowGenerator)) {
3389            return false;
3390        }
3391        // can't find any difference...
3392        return true;
3393    }
3394
3395    /**
3396     * Returns a clone of the plot.
3397     *
3398     * @return A clone.
3399     *
3400     * @throws CloneNotSupportedException if some component of the plot does
3401     *         not support cloning.
3402     */
3403    @Override
3404    public Object clone() throws CloneNotSupportedException {
3405        PiePlot clone = (PiePlot) super.clone();
3406        clone.sectionPaintMap = (PaintMap) this.sectionPaintMap.clone();
3407        clone.sectionOutlinePaintMap 
3408                = (PaintMap) this.sectionOutlinePaintMap.clone();
3409        clone.sectionOutlineStrokeMap 
3410                = (StrokeMap) this.sectionOutlineStrokeMap.clone();
3411        clone.explodePercentages 
3412                = new TreeMap<Comparable, Double>(this.explodePercentages);
3413        if (this.labelGenerator != null) {
3414            clone.labelGenerator = (PieSectionLabelGenerator) 
3415                    ObjectUtils.clone(this.labelGenerator);
3416        }
3417        if (clone.dataset != null) {
3418            clone.dataset.addChangeListener(clone);
3419        }
3420        if (this.urlGenerator instanceof PublicCloneable) {
3421            clone.urlGenerator = (PieURLGenerator) ObjectUtils.clone(
3422                    this.urlGenerator);
3423        }
3424        clone.legendItemShape = ShapeUtils.clone(this.legendItemShape);
3425        if (this.legendLabelGenerator != null) {
3426            clone.legendLabelGenerator = (PieSectionLabelGenerator)
3427                    ObjectUtils.clone(this.legendLabelGenerator);
3428        }
3429        if (this.legendLabelToolTipGenerator != null) {
3430            clone.legendLabelToolTipGenerator = (PieSectionLabelGenerator)
3431                    ObjectUtils.clone(this.legendLabelToolTipGenerator);
3432        }
3433        if (this.legendLabelURLGenerator instanceof PublicCloneable) {
3434            clone.legendLabelURLGenerator = (PieURLGenerator)
3435                    ObjectUtils.clone(this.legendLabelURLGenerator);
3436        }
3437        return clone;
3438    }
3439
3440    /**
3441     * Provides serialization support.
3442     *
3443     * @param stream  the output stream.
3444     *
3445     * @throws IOException  if there is an I/O error.
3446     */
3447    private void writeObject(ObjectOutputStream stream) throws IOException {
3448        stream.defaultWriteObject();
3449        SerialUtils.writePaint(this.defaultSectionPaint, stream);
3450        SerialUtils.writePaint(this.defaultSectionOutlinePaint, stream);
3451        SerialUtils.writeStroke(this.defaultSectionOutlineStroke, stream);
3452        SerialUtils.writePaint(this.shadowPaint, stream);
3453        SerialUtils.writePaint(this.labelPaint, stream);
3454        SerialUtils.writePaint(this.labelBackgroundPaint, stream);
3455        SerialUtils.writePaint(this.labelOutlinePaint, stream);
3456        SerialUtils.writeStroke(this.labelOutlineStroke, stream);
3457        SerialUtils.writePaint(this.labelShadowPaint, stream);
3458        SerialUtils.writePaint(this.labelLinkPaint, stream);
3459        SerialUtils.writeStroke(this.labelLinkStroke, stream);
3460        SerialUtils.writeShape(this.legendItemShape, stream);
3461    }
3462
3463    /**
3464     * Provides serialization support.
3465     *
3466     * @param stream  the input stream.
3467     *
3468     * @throws IOException  if there is an I/O error.
3469     * @throws ClassNotFoundException  if there is a classpath problem.
3470     */
3471    private void readObject(ObjectInputStream stream)
3472        throws IOException, ClassNotFoundException {
3473        stream.defaultReadObject();
3474        this.defaultSectionPaint = SerialUtils.readPaint(stream);
3475        this.defaultSectionOutlinePaint = SerialUtils.readPaint(stream);
3476        this.defaultSectionOutlineStroke = SerialUtils.readStroke(stream);
3477        this.shadowPaint = SerialUtils.readPaint(stream);
3478        this.labelPaint = SerialUtils.readPaint(stream);
3479        this.labelBackgroundPaint = SerialUtils.readPaint(stream);
3480        this.labelOutlinePaint = SerialUtils.readPaint(stream);
3481        this.labelOutlineStroke = SerialUtils.readStroke(stream);
3482        this.labelShadowPaint = SerialUtils.readPaint(stream);
3483        this.labelLinkPaint = SerialUtils.readPaint(stream);
3484        this.labelLinkStroke = SerialUtils.readStroke(stream);
3485        this.legendItemShape = SerialUtils.readShape(stream);
3486    }
3487
3488}