KickJava   Java API By Example, From Geeks To Geeks.

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


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

42
43 package org.jfree.chart.labels;
44
45 import java.io.Serializable JavaDoc;
46 import java.text.MessageFormat JavaDoc;
47 import java.text.NumberFormat JavaDoc;
48
49 import org.jfree.data.category.CategoryDataset;
50 import org.jfree.data.statistics.BoxAndWhiskerCategoryDataset;
51 import org.jfree.util.PublicCloneable;
52
53 /**
54  * An item label generator for plots that use data from a
55  * {@link BoxAndWhiskerCategoryDataset}.
56  * <P>
57  * The tooltip text and item label text are composed using a
58  * {@link java.text.MessageFormat} object, that can aggregate some or all of
59  * the following string values into a message.
60  * <table>
61  * <tr><td>0</td><td>Series Name</td></tr>
62  * <tr><td>1</td><td>X (value or date)</td></tr>
63  * <tr><td>2</td><td>Mean</td></tr>
64  * <tr><td>3</td><td>Median</td></tr>
65  * <tr><td>4</td><td>Minimum</td></tr>
66  * <tr><td>5</td><td>Maximum</td></tr>
67  * <tr><td>6</td><td>Quartile 1</td></tr>
68  * <tr><td>7</td><td>Quartile 3</td></tr>
69  * </table>
70  */

71 public class BoxAndWhiskerToolTipGenerator
72     extends StandardCategoryToolTipGenerator
73     implements CategoryToolTipGenerator, Cloneable JavaDoc, PublicCloneable,
74                Serializable JavaDoc {
75
76     /** For serialization. */
77     private static final long serialVersionUID = -6076837753823076334L;
78     
79     /** The default tooltip format string. */
80     public static final String JavaDoc DEFAULT_TOOL_TIP_FORMAT
81         = "X: {1} Mean: {2} Median: {3} Min: {4} Max: {5} Q1: {6} Q3: {7} ";
82     
83     /**
84      * Creates a default tool tip generator.
85      */

86     public BoxAndWhiskerToolTipGenerator() {
87         super(DEFAULT_TOOL_TIP_FORMAT, NumberFormat.getInstance());
88     }
89     
90     /**
91      * Creates a tool tip formatter.
92      *
93      * @param format the tool tip format string.
94      * @param formatter the formatter.
95      */

96     public BoxAndWhiskerToolTipGenerator(String JavaDoc format,
97                                          NumberFormat JavaDoc formatter) {
98         super(format, formatter);
99     }
100     
101     /**
102      * Creates the array of items that can be passed to the
103      * {@link MessageFormat} class for creating labels.
104      *
105      * @param dataset the dataset (<code>null</code> not permitted).
106      * @param series the series (zero-based index).
107      * @param item the item (zero-based index).
108      *
109      * @return The items (never <code>null</code>).
110      */

111     protected Object JavaDoc[] createItemArray(CategoryDataset dataset, int series,
112                                        int item) {
113         Object JavaDoc[] result = new Object JavaDoc[8];
114         result[0] = dataset.getRowKey(series);
115         Number JavaDoc y = dataset.getValue(series, item);
116         NumberFormat JavaDoc formatter = getNumberFormat();
117         result[1] = formatter.format(y);
118         if (dataset instanceof BoxAndWhiskerCategoryDataset) {
119             BoxAndWhiskerCategoryDataset d
120                 = (BoxAndWhiskerCategoryDataset) dataset;
121             result[2] = formatter.format(d.getMeanValue(series, item));
122             result[3] = formatter.format(d.getMedianValue(series, item));
123             result[4] = formatter.format(d.getMinRegularValue(series, item));
124             result[5] = formatter.format(d.getMaxRegularValue(series, item));
125             result[6] = formatter.format(d.getQ1Value(series, item));
126             result[7] = formatter.format(d.getQ3Value(series, item));
127         }
128         return result;
129     }
130
131     /**
132      * Tests if this object is equal to another.
133      *
134      * @param obj the other object.
135      *
136      * @return A boolean.
137      */

138     public boolean equals(Object JavaDoc obj) {
139         if (obj == this) {
140             return true;
141         }
142         if (obj instanceof BoxAndWhiskerToolTipGenerator) {
143             return super.equals(obj);
144         }
145         return false;
146     }
147     
148 }
149
Popular Tags