001/* ===========================================================
002 * JFreeChart : a free chart library for the Java(tm) platform
003 * ===========================================================
004 *
005 * (C) Copyright 2000-2013, 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 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 
025 * Other names may be trademarks of their respective owners.]
026 *
027 * ------------------------------------
028 * StandardContourToolTipGenerator.java
029 * ------------------------------------
030 * (C) Copyright 2002-2008, 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 * Changes
036 * -------
037 * 23-Jan-2003 : Added standard header (DG);
038 * 21-Mar-2003 : Implemented Serializable (DG);
039 * 15-Jul-2004 : Switched the getZ() and getZValue() methods (DG);
040 * 19-Jan-2005 : Now accesses primitives only from dataset (DG);
041 *
042 */
043
044package org.jfree.chart.labels;
045
046import java.io.Serializable;
047import java.text.DecimalFormat;
048import java.text.SimpleDateFormat;
049import java.util.Date;
050
051import org.jfree.chart.plot.XYPlot;
052import org.jfree.chart.renderer.xy.XYBlockRenderer;
053import 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).  If
060 *     you are creating contour plots, please try to use {@link XYPlot} and
061 *     {@link XYBlockRenderer}.
062 */
063public class StandardContourToolTipGenerator implements ContourToolTipGenerator,
064                                                        Serializable {
065
066    /** For serialization. */
067    private static final long serialVersionUID = -1881659351247502711L;
068
069    /** The number formatter. */
070    private DecimalFormat valueForm = new DecimalFormat("##.###");
071
072    /**
073     * Generates a tooltip text item for a particular item within a series.
074     *
075     * @param data  the dataset.
076     * @param item  the item index (zero-based).
077     *
078     * @return The tooltip text.
079     */
080    @Override
081    public String generateToolTip(ContourDataset data, int item) {
082
083        double x = data.getXValue(0, item);
084        double y = data.getYValue(0, item);
085        double z = data.getZValue(0, item);
086        String xString;
087
088        if (data.isDateAxis(0)) {
089            SimpleDateFormat formatter
090                = new java.text.SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
091            StringBuffer strbuf = new StringBuffer();
092            strbuf = formatter.format(
093                new Date((long) x), strbuf, new java.text.FieldPosition(0)
094            );
095            xString = strbuf.toString();
096        }
097        else {
098            xString = this.valueForm.format(x);
099        }
100        if (!Double.isNaN(z)) {
101            return "X: " + xString
102                   + ", Y: " + this.valueForm.format(y)
103                   + ", Z: " + this.valueForm.format(z);
104        }
105        else {
106            return "X: " + xString
107                 + ", Y: " + this.valueForm.format(y)
108                 + ", Z: no data";
109        }
110
111    }
112
113    /**
114     * Tests if this object is equal to another.
115     *
116     * @param obj  the other object.
117     *
118     * @return A boolean.
119     */
120    @Override
121    public boolean equals(Object obj) {
122        if (obj == this) {
123            return true;
124        }
125        if (!(obj instanceof StandardContourToolTipGenerator)) {
126            return false;
127        }
128        StandardContourToolTipGenerator that
129                = (StandardContourToolTipGenerator) obj;
130        if (this.valueForm != null) {
131            return this.valueForm.equals(that.valueForm);
132        }
133        return false;
134    }
135
136}