001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jfreechart/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * ------------------------------------
028: * BoxAndWhiskerToolTipGenerator.java
029: * ------------------------------------
030: * (C) Copyright 2004, 2005, by David Browning and Contributors.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: BoxAndWhiskerToolTipGenerator.java,v 1.3.2.1 2005/10/25 20:49:02 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 02-Jun-2004 : Version 1 (DG);
040: * 23-Mar-2005 : Implemented PublicCloneable (DG);
041: *
042: */
043:
044: package org.jfree.chart.labels;
045:
046: import java.io.Serializable;
047: import java.text.MessageFormat;
048: import java.text.NumberFormat;
049:
050: import org.jfree.data.category.CategoryDataset;
051: import org.jfree.data.statistics.BoxAndWhiskerCategoryDataset;
052: import org.jfree.util.PublicCloneable;
053:
054: /**
055: * An item label generator for plots that use data from a
056: * {@link BoxAndWhiskerCategoryDataset}.
057: * <P>
058: * The tooltip text and item label text are composed using a
059: * {@link java.text.MessageFormat} object, that can aggregate some or all of
060: * the following string values into a message.
061: * <table>
062: * <tr><td>0</td><td>Series Name</td></tr>
063: * <tr><td>1</td><td>X (value or date)</td></tr>
064: * <tr><td>2</td><td>Mean</td></tr>
065: * <tr><td>3</td><td>Median</td></tr>
066: * <tr><td>4</td><td>Minimum</td></tr>
067: * <tr><td>5</td><td>Maximum</td></tr>
068: * <tr><td>6</td><td>Quartile 1</td></tr>
069: * <tr><td>7</td><td>Quartile 3</td></tr>
070: * </table>
071: */
072: public class BoxAndWhiskerToolTipGenerator extends
073: StandardCategoryToolTipGenerator implements
074: CategoryToolTipGenerator, Cloneable, PublicCloneable,
075: Serializable {
076:
077: /** For serialization. */
078: private static final long serialVersionUID = -6076837753823076334L;
079:
080: /** The default tooltip format string. */
081: public static final String DEFAULT_TOOL_TIP_FORMAT = "X: {1} Mean: {2} Median: {3} Min: {4} Max: {5} Q1: {6} Q3: {7} ";
082:
083: /**
084: * Creates a default tool tip generator.
085: */
086: public BoxAndWhiskerToolTipGenerator() {
087: super (DEFAULT_TOOL_TIP_FORMAT, NumberFormat.getInstance());
088: }
089:
090: /**
091: * Creates a tool tip formatter.
092: *
093: * @param format the tool tip format string.
094: * @param formatter the formatter.
095: */
096: public BoxAndWhiskerToolTipGenerator(String format,
097: NumberFormat formatter) {
098: super (format, formatter);
099: }
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[] createItemArray(CategoryDataset dataset,
112: int series, int item) {
113: Object[] result = new Object[8];
114: result[0] = dataset.getRowKey(series);
115: Number y = dataset.getValue(series, item);
116: NumberFormat formatter = getNumberFormat();
117: result[1] = formatter.format(y);
118: if (dataset instanceof BoxAndWhiskerCategoryDataset) {
119: BoxAndWhiskerCategoryDataset d = (BoxAndWhiskerCategoryDataset) dataset;
120: result[2] = formatter.format(d.getMeanValue(series, item));
121: result[3] = formatter
122: .format(d.getMedianValue(series, item));
123: result[4] = formatter.format(d.getMinRegularValue(series,
124: item));
125: result[5] = formatter.format(d.getMaxRegularValue(series,
126: item));
127: result[6] = formatter.format(d.getQ1Value(series, item));
128: result[7] = formatter.format(d.getQ3Value(series, item));
129: }
130: return result;
131: }
132:
133: /**
134: * Tests if this object is equal to another.
135: *
136: * @param obj the other object.
137: *
138: * @return A boolean.
139: */
140: public boolean equals(Object obj) {
141: if (obj == this ) {
142: return true;
143: }
144: if (obj instanceof BoxAndWhiskerToolTipGenerator) {
145: return super .equals(obj);
146: }
147: return false;
148: }
149:
150: }
|