KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > ChartPanel


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jfreechart/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this library; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
24  * in the United States and other countries.]
25  *
26  * ---------------
27  * ChartPanel.java
28  * ---------------
29  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
30  *
31  * Original Author: David Gilbert (for Object Refinery Limited);
32  * Contributor(s): Andrzej Porebski;
33  * S???ren Caspersen;
34  * Jonathan Nash;
35  * Hans-Jurgen Greiner;
36  * Andreas Schneider;
37  * Daniel van Enckevort;
38  * David M O'Donnell;
39  * Arnaud Lelievre;
40  * Matthias Rose;
41  * Onno vd Akker;
42  *
43  * $Id: ChartPanel.java,v 1.20 2005/06/02 08:36:23 mungady Exp $
44  *
45  * Changes (from 28-Jun-2001)
46  * --------------------------
47  * 28-Jun-2001 : Integrated buffering code contributed by S???ren
48  * Caspersen (DG);
49  * 18-Sep-2001 : Updated header and fixed DOS encoding problem (DG);
50  * 22-Nov-2001 : Added scaling to improve display of charts in small sizes (DG);
51  * 26-Nov-2001 : Added property editing, saving and printing (DG);
52  * 11-Dec-2001 : Transferred saveChartAsPNG method to new ChartUtilities
53  * class (DG);
54  * 13-Dec-2001 : Added tooltips (DG);
55  * 16-Jan-2002 : Added an optional crosshair, based on the implementation by
56  * Jonathan Nash. Renamed the tooltips class (DG);
57  * 23-Jan-2002 : Implemented zooming based on code by Hans-Jurgen Greiner (DG);
58  * 05-Feb-2002 : Improved tooltips setup. Renamed method attemptSaveAs()
59  * --> doSaveAs() and made it public rather than private (DG);
60  * 28-Mar-2002 : Added a new constructor (DG);
61  * 09-Apr-2002 : Changed initialisation of tooltip generation, as suggested by
62  * Hans-Jurgen Greiner (DG);
63  * 27-May-2002 : New interactive zooming methods based on code by Hans-Jurgen
64  * Greiner. Renamed JFreeChartPanel --> ChartPanel, moved
65  * constants to ChartPanelConstants interface (DG);
66  * 31-May-2002 : Fixed a bug with interactive zooming and added a way to
67  * control if the zoom rectangle is filled in or drawn as an
68  * outline. A mouse drag gesture towards the top left now causes
69  * an autoRangeBoth() and is a way to undo zooms (AS);
70  * 11-Jun-2002 : Reinstated handleClick method call in mouseClicked() to get
71  * crosshairs working again (DG);
72  * 13-Jun-2002 : Added check for null popup menu in mouseDragged method (DG);
73  * 18-Jun-2002 : Added get/set methods for minimum and maximum chart
74  * dimensions (DG);
75  * 25-Jun-2002 : Removed redundant code (DG);
76  * 27-Aug-2002 : Added get/set methods for popup menu (DG);
77  * 26-Sep-2002 : Fixed errors reported by Checkstyle (DG);
78  * 22-Oct-2002 : Added translation methods for screen <--> Java2D, contributed
79  * by Daniel van Enckevort (DG);
80  * 05-Nov-2002 : Added a chart reference to the ChartMouseEvent class (DG);
81  * 22-Nov-2002 : Added test in zoom method for inverted axes, supplied by
82  * David M O'Donnell (DG);
83  * 14-Jan-2003 : Implemented ChartProgressListener interface (DG);
84  * 14-Feb-2003 : Removed deprecated setGenerateTooltips method (DG);
85  * 12-Mar-2003 : Added option to enforce filename extension (see bug id
86  * 643173) (DG);
87  * 08-Sep-2003 : Added internationalization via use of properties
88  * resourceBundle (RFE 690236) (AL);
89  * 18-Sep-2003 : Added getScaleX() and getScaleY() methods (protected) as
90  * requested by Irv Thomae (DG);
91  * 12-Nov-2003 : Added zooming support for the FastScatterPlot class (DG);
92  * 24-Nov-2003 : Minor Javadoc updates (DG);
93  * 04-Dec-2003 : Added anchor point for crosshair calculation (DG);
94  * 17-Jan-2004 : Added new methods to set tooltip delays to be used in this
95  * chart panel. Refer to patch 877565 (MR);
96  * 02-Feb-2004 : Fixed bug in zooming trigger and added zoomTriggerDistance
97  * attribute (DG);
98  * 08-Apr-2004 : Changed getScaleX() and getScaleY() from protected to
99  * public (DG);
100  * 15-Apr-2004 : Added zoomOutFactor and zoomInFactor (DG);
101  * 21-Apr-2004 : Fixed zooming bug in mouseReleased() method (DG);
102  * 13-Jul-2004 : Added check for null chart (DG);
103  * 04-Oct-2004 : Renamed ShapeUtils --> ShapeUtilities (DG);
104  * 11-Nov-2004 : Moved constants back in from ChartPanelConstants (DG);
105  * 12-Nov-2004 : Modified zooming mechanism to support zooming within
106  * subplots (DG);
107  * 26-Jan-2005 : Fixed mouse zooming for horizontal category plots (DG);
108  * 11-Apr-2005 : Added getFillZoomRectangle() method, renamed
109  * setHorizontalZoom() --> setDomainZoomable(),
110  * setVerticalZoom() --> setRangeZoomable(), added
111  * isDomainZoomable() and isRangeZoomable(), added
112  * getHorizontalAxisTrace() and getVerticalAxisTrace(),
113  * renamed autoRangeBoth() --> restoreAutoBounds(),
114  * autoRangeHorizontal() --> restoreAutoDomainBounds(),
115  * autoRangeVertical() --> restoreAutoRangeBounds() (DG);
116  * 12-Apr-2005 : Removed working areas, added getAnchorPoint() method,
117  * added protected accessors for tracelines (DG);
118  * 18-Apr-2005 : Made constants final (DG);
119  * 26-Apr-2005 : Removed LOGGER (DG);
120  * 01-Jun-2005 : Fixed zooming for combined plots - see bug report
121  * 1212039, fix thanks to Onno vd Akker (DG);
122  */

