KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > labels > StandardXYToolTipGenerator


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  * StandardXYToolTipGenerator.java
28  * -------------------------------
29  * (C) Copyright 2004, 2005, by Object Refinery Limited.
30  *
31  * Original Author: David Gilbert (for Object Refinery Limited);
32  * Contributor(s): -;
33  *
34  * $Id: StandardXYToolTipGenerator.java,v 1.3 2005/05/19 15:43:00 mungady Exp $
35  *
36  * Changes
37  * -------
38  * 12-May-2004 : Version 1 (DG);
39  *
40  */

41
42 package org.jfree.chart.labels;
43
44 import java.io.Serializable JavaDoc;
45 import java.text.DateFormat JavaDoc;
46 import java.text.NumberFormat JavaDoc;
47
48 import org.jfree.data.xy.XYDataset;
49 import org.jfree.util.PublicCloneable;
50
51 /**
52  * A standard tool tip generator for use with an
53  * {@link org.jfree.chart.renderer.xy.XYItemRenderer}.
54  */

55 public class StandardXYToolTipGenerator extends AbstractXYItemLabelGenerator
56                                         implements XYToolTipGenerator,
57                                                    Cloneable JavaDoc,
58                                                    PublicCloneable,
59                                                    Serializable JavaDoc {
60
61     /** For serialization. */
62     private static final long serialVersionUID = -3564164459039540784L;
63     
64     /** The default tooltip format. */
65     public static final String JavaDoc DEFAULT_TOOL_TIP_FORMAT = "{0}: ({1}, {2})";
66
67     /**
68      * Returns a tool tip generator that formats the x-values as dates and the
69      * y-values as numbers.
70      *
71      * @return A tool tip generator (never <code>null</code>).
72      */

73     public static StandardXYToolTipGenerator getTimeSeriesInstance() {
74         return new StandardXYToolTipGenerator(
75             DEFAULT_TOOL_TIP_FORMAT, DateFormat.getInstance(),
76             NumberFormat.getInstance()
77         );
78     }
79     
80     /**
81      * Creates a tool tip generator using default number formatters.
82      */

83     public StandardXYToolTipGenerator() {
84         this(
85             DEFAULT_TOOL_TIP_FORMAT,
86             NumberFormat.getNumberInstance(), NumberFormat.getNumberInstance()
87         );
88     }
89
90     /**
91      * Creates a tool tip generator using the specified number formatters.
92      *
93      * @param formatString the item label format string (<code>null</code> not
94      * permitted).
95      * @param xFormat the format object for the x values (<code>null</code>
96      * not permitted).
97      * @param yFormat the format object for the y values (<code>null</code>
98      * not permitted).
99      */

100     public StandardXYToolTipGenerator(String JavaDoc formatString,
101                                       NumberFormat JavaDoc xFormat,
102                                       NumberFormat JavaDoc yFormat) {
103         
104         super(formatString, xFormat, yFormat);
105     
106     }
107
108     /**
109      * Creates a tool tip generator using the specified number formatters.
110      *
111      * @param formatString the label format string (<code>null</code> not
112      * permitted).
113      * @param xFormat the format object for the x values (<code>null</code>
114      * not permitted).
115      * @param yFormat the format object for the y values (<code>null</code>
116      * not permitted).
117      */

118     public StandardXYToolTipGenerator(String JavaDoc formatString,
119                                       DateFormat JavaDoc xFormat,
120                                       NumberFormat JavaDoc yFormat) {
121         
122         super(formatString, xFormat, yFormat);
123     
124     }
125
126     /**
127      * Creates a tool tip generator using the specified date formatters.
128      *
129      * @param formatString the label format string (<code>null</code> not
130      * permitted).
131      * @param xFormat the format object for the x values (<code>null</code>
132      * not permitted).
133      * @param yFormat the format object for the y values (<code>null</code>
134      * not permitted).
135      */

136     public StandardXYToolTipGenerator(String JavaDoc formatString,
137                                       DateFormat JavaDoc xFormat,
138                                       DateFormat JavaDoc yFormat) {
139         
140         super(formatString, xFormat, yFormat);
141     
142     }
143
144     /**
145      * Generates the tool tip text for an item in a dataset.
146      *
147      * @param dataset the dataset (<code>null</code> not permitted).
148      * @param series the series index (zero-based).
149      * @param item the item index (zero-based).
150      *
151      * @return The tooltip text (possibly <code>null</code>).
152      */

153     public String JavaDoc generateToolTip(XYDataset dataset, int series, int item) {
154         return generateLabelString(dataset, series, item);
155     }
156
157     /**
158      * Tests this object for equality with an arbitrary object.
159      *
160      * @param obj the other object (<code>null</code> permitted).
161      *
162      * @return A boolean.
163      */

164     public boolean equals(Object JavaDoc obj) {
165         if (obj == this) {
166             return true;
167         }
168         if (obj instanceof StandardXYToolTipGenerator) {
169             return super.equals(obj);
170         }
171         return false;
172     }
173
174     /**
175      * Returns an independent copy of the generator.
176      *
177      * @return A clone.
178      *
179      * @throws CloneNotSupportedException if cloning is not supported.
180      */

181     public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
182         return super.clone();
183     }
184     
185 }
186
Popular Tags