KickJava   Java API By Example, From Geeks To Geeks.

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


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  * StandardContourToolTipGenerator.java
28  * ------------------------------------
29  * (C) Copyright 2002-2005, by David M. O'Donnell and Contributors.
30  *
31  * Original Author: David M. O'Donnell;
32  * Contributor(s): David Gilbert (for Object Refinery Limited);
33  *
34  * $Id: StandardContourToolTipGenerator.java,v 1.4 2005/05/19 15:43:00 mungady Exp $
35  *
36  * Changes
37  * -------
38  * 23-Jan-2003 : Added standard header (DG);
39  * 21-Mar-2003 : Implemented Serializable (DG);
40  * 15-Jul-2004 : Switched the getZ() and getZValue() methods (DG);
41  * 19-Jan-2005 : Now accesses primitives only from dataset (DG);
42  *
43  */

44
45 package org.jfree.chart.labels;
46
47 import java.io.Serializable JavaDoc;
48 import java.text.DecimalFormat JavaDoc;
49 import java.text.SimpleDateFormat JavaDoc;
50 import java.util.Date JavaDoc;
51
52 import org.jfree.data.contour.ContourDataset;
53
54 /**
55  * A standard tooltip generator for plots that use data from an
56  * {@link ContourDataset}.
57  *
58  * @author David M. O'Donnell
59  */

60 public class StandardContourToolTipGenerator implements ContourToolTipGenerator,
61                                                         Serializable JavaDoc {
62
63     /** For serialization. */
64     private static final long serialVersionUID = -1881659351247502711L;
65     
66     /** The number formatter. */
67     private DecimalFormat JavaDoc valueForm = new DecimalFormat JavaDoc("##.###");
68
69     /**
70      * Generates a tooltip text item for a particular item within a series.
71      *
72      * @param data the dataset.
73      * @param item the item index (zero-based).
74      *
75      * @return The tooltip text.
76      */

77     public String JavaDoc generateToolTip(ContourDataset data, int item) {
78
79         double x = data.getXValue(0, item);
80         double y = data.getYValue(0, item);
81         double z = data.getZValue(0, item);
82         String JavaDoc xString = null;
83
84         if (data.isDateAxis(0)) {
85             SimpleDateFormat JavaDoc formatter
86                 = new java.text.SimpleDateFormat JavaDoc("MM/dd/yyyy hh:mm:ss");
87             StringBuffer JavaDoc strbuf = new StringBuffer JavaDoc();
88             strbuf = formatter.format(
89                 new Date JavaDoc((long) x), strbuf, new java.text.FieldPosition JavaDoc(0)
90             );
91             xString = strbuf.toString();
92         }
93         else {
94             xString = this.valueForm.format(x);
95         }
96         if (!Double.isNaN(z)) {
97             return "X: " + xString
98                    + ", Y: " + this.valueForm.format(y)
99                    + ", Z: " + this.valueForm.format(z);
100         }
101         else {
102             return "X: " + xString
103                  + ", Y: " + this.valueForm.format(y)
104                  + ", Z: no data";
105         }
106
107     }
108
109     /**
110      * Tests if this object is equal to another.
111      *
112      * @param obj the other object.
113      *
114      * @return A boolean.
115      */

116     public boolean equals(Object JavaDoc obj) {
117
118         if (obj == this) {
119             return true;
120         }
121
122         if (!(obj instanceof StandardContourToolTipGenerator)) {
123             return false;
124         }
125         StandardContourToolTipGenerator that
126             = (StandardContourToolTipGenerator) obj;
127         if (this.valueForm != null) {
128             return this.valueForm.equals(that.valueForm);
129         }
130         return false;
131
132     }
133
134 }
135
Popular Tags