123
124 package org.jfree.chart;
125
126 import java.awt.AWTEvent JavaDoc;
127 import java.awt.Dimension JavaDoc;
128 import java.awt.Graphics JavaDoc;
129 import java.awt.Graphics2D JavaDoc;
130 import java.awt.Image JavaDoc;
131 import java.awt.Insets JavaDoc;
132 import java.awt.Point JavaDoc;
133 import java.awt.event.ActionEvent JavaDoc;
134 import java.awt.event.ActionListener JavaDoc;
135 import java.awt.event.MouseEvent JavaDoc;
136 import java.awt.event.MouseListener JavaDoc;
137 import java.awt.event.MouseMotionListener JavaDoc;
138 import java.awt.geom.AffineTransform JavaDoc;
139 import java.awt.geom.Line2D JavaDoc;
140 import java.awt.geom.Point2D JavaDoc;
141 import java.awt.geom.Rectangle2D JavaDoc;
142 import java.awt.print.PageFormat JavaDoc;
143 import java.awt.print.Printable JavaDoc;
144 import java.awt.print.PrinterException JavaDoc;
145 import java.awt.print.PrinterJob JavaDoc;
146 import java.io.File JavaDoc;
147 import java.io.IOException JavaDoc;
148 import java.io.Serializable JavaDoc;
149 import java.util.Iterator JavaDoc;
150 import java.util.List JavaDoc;
151 import java.util.ResourceBundle JavaDoc;
152
153 import javax.swing.JFileChooser JavaDoc;
154 import javax.swing.JMenu JavaDoc;
155 import javax.swing.JMenuItem JavaDoc;
156 import javax.swing.JOptionPane JavaDoc;
157 import javax.swing.JPanel JavaDoc;
158 import javax.swing.JPopupMenu JavaDoc;
159 import javax.swing.ToolTipManager JavaDoc;
160
161 import org.jfree.chart.entity.ChartEntity;
162 import org.jfree.chart.entity.EntityCollection;
163 import org.jfree.chart.event.ChartChangeEvent;
164 import org.jfree.chart.event.ChartChangeListener;
165 import org.jfree.chart.event.ChartProgressEvent;
166 import org.jfree.chart.event.ChartProgressListener;
167 import org.jfree.chart.plot.Plot;
168 import org.jfree.chart.plot.PlotOrientation;
169 import org.jfree.chart.plot.PlotRenderingInfo;
170 import org.jfree.chart.plot.ValueAxisPlot;
171 import org.jfree.chart.plot.Zoomable;
172 import org.jfree.chart.ui.ChartPropertyEditPanel;
173 import org.jfree.ui.ExtensionFileFilter;
174
175 /**
176  * A Swing GUI component for displaying a {@link JFreeChart} object.
177  * <P>
178  * The panel registers with the chart to receive notification of changes to any
179  * component of the chart. The chart is redrawn automatically whenever this
180  * notification is received.
181  */

