    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     * 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
    044    package org.jfree.chart.labels;
    045
    046    import java.io.Serializable;
    047    import java.text.DecimalFormat;
    048    import java.text.SimpleDateFormat;
    049    import java.util.Date;
    050
    051    import org.jfree.chart.plot.XYPlot;
    052    import org.jfree.chart.renderer.xy.XYBlockRenderer;
    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).  If
    060     *     you are creating contour plots, please try to use {@link XYPlot} and
    061     *     {@link XYBlockRenderer}.
    062     */
    063    public 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        public String generateToolTip(ContourDataset data, int item) {
    081
    082            double x = data.getXValue(0, item);
    083            double y = data.getYValue(0, item);
    084            double z = data.getZValue(0, item);
    085            String xString = null;
    086
    087            if (data.isDateAxis(0)) {
    088                SimpleDateFormat formatter
    089                    = new java.text.SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
    090                StringBuffer strbuf = new StringBuffer();
    091                strbuf = formatter.format(
    092                    new Date((long) x), strbuf, new java.text.FieldPosition(0)
    093                );
    094                xString = strbuf.toString();
    095            }
    096            else {
    097                xString = this.valueForm.format(x);
    098            }
    099            if (!Double.isNaN(z)) {
    100                return "X: " + xString
    101                       + ", Y: " + this.valueForm.format(y)
    102                       + ", Z: " + this.valueForm.format(z);
    103            }
    104            else {
    105                return "X: " + xString
    106                     + ", Y: " + this.valueForm.format(y)
    107                     + ", Z: no data";
    108            }
    109
    110        }
    111
    112        /**
    113         * Tests if this object is equal to another.
    114         *
    115         * @param obj  the other object.
    116         *
    117         * @return A boolean.
    118         */
    119        public boolean equals(Object obj) {
    120
    121            if (obj == this) {
    122                return true;
    123            }
    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
    137    }