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