182 public class ChartPanel extends JPanel JavaDoc
183                         implements ChartChangeListener,
184                                    ChartProgressListener,
185                                    ActionListener JavaDoc,
186                                    MouseListener JavaDoc,
187                                    MouseMotionListener JavaDoc,
188                                    Printable JavaDoc,
189                                    Serializable JavaDoc {
190
191     /** For serialization. */
192     private static final long serialVersionUID = 6046366297214274674L;
193     
194     /** Default setting for buffer usage. */
195     public static final boolean DEFAULT_BUFFER_USED = false;
196
197     /** The default panel width. */
198     public static final int DEFAULT_WIDTH = 680;
199
200     /** The default panel height. */
201     public static final int DEFAULT_HEIGHT = 420;
202
203     /** The default limit below which chart scaling kicks in. */
204     public static final int DEFAULT_MINIMUM_DRAW_WIDTH = 300;
205
206     /** The default limit below which chart scaling kicks in. */
207     public static final int DEFAULT_MINIMUM_DRAW_HEIGHT = 200;
208
209     /** The default limit below which chart scaling kicks in. */
210     public static final int DEFAULT_MAXIMUM_DRAW_WIDTH = 800;
211
212     /** The default limit below which chart scaling kicks in. */
213     public static final int DEFAULT_MAXIMUM_DRAW_HEIGHT = 600;
214
215     /** The minimum size required to perform a zoom on a rectangle */
216     public static final int DEFAULT_ZOOM_TRIGGER_DISTANCE = 10;
217
218     /** Properties action command. */
219     public static final String JavaDoc PROPERTIES_COMMAND = "PROPERTIES";
220
221     /** Save action command. */
222     public static final String JavaDoc SAVE_COMMAND = "SAVE";
223
224     /** Print action command. */
225     public static final String JavaDoc PRINT_COMMAND = "PRINT";
226
227     /** Zoom in (both axes) action command. */
228     public static final String JavaDoc ZOOM_IN_BOTH_COMMAND = "ZOOM_IN_BOTH";
229
230     /** Zoom in (domain axis only) action command. */
231     public static final String JavaDoc ZOOM_IN_DOMAIN_COMMAND = "ZOOM_IN_DOMAIN";
232
233     /** Zoom in (range axis only) action command. */
234     public static final String JavaDoc ZOOM_IN_RANGE_COMMAND = "ZOOM_IN_RANGE";
235
236     /** Zoom out (both axes) action command. */
237     public static final String JavaDoc ZOOM_OUT_BOTH_COMMAND = "ZOOM_OUT_BOTH";
238
239     /** Zoom out (domain axis only) action command. */
240     public static final String JavaDoc ZOOM_OUT_DOMAIN_COMMAND = "ZOOM_DOMAIN_BOTH";
241
242     /** Zoom out (range axis only) action command. */
243     public static final String JavaDoc ZOOM_OUT_RANGE_COMMAND = "ZOOM_RANGE_BOTH";
244
245     /** Zoom reset (both axes) action command. */
246     public static final String JavaDoc ZOOM_RESET_BOTH_COMMAND = "ZOOM_RESET_BOTH";
247
248     /** Zoom reset (domain axis only) action command. */
249     public static final String JavaDoc ZOOM_RESET_DOMAIN_COMMAND = "ZOOM_RESET_DOMAIN";
250
251     /** Zoom reset (range axis only) action command. */
252     public static final String JavaDoc ZOOM_RESET_RANGE_COMMAND = "ZOOM_RESET_RANGE";
253
254     /** The chart that is displayed in the panel. */
255     private JFreeChart chart;
256
257     /** Storage for registered (chart) mouse listeners. */
258     private List JavaDoc chartMouseListeners;
259
260     /** A flag that controls whether or not the off-screen buffer is used. */
261     private boolean useBuffer;
262
263     /** A flag that indicates that the buffer should be refreshed. */
264     private boolean refreshBuffer;
265
266     /** A buffer for the rendered chart. */
267     private Image JavaDoc chartBuffer;
268
269     /** The height of the chart buffer. */
270     private int chartBufferHeight;
271
272     /** The width of the chart buffer. */
273     private int chartBufferWidth;
274
275     /**
276      * The minimum width for drawing a chart (uses scaling for smaller widths).
277      */

278     private int minimumDrawWidth;
279
280     /**
281      * The minimum height for drawing a chart (uses scaling for smaller
282      * heights).
283      */

284     private int minimumDrawHeight;
285
286     /**
287      * The maximum width for drawing a chart (uses scaling for bigger
288      * widths).
289      */

290     private int maximumDrawWidth;
291
292     /**
293      * The maximum height for drawing a chart (uses scaling for bigger
294      * heights).
295      */

296     private int maximumDrawHeight;
297
298     /** The popup menu for the frame. */
299     private JPopupMenu JavaDoc popup;
300
301     /** The drawing info collected the last time the chart was drawn. */
302     private ChartRenderingInfo info;
303     
304     /** The chart anchor point. */
305     private Point2D JavaDoc anchor;
306
307     /** The scale factor used to draw the chart. */
308     private double scaleX;
309
310     /** The scale factor used to draw the chart. */
311     private double scaleY;
312
313     /** The plot orientation. */
314     private PlotOrientation orientation = PlotOrientation.VERTICAL;
315     
316     /** A flag that controls whether or not domain zooming is enabled. */
317     private boolean domainZoomable = false;
318
319     /** A flag that controls whether or not range zooming is enabled. */
320     private boolean rangeZoomable = false;
321
322     /**
323      * The zoom rectangle starting point (selected by the user with a mouse
324      * click). This is a point on the screen, not the chart (which may have
325      * been scaled up or down to fit the panel).
326      */

327     private Point JavaDoc zoomPoint = null;
328
329     /** The zoom rectangle (selected by the user with the mouse). */
330     private transient Rectangle2D JavaDoc zoomRectangle = null;
331
332     /** Controls if the zoom rectangle is drawn as an outline or filled. */
333     private boolean fillZoomRectangle = false;
334
335     /** The minimum distance required to drag the mouse to trigger a zoom. */
336     private int zoomTriggerDistance;
337     
338     /** A flag that controls whether or not horizontal tracing is enabled. */
339     private boolean horizontalAxisTrace = false;
340
341     /** A flag that controls whether or not vertical tracing is enabled. */
342     private boolean verticalAxisTrace = false;
343
344     /** A vertical trace line. */
345     private transient Line2D JavaDoc verticalTraceLine;
346
347     /** A horizontal trace line. */
348     private transient Line2D JavaDoc horizontalTraceLine;
349
350     /** Menu item for zooming in on a chart (both axes). */
351     private JMenuItem JavaDoc zoomInBothMenuItem;
352
353     /** Menu item for zooming in on a chart (domain axis). */
354     private JMenuItem JavaDoc zoomInDomainMenuItem;
355
356     /** Menu item for zooming in on a chart (range axis). */
357     private JMenuItem JavaDoc zoomInRangeMenuItem;
358
359     /** Menu item for zooming out on a chart. */
360     private JMenuItem JavaDoc zoomOutBothMenuItem;
361
362     /** Menu item for zooming out on a chart (domain axis). */
363     private JMenuItem JavaDoc zoomOutDomainMenuItem;
364
365     /** Menu item for zooming out on a chart (range axis). */
366     private JMenuItem JavaDoc zoomOutRangeMenuItem;
367
368     /** Menu item for resetting the zoom (both axes). */
369     private JMenuItem JavaDoc zoomResetBothMenuItem;
370
371     /** Menu item for resetting the zoom (domain axis only). */
372     private JMenuItem JavaDoc zoomResetDomainMenuItem;
373
374     /** Menu item for resetting the zoom (range axis only). */
375     private JMenuItem JavaDoc zoomResetRangeMenuItem;
376
377     /** A flag that controls whether or not file extensions are enforced. */
378     private boolean enforceFileExtensions;
379
380     /** A flag that indicates if original tooltip delays are changed. */
381     private boolean ownToolTipDelaysActive;
382     
383     /** Original initial tooltip delay of ToolTipManager.sharedInstance(). */
384     private int originalToolTipInitialDelay;
385
386     /** Original reshow tooltip delay of ToolTipManager.sharedInstance(). */
387     private int originalToolTipReshowDelay;
388
389     /** Original dismiss tooltip delay of ToolTipManager.sharedInstance(). */
390     private int originalToolTipDismissDelay;
391
392     /** Own initial tooltip delay to be used in this chart panel. */
393     private int ownToolTipInitialDelay;
394     
395     /** Own reshow tooltip delay to be used in this chart panel. */
396     private int ownToolTipReshowDelay;
397
398     /** Own dismiss tooltip delay to be used in this chart panel. */
399     private int ownToolTipDismissDelay;
400
401     /** The factor used to zoom in on an axis range. */
402     private double zoomInFactor = 0.5;
403     
404     /** The factor used to zoom out on an axis range. */
405     private double zoomOutFactor = 2.0;
406     
407     /** The resourceBundle for the localization. */
408     protected static ResourceBundle JavaDoc localizationResources
409         = ResourceBundle.getBundle("org.jfree.chart.LocalizationBundle");
410
411     /**
412      * Constructs a panel that displays the specified chart.
413      *
414      * @param chart the chart.
415      */

416     public ChartPanel(JFreeChart chart) {
417
418         this(
419             chart,
420             DEFAULT_WIDTH,
421             DEFAULT_HEIGHT,
422             DEFAULT_MINIMUM_DRAW_WIDTH,
423             DEFAULT_MINIMUM_DRAW_HEIGHT,
424             DEFAULT_MAXIMUM_DRAW_WIDTH,
425             DEFAULT_MAXIMUM_DRAW_HEIGHT,
426             DEFAULT_BUFFER_USED,
427             true, // properties
428
true, // save
429
true, // print
430
true, // zoom
431
true // tooltips
432
);
433
434     }
435
436     /**
437      * Constructs a panel containing a chart.
438      *
439      * @param chart the chart.
440      * @param useBuffer a flag controlling whether or not an off-screen buffer
441      * is used.
442      */

443     public ChartPanel(JFreeChart chart, boolean useBuffer) {
444
445         this(chart,
446              DEFAULT_WIDTH,
447              DEFAULT_HEIGHT,
448              DEFAULT_MINIMUM_DRAW_WIDTH,
449              DEFAULT_MINIMUM_DRAW_HEIGHT,
450              DEFAULT_MAXIMUM_DRAW_WIDTH,
451              DEFAULT_MAXIMUM_DRAW_HEIGHT,
452              useBuffer,
453              true, // properties
454
true, // save
455
true, // print
456
true, // zoom
457
true // tooltips
458
);
459
460     }
461
462     /**
463      * Constructs a JFreeChart panel.
464      *
465      * @param chart the chart.
466      * @param properties a flag indicating whether or not the chart property
467      * editor should be available via the popup menu.
468      * @param save a flag indicating whether or not save options should be
469      * available via the popup menu.
470      * @param print a flag indicating whether or not the print option
471      * should be available via the popup menu.
472      * @param zoom a flag indicating whether or not zoom options should
473      * be added to the popup menu.
474      * @param tooltips a flag indicating whether or not tooltips should be
475      * enabled for the chart.
476      */

477     public ChartPanel(JFreeChart chart,
478                       boolean properties,
479                       boolean save,
480                       boolean print,
481                       boolean zoom,
482                       boolean tooltips) {
483
484         this(chart,
485              DEFAULT_WIDTH,
486              DEFAULT_HEIGHT,
487              DEFAULT_MINIMUM_DRAW_WIDTH,
488              DEFAULT_MINIMUM_DRAW_HEIGHT,
489              DEFAULT_MAXIMUM_DRAW_WIDTH,
490              DEFAULT_MAXIMUM_DRAW_HEIGHT,
491              DEFAULT_BUFFER_USED,
492              properties,
493              save,
494              print,
495              zoom,
496              tooltips
497              );
498
499     }
500
501     /**
502      * Constructs a JFreeChart panel.
503      *
504      * @param chart the chart.
505      * @param width the preferred width of the panel.
506      * @param height the preferred height of the panel.
507      * @param minimumDrawWidth the minimum drawing width.
508      * @param minimumDrawHeight the minimum drawing height.
509      * @param maximumDrawWidth the maximum drawing width.
510      * @param maximumDrawHeight the maximum drawing height.
511      * @param useBuffer a flag that indicates whether to use the off-screen
512      * buffer to improve performance (at the expense of
513      * memory).
514      * @param properties a flag indicating whether or not the chart property
515      * editor should be available via the popup menu.
516      * @param save a flag indicating whether or not save options should be
517      * available via the popup menu.
518      * @param print a flag indicating whether or not the print option
519      * should be available via the popup menu.
520      * @param zoom a flag indicating whether or not zoom options should be
521      * added to the popup menu.
522      * @param tooltips a flag indicating whether or not tooltips should be
523      * enabled for the chart.
524      */

525     public ChartPanel(JFreeChart chart,
526                       int width,
527                       int height,
528                       int minimumDrawWidth,
529                       int minimumDrawHeight,
530                       int maximumDrawWidth,
531                       int maximumDrawHeight,
532                       boolean useBuffer,
533                       boolean properties,
534                       boolean save,
535                       boolean print,
536                       boolean zoom,
537                       boolean tooltips) {
538
539         this.chart = chart;
540         this.chartMouseListeners = new java.util.ArrayList JavaDoc();
541         if (chart != null) {
542             chart.addChangeListener(this);
543             Plot plot = chart.getPlot();
544             this.domainZoomable = false;
545             this.rangeZoomable = false;
546             if (plot instanceof Zoomable) {
547                 Zoomable z = (Zoomable) plot;
548                 this.domainZoomable = z.isDomainZoomable();
549                 this.rangeZoomable = z.isRangeZoomable();
550                 this.orientation = z.getOrientation();
551             }
552         }
553         this.info = new ChartRenderingInfo();
554         setPreferredSize(new Dimension JavaDoc(width, height));
555         this.useBuffer = useBuffer;
556         this.refreshBuffer = false;
557         this.minimumDrawWidth = minimumDrawWidth;
558         this.minimumDrawHeight = minimumDrawHeight;
559         this.maximumDrawWidth = maximumDrawWidth;
560         this.maximumDrawHeight = maximumDrawHeight;
561         this.zoomTriggerDistance = DEFAULT_ZOOM_TRIGGER_DISTANCE;
562
563         // set up popup menu...
564
this.popup = null;
565         if (properties || save || print || zoom) {
566             this.popup = createPopupMenu(properties, save, print, zoom);
567         }
568
569         enableEvents(AWTEvent.MOUSE_EVENT_MASK);
570         enableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK);
571         setDisplayToolTips(tooltips);
572         addMouseListener(this);
573         addMouseMotionListener(this);
574
575         this.enforceFileExtensions = true;
576
577         // initialize ChartPanel-specific tool tip delays with
578
// values the from ToolTipManager.sharedInstance()
579
ToolTipManager JavaDoc ttm = ToolTipManager.sharedInstance();
580         this.ownToolTipInitialDelay = ttm.getInitialDelay();
581         this.ownToolTipDismissDelay = ttm.getDismissDelay();
582         this.ownToolTipReshowDelay = ttm.getReshowDelay();
583
584     }
585
586     /**
587      * Returns the chart contained in the panel.
588      *
589      * @return The chart (possibly <code>null</code>).
590      */

