001/* ===========================================================
002 * JFreeChart : a free chart library for the Java(tm) platform
003 * ===========================================================
004 *
005 * (C) Copyright 2000-2017, by Object Refinery Limited and Contributors.
006 *
007 * Project Info:  http://www.jfree.org/jfreechart/index.html
008 *
009 * This library is free software; you can redistribute it and/or modify it
010 * under the terms of the GNU Lesser General Public License as published by
011 * the Free Software Foundation; either version 2.1 of the License, or
012 * (at your option) any later version.
013 *
014 * This library is distributed in the hope that it will be useful, but
015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017 * License for more details.
018 *
019 * You should have received a copy of the GNU Lesser General Public
020 * License along with this library; if not, write to the Free Software
021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
022 * USA.
023 *
024 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates.
025 * Other names may be trademarks of their respective owners.]
026 *
027 * ---------
028 * Plot.java
029 * ---------
030 * (C) Copyright 2000-2017, by Object Refinery Limited and Contributors.
031 *
032 * Original Author:  David Gilbert (for Object Refinery Limited);
033 * Contributor(s):   Sylvain Vieujot;
034 *                   Jeremy Bowman;
035 *                   Andreas Schneider;
036 *                   Gideon Krause;
037 *                   Nicolas Brodu;
038 *                   Michal Krause;
039 *                   Richard West, Advanced Micro Devices, Inc.;
040 *                   Peter Kolb - patches 2603321, 2809117;
041 *
042 * Changes
043 * -------
044 * 21-Jun-2001 : Removed redundant JFreeChart parameter from constructors (DG);
045 * 18-Sep-2001 : Updated header info and fixed DOS encoding problem (DG);
046 * 19-Oct-2001 : Moved series paint and stroke methods from JFreeChart
047 *               class (DG);
048 * 23-Oct-2001 : Created renderer for LinePlot class (DG);
049 * 07-Nov-2001 : Changed type names for ChartChangeEvent (DG);
050 *               Tidied up some Javadoc comments (DG);
051 * 13-Nov-2001 : Changes to allow for null axes on plots such as PiePlot (DG);
052 *               Added plot/axis compatibility checks (DG);
053 * 12-Dec-2001 : Changed constructors to protected, and removed unnecessary
054 *               'throws' clauses (DG);
055 * 13-Dec-2001 : Added tooltips (DG);
056 * 22-Jan-2002 : Added handleClick() method, as part of implementation for
057 *               crosshairs (DG);
058 *               Moved tooltips reference into ChartInfo class (DG);
059 * 23-Jan-2002 : Added test for null axes in chartChanged() method, thanks
060 *               to Barry Evans for the bug report (number 506979 on
061 *               SourceForge) (DG);
062 *               Added a zoom() method (DG);
063 * 05-Feb-2002 : Updated setBackgroundPaint(), setOutlineStroke() and
064 *               setOutlinePaint() to better handle null values, as suggested
065 *               by Sylvain Vieujot (DG);
066 * 06-Feb-2002 : Added background image, plus alpha transparency for background
067 *               and foreground (DG);
068 * 06-Mar-2002 : Added AxisConstants interface (DG);
069 * 26-Mar-2002 : Changed zoom method from empty to abstract (DG);
070 * 23-Apr-2002 : Moved dataset from JFreeChart class (DG);
071 * 11-May-2002 : Added ShapeFactory interface for getShape() methods,
072 *               contributed by Jeremy Bowman (DG);
073 * 28-May-2002 : Fixed bug in setSeriesPaint(int, Paint) for subplots (AS);
074 * 25-Jun-2002 : Removed redundant imports (DG);
075 * 30-Jul-2002 : Added 'no data' message for charts with null or empty
076 *               datasets (DG);
077 * 21-Aug-2002 : Added code to extend series array if necessary (refer to
078 *               SourceForge bug id 594547 for details) (DG);
079 * 17-Sep-2002 : Fixed bug in getSeriesOutlineStroke() method, reported by
080 *               Andreas Schroeder (DG);
081 * 23-Sep-2002 : Added getLegendItems() abstract method (DG);
082 * 24-Sep-2002 : Removed firstSeriesIndex, subplots now use their own paint
083 *               settings, there is a new mechanism for the legend to collect
084 *               the legend items (DG);
085 * 27-Sep-2002 : Added dataset group (DG);
086 * 14-Oct-2002 : Moved listener storage into EventListenerList.  Changed some
087 *               abstract methods to empty implementations (DG);
088 * 28-Oct-2002 : Added a getBackgroundImage() method (DG);
089 * 21-Nov-2002 : Added a plot index for identifying subplots in combined and
090 *               overlaid charts (DG);
091 * 22-Nov-2002 : Changed all attributes from 'protected' to 'private'.  Added
092 *               dataAreaRatio attribute from David M O'Donnell's code (DG);
093 * 09-Jan-2003 : Integrated fix for plot border contributed by Gideon
094 *               Krause (DG);
095 * 17-Jan-2003 : Moved to com.jrefinery.chart.plot (DG);
096 * 23-Jan-2003 : Removed one constructor (DG);
097 * 26-Mar-2003 : Implemented Serializable (DG);
098 * 14-Jul-2003 : Moved the dataset and secondaryDataset attributes to the
099 *               CategoryPlot and XYPlot classes (DG);
100 * 21-Jul-2003 : Moved DrawingSupplier from CategoryPlot and XYPlot up to this
101 *               class (DG);
102 * 20-Aug-2003 : Implemented Cloneable (DG);
103 * 11-Sep-2003 : Listeners and clone (NB);
104 * 29-Oct-2003 : Added workaround for font alignment in PDF output (DG);
105 * 03-Dec-2003 : Modified draw method to accept anchor (DG);
106 * 12-Mar-2004 : Fixed clipping bug in drawNoDataMessage() method (DG);
107 * 07-Apr-2004 : Modified string bounds calculation (DG);
108 * 04-Nov-2004 : Added default shapes for legend items (DG);
109 * 25-Nov-2004 : Some changes to the clone() method implementation (DG);
110 * 23-Feb-2005 : Implemented new LegendItemSource interface (and also
111 *               PublicCloneable) (DG);
112 * 21-Apr-2005 : Replaced Insets with RectangleInsets (DG);
113 * 05-May-2005 : Removed unused draw() method (DG);
114 * 06-Jun-2005 : Fixed bugs in equals() method (DG);
115 * 01-Sep-2005 : Moved dataAreaRatio from here to ContourPlot (DG);
116 * ------------- JFREECHART 1.0.x ---------------------------------------------
117 * 30-Jun-2006 : Added background image alpha - see bug report 1514904 (DG);
118 * 05-Sep-2006 : Implemented the MarkerChangeListener interface (DG);
119 * 11-Jan-2007 : Added some argument checks, event notifications, and many
120 *               API doc updates (DG);
121 * 03-Apr-2007 : Made drawBackgroundImage() public (DG);
122 * 07-Jun-2007 : Added new fillBackground() method to handle GradientPaint
123 *               taking into account orientation (DG);
124 * 25-Mar-2008 : Added fireChangeEvent() method - see patch 1914411 (DG);
125 * 15-Aug-2008 : Added setDrawingSupplier() method with notify flag (DG);
126 * 13-Jan-2009 : Added notify flag (DG);
127 * 19-Mar-2009 : Added entity support - see patch 2603321 by Peter Kolb (DG);
128 * 24-Jun-2009 : Implemented AnnotationChangeListener (see patch 2809117 by
129 *               PK) (DG);
130 * 13-Jul-2009 : Plot background image should be clipped if necessary (DG);
131 * 02-Jul-2013 : Use ParamChecks (DG);
132 * 29-Jul-2014 : Add hint to normalise stroke for plot border (DG);
133 * 
134 */
135
136package org.jfree.chart.plot;
137
138import java.awt.AlphaComposite;
139import java.awt.BasicStroke;
140import java.awt.Color;
141import java.awt.Composite;
142import java.awt.Font;
143import java.awt.GradientPaint;
144import java.awt.Graphics2D;
145import java.awt.Image;
146import java.awt.Paint;
147import java.awt.RenderingHints;
148import java.awt.Shape;
149import java.awt.Stroke;
150import java.awt.geom.Ellipse2D;
151import java.awt.geom.Point2D;
152import java.awt.geom.Rectangle2D;
153import java.io.IOException;
154import java.io.ObjectInputStream;
155import java.io.ObjectOutputStream;
156import java.io.Serializable;
157
158import javax.swing.event.EventListenerList;
159
160import org.jfree.chart.JFreeChart;
161import org.jfree.chart.LegendItemCollection;
162import org.jfree.chart.LegendItemSource;
163import org.jfree.chart.annotations.Annotation;
164import org.jfree.chart.axis.AxisLocation;
165import org.jfree.chart.entity.EntityCollection;
166import org.jfree.chart.entity.PlotEntity;
167import org.jfree.chart.event.AnnotationChangeEvent;
168import org.jfree.chart.event.AnnotationChangeListener;
169import org.jfree.chart.event.AxisChangeEvent;
170import org.jfree.chart.event.AxisChangeListener;
171import org.jfree.chart.event.ChartChangeEventType;
172import org.jfree.chart.event.MarkerChangeEvent;
173import org.jfree.chart.event.MarkerChangeListener;
174import org.jfree.chart.event.PlotChangeEvent;
175import org.jfree.chart.event.PlotChangeListener;
176import org.jfree.chart.text.G2TextMeasurer;
177import org.jfree.chart.text.TextBlock;
178import org.jfree.chart.text.TextBlockAnchor;
179import org.jfree.chart.text.TextUtils;
180import org.jfree.chart.ui.Align;
181import org.jfree.chart.ui.RectangleEdge;
182import org.jfree.chart.ui.RectangleInsets;
183import org.jfree.chart.util.ObjectUtils;
184import org.jfree.chart.util.PaintUtils;
185import org.jfree.chart.util.Args;
186import org.jfree.chart.util.PublicCloneable;
187import org.jfree.chart.util.SerialUtils;
188import org.jfree.data.general.DatasetChangeEvent;
189import org.jfree.data.general.DatasetChangeListener;
190import org.jfree.data.general.DatasetGroup;
191
192/**
193 * The base class for all plots in JFreeChart.  The {@link JFreeChart} class
194 * delegates the drawing of axes and data to the plot.  This base class
195 * provides facilities common to most plot types.
196 */
197public abstract class Plot implements AxisChangeListener,
198        DatasetChangeListener, AnnotationChangeListener, MarkerChangeListener,
199        LegendItemSource, PublicCloneable, Cloneable, Serializable {
200
201    /** For serialization. */
202    private static final long serialVersionUID = -8831571430103671324L;
203
204    /** Useful constant representing zero. */
205    public static final Number ZERO = 0;
206
207    /** The default insets. */
208    public static final RectangleInsets DEFAULT_INSETS
209            = new RectangleInsets(4.0, 8.0, 4.0, 8.0);
210
211    /** The default outline stroke. */
212    public static final Stroke DEFAULT_OUTLINE_STROKE = new BasicStroke(0.5f,
213            BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
214
215    /** The default outline color. */
216    public static final Paint DEFAULT_OUTLINE_PAINT = Color.GRAY;
217
218    /** The default foreground alpha transparency. */
219    public static final float DEFAULT_FOREGROUND_ALPHA = 1.0f;
220
221    /** The default background alpha transparency. */
222    public static final float DEFAULT_BACKGROUND_ALPHA = 1.0f;
223
224    /** The default background color. */
225    public static final Paint DEFAULT_BACKGROUND_PAINT = Color.WHITE;
226
227    /** The minimum width at which the plot should be drawn. */
228    public static final int MINIMUM_WIDTH_TO_DRAW = 10;
229
230    /** The minimum height at which the plot should be drawn. */
231    public static final int MINIMUM_HEIGHT_TO_DRAW = 10;
232
233    /** A default box shape for legend items. */
234    public static final Shape DEFAULT_LEGEND_ITEM_BOX
235            = new Rectangle2D.Double(-4.0, -4.0, 8.0, 8.0);
236
237    /** A default circle shape for legend items. */
238    public static final Shape DEFAULT_LEGEND_ITEM_CIRCLE
239            = new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0);
240
241    /** 
242     * The chart that the plot is assigned to.  It can be {@code null} if the
243     * plot is not assigned to a chart yet, or if the plot is a subplot of a
244     * another plot.
245     * 
246     * @since 1.0.20
247     */
248    private JFreeChart chart;
249    
250    /** The parent plot ({@code null} if this is the root plot). */
251    private Plot parent;
252
253    /** The dataset group (to be used for thread synchronisation). */
254    private DatasetGroup datasetGroup;
255
256    /** The message to display if no data is available. */
257    private String noDataMessage;
258
259    /** The font used to display the 'no data' message. */
260    private Font noDataMessageFont;
261
262    /** The paint used to draw the 'no data' message. */
263    private transient Paint noDataMessagePaint;
264
265    /** Amount of blank space around the plot area. */
266    private RectangleInsets insets;
267
268    /**
269     * A flag that controls whether or not the plot outline is drawn.
270     *
271     * @since 1.0.6
272     */
273    private boolean outlineVisible;
274
275    /** The Stroke used to draw an outline around the plot. */
276    private transient Stroke outlineStroke;
277
278    /** The Paint used to draw an outline around the plot. */
279    private transient Paint outlinePaint;
280
281    /** An optional color used to fill the plot background. */
282    private transient Paint backgroundPaint;
283
284    /** An optional image for the plot background. */
285    private transient Image backgroundImage;  // not currently serialized
286
287    /** The alignment for the background image. */
288    private int backgroundImageAlignment = Align.FIT;
289
290    /** The alpha value used to draw the background image. */
291    private float backgroundImageAlpha = 0.5f;
292
293    /** The alpha-transparency for the plot. */
294    private float foregroundAlpha;
295
296    /** The alpha transparency for the background paint. */
297    private float backgroundAlpha;
298
299    /** The drawing supplier. */
300    private DrawingSupplier drawingSupplier;
301
302    /** Storage for registered change listeners. */
303    private transient EventListenerList listenerList;
304
305    /**
306     * A flag that controls whether or not the plot will notify listeners
307     * of changes (defaults to true, but sometimes it is useful to disable
308     * this).
309     *
310     * @since 1.0.13
311     */
312    private boolean notify;
313
314    /**
315     * Creates a new plot.
316     */
317    protected Plot() {
318        this.chart = null;
319        this.parent = null;
320        this.insets = DEFAULT_INSETS;
321        this.backgroundPaint = DEFAULT_BACKGROUND_PAINT;
322        this.backgroundAlpha = DEFAULT_BACKGROUND_ALPHA;
323        this.backgroundImage = null;
324        this.outlineVisible = true;
325        this.outlineStroke = DEFAULT_OUTLINE_STROKE;
326        this.outlinePaint = DEFAULT_OUTLINE_PAINT;
327        this.foregroundAlpha = DEFAULT_FOREGROUND_ALPHA;
328
329        this.noDataMessage = null;
330        this.noDataMessageFont = new Font("SansSerif", Font.PLAIN, 12);
331        this.noDataMessagePaint = Color.BLACK;
332
333        this.drawingSupplier = new DefaultDrawingSupplier();
334
335        this.notify = true;
336        this.listenerList = new EventListenerList();
337    }
338    
339    /**
340     * Returns the chart that this plot is assigned to.  This method can
341     * return {@code null} if the plot is not yet assigned to a plot, or if the
342     * plot is a subplot of another plot.
343     * 
344     * @return The chart (possibly {@code null}).
345     * 
346     * @since 1.0.20
347     */
348    public JFreeChart getChart() {
349        return this.chart;
350    }
351    
352    /**
353     * Sets the chart that the plot is assigned to.  This method is not 
354     * intended for external use.
355     * 
356     * @param chart  the chart ({@code null} permitted).
357     * 
358     * @since 1.0.20
359     */
360    public void setChart(JFreeChart chart) {
361        this.chart = chart;
362    }
363    
364    /**
365     * Fetches the element hinting flag from the chart that this plot is 
366     * assigned to.  If the plot is not assigned (directly or indirectly) to
367     * a chart instance, this method will return {@code false}.
368     * 
369     * @return A boolean.
370     * 
371     * @since 1.0.20
372     */
373    public boolean fetchElementHintingFlag() {
374        if (this.parent != null) {
375            return this.parent.fetchElementHintingFlag();
376        }
377        if (this.chart != null) {
378            return this.chart.getElementHinting();
379        }
380        return false;
381    }
382
383    /**
384     * Returns the dataset group for the plot (not currently used).
385     *
386     * @return The dataset group.
387     *
388     * @see #setDatasetGroup(DatasetGroup)
389     */
390    public DatasetGroup getDatasetGroup() {
391        return this.datasetGroup;
392    }
393
394    /**
395     * Sets the dataset group (not currently used).
396     *
397     * @param group  the dataset group ({@code null} permitted).
398     *
399     * @see #getDatasetGroup()
400     */
401    protected void setDatasetGroup(DatasetGroup group) {
402        this.datasetGroup = group;
403    }
404
405    /**
406     * Returns the string that is displayed when the dataset is empty or
407     * {@code null}.
408     *
409     * @return The 'no data' message ({@code null} possible).
410     *
411     * @see #setNoDataMessage(String)
412     * @see #getNoDataMessageFont()
413     * @see #getNoDataMessagePaint()
414     */
415    public String getNoDataMessage() {
416        return this.noDataMessage;
417    }
418
419    /**
420     * Sets the message that is displayed when the dataset is empty or
421     * {@code null}, and sends a {@link PlotChangeEvent} to all registered
422     * listeners.
423     *
424     * @param message  the message ({@code null} permitted).
425     *
426     * @see #getNoDataMessage()
427     */
428    public void setNoDataMessage(String message) {
429        this.noDataMessage = message;
430        fireChangeEvent();
431    }
432
433    /**
434     * Returns the font used to display the 'no data' message.
435     *
436     * @return The font (never {@code null}).
437     *
438     * @see #setNoDataMessageFont(Font)
439     * @see #getNoDataMessage()
440     */
441    public Font getNoDataMessageFont() {
442        return this.noDataMessageFont;
443    }
444
445    /**
446     * Sets the font used to display the 'no data' message and sends a
447     * {@link PlotChangeEvent} to all registered listeners.
448     *
449     * @param font  the font ({@code null} not permitted).
450     *
451     * @see #getNoDataMessageFont()
452     */
453    public void setNoDataMessageFont(Font font) {
454        Args.nullNotPermitted(font, "font");
455        this.noDataMessageFont = font;
456        fireChangeEvent();
457    }
458
459    /**
460     * Returns the paint used to display the 'no data' message.
461     *
462     * @return The paint (never {@code null}).
463     *
464     * @see #setNoDataMessagePaint(Paint)
465     * @see #getNoDataMessage()
466     */
467    public Paint getNoDataMessagePaint() {
468        return this.noDataMessagePaint;
469    }
470
471    /**
472     * Sets the paint used to display the 'no data' message and sends a
473     * {@link PlotChangeEvent} to all registered listeners.
474     *
475     * @param paint  the paint ({@code null} not permitted).
476     *
477     * @see #getNoDataMessagePaint()
478     */
479    public void setNoDataMessagePaint(Paint paint) {
480        Args.nullNotPermitted(paint, "paint");
481        this.noDataMessagePaint = paint;
482        fireChangeEvent();
483    }
484
485    /**
486     * Returns a short string describing the plot type.
487     * <P>
488     * Note: this gets used in the chart property editing user interface,
489     * but there needs to be a better mechanism for identifying the plot type.
490     *
491     * @return A short string describing the plot type (never
492     *     {@code null}).
493     */
494    public abstract String getPlotType();
495
496    /**
497     * Returns the parent plot (or {@code null} if this plot is not part
498     * of a combined plot).
499     *
500     * @return The parent plot.
501     *
502     * @see #setParent(Plot)
503     * @see #getRootPlot()
504     */
505    public Plot getParent() {
506        return this.parent;
507    }
508
509    /**
510     * Sets the parent plot.  This method is intended for internal use, you
511     * shouldn't need to call it directly.
512     *
513     * @param parent  the parent plot ({@code null} permitted).
514     *
515     * @see #getParent()
516     */
517    public void setParent(Plot parent) {
518        this.parent = parent;
519    }
520
521    /**
522     * Returns the root plot.
523     *
524     * @return The root plot.
525     *
526     * @see #getParent()
527     */
528    public Plot getRootPlot() {
529
530        Plot p = getParent();
531        if (p == null) {
532            return this;
533        }
534        return p.getRootPlot();
535
536    }
537
538    /**
539     * Returns {@code true} if this plot is part of a combined plot
540     * structure (that is, {@link #getParent()} returns a non-{@code null}
541     * value), and {@code false} otherwise.
542     *
543     * @return {@code true} if this plot is part of a combined plot
544     *         structure.
545     *
546     * @see #getParent()
547     */
548    public boolean isSubplot() {
549        return (getParent() != null);
550    }
551
552    /**
553     * Returns the insets for the plot area.
554     *
555     * @return The insets (never {@code null}).
556     *
557     * @see #setInsets(RectangleInsets)
558     */
559    public RectangleInsets getInsets() {
560        return this.insets;
561    }
562
563    /**
564     * Sets the insets for the plot and sends a {@link PlotChangeEvent} to
565     * all registered listeners.
566     *
567     * @param insets  the new insets ({@code null} not permitted).
568     *
569     * @see #getInsets()
570     * @see #setInsets(RectangleInsets, boolean)
571     */
572    public void setInsets(RectangleInsets insets) {
573        setInsets(insets, true);
574    }
575
576    /**
577     * Sets the insets for the plot and, if requested,  and sends a
578     * {@link PlotChangeEvent} to all registered listeners.
579     *
580     * @param insets  the new insets ({@code null} not permitted).
581     * @param notify  a flag that controls whether the registered listeners are
582     *                notified.
583     *
584     * @see #getInsets()
585     * @see #setInsets(RectangleInsets)
586     */
587    public void setInsets(RectangleInsets insets, boolean notify) {
588        Args.nullNotPermitted(insets, "insets");
589        if (!this.insets.equals(insets)) {
590            this.insets = insets;
591            if (notify) {
592                fireChangeEvent();
593            }
594        }
595
596    }
597
598    /**
599     * Returns the background color of the plot area.
600     *
601     * @return The paint (possibly {@code null}).
602     *
603     * @see #setBackgroundPaint(Paint)
604     */
605    public Paint getBackgroundPaint() {
606        return this.backgroundPaint;
607    }
608
609    /**
610     * Sets the background color of the plot area and sends a
611     * {@link PlotChangeEvent} to all registered listeners.
612     *
613     * @param paint  the paint ({@code null} permitted).
614     *
615     * @see #getBackgroundPaint()
616     */
617    public void setBackgroundPaint(Paint paint) {
618
619        if (paint == null) {
620            if (this.backgroundPaint != null) {
621                this.backgroundPaint = null;
622                fireChangeEvent();
623            }
624        }
625        else {
626            if (this.backgroundPaint != null) {
627                if (this.backgroundPaint.equals(paint)) {
628                    return;  // nothing to do
629                }
630            }
631            this.backgroundPaint = paint;
632            fireChangeEvent();
633        }
634
635    }
636
637    /**
638     * Returns the alpha transparency of the plot area background.
639     *
640     * @return The alpha transparency.
641     *
642     * @see #setBackgroundAlpha(float)
643     */
644    public float getBackgroundAlpha() {
645        return this.backgroundAlpha;
646    }
647
648    /**
649     * Sets the alpha transparency of the plot area background, and notifies
650     * registered listeners that the plot has been modified.
651     *
652     * @param alpha the new alpha value (in the range 0.0f to 1.0f).
653     *
654     * @see #getBackgroundAlpha()
655     */
656    public void setBackgroundAlpha(float alpha) {
657        if (this.backgroundAlpha != alpha) {
658            this.backgroundAlpha = alpha;
659            fireChangeEvent();
660        }
661    }
662
663    /**
664     * Returns the drawing supplier for the plot.
665     *
666     * @return The drawing supplier (possibly {@code null}).
667     *
668     * @see #setDrawingSupplier(DrawingSupplier)
669     */
670    public DrawingSupplier getDrawingSupplier() {
671        DrawingSupplier result;
672        Plot p = getParent();
673        if (p != null) {
674            result = p.getDrawingSupplier();
675        }
676        else {
677            result = this.drawingSupplier;
678        }
679        return result;
680    }
681
682    /**
683     * Sets the drawing supplier for the plot and sends a
684     * {@link PlotChangeEvent} to all registered listeners.  The drawing
685     * supplier is responsible for supplying a limitless (possibly repeating)
686     * sequence of {@code Paint}, {@code Stroke} and
687     * {@code Shape} objects that the plot's renderer(s) can use to
688     * populate its (their) tables.
689     *
690     * @param supplier  the new supplier.
691     *
692     * @see #getDrawingSupplier()
693     */
694    public void setDrawingSupplier(DrawingSupplier supplier) {
695        this.drawingSupplier = supplier;
696        fireChangeEvent();
697    }
698
699    /**
700     * Sets the drawing supplier for the plot and, if requested, sends a
701     * {@link PlotChangeEvent} to all registered listeners.  The drawing
702     * supplier is responsible for supplying a limitless (possibly repeating)
703     * sequence of {@code Paint}, {@code Stroke} and
704     * {@code Shape} objects that the plot's renderer(s) can use to
705     * populate its (their) tables.
706     *
707     * @param supplier  the new supplier.
708     * @param notify  notify listeners?
709     *
710     * @see #getDrawingSupplier()
711     *
712     * @since 1.0.11
713     */
714    public void setDrawingSupplier(DrawingSupplier supplier, boolean notify) {
715        this.drawingSupplier = supplier;
716        if (notify) {
717            fireChangeEvent();
718        }
719    }
720
721    /**
722     * Returns the background image that is used to fill the plot's background
723     * area.
724     *
725     * @return The image (possibly {@code null}).
726     *
727     * @see #setBackgroundImage(Image)
728     */
729    public Image getBackgroundImage() {
730        return this.backgroundImage;
731    }
732
733    /**
734     * Sets the background image for the plot and sends a
735     * {@link PlotChangeEvent} to all registered listeners.
736     *
737     * @param image  the image ({@code null} permitted).
738     *
739     * @see #getBackgroundImage()
740     */
741    public void setBackgroundImage(Image image) {
742        this.backgroundImage = image;
743        fireChangeEvent();
744    }
745
746    /**
747     * Returns the background image alignment. Alignment constants are defined
748     * in the {@code Align} class.
749     *
750     * @return The alignment.
751     *
752     * @see #setBackgroundImageAlignment(int)
753     */
754    public int getBackgroundImageAlignment() {
755        return this.backgroundImageAlignment;
756    }
757
758    /**
759     * Sets the alignment for the background image and sends a
760     * {@link PlotChangeEvent} to all registered listeners.  Alignment options
761     * are defined by the {@link org.jfree.chart.ui.Align} class.
762     *
763     * @param alignment  the alignment.
764     *
765     * @see #getBackgroundImageAlignment()
766     */
767    public void setBackgroundImageAlignment(int alignment) {
768        if (this.backgroundImageAlignment != alignment) {
769            this.backgroundImageAlignment = alignment;
770            fireChangeEvent();
771        }
772    }
773
774    /**
775     * Returns the alpha transparency used to draw the background image.  This
776     * is a value in the range 0.0f to 1.0f, where 0.0f is fully transparent
777     * and 1.0f is fully opaque.
778     *
779     * @return The alpha transparency.
780     *
781     * @see #setBackgroundImageAlpha(float)
782     */
783    public float getBackgroundImageAlpha() {
784        return this.backgroundImageAlpha;
785    }
786
787    /**
788     * Sets the alpha transparency used when drawing the background image.
789     *
790     * @param alpha  the alpha transparency (in the range 0.0f to 1.0f, where
791     *     0.0f is fully transparent, and 1.0f is fully opaque).
792     *
793     * @throws IllegalArgumentException if {@code alpha} is not within
794     *     the specified range.
795     *
796     * @see #getBackgroundImageAlpha()
797     */
798    public void setBackgroundImageAlpha(float alpha) {
799        if (alpha < 0.0f || alpha > 1.0f) {
800            throw new IllegalArgumentException(
801                    "The 'alpha' value must be in the range 0.0f to 1.0f.");
802        }
803        if (this.backgroundImageAlpha != alpha) {
804            this.backgroundImageAlpha = alpha;
805            fireChangeEvent();
806        }
807    }
808
809    /**
810     * Returns the flag that controls whether or not the plot outline is
811     * drawn.  The default value is {@code true}.  Note that for
812     * historical reasons, the plot's outline paint and stroke can take on
813     * {@code null} values, in which case the outline will not be drawn
814     * even if this flag is set to {@code true}.
815     *
816     * @return The outline visibility flag.
817     *
818     * @since 1.0.6
819     *
820     * @see #setOutlineVisible(boolean)
821     */
822    public boolean isOutlineVisible() {
823        return this.outlineVisible;
824    }
825
826    /**
827     * Sets the flag that controls whether or not the plot's outline is
828     * drawn, and sends a {@link PlotChangeEvent} to all registered listeners.
829     *
830     * @param visible  the new flag value.
831     *
832     * @since 1.0.6
833     *
834     * @see #isOutlineVisible()
835     */
836    public void setOutlineVisible(boolean visible) {
837        this.outlineVisible = visible;
838        fireChangeEvent();
839    }
840
841    /**
842     * Returns the stroke used to outline the plot area.
843     *
844     * @return The stroke (possibly {@code null}).
845     *
846     * @see #setOutlineStroke(Stroke)
847     */
848    public Stroke getOutlineStroke() {
849        return this.outlineStroke;
850    }
851
852    /**
853     * Sets the stroke used to outline the plot area and sends a
854     * {@link PlotChangeEvent} to all registered listeners. If you set this
855     * attribute to {@code null}, no outline will be drawn.
856     *
857     * @param stroke  the stroke ({@code null} permitted).
858     *
859     * @see #getOutlineStroke()
860     */
861    public void setOutlineStroke(Stroke stroke) {
862        if (stroke == null) {
863            if (this.outlineStroke != null) {
864                this.outlineStroke = null;
865                fireChangeEvent();
866            }
867        }
868        else {
869            if (this.outlineStroke != null) {
870                if (this.outlineStroke.equals(stroke)) {
871                    return;  // nothing to do
872                }
873            }
874            this.outlineStroke = stroke;
875            fireChangeEvent();
876        }
877    }
878
879    /**
880     * Returns the color used to draw the outline of the plot area.
881     *
882     * @return The color (possibly {@code null}).
883     *
884     * @see #setOutlinePaint(Paint)
885     */
886    public Paint getOutlinePaint() {
887        return this.outlinePaint;
888    }
889
890    /**
891     * Sets the paint used to draw the outline of the plot area and sends a
892     * {@link PlotChangeEvent} to all registered listeners.  If you set this
893     * attribute to {@code null}, no outline will be drawn.
894     *
895     * @param paint  the paint ({@code null} permitted).
896     *
897     * @see #getOutlinePaint()
898     */
899    public void setOutlinePaint(Paint paint) {
900        if (paint == null) {
901            if (this.outlinePaint != null) {
902                this.outlinePaint = null;
903                fireChangeEvent();
904            }
905        }
906        else {
907            if (this.outlinePaint != null) {
908                if (this.outlinePaint.equals(paint)) {
909                    return;  // nothing to do
910                }
911            }
912            this.outlinePaint = paint;
913            fireChangeEvent();
914        }
915    }
916
917    /**
918     * Returns the alpha-transparency for the plot foreground.
919     *
920     * @return The alpha-transparency.
921     *
922     * @see #setForegroundAlpha(float)
923     */
924    public float getForegroundAlpha() {
925        return this.foregroundAlpha;
926    }
927
928    /**
929     * Sets the alpha-transparency for the plot and sends a
930     * {@link PlotChangeEvent} to all registered listeners.
931     *
932     * @param alpha  the new alpha transparency.
933     *
934     * @see #getForegroundAlpha()
935     */
936    public void setForegroundAlpha(float alpha) {
937        if (this.foregroundAlpha != alpha) {
938            this.foregroundAlpha = alpha;
939            fireChangeEvent();
940        }
941    }
942
943    /**
944     * Returns the legend items for the plot.  By default, this method returns
945     * {@code null}.  Subclasses should override to return a
946     * {@link LegendItemCollection}.
947     *
948     * @return The legend items for the plot (possibly {@code null}).
949     */
950    @Override
951    public LegendItemCollection getLegendItems() {
952        return null;
953    }
954
955    /**
956     * Returns a flag that controls whether or not change events are sent to
957     * registered listeners.
958     *
959     * @return A boolean.
960     *
961     * @see #setNotify(boolean)
962     *
963     * @since 1.0.13
964     */
965    public boolean isNotify() {
966        return this.notify;
967    }
968
969    /**
970     * Sets a flag that controls whether or not listeners receive
971     * {@link PlotChangeEvent} notifications.
972     *
973     * @param notify  a boolean.
974     *
975     * @see #isNotify()
976     *
977     * @since 1.0.13
978     */
979    public void setNotify(boolean notify) {
980        this.notify = notify;
981        // if the flag is being set to true, there may be queued up changes...
982        if (notify) {
983            notifyListeners(new PlotChangeEvent(this));
984        }
985    }
986
987    /**
988     * Registers an object for notification of changes to the plot.
989     *
990     * @param listener  the object to be registered.
991     *
992     * @see #removeChangeListener(PlotChangeListener)
993     */
994    public void addChangeListener(PlotChangeListener listener) {
995        this.listenerList.add(PlotChangeListener.class, listener);
996    }
997
998    /**
999     * Unregisters an object for notification of changes to the plot.
1000     *
1001     * @param listener  the object to be unregistered.
1002     *
1003     * @see #addChangeListener(PlotChangeListener)
1004     */
1005    public void removeChangeListener(PlotChangeListener listener) {
1006        this.listenerList.remove(PlotChangeListener.class, listener);
1007    }
1008
1009    /**
1010     * Notifies all registered listeners that the plot has been modified.
1011     *
1012     * @param event  information about the change event.
1013     */
1014    public void notifyListeners(PlotChangeEvent event) {
1015        // if the 'notify' flag has been switched to false, we don't notify
1016        // the listeners
1017        if (!this.notify) {
1018            return;
1019        }
1020        Object[] listeners = this.listenerList.getListenerList();
1021        for (int i = listeners.length - 2; i >= 0; i -= 2) {
1022            if (listeners[i] == PlotChangeListener.class) {
1023                ((PlotChangeListener) listeners[i + 1]).plotChanged(event);
1024            }
1025        }
1026    }
1027
1028    /**
1029     * Sends a {@link PlotChangeEvent} to all registered listeners.
1030     *
1031     * @since 1.0.10
1032     */
1033    protected void fireChangeEvent() {
1034        notifyListeners(new PlotChangeEvent(this));
1035    }
1036
1037    /**
1038     * Draws the plot within the specified area.  The anchor is a point on the
1039     * chart that is specified externally (for instance, it may be the last
1040     * point of the last mouse click performed by the user) - plots can use or
1041     * ignore this value as they see fit.
1042     * <br><br>
1043     * Subclasses need to provide an implementation of this method, obviously.
1044     *
1045     * @param g2  the graphics device.
1046     * @param area  the plot area.
1047     * @param anchor  the anchor point ({@code null} permitted).
1048     * @param parentState  the parent state (if any, {@code null} permitted).
1049     * @param info  carries back plot rendering info.
1050     */
1051    public abstract void draw(Graphics2D g2, Rectangle2D area, Point2D anchor,
1052            PlotState parentState, PlotRenderingInfo info);
1053
1054    /**
1055     * Draws the plot background (the background color and/or image).
1056     * <P>
1057     * This method will be called during the chart drawing process and is
1058     * declared public so that it can be accessed by the renderers used by
1059     * certain subclasses.  You shouldn't need to call this method directly.
1060     *
1061     * @param g2  the graphics device.
1062     * @param area  the area within which the plot should be drawn.
1063     */
1064    public void drawBackground(Graphics2D g2, Rectangle2D area) {
1065        // some subclasses override this method completely, so don't put
1066        // anything here that *must* be done
1067        fillBackground(g2, area);
1068        drawBackgroundImage(g2, area);
1069    }
1070
1071    /**
1072     * Fills the specified area with the background paint.
1073     *
1074     * @param g2  the graphics device.
1075     * @param area  the area.
1076     *
1077     * @see #getBackgroundPaint()
1078     * @see #getBackgroundAlpha()
1079     * @see #fillBackground(Graphics2D, Rectangle2D, PlotOrientation)
1080     */
1081    protected void fillBackground(Graphics2D g2, Rectangle2D area) {
1082        fillBackground(g2, area, PlotOrientation.VERTICAL);
1083    }
1084
1085    /**
1086     * Fills the specified area with the background paint.  If the background
1087     * paint is an instance of {@code GradientPaint}, the gradient will
1088     * run in the direction suggested by the plot's orientation.
1089     *
1090     * @param g2  the graphics target.
1091     * @param area  the plot area.
1092     * @param orientation  the plot orientation ({@code null} not
1093     *         permitted).
1094     *
1095     * @since 1.0.6
1096     */
1097    protected void fillBackground(Graphics2D g2, Rectangle2D area,
1098            PlotOrientation orientation) {
1099        Args.nullNotPermitted(orientation, "orientation");
1100        if (this.backgroundPaint == null) {
1101            return;
1102        }
1103        Paint p = this.backgroundPaint;
1104        if (p instanceof GradientPaint) {
1105            GradientPaint gp = (GradientPaint) p;
1106            if (orientation == PlotOrientation.VERTICAL) {
1107                p = new GradientPaint((float) area.getCenterX(),
1108                        (float) area.getMaxY(), gp.getColor1(),
1109                        (float) area.getCenterX(), (float) area.getMinY(),
1110                        gp.getColor2());
1111            }
1112            else if (orientation == PlotOrientation.HORIZONTAL) {
1113                p = new GradientPaint((float) area.getMinX(),
1114                        (float) area.getCenterY(), gp.getColor1(),
1115                        (float) area.getMaxX(), (float) area.getCenterY(),
1116                        gp.getColor2());
1117            }
1118        }
1119        Composite originalComposite = g2.getComposite();
1120        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
1121                this.backgroundAlpha));
1122        g2.setPaint(p);
1123        g2.fill(area);
1124        g2.setComposite(originalComposite);
1125    }
1126
1127    /**
1128     * Draws the background image (if there is one) aligned within the
1129     * specified area.
1130     *
1131     * @param g2  the graphics device.
1132     * @param area  the area.
1133     *
1134     * @see #getBackgroundImage()
1135     * @see #getBackgroundImageAlignment()
1136     * @see #getBackgroundImageAlpha()
1137     */
1138    public void drawBackgroundImage(Graphics2D g2, Rectangle2D area) {
1139        if (this.backgroundImage == null) {
1140            return;  // nothing to do
1141        }
1142        Composite savedComposite = g2.getComposite();
1143        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
1144                this.backgroundImageAlpha));
1145        Rectangle2D dest = new Rectangle2D.Double(0.0, 0.0,
1146                this.backgroundImage.getWidth(null),
1147                this.backgroundImage.getHeight(null));
1148        Align.align(dest, area, this.backgroundImageAlignment);
1149        Shape savedClip = g2.getClip();
1150        g2.clip(area);
1151        g2.drawImage(this.backgroundImage, (int) dest.getX(),
1152                (int) dest.getY(), (int) dest.getWidth() + 1,
1153                (int) dest.getHeight() + 1, null);
1154        g2.setClip(savedClip);
1155        g2.setComposite(savedComposite);
1156    }
1157
1158    /**
1159     * Draws the plot outline.  This method will be called during the chart
1160     * drawing process and is declared public so that it can be accessed by the
1161     * renderers used by certain subclasses. You shouldn't need to call this
1162     * method directly.
1163     *
1164     * @param g2  the graphics device.
1165     * @param area  the area within which the plot should be drawn.
1166     */
1167    public void drawOutline(Graphics2D g2, Rectangle2D area) {
1168        if (!this.outlineVisible) {
1169            return;
1170        }
1171        if ((this.outlineStroke != null) && (this.outlinePaint != null)) {
1172            g2.setStroke(this.outlineStroke);
1173            g2.setPaint(this.outlinePaint);
1174            Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
1175            g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
1176            g2.draw(area);
1177            g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, saved);
1178        }
1179    }
1180
1181    /**
1182     * Draws a message to state that there is no data to plot.
1183     *
1184     * @param g2  the graphics device.
1185     * @param area  the area within which the plot should be drawn.
1186     */
1187    protected void drawNoDataMessage(Graphics2D g2, Rectangle2D area) {
1188        Shape savedClip = g2.getClip();
1189        g2.clip(area);
1190        String message = this.noDataMessage;
1191        if (message != null) {
1192            g2.setFont(this.noDataMessageFont);
1193            g2.setPaint(this.noDataMessagePaint);
1194            TextBlock block = TextUtils.createTextBlock(
1195                    this.noDataMessage, this.noDataMessageFont,
1196                    this.noDataMessagePaint, 0.9f * (float) area.getWidth(),
1197                    new G2TextMeasurer(g2));
1198            block.draw(g2, (float) area.getCenterX(),
1199                    (float) area.getCenterY(), TextBlockAnchor.CENTER);
1200        }
1201        g2.setClip(savedClip);
1202    }
1203
1204    /**
1205     * Creates a plot entity that contains a reference to the plot and the
1206     * data area as shape.
1207     *
1208     * @param dataArea  the data area used as hot spot for the entity.
1209     * @param plotState  the plot rendering info containing a reference to the
1210     *     EntityCollection.
1211     * @param toolTip  the tool tip (defined in the respective Plot
1212     *     subclass) ({@code null} permitted).
1213     * @param urlText  the url (defined in the respective Plot subclass)
1214     *     ({@code null} permitted).
1215     *
1216     *  @since 1.0.13
1217     */
1218    protected void createAndAddEntity(Rectangle2D dataArea,
1219            PlotRenderingInfo plotState, String toolTip, String urlText) {
1220        if (plotState != null && plotState.getOwner() != null) {
1221            EntityCollection e = plotState.getOwner().getEntityCollection();
1222            if (e != null) {
1223                e.add(new PlotEntity(dataArea, this, toolTip, urlText));
1224            }
1225        }
1226    }
1227
1228    /**
1229     * Handles a 'click' on the plot.  Since the plot does not maintain any
1230     * information about where it has been drawn, the plot rendering info is
1231     * supplied as an argument so that the plot dimensions can be determined.
1232     *
1233     * @param x  the x coordinate (in Java2D space).
1234     * @param y  the y coordinate (in Java2D space).
1235     * @param info  an object containing information about the dimensions of
1236     *              the plot.
1237     */
1238    public void handleClick(int x, int y, PlotRenderingInfo info) {
1239        // provides a 'no action' default
1240    }
1241
1242    /**
1243     * Performs a zoom on the plot.  Subclasses should override if zooming is
1244     * appropriate for the type of plot.
1245     *
1246     * @param percent  the zoom percentage.
1247     */
1248    public void zoom(double percent) {
1249        // do nothing by default.
1250    }
1251
1252    /**
1253     * Receives notification of a change to an {@link Annotation} added to
1254     * this plot.
1255     *
1256     * @param event  information about the event (not used here).
1257     *
1258     * @since 1.0.14
1259     */
1260    @Override
1261    public void annotationChanged(AnnotationChangeEvent event) {
1262        fireChangeEvent();
1263    }
1264
1265    /**
1266     * Receives notification of a change to one of the plot's axes.
1267     *
1268     * @param event  information about the event (not used here).
1269     */
1270    @Override
1271    public void axisChanged(AxisChangeEvent event) {
1272        fireChangeEvent();
1273    }
1274
1275    /**
1276     * Receives notification of a change to the plot's dataset.
1277     * <P>
1278     * The plot reacts by passing on a plot change event to all registered
1279     * listeners.
1280     *
1281     * @param event  information about the event (not used here).
1282     */
1283    @Override
1284    public void datasetChanged(DatasetChangeEvent event) {
1285        PlotChangeEvent newEvent = new PlotChangeEvent(this);
1286        newEvent.setType(ChartChangeEventType.DATASET_UPDATED);
1287        notifyListeners(newEvent);
1288    }
1289
1290    /**
1291     * Receives notification of a change to a marker that is assigned to the
1292     * plot.
1293     *
1294     * @param event  the event.
1295     *
1296     * @since 1.0.3
1297     */
1298    @Override
1299    public void markerChanged(MarkerChangeEvent event) {
1300        fireChangeEvent();
1301    }
1302
1303    /**
1304     * Adjusts the supplied x-value.
1305     *
1306     * @param x  the x-value.
1307     * @param w1  width 1.
1308     * @param w2  width 2.
1309     * @param edge  the edge (left or right).
1310     *
1311     * @return The adjusted x-value.
1312     */
1313    protected double getRectX(double x, double w1, double w2,
1314                              RectangleEdge edge) {
1315
1316        double result = x;
1317        if (edge == RectangleEdge.LEFT) {
1318            result = result + w1;
1319        }
1320        else if (edge == RectangleEdge.RIGHT) {
1321            result = result + w2;
1322        }
1323        return result;
1324
1325    }
1326
1327    /**
1328     * Adjusts the supplied y-value.
1329     *
1330     * @param y  the x-value.
1331     * @param h1  height 1.
1332     * @param h2  height 2.
1333     * @param edge  the edge (top or bottom).
1334     *
1335     * @return The adjusted y-value.
1336     */
1337    protected double getRectY(double y, double h1, double h2,
1338                              RectangleEdge edge) {
1339
1340        double result = y;
1341        if (edge == RectangleEdge.TOP) {
1342            result = result + h1;
1343        }
1344        else if (edge == RectangleEdge.BOTTOM) {
1345            result = result + h2;
1346        }
1347        return result;
1348
1349    }
1350
1351    /**
1352     * Tests this plot for equality with another object.
1353     *
1354     * @param obj  the object ({@code null} permitted).
1355     *
1356     * @return {@code true} or {@code false}.
1357     */
1358    @Override
1359    public boolean equals(Object obj) {
1360        if (obj == this) {
1361            return true;
1362        }
1363        if (!(obj instanceof Plot)) {
1364            return false;
1365        }
1366        Plot that = (Plot) obj;
1367        if (!ObjectUtils.equal(this.noDataMessage, that.noDataMessage)) {
1368            return false;
1369        }
1370        if (!ObjectUtils.equal(
1371            this.noDataMessageFont, that.noDataMessageFont
1372        )) {
1373            return false;
1374        }
1375        if (!PaintUtils.equal(this.noDataMessagePaint,
1376                that.noDataMessagePaint)) {
1377            return false;
1378        }
1379        if (!ObjectUtils.equal(this.insets, that.insets)) {
1380            return false;
1381        }
1382        if (this.outlineVisible != that.outlineVisible) {
1383            return false;
1384        }
1385        if (!ObjectUtils.equal(this.outlineStroke, that.outlineStroke)) {
1386            return false;
1387        }
1388        if (!PaintUtils.equal(this.outlinePaint, that.outlinePaint)) {
1389            return false;
1390        }
1391        if (!PaintUtils.equal(this.backgroundPaint, that.backgroundPaint)) {
1392            return false;
1393        }
1394        if (!ObjectUtils.equal(this.backgroundImage,
1395                that.backgroundImage)) {
1396            return false;
1397        }
1398        if (this.backgroundImageAlignment != that.backgroundImageAlignment) {
1399            return false;
1400        }
1401        if (this.backgroundImageAlpha != that.backgroundImageAlpha) {
1402            return false;
1403        }
1404        if (this.foregroundAlpha != that.foregroundAlpha) {
1405            return false;
1406        }
1407        if (this.backgroundAlpha != that.backgroundAlpha) {
1408            return false;
1409        }
1410        if (!this.drawingSupplier.equals(that.drawingSupplier)) {
1411            return false;
1412        }
1413        if (this.notify != that.notify) {
1414            return false;
1415        }
1416        return true;
1417    }
1418
1419    /**
1420     * Creates a clone of the plot.
1421     *
1422     * @return A clone.
1423     *
1424     * @throws CloneNotSupportedException if some component of the plot does not
1425     *         support cloning.
1426     */
1427    @Override
1428    public Object clone() throws CloneNotSupportedException {
1429
1430        Plot clone = (Plot) super.clone();
1431        // private Plot parent <-- don't clone the parent plot, but take care
1432        // childs in combined plots instead
1433        if (this.datasetGroup != null) {
1434            clone.datasetGroup
1435                = (DatasetGroup) ObjectUtils.clone(this.datasetGroup);
1436        }
1437        clone.drawingSupplier
1438            = (DrawingSupplier) ObjectUtils.clone(this.drawingSupplier);
1439        clone.listenerList = new EventListenerList();
1440        return clone;
1441
1442    }
1443
1444    /**
1445     * Provides serialization support.
1446     *
1447     * @param stream  the output stream.
1448     *
1449     * @throws IOException  if there is an I/O error.
1450     */
1451    private void writeObject(ObjectOutputStream stream) throws IOException {
1452        stream.defaultWriteObject();
1453        SerialUtils.writePaint(this.noDataMessagePaint, stream);
1454        SerialUtils.writeStroke(this.outlineStroke, stream);
1455        SerialUtils.writePaint(this.outlinePaint, stream);
1456        // backgroundImage
1457        SerialUtils.writePaint(this.backgroundPaint, stream);
1458    }
1459
1460    /**
1461     * Provides serialization support.
1462     *
1463     * @param stream  the input stream.
1464     *
1465     * @throws IOException  if there is an I/O error.
1466     * @throws ClassNotFoundException  if there is a classpath problem.
1467     */
1468    private void readObject(ObjectInputStream stream)
1469        throws IOException, ClassNotFoundException {
1470        stream.defaultReadObject();
1471        this.noDataMessagePaint = SerialUtils.readPaint(stream);
1472        this.outlineStroke = SerialUtils.readStroke(stream);
1473        this.outlinePaint = SerialUtils.readPaint(stream);
1474        // backgroundImage
1475        this.backgroundPaint = SerialUtils.readPaint(stream);
1476
1477        this.listenerList = new EventListenerList();
1478
1479    }
1480
1481    /**
1482     * Resolves a domain axis location for a given plot orientation.
1483     *
1484     * @param location  the location ({@code null} not permitted).
1485     * @param orientation  the orientation ({@code null} not permitted).
1486     *
1487     * @return The edge (never {@code null}).
1488     */
1489    public static RectangleEdge resolveDomainAxisLocation(
1490            AxisLocation location, PlotOrientation orientation) {
1491
1492        Args.nullNotPermitted(location, "location");
1493        Args.nullNotPermitted(orientation, "orientation");
1494
1495        RectangleEdge result = null;
1496        if (location == AxisLocation.TOP_OR_RIGHT) {
1497            if (orientation == PlotOrientation.HORIZONTAL) {
1498                result = RectangleEdge.RIGHT;
1499            }
1500            else if (orientation == PlotOrientation.VERTICAL) {
1501                result = RectangleEdge.TOP;
1502            }
1503        }
1504        else if (location == AxisLocation.TOP_OR_LEFT) {
1505            if (orientation == PlotOrientation.HORIZONTAL) {
1506                result = RectangleEdge.LEFT;
1507            }
1508            else if (orientation == PlotOrientation.VERTICAL) {
1509                result = RectangleEdge.TOP;
1510            }
1511        }
1512        else if (location == AxisLocation.BOTTOM_OR_RIGHT) {
1513            if (orientation == PlotOrientation.HORIZONTAL) {
1514                result = RectangleEdge.RIGHT;
1515            }
1516            else if (orientation == PlotOrientation.VERTICAL) {
1517                result = RectangleEdge.BOTTOM;
1518            }
1519        }
1520        else if (location == AxisLocation.BOTTOM_OR_LEFT) {
1521            if (orientation == PlotOrientation.HORIZONTAL) {
1522                result = RectangleEdge.LEFT;
1523            }
1524            else if (orientation == PlotOrientation.VERTICAL) {
1525                result = RectangleEdge.BOTTOM;
1526            }
1527        }
1528        // the above should cover all the options...
1529        if (result == null) {
1530            throw new IllegalStateException("resolveDomainAxisLocation()");
1531        }
1532        return result;
1533
1534    }
1535
1536    /**
1537     * Resolves a range axis location for a given plot orientation.
1538     *
1539     * @param location  the location ({@code null} not permitted).
1540     * @param orientation  the orientation ({@code null} not permitted).
1541     *
1542     * @return The edge (never {@code null}).
1543     */
1544    public static RectangleEdge resolveRangeAxisLocation(
1545            AxisLocation location, PlotOrientation orientation) {
1546
1547        Args.nullNotPermitted(location, "location");
1548        Args.nullNotPermitted(orientation, "orientation");
1549
1550        RectangleEdge result = null;
1551        if (location == AxisLocation.TOP_OR_RIGHT) {
1552            if (orientation == PlotOrientation.HORIZONTAL) {
1553                result = RectangleEdge.TOP;
1554            }
1555            else if (orientation == PlotOrientation.VERTICAL) {
1556                result = RectangleEdge.RIGHT;
1557            }
1558        }
1559        else if (location == AxisLocation.TOP_OR_LEFT) {
1560            if (orientation == PlotOrientation.HORIZONTAL) {
1561                result = RectangleEdge.TOP;
1562            }
1563            else if (orientation == PlotOrientation.VERTICAL) {
1564                result = RectangleEdge.LEFT;
1565            }
1566        }
1567        else if (location == AxisLocation.BOTTOM_OR_RIGHT) {
1568            if (orientation == PlotOrientation.HORIZONTAL) {
1569                result = RectangleEdge.BOTTOM;
1570            }
1571            else if (orientation == PlotOrientation.VERTICAL) {
1572                result = RectangleEdge.RIGHT;
1573            }
1574        }
1575        else if (location == AxisLocation.BOTTOM_OR_LEFT) {
1576            if (orientation == PlotOrientation.HORIZONTAL) {
1577                result = RectangleEdge.BOTTOM;
1578            }
1579            else if (orientation == PlotOrientation.VERTICAL) {
1580                result = RectangleEdge.LEFT;
1581            }
1582        }
1583
1584        // the above should cover all the options...
1585        if (result == null) {
1586            throw new IllegalStateException("resolveRangeAxisLocation()");
1587        }
1588        return result;
1589
1590    }
1591
1592}