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 * DefaultPolarItemRenderer.java
029 * -----------------------------
030 * (C) Copyright 2004-2017, by Solution Engineering, Inc. and
031 *     Contributors.
032 *
033 * Original Author:  Daniel Bridenbecker, Solution Engineering, Inc.;
034 * Contributor(s):   David Gilbert (for Object Refinery Limited);
035 *                   Martin Hoeller (patch 2850344);
036 *
037 * Changes
038 * -------
039 * 19-Jan-2004 : Version 1, contributed by DB with minor changes by DG (DG);
040 * 15-Jul-2004 : Switched getX() with getXValue() and getY() with
041 *               getYValue() (DG);
042 * 04-Oct-2004 : Renamed BooleanUtils --> BooleanUtilities (DG);
043 * 20-Apr-2005 : Update for change to LegendItem class (DG);
044 * ------------- JFREECHART 1.0.x ---------------------------------------------
045 * 04-Aug-2006 : Implemented equals() and clone() (DG);
046 * 02-Feb-2007 : Removed author tags from all over JFreeChart sources (DG);
047 * 14-Mar-2007 : Fixed clone() method (DG);
048 * 04-May-2007 : Fixed lookup for series paint and stroke (DG);
049 * 18-May-2007 : Set dataset for LegendItem (DG);
050 * 03-Sep-2009 : Applied patch 2850344 by Martin Hoeller (DG);
051 * 27-Nov-2009 : Updated for modification to PolarItemRenderer interface (DG);
052 * 03-Oct-2011 : Fixed potential NPE in equals() (MH);
053 * 03-Oct-2011 : Added flag to connectFirstAndLastPoint (MH);
054 * 03-Oct-2011 : Added tooltip and URL generator support (MH);
055 * 03-Oct-2011 : Added some configuration options for the legend (MH);
056 * 03-Oct-2011 : Added support for PolarPlot's angleOffset and direction (MH);
057 * 16-Oct-2011 : Fixed serialization problems with fillComposite (MH);
058 * 18-Sep-2012 : Fixed bug 3508799: seriesKey always null in LegendItem (DG);
059 * 01-Jul-2013 : Remove deprecated method calls (DG);
060 * 04-Jul-2013 : Fix rendering bug when axis is inverted (DG);
061 * 
062 */
063
064package org.jfree.chart.renderer;
065
066import java.awt.AlphaComposite;
067import java.awt.Composite;
068import java.awt.Graphics2D;
069import java.awt.Paint;
070import java.awt.Point;
071import java.awt.Shape;
072import java.awt.Stroke;
073import java.awt.geom.Ellipse2D;
074import java.awt.geom.GeneralPath;
075import java.awt.geom.Line2D;
076import java.awt.geom.PathIterator;
077import java.awt.geom.Rectangle2D;
078import java.io.IOException;
079import java.io.ObjectInputStream;
080import java.io.ObjectOutputStream;
081import java.util.Iterator;
082import java.util.List;
083
084import org.jfree.chart.LegendItem;
085import org.jfree.chart.axis.NumberTick;
086import org.jfree.chart.axis.ValueAxis;
087import org.jfree.chart.entity.EntityCollection;
088import org.jfree.chart.entity.XYItemEntity;
089import org.jfree.chart.event.RendererChangeEvent;
090import org.jfree.chart.labels.XYSeriesLabelGenerator;
091import org.jfree.chart.labels.XYToolTipGenerator;
092import org.jfree.chart.plot.DrawingSupplier;
093import org.jfree.chart.plot.PlotOrientation;
094import org.jfree.chart.plot.PlotRenderingInfo;
095import org.jfree.chart.plot.PolarPlot;
096import org.jfree.chart.text.TextUtils;
097import org.jfree.chart.urls.XYURLGenerator;
098import org.jfree.chart.util.BooleanList;
099import org.jfree.chart.util.ObjectList;
100import org.jfree.chart.util.ObjectUtils;
101import org.jfree.chart.util.Args;
102import org.jfree.chart.util.PublicCloneable;
103import org.jfree.chart.util.SerialUtils;
104import org.jfree.chart.util.ShapeUtils;
105import org.jfree.data.xy.XYDataset;
106
107/**
108 * A renderer that can be used with the {@link PolarPlot} class.
109 */
110public class DefaultPolarItemRenderer extends AbstractRenderer
111        implements PolarItemRenderer {
112
113    /** The plot that the renderer is assigned to. */
114    private PolarPlot plot;
115
116    /** Flags that control whether the renderer fills each series or not. */
117    private BooleanList seriesFilled;
118
119    /**
120     * Flag that controls whether an outline is drawn for filled series or
121     * not.
122     *
123     * @since 1.0.14
124     */
125    private boolean drawOutlineWhenFilled;
126
127    /**
128     * The composite to use when filling series.
129     * 
130     * @since 1.0.14
131     */
132    private transient Composite fillComposite;
133
134    /**
135     * A flag that controls whether the fill paint is used for filling
136     * shapes.
137     * 
138     * @since 1.0.14
139     */
140    private boolean useFillPaint;
141
142    /**
143     * The shape that is used to represent a line in the legend.
144     * 
145     * @since 1.0.14
146     */
147    private transient Shape legendLine;
148
149    /**
150     * Flag that controls whether item shapes are visible or not.
151     * 
152     * @since 1.0.14
153     */
154    private boolean shapesVisible;
155
156    /**
157     * Flag that controls if the first and last point of the dataset should be
158     * connected or not.
159     * 
160     *  @since 1.0.14
161     */
162    private boolean connectFirstAndLastPoint;
163    
164    /**
165     * A list of tool tip generators (one per series).
166     * 
167     * @since 1.0.14
168     */
169    private ObjectList toolTipGeneratorList;
170
171    /**
172     * The base tool tip generator.
173     * 
174     * @since 1.0.14
175     */
176    private XYToolTipGenerator baseToolTipGenerator;
177
178    /**
179     * The URL text generator.
180     * 
181     * @since 1.0.14
182     */
183    private XYURLGenerator urlGenerator;
184
185    /**
186     * The legend item tool tip generator.
187     * 
188     * @since 1.0.14
189     */
190    private XYSeriesLabelGenerator legendItemToolTipGenerator;
191
192    /**
193     * The legend item URL generator.
194     * 
195     * @since 1.0.14
196     */
197    private XYSeriesLabelGenerator legendItemURLGenerator;
198
199    /**
200     * Creates a new instance of DefaultPolarItemRenderer
201     */
202    public DefaultPolarItemRenderer() {
203        this.seriesFilled = new BooleanList();
204        this.drawOutlineWhenFilled = true;
205        this.fillComposite = AlphaComposite.getInstance(
206                AlphaComposite.SRC_OVER, 0.3f);
207        this.useFillPaint = false;     // use item paint for fills by default
208        this.legendLine = new Line2D.Double(-7.0, 0.0, 7.0, 0.0);
209        this.shapesVisible = true;
210        this.connectFirstAndLastPoint = true;
211        
212        this.toolTipGeneratorList = new ObjectList();
213        this.urlGenerator = null;
214        this.legendItemToolTipGenerator = null;
215        this.legendItemURLGenerator = null;
216    }
217
218    /**
219     * Set the plot associated with this renderer.
220     *
221     * @param plot  the plot.
222     *
223     * @see #getPlot()
224     */
225    @Override
226    public void setPlot(PolarPlot plot) {
227        this.plot = plot;
228    }
229
230    /**
231     * Return the plot associated with this renderer.
232     *
233     * @return The plot.
234     *
235     * @see #setPlot(PolarPlot)
236     */
237    @Override
238    public PolarPlot getPlot() {
239        return this.plot;
240    }
241
242    /**
243     * Returns {@code true} if the renderer will draw an outline around
244     * a filled polygon, {@code false} otherwise.
245     *
246     * @return A boolean.
247     *
248     * @since 1.0.14
249     */
250    public boolean getDrawOutlineWhenFilled() {
251        return this.drawOutlineWhenFilled;
252    }
253
254    /**
255     * Set the flag that controls whether the outline around a filled
256     * polygon will be drawn or not and sends a {@link RendererChangeEvent}
257     * to all registered listeners.
258     *
259     * @param drawOutlineWhenFilled  the flag.
260     *
261     * @since 1.0.14
262     */
263    public void setDrawOutlineWhenFilled(boolean drawOutlineWhenFilled) {
264        this.drawOutlineWhenFilled = drawOutlineWhenFilled;
265        fireChangeEvent();
266    }
267
268    /**
269     * Get the composite that is used for filling.
270     *
271     * @return The composite (never {@code null}).
272     *
273     * @since 1.0.14
274     */
275    public Composite getFillComposite() {
276        return this.fillComposite;
277    }
278
279    /**
280     * Sets the composite which will be used for filling polygons and sends a
281     * {@link RendererChangeEvent} to all registered listeners.
282     *
283     * @param composite  the composite to use ({@code null} not
284     *         permitted).
285     *
286     * @since 1.0.14
287     */
288    public void setFillComposite(Composite composite) {
289        Args.nullNotPermitted(composite, "composite");
290        this.fillComposite = composite;
291        fireChangeEvent();
292    }
293
294    /**
295     * Returns {@code true} if a shape will be drawn for every item, or
296     * {@code false} if not.
297     *
298     * @return A boolean.
299     *
300     * @since 1.0.14
301     */
302    public boolean getShapesVisible() {
303        return this.shapesVisible;
304    }
305
306    /**
307     * Set the flag that controls whether a shape will be drawn for every
308     * item, or not and sends a {@link RendererChangeEvent} to all registered
309     * listeners.
310     *
311     * @param visible  the flag.
312     *
313     * @since 1.0.14
314     */
315    public void setShapesVisible(boolean visible) {
316        this.shapesVisible = visible;
317        fireChangeEvent();
318    }
319
320    /**
321     * Returns {@code true} if first and last point of a series will be
322     * connected, {@code false} otherwise.
323     * 
324     * @return The current status of the flag.
325     * 
326     * @since 1.0.14
327     */
328    public boolean getConnectFirstAndLastPoint() {
329        return this.connectFirstAndLastPoint;
330    }
331
332    /**
333     * Set the flag that controls whether the first and last point of a series
334     * will be connected or not and sends a {@link RendererChangeEvent} to all
335     * registered listeners.
336     * 
337     * @param connect the flag.
338     * 
339     * @since 1.0.14
340     */
341    public void setConnectFirstAndLastPoint(boolean connect) {
342        this.connectFirstAndLastPoint = connect;
343        fireChangeEvent();
344    }
345
346    /**
347     * Returns the drawing supplier from the plot.
348     *
349     * @return The drawing supplier.
350     */
351    @Override
352    public DrawingSupplier getDrawingSupplier() {
353        DrawingSupplier result = null;
354        PolarPlot p = getPlot();
355        if (p != null) {
356            result = p.getDrawingSupplier();
357        }
358        return result;
359    }
360
361    /**
362     * Returns {@code true} if the renderer should fill the specified
363     * series, and {@code false} otherwise.
364     *
365     * @param series  the series index (zero-based).
366     *
367     * @return A boolean.
368     */
369    public boolean isSeriesFilled(int series) {
370        boolean result = false;
371        Boolean b = this.seriesFilled.getBoolean(series);
372        if (b != null) {
373            result = b;
374        }
375        return result;
376    }
377
378    /**
379     * Sets a flag that controls whether or not a series is filled.
380     *
381     * @param series  the series index.
382     * @param filled  the flag.
383     */
384    public void setSeriesFilled(int series, boolean filled) {
385        this.seriesFilled.setBoolean(series, filled);
386    }
387
388    /**
389     * Returns {@code true} if the renderer should use the fill paint
390     * setting to fill shapes, and {@code false} if it should just
391     * use the regular paint.
392     *
393     * @return A boolean.
394     *
395     * @see #setUseFillPaint(boolean)
396     * @since 1.0.14
397     */
398    public boolean getUseFillPaint() {
399        return this.useFillPaint;
400    }
401
402    /**
403     * Sets the flag that controls whether the fill paint is used to fill
404     * shapes, and sends a {@link RendererChangeEvent} to all
405     * registered listeners.
406     *
407     * @param flag  the flag.
408     *
409     * @see #getUseFillPaint()
410     * @since 1.0.14
411     */
412    public void setUseFillPaint(boolean flag) {
413        this.useFillPaint = flag;
414        fireChangeEvent();
415    }
416
417    /**
418     * Returns the shape used to represent a line in the legend.
419     *
420     * @return The legend line (never {@code null}).
421     *
422     * @see #setLegendLine(Shape)
423     */
424    public Shape getLegendLine() {
425        return this.legendLine;
426    }
427
428    /**
429     * Sets the shape used as a line in each legend item and sends a
430     * {@link RendererChangeEvent} to all registered listeners.
431     *
432     * @param line  the line ({@code null} not permitted).
433     *
434     * @see #getLegendLine()
435     */
436    public void setLegendLine(Shape line) {
437        Args.nullNotPermitted(line, "line");
438        this.legendLine = line;
439        fireChangeEvent();
440    }
441
442    /**
443     * Adds an entity to the collection.
444     *
445     * @param entities  the entity collection being populated.
446     * @param area  the entity area (if {@code null} a default will be
447     *              used).
448     * @param dataset  the dataset.
449     * @param series  the series.
450     * @param item  the item.
451     * @param entityX  the entity's center x-coordinate in user space (only
452     *                 used if {@code area} is {@code null}).
453     * @param entityY  the entity's center y-coordinate in user space (only
454     *                 used if {@code area} is {@code null}).
455     */
456    protected void addEntity(EntityCollection entities, Shape area,
457                             XYDataset dataset, int series, int item,
458                             double entityX, double entityY) {
459        if (!getItemCreateEntity(series, item)) {
460            return;
461        }
462        Shape hotspot = area;
463        if (hotspot == null) {
464            double r = getDefaultEntityRadius();
465            double w = r * 2;
466            if (getPlot().getOrientation() == PlotOrientation.VERTICAL) {
467                hotspot = new Ellipse2D.Double(entityX - r, entityY - r, w, w);
468            }
469            else {
470                hotspot = new Ellipse2D.Double(entityY - r, entityX - r, w, w);
471            }
472        }
473        String tip = null;
474        XYToolTipGenerator generator = getToolTipGenerator(series, item);
475        if (generator != null) {
476            tip = generator.generateToolTip(dataset, series, item);
477        }
478        String url = null;
479        if (getURLGenerator() != null) {
480            url = getURLGenerator().generateURL(dataset, series, item);
481        }
482        XYItemEntity entity = new XYItemEntity(hotspot, dataset, series, item,
483                tip, url);
484        entities.add(entity);
485    }
486
487    /**
488     * Plots the data for a given series.
489     *
490     * @param g2  the drawing surface.
491     * @param dataArea  the data area.
492     * @param info  collects plot rendering info.
493     * @param plot  the plot.
494     * @param dataset  the dataset.
495     * @param seriesIndex  the series index.
496     */
497    @Override
498    public void drawSeries(Graphics2D g2, Rectangle2D dataArea,
499            PlotRenderingInfo info, PolarPlot plot, XYDataset dataset,
500            int seriesIndex) {
501
502        final int numPoints = dataset.getItemCount(seriesIndex);
503        if (numPoints == 0) {
504            return;
505        }
506        GeneralPath poly = null;
507        ValueAxis axis = plot.getAxisForDataset(plot.indexOf(dataset));
508        for (int i = 0; i < numPoints; i++) {
509            double theta = dataset.getXValue(seriesIndex, i);
510            double radius = dataset.getYValue(seriesIndex, i);
511            Point p = plot.translateToJava2D(theta, radius, axis, dataArea);
512            if (poly == null) {
513                poly = new GeneralPath();
514                poly.moveTo(p.x, p.y);
515            }
516            else {
517                poly.lineTo(p.x, p.y);
518            }
519        }
520        assert poly != null;
521        if (getConnectFirstAndLastPoint()) {
522            poly.closePath();
523        }
524
525        g2.setPaint(lookupSeriesPaint(seriesIndex));
526        g2.setStroke(lookupSeriesStroke(seriesIndex));
527        if (isSeriesFilled(seriesIndex)) {
528            Composite savedComposite = g2.getComposite();
529            g2.setComposite(this.fillComposite);
530            g2.fill(poly);
531            g2.setComposite(savedComposite);
532            if (this.drawOutlineWhenFilled) {
533                // draw the outline of the filled polygon
534                g2.setPaint(lookupSeriesOutlinePaint(seriesIndex));
535                g2.draw(poly);
536            }
537        }
538        else {
539            // just the lines, no filling
540            g2.draw(poly);
541        }
542        
543        // draw the item shapes
544        if (this.shapesVisible) {
545            // setup for collecting optional entity info...
546            EntityCollection entities = null;
547            if (info != null) {
548                entities = info.getOwner().getEntityCollection();
549            }
550
551            PathIterator pi = poly.getPathIterator(null);
552            int i = 0;
553            while (!pi.isDone()) {
554                final float[] coords = new float[6];
555                final int segType = pi.currentSegment(coords);
556                pi.next();
557                if (segType != PathIterator.SEG_LINETO &&
558                        segType != PathIterator.SEG_MOVETO) {
559                    continue;
560                }
561                final int x = Math.round(coords[0]);
562                final int y = Math.round(coords[1]);
563                final Shape shape = ShapeUtils.createTranslatedShape(
564                        getItemShape(seriesIndex, i++), x,  y);
565
566                Paint paint;
567                if (useFillPaint) {
568                    paint = lookupSeriesFillPaint(seriesIndex);
569                }
570                else {
571                    paint = lookupSeriesPaint(seriesIndex);
572                }
573                g2.setPaint(paint);
574                g2.fill(shape);
575                if (isSeriesFilled(seriesIndex) && this.drawOutlineWhenFilled) {
576                    g2.setPaint(lookupSeriesOutlinePaint(seriesIndex));
577                    g2.setStroke(lookupSeriesOutlineStroke(seriesIndex));
578                    g2.draw(shape);
579                }
580
581                // add an entity for the item, but only if it falls within the
582                // data area...
583                if (entities != null && ShapeUtils.isPointInRect(dataArea, x, 
584                        y)) {
585                    addEntity(entities, shape, dataset, seriesIndex, i-1, x, y);
586                }
587            }
588        }
589    }
590
591    /**
592     * Draw the angular gridlines - the spokes.
593     *
594     * @param g2  the drawing surface.
595     * @param plot  the plot ({@code null} not permitted).
596     * @param ticks  the ticks ({@code null} not permitted).
597     * @param dataArea  the data area.
598     */
599    @Override
600    public void drawAngularGridLines(Graphics2D g2, PolarPlot plot,
601                List ticks, Rectangle2D dataArea) {
602
603        g2.setFont(plot.getAngleLabelFont());
604        g2.setStroke(plot.getAngleGridlineStroke());
605        g2.setPaint(plot.getAngleGridlinePaint());
606
607        ValueAxis axis = plot.getAxis();
608        double centerValue, outerValue;
609        if (axis.isInverted()) {
610            outerValue = axis.getLowerBound();
611            centerValue = axis.getUpperBound();
612        } else {
613            outerValue = axis.getUpperBound();
614            centerValue = axis.getLowerBound();
615        }
616        Point center = plot.translateToJava2D(0, centerValue, axis, dataArea);
617        Iterator iterator = ticks.iterator();
618        while (iterator.hasNext()) {
619            NumberTick tick = (NumberTick) iterator.next();
620            double tickVal = tick.getNumber().doubleValue();
621            Point p = plot.translateToJava2D(tickVal, outerValue, axis, 
622                    dataArea);
623            g2.setPaint(plot.getAngleGridlinePaint());
624            g2.drawLine(center.x, center.y, p.x, p.y);
625            if (plot.isAngleLabelsVisible()) {
626                int x = p.x;
627                int y = p.y;
628                g2.setPaint(plot.getAngleLabelPaint());
629                TextUtils.drawAlignedString(tick.getText(), g2, x, y,
630                        tick.getTextAnchor());
631            }
632        }
633    }
634
635    /**
636     * Draw the radial gridlines - the rings.
637     *
638     * @param g2  the drawing surface ({@code null} not permitted).
639     * @param plot  the plot ({@code null} not permitted).
640     * @param radialAxis  the radial axis ({@code null} not permitted).
641     * @param ticks  the ticks ({@code null} not permitted).
642     * @param dataArea  the data area.
643     */
644    @Override
645    public void drawRadialGridLines(Graphics2D g2, PolarPlot plot, 
646            ValueAxis radialAxis, List ticks, Rectangle2D dataArea) {
647
648        Args.nullNotPermitted(radialAxis, "radialAxis");
649        g2.setFont(radialAxis.getTickLabelFont());
650        g2.setPaint(plot.getRadiusGridlinePaint());
651        g2.setStroke(plot.getRadiusGridlineStroke());
652
653        double centerValue;
654        if (radialAxis.isInverted()) {
655            centerValue = radialAxis.getUpperBound();
656        } else {
657            centerValue = radialAxis.getLowerBound();
658        }
659        Point center = plot.translateToJava2D(0, centerValue, radialAxis, dataArea);
660
661        Iterator iterator = ticks.iterator();
662        while (iterator.hasNext()) {
663            NumberTick tick = (NumberTick) iterator.next();
664            double angleDegrees = plot.isCounterClockwise() 
665                    ? plot.getAngleOffset() : -plot.getAngleOffset();
666            Point p = plot.translateToJava2D(angleDegrees,
667                    tick.getNumber().doubleValue(), radialAxis, dataArea);
668            int r = p.x - center.x;
669            int upperLeftX = center.x - r;
670            int upperLeftY = center.y - r;
671            int d = 2 * r;
672            Ellipse2D ring = new Ellipse2D.Double(upperLeftX, upperLeftY, d, d);
673            g2.setPaint(plot.getRadiusGridlinePaint());
674            g2.draw(ring);
675        }
676    }
677
678    /**
679     * Return the legend for the given series.
680     *
681     * @param series  the series index.
682     *
683     * @return The legend item.
684     */
685    @Override
686    public LegendItem getLegendItem(int series) {
687        LegendItem result;
688        PolarPlot p = getPlot();
689        if (p == null) {
690            return null;
691        }
692        XYDataset dataset = p.getDataset(p.getIndexOf(this));
693        if (dataset == null) {
694            return null;
695        }
696        
697        String toolTipText = null;
698        if (getLegendItemToolTipGenerator() != null) {
699            toolTipText = getLegendItemToolTipGenerator().generateLabel(
700                    dataset, series);
701        }
702        String urlText = null;
703        if (getLegendItemURLGenerator() != null) {
704            urlText = getLegendItemURLGenerator().generateLabel(dataset,
705                    series);
706        }
707
708        Comparable seriesKey = dataset.getSeriesKey(series);
709        String label = seriesKey.toString();
710        String description = label;
711        Shape shape = lookupSeriesShape(series);
712        Paint paint;
713        if (this.useFillPaint) {
714            paint = lookupSeriesFillPaint(series);
715        }
716        else {
717            paint = lookupSeriesPaint(series);
718        }
719        Stroke stroke = lookupSeriesStroke(series);
720        Paint outlinePaint = lookupSeriesOutlinePaint(series);
721        Stroke outlineStroke = lookupSeriesOutlineStroke(series);
722        boolean shapeOutlined = isSeriesFilled(series)
723                && this.drawOutlineWhenFilled;
724        result = new LegendItem(label, description, toolTipText, urlText,
725                getShapesVisible(), shape, /* shapeFilled=*/ true, paint,
726                shapeOutlined, outlinePaint, outlineStroke, 
727                /* lineVisible= */ true, this.legendLine, stroke, paint);
728        result.setToolTipText(toolTipText);
729        result.setURLText(urlText);
730        result.setDataset(dataset);
731        result.setSeriesKey(seriesKey);
732        result.setSeriesIndex(series);
733
734        return result;
735    }
736
737    /**
738     * Returns the tooltip generator for the specified series and item.
739     * 
740     * @param series  the series index.
741     * @param item  the item index.
742     * 
743     * @return The tooltip generator (possibly {@code null}).
744     * 
745     * @since 1.0.14
746     */
747    @Override
748    public XYToolTipGenerator getToolTipGenerator(int series, int item) {
749        XYToolTipGenerator generator
750            = (XYToolTipGenerator) this.toolTipGeneratorList.get(series);
751        if (generator == null) {
752            generator = this.baseToolTipGenerator;
753        }
754        return generator;
755    }
756
757    /**
758     * Returns the tool tip generator for the specified series.
759     * 
760     * @return The tooltip generator (possibly {@code null}).
761     *
762     * @since 1.0.14
763     */
764    @Override
765    public XYToolTipGenerator getSeriesToolTipGenerator(int series) {
766        return (XYToolTipGenerator) this.toolTipGeneratorList.get(series);
767    }
768
769    /**
770     * Sets the tooltip generator for the specified series.
771     * 
772     * @param series  the series index.
773     * @param generator  the tool tip generator ({@code null} permitted).
774     * 
775     * @since 1.0.14
776     */
777    @Override
778    public void setSeriesToolTipGenerator(int series,
779            XYToolTipGenerator generator) {
780        this.toolTipGeneratorList.set(series, generator);
781        fireChangeEvent();
782    }
783
784    /**
785     * Returns the default tool tip generator.
786     * 
787     * @return The default tool tip generator (possibly {@code null}).
788     * 
789     * @since 1.0.14
790     */
791    @Override
792    public XYToolTipGenerator getBaseToolTipGenerator() {
793        return this.baseToolTipGenerator;
794    }
795
796    /**
797     * Sets the default tool tip generator and sends a 
798     * {@link RendererChangeEvent} to all registered listeners.
799     * 
800     * @param generator  the generator ({@code null} permitted).
801     * 
802     * @since 1.0.14
803     */
804    @Override
805    public void setBaseToolTipGenerator(XYToolTipGenerator generator) {
806        this.baseToolTipGenerator = generator;
807        fireChangeEvent();
808    }
809
810    /**
811     * Returns the URL generator.
812     * 
813     * @return The URL generator (possibly {@code null}).
814     * 
815     * @since 1.0.14
816     */
817    @Override
818    public XYURLGenerator getURLGenerator() {
819        return this.urlGenerator;
820    }
821
822    /**
823     * Sets the URL generator.
824     * 
825     * @param urlGenerator  the generator ({@code null} permitted)
826     * 
827     * @since 1.0.14
828     */
829    @Override
830    public void setURLGenerator(XYURLGenerator urlGenerator) {
831        this.urlGenerator = urlGenerator;
832        fireChangeEvent();
833    }
834
835    /**
836     * Returns the legend item tool tip generator.
837     *
838     * @return The tool tip generator (possibly {@code null}).
839     *
840     * @see #setLegendItemToolTipGenerator(XYSeriesLabelGenerator)
841     * @since 1.0.14
842     */
843    public XYSeriesLabelGenerator getLegendItemToolTipGenerator() {
844        return this.legendItemToolTipGenerator;
845    }
846
847    /**
848     * Sets the legend item tool tip generator and sends a
849     * {@link RendererChangeEvent} to all registered listeners.
850     *
851     * @param generator  the generator ({@code null} permitted).
852     *
853     * @see #getLegendItemToolTipGenerator()
854     * @since 1.0.14
855     */
856    public void setLegendItemToolTipGenerator(
857            XYSeriesLabelGenerator generator) {
858        this.legendItemToolTipGenerator = generator;
859        fireChangeEvent();
860    }
861
862    /**
863     * Returns the legend item URL generator.
864     *
865     * @return The URL generator (possibly {@code null}).
866     *
867     * @see #setLegendItemURLGenerator(XYSeriesLabelGenerator)
868     * @since 1.0.14
869     */
870    public XYSeriesLabelGenerator getLegendItemURLGenerator() {
871        return this.legendItemURLGenerator;
872    }
873
874    /**
875     * Sets the legend item URL generator and sends a
876     * {@link RendererChangeEvent} to all registered listeners.
877     *
878     * @param generator  the generator ({@code null} permitted).
879     *
880     * @see #getLegendItemURLGenerator()
881     * @since 1.0.14
882     */
883    public void setLegendItemURLGenerator(XYSeriesLabelGenerator generator) {
884        this.legendItemURLGenerator = generator;
885        fireChangeEvent();
886    }
887
888    /**
889     * Tests this renderer for equality with an arbitrary object.
890     *
891     * @param obj  the object ({@code null} not permitted).
892     *
893     * @return {@code true} if this renderer is equal to {@code obj},
894     *     and {@code false} otherwise.
895     */
896    @Override
897    public boolean equals(Object obj) {
898        if (obj == null) {
899            return false;
900        }
901        if (!(obj instanceof DefaultPolarItemRenderer)) {
902            return false;
903        }
904        DefaultPolarItemRenderer that = (DefaultPolarItemRenderer) obj;
905        if (!this.seriesFilled.equals(that.seriesFilled)) {
906            return false;
907        }
908        if (this.drawOutlineWhenFilled != that.drawOutlineWhenFilled) {
909            return false;
910        }
911        if (!ObjectUtils.equal(this.fillComposite, that.fillComposite)) {
912            return false;
913        }
914        if (this.useFillPaint != that.useFillPaint) {
915            return false;
916        }
917        if (!ShapeUtils.equal(this.legendLine, that.legendLine)) {
918            return false;
919        }
920        if (this.shapesVisible != that.shapesVisible) {
921            return false;
922        }
923        if (this.connectFirstAndLastPoint != that.connectFirstAndLastPoint) {
924            return false;
925        }
926        if (!this.toolTipGeneratorList.equals(that.toolTipGeneratorList)) {
927            return false;
928        }
929        if (!ObjectUtils.equal(this.baseToolTipGenerator,
930                that.baseToolTipGenerator)) {
931            return false;
932        }
933        if (!ObjectUtils.equal(this.urlGenerator, that.urlGenerator)) {
934            return false;
935        }
936        if (!ObjectUtils.equal(this.legendItemToolTipGenerator,
937                that.legendItemToolTipGenerator)) {
938            return false;
939        }
940        if (!ObjectUtils.equal(this.legendItemURLGenerator,
941                that.legendItemURLGenerator)) {
942            return false;
943        }
944        return super.equals(obj);
945    }
946
947    /**
948     * Returns a clone of the renderer.
949     *
950     * @return A clone.
951     *
952     * @throws CloneNotSupportedException if the renderer cannot be cloned.
953     */
954    @Override
955    public Object clone() throws CloneNotSupportedException {
956        DefaultPolarItemRenderer clone
957                = (DefaultPolarItemRenderer) super.clone();
958        if (this.legendLine != null) {
959            clone.legendLine = ShapeUtils.clone(this.legendLine);
960        }
961        clone.seriesFilled = (BooleanList) this.seriesFilled.clone();
962        clone.toolTipGeneratorList
963                = (ObjectList) this.toolTipGeneratorList.clone();
964        if (clone.baseToolTipGenerator instanceof PublicCloneable) {
965            clone.baseToolTipGenerator = (XYToolTipGenerator)
966                    ObjectUtils.clone(this.baseToolTipGenerator);
967        }
968        if (clone.urlGenerator instanceof PublicCloneable) {
969            clone.urlGenerator = (XYURLGenerator)
970                    ObjectUtils.clone(this.urlGenerator);
971        }
972        if (clone.legendItemToolTipGenerator instanceof PublicCloneable) {
973            clone.legendItemToolTipGenerator = (XYSeriesLabelGenerator)
974                    ObjectUtils.clone(this.legendItemToolTipGenerator);
975        }
976        if (clone.legendItemURLGenerator instanceof PublicCloneable) {
977            clone.legendItemURLGenerator = (XYSeriesLabelGenerator)
978                    ObjectUtils.clone(this.legendItemURLGenerator);
979        }
980        return clone;
981    }
982
983    /**
984     * Provides serialization support.
985     *
986     * @param stream  the input stream.
987     *
988     * @throws IOException  if there is an I/O error.
989     * @throws ClassNotFoundException  if there is a classpath problem.
990     */
991    private void readObject(ObjectInputStream stream)
992            throws IOException, ClassNotFoundException {
993        stream.defaultReadObject();
994        this.legendLine = SerialUtils.readShape(stream);
995        this.fillComposite = SerialUtils.readComposite(stream);
996    }
997
998    /**
999     * Provides serialization support.
1000     *
1001     * @param stream  the output stream.
1002     *
1003     * @throws IOException  if there is an I/O error.
1004     */
1005    private void writeObject(ObjectOutputStream stream) throws IOException {
1006        stream.defaultWriteObject();
1007        SerialUtils.writeShape(this.legendLine, stream);
1008        SerialUtils.writeComposite(this.fillComposite, stream);
1009    }
1010}