591     public JFreeChart getChart() {
592         return this.chart;
593     }
594
595     /**
596      * Sets the chart that is displayed in the panel.
597      *
598      * @param chart the chart (<code>null</code> permitted).
599      */

600     public void setChart(JFreeChart chart) {
601
602         // stop listening for changes to the existing chart
603
if (this.chart != null) {
604             this.chart.removeChangeListener(this);
605             this.chart.removeProgressListener(this);
606         }
607
608         // add the new chart
609
this.chart = chart;
610         if (chart != null) {
611             this.chart.addChangeListener(this);
612             this.chart.addProgressListener(this);
613             Plot plot = chart.getPlot();
614             this.domainZoomable = false;
615             this.rangeZoomable = false;
616             if (plot instanceof Zoomable) {
617                 Zoomable z = (Zoomable) plot;
618                 this.domainZoomable = z.isDomainZoomable();
619                 this.rangeZoomable = z.isRangeZoomable();
620                 this.orientation = z.getOrientation();
621             }
622         }
623         else {
624             this.domainZoomable = false;
625             this.rangeZoomable = false;
626         }
627         if (this.useBuffer) {
628             this.refreshBuffer = true;
629         }
630         repaint();
631
632     }
633
634     /**
635      * Returns the minimum drawing width for charts.
636      * <P>
637      * If the width available on the panel is less than this, then the chart is
638      * drawn at the minimum width then scaled down to fit.
639      *
640      * @return The minimum drawing width.
641      */

