001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2007, 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: * StandardContourToolTipGenerator.java
029: * ------------------------------------
030: * (C) Copyright 2002-2007, by David M. O'Donnell and Contributors.
031: *
032: * Original Author: David M. O'Donnell;
033: * Contributor(s): David Gilbert (for Object Refinery Limited);
034: *
035: * $Id: StandardContourToolTipGenerator.java,v 1.4.2.4 2007/04/04 09:10:49 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 23-Jan-2003 : Added standard header (DG);
040: * 21-Mar-2003 : Implemented Serializable (DG);
041: * 15-Jul-2004 : Switched the getZ() and getZValue() methods (DG);
042: * 19-Jan-2005 : Now accesses primitives only from dataset (DG);
043: *
044: */
045:
046: package org.jfree.chart.labels;
047:
048: import java.io.Serializable;
049: import java.text.DecimalFormat;
050: import java.text.SimpleDateFormat;
051: import java.util.Date;
052:
053: import org.jfree.chart.plot.XYPlot;
054: import org.jfree.chart.renderer.xy.XYBlockRenderer;
055: import org.jfree.data.contour.ContourDataset;
056:
057: /**
058: * A standard tooltip generator for plots that use data from an
059: * {@link ContourDataset}.
060: *
061: * @deprecated This class is no longer supported (as of version 1.0.4). If
062: * you are creating contour plots, please try to use {@link XYPlot} and
063: * {@link XYBlockRenderer}.
064: */
065: public class StandardContourToolTipGenerator implements
066: ContourToolTipGenerator, Serializable {
067:
068: /** For serialization. */
069: private static final long serialVersionUID = -1881659351247502711L;
070:
071: /** The number formatter. */
072: private DecimalFormat valueForm = new DecimalFormat("##.###");
073:
074: /**
075: * Generates a tooltip text item for a particular item within a series.
076: *
077: * @param data the dataset.
078: * @param item the item index (zero-based).
079: *
080: * @return The tooltip text.
081: */
082: public String generateToolTip(ContourDataset data, int item) {
083:
084: double x = data.getXValue(0, item);
085: double y = data.getYValue(0, item);
086: double z = data.getZValue(0, item);
087: String xString = null;
088:
089: if (data.isDateAxis(0)) {
090: SimpleDateFormat formatter = new java.text.SimpleDateFormat(
091: "MM/dd/yyyy hh:mm:ss");
092: StringBuffer strbuf = new StringBuffer();
093: strbuf = formatter.format(new Date((long) x), strbuf,
094: new java.text.FieldPosition(0));
095: xString = strbuf.toString();
096: } else {
097: xString = this .valueForm.format(x);
098: }
099: if (!Double.isNaN(z)) {
100: return "X: " + xString + ", Y: " + this .valueForm.format(y)
101: + ", Z: " + this .valueForm.format(z);
102: } else {
103: return "X: " + xString + ", 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 obj) {
117:
118: if (obj == this ) {
119: return true;
120: }
121:
122: if (!(obj instanceof StandardContourToolTipGenerator)) {
123: return false;
124: }
125: StandardContourToolTipGenerator that = (StandardContourToolTipGenerator) obj;
126: if (this .valueForm != null) {
127: return this .valueForm.equals(that.valueForm);
128: }
129: return false;
130:
131: }
132:
133: }
|