KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* ======================================
2  * JFreeChart : a free Java chart library
3  * ======================================
4  *
5  * Project Info: http://www.jfree.org/jfreechart/index.html
6  * Project Lead: David Gilbert (david.gilbert@object-refinery.com);
7  *
8  * (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
9  *
10  * This library is free software; you can redistribute it and/or modify it under the terms
11  * of the GNU Lesser General Public License as published by the Free Software Foundation;
12  * either version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License along with this
19  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  *
22  * --------------------------------
23  * StandardPieToolTipGenerator.java
24  * --------------------------------
25  * (C) Copyright 2001-2003, by Object Refinery Limited.
26  *
27  * Original Author: David Gilbert (for Object Refinery Limited);
28  * Contributor(s): Richard Atkinson;
29  *
30  * $Id: StandardPieToolTipGenerator.java,v 1.4 2003/08/20 11:45:21 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 13-Dec-2001 : Version 1 (DG);
35  * 16-Jan-2002 : Completed Javadocs (DG);
36  * 29-Aug-2002 : Changed to format numbers using default locale (RA);
37  * 26-Sep-2002 : Fixed errors reported by Checkstyle (DG);
38  * 30-Oct-2002 : Changed PieToolTipGenerator interface (DG);
39  * 21-Mar-2003 : Implemented Serializable (DG);
40  * 13-Aug-2003 : Implemented Cloneable (DG);
41  *
42  */

43
44 package org.jfree.chart.labels;
45
46 import java.io.Serializable JavaDoc;
47 import java.text.NumberFormat JavaDoc;
48
49 import org.jfree.data.PieDataset;
50 import org.jfree.util.ObjectUtils;
51
52 /**
53  * A standard tool tip generator for plots that use data from a {@link PieDataset}.
54  *
55  * @author David Gilbert
56  *
57  * @deprecated Use {@link StandardPieItemLabelGenerator}.
58  */

59 public class StandardPieToolTipGenerator implements PieItemLabelGenerator,
60                                                     Cloneable JavaDoc,
61                                                     Serializable JavaDoc {
62
63     /** The number formatter. */
64     private NumberFormat JavaDoc numberFormat;
65
66     /**
67      * Creates a tool tip generator with a default number formatter.
68      */

69     public StandardPieToolTipGenerator() {
70         this(NumberFormat.getInstance());
71     }
72
73     /**
74      * Creates a tool tip generator with the specified number formatter.
75      *
76      * @param formatter the number formatter.
77      */

78     public StandardPieToolTipGenerator(NumberFormat JavaDoc formatter) {
79         this.numberFormat = formatter;
80     }
81
82     /**
83      * Returns the number formatter.
84      *
85      * @return the number formatter.
86      */

87     public NumberFormat JavaDoc getNumberFormat() {
88         return this.numberFormat;
89     }
90
91     /**
92      * Generates a tool tip text item for one section in a pie chart.
93      *
94      * @param data the dataset.
95      * @param key the item key.
96      * @param pieIndex the pie index (ignored).
97      *
98      * @return The tool tip text (possibly <code>null</code>).
99      */

100     public String JavaDoc generateToolTip(PieDataset data, Comparable JavaDoc key, int pieIndex) {
101
102         String JavaDoc result = null;
103         Number JavaDoc value = data.getValue(key);
104         if (value != null) {
105             String JavaDoc sectionLabel = key.toString();
106             result = sectionLabel + " = " + this.numberFormat.format(value);
107         }
108
109         return result;
110
111     }
112
113     /**
114      * Returns an independent copy of the generator.
115      *
116      * @return A clone.
117      *
118      * @throws CloneNotSupportedException should not happen.
119      */

120     public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
121         
122         StandardPieToolTipGenerator clone = (StandardPieToolTipGenerator) super.clone();
123         
124         if (this.numberFormat != null) {
125             clone.numberFormat = (NumberFormat JavaDoc) this.numberFormat.clone();
126         }
127         
128         return clone;
129         
130     }
131
132     /**
133      * Tests if this object is equal to another.
134      *
135      * @param o the other object.
136      *
137      * @return A boolean.
138      */

139     public boolean equals(Object JavaDoc o) {
140
141         if (o == null) {
142             return false;
143         }
144         if (o == this) {
145             return true;
146         }
147
148         if (o instanceof StandardPieToolTipGenerator) {
149             StandardPieToolTipGenerator generator = (StandardPieToolTipGenerator) o;
150             return ObjectUtils.equal(this.numberFormat, generator.getNumberFormat());
151         }
152         return false;
153
154     }
155
156 }
157
Popular Tags