642     public int getMinimumDrawWidth() {
643         return this.minimumDrawWidth;
644     }
645
646     /**
647      * Sets the minimum drawing width for the chart on this panel.
648      * <P>
649      * At the time the chart is drawn on the panel, if the available width is
650      * less than this amount, the chart will be drawn using the minimum width
651      * then scaled down to fit the available space.
652      *
653      * @param width The width.
654      */

655     public void setMinimumDrawWidth(int width) {
656         this.minimumDrawWidth = width;
657     }
658
659     /**
660      * Returns the maximum drawing width for charts.
661      * <P>
662      * If the width available on the panel is greater than this, then the chart
663      * is drawn at the maximum width then scaled up to fit.
664      *
665      * @return The maximum drawing width.
666      */

667     public int getMaximumDrawWidth() {
668         return this.maximumDrawWidth;
669     }
670
671     /**
672      * Sets the maximum drawing width for the chart on this panel.
673      * <P>
674      * At the time the chart is drawn on the panel, if the available width is
675      * greater than this amount, the chart will be drawn using the maximum
676      * width then scaled up to fit the available space.
677      *
678      * @param width The width.
679      */

680     public void setMaximumDrawWidth(int width) {
681         this.maximumDrawWidth = width;
682     }
683
684     /**
685      * Returns the minimum drawing height for charts.
686      * <P>
687      * If the height available on the panel is less than this, then the chart
688      * is drawn at the minimum height then scaled down to fit.
689      *
690      * @return The minimum drawing height.
691      */

