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.3 2007/02/13 16:05:06 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.data.contour.ContourDataset;
054
055 /**
056 * A standard tooltip generator for plots that use data from an
057 * {@link ContourDataset}.
058 *
059 * @deprecated This class is no longer supported (as of version 1.0.4).
060 */
061 public class StandardContourToolTipGenerator implements ContourToolTipGenerator,
062 Serializable {
063
064 /** For serialization. */
065 private static final long serialVersionUID = -1881659351247502711L;
066
067 /** The number formatter. */
068 private DecimalFormat valueForm = new DecimalFormat("##.###");
069
070 /**
071 * Generates a tooltip text item for a particular item within a series.
072 *
073 * @param data the dataset.
074 * @param item the item index (zero-based).
075 *
076 * @return The tooltip text.
077 */
078 public String generateToolTip(ContourDataset data, int item) {
079
080 double x = data.getXValue(0, item);
081 double y = data.getYValue(0, item);
082 double z = data.getZValue(0, item);
083 String xString = null;
084
085 if (data.isDateAxis(0)) {
086 SimpleDateFormat formatter
087 = new java.text.SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
088 StringBuffer strbuf = new StringBuffer();
089 strbuf = formatter.format(
090 new Date((long) x), strbuf, new java.text.FieldPosition(0)
091 );
092 xString = strbuf.toString();
093 }
094 else {
095 xString = this.valueForm.format(x);
096 }
097 if (!Double.isNaN(z)) {
098 return "X: " + xString
099 + ", Y: " + this.valueForm.format(y)
100 + ", Z: " + this.valueForm.format(z);
101 }
102 else {
103 return "X: " + xString
104 + ", Y: " + this.valueForm.format(y)
105 + ", Z: no data";
106 }
107
108 }
109
110 /**
111 * Tests if this object is equal to another.
112 *
113 * @param obj the other object.
114 *
115 * @return A boolean.
116 */
117 public boolean equals(Object obj) {
118
119 if (obj == this) {
120 return true;
121 }
122
123 if (!(obj instanceof StandardContourToolTipGenerator)) {
124 return false;
125 }
126 StandardContourToolTipGenerator that
127 = (StandardContourToolTipGenerator) obj;
128 if (this.valueForm != null) {
129 return this.valueForm.equals(that.valueForm);
130 }
131 return false;
132
133 }
134
135 }