692     public int getMinimumDrawHeight() {
693         return this.minimumDrawHeight;
694     }
695
696     /**
697      * Sets the minimum drawing height for the chart on this panel.
698      * <P>
699      * At the time the chart is drawn on the panel, if the available height is
700      * less than this amount, the chart will be drawn using the minimum height
701      * then scaled down to fit the available space.
702      *
703      * @param height The height.
704      */

705     public void setMinimumDrawHeight(int height) {
706         this.minimumDrawHeight = height;
707     }
708
709     /**
710      * Returns the maximum drawing height for charts.
711      * <P>
712      * If the height available on the panel is greater than this, then the
713      * chart is drawn at the maximum height then scaled up to fit.
714      *
715      * @return The maximum drawing height.
716      */

717     public int getMaximumDrawHeight() {
718         return this.maximumDrawHeight;
719     }
720
721     /**
722      * Sets the maximum drawing height for the chart on this panel.
723      * <P>
724      * At the time the chart is drawn on the panel, if the available height is
725      * greater than this amount, the chart will be drawn using the maximum
726      * height then scaled up to fit the available space.
727      *
728      * @param height The height.
729      */

730     public void setMaximumDrawHeight(int height) {
731         this.maximumDrawHeight = height;
732     }
733
734     /**
735      * Returns the X scale factor for the chart. This will be 1.0 if no
736      * scaling has been used.
737      *
738      * @return The scale factor.
739      */

740     public double getScaleX() {
741         return this.scaleX;
742     }
743     
744     /**
745      * Returns the Y scale factory for the chart. This will be 1.0 if no
746      * scaling has been used.
747      *
748      * @return The scale factor.
749      */

750     public double getScaleY() {
751         return this.scaleY;
752     }
753     
754     /**
755      * Returns the anchor point.
756      *
757      * @return The anchor point (possibly <code>null</code>).
758      */

759     public Point2D JavaDoc getAnchor() {
760         return this.anchor;
761     }
762     
763     /**
764      * Sets the anchor point. This method is provided for the use of
765      * subclasses, not end users.
766      *
767      * @param anchor the anchor point (<code>null</code> permitted).
768      */

769     protected void setAnchor(Point2D JavaDoc anchor) {
770         this.anchor = anchor;
771     }
772     
773     /**
774      * Returns the popup menu.
775      *
776      * @return The popup menu.
777      */

778     public JPopupMenu JavaDoc getPopupMenu() {
779         return this.popup;
780     }
781
782     /**
783      * Sets the popup menu for the panel.
784      *
785      * @param popup the popup menu (<code>null</code> permitted).
786      */

787     public void setPopupMenu(JPopupMenu JavaDoc popup) {
788         this.popup = popup;
789     }
790
791     /**
792      * Returns the chart rendering info from the most recent chart redraw.
793      *
794      * @return The chart rendering info.
795      */

796     public ChartRenderingInfo getChartRenderingInfo() {
797         return this.info;
798     }
799
800     /**
801      * A convenience method that switches on mouse-based zooming.
802      *
803      * @param flag <code>true</code> enables zooming and rectangle fill on
804      * zoom.
805      */

806     public void setMouseZoomable(boolean flag) {
807         setMouseZoomable(flag, true);
808     }
809
810     /**
811      * A convenience method that switches on mouse-based zooming.
812      *
813      * @param flag <code>true</code> if zooming enabled
814      * @param fillRectangle <code>true</code> if zoom rectangle is filled,
815      * false if rectangle is shown as outline only.
816      */

817     public void setMouseZoomable(boolean flag, boolean fillRectangle) {
818         setDomainZoomable(flag);
819         setRangeZoomable(flag);
820         setFillZoomRectangle(fillRectangle);
821     }
822
823     /**
824      * Returns the flag that determines whether or not zooming is enabled for
825      * the domain axis.
826      *
827      * @return A boolean.
828      */

829     public boolean isDomainZoomable() {
830         return this.domainZoomable;
831     }
832     
833     /**
834      * Sets the flag that controls whether or not zooming is enable for the
835      * domain axis. A check is made to ensure that the current plot supports
836      * zooming for the domain values.
837      *
838      * @param flag <code>true</code> enables zooming if possible.
839      */

840     public void setDomainZoomable(boolean flag) {
841         if (flag) {
842             Plot plot = this.chart.getPlot();
843             if (plot instanceof Zoomable) {
844                 Zoomable z = (Zoomable) plot;
845                 this.domainZoomable = flag && (z.isDomainZoomable());
846             }
847         }
848         else {
849             this.domainZoomable = false;
850         }
851     }
852
853     /**
854      * Returns the flag that determines whether or not zooming is enabled for
855      * the range axis.
856      *
857      * @return A boolean.
858      */

859     public boolean isRangeZoomable() {
860         return this.rangeZoomable;
861     }
862     
863     /**
864      * A flag that controls mouse-based zooming on the vertical axis.
865      *
866      * @param flag <code>true</code> enables zooming.
867      */

868     public void setRangeZoomable(boolean flag) {
869         if (flag) {
870             Plot plot = this.chart.getPlot();
871             if (plot instanceof Zoomable) {
872                 Zoomable z = (Zoomable) plot;
873                 this.rangeZoomable = flag && (z.isRangeZoomable());
874             }
875         }
876         else {
877             this.rangeZoomable = false;
878         }
879     }
880
881     /**
882      * Returns the flag that controls whether or not the zoom rectangle is
883      * filled when drawn.
884      *
885      * @return A boolean.
886      */

887     public boolean getFillZoomRectangle() {
888         return this.fillZoomRectangle;
889     }
890     
891     /**
892      * A flag that controls how the zoom rectangle is drawn.
893      *
894      * @param flag <code>true</code> instructs to fill the rectangle on
895      * zoom, otherwise it will be outlined.
896      */

897     public void setFillZoomRectangle(boolean flag) {
898         this.fillZoomRectangle = flag;
899     }
900
901     /**
902      * Returns the zoom trigger distance. This controls how far the mouse must
903      * move before a zoom action is triggered.
904      *
905      * @return The distance (in Java2D units).
906      */

907     public int getZoomTriggerDistance() {
908         return this.zoomTriggerDistance;
909     }
910     
911     /**
912      * Sets the zoom trigger distance. This controls how far the mouse must
913      * move before a zoom action is triggered.
914      *
915      * @param distance the distance (in Java2D units).
916      */

917     public void setZoomTriggerDistance(int distance) {
918         this.zoomTriggerDistance = distance;
919     }
920     
921     /**
922      * Returns the flag that controls whether or not a horizontal axis trace
923      * line is drawn over the plot area at the current mouse location.
924      *
925      * @return A boolean.
926      */

927     public boolean getHorizontalAxisTrace() {
928         return this.horizontalAxisTrace;
929     }
930     
931     /**
932      * A flag that controls trace lines on the horizontal axis.
9