    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     * StandardCategoryToolTipGenerator.java
    029     * -------------------------------------
    030     * (C) Copyright 2004-2007, by Object Refinery Limited.
    031     *
    032     * Original Author:  David Gilbert (for Object Refinery Limited);
    033     * Contributor(s):   -;
    034     *
    035     * Changes
    036     * -------
    037     * 11-May-2004 : Version 1 (DG);
    038     * ------------- JFREECHART 1.0.x ---------------------------------------------
    039     * 03-May-2006 : Added equals() method to fix bug 1481087 (DG);
    040     *
    041     */
    042
    043    package org.jfree.chart.labels;
    044
    045    import java.io.Serializable;
    046    import java.text.DateFormat;
    047    import java.text.NumberFormat;
    048
    049    import org.jfree.data.category.CategoryDataset;
    050
    051    /**
    052     * A standard tool tip generator that can be used with a
    053     * {@link org.jfree.chart.renderer.category.CategoryItemRenderer}.
    054     */
    055    public class StandardCategoryToolTipGenerator
    056            extends AbstractCategoryItemLabelGenerator
    057            implements CategoryToolTipGenerator, Serializable {
    058
    059        /** For serialization. */
    060        private static final long serialVersionUID = -6768806592218710764L;
    061
    062        /** The default format string. */
    063        public static final String DEFAULT_TOOL_TIP_FORMAT_STRING
    064                = "({0}, {1}) = {2}";
    065
    066        /**
    067         * Creates a new generator with a default number formatter.
    068         */
    069        public StandardCategoryToolTipGenerator() {
    070            super(DEFAULT_TOOL_TIP_FORMAT_STRING, NumberFormat.getInstance());
    071        }
    072
    073        /**
    074         * Creates a new generator with the specified number formatter.
    075         *
    076         * @param labelFormat  the label format string (<code>null</code> not
    077         *                     permitted).
    078         * @param formatter  the number formatter (<code>null</code> not permitted).
    079         */
    080        public StandardCategoryToolTipGenerator(String labelFormat,
    081                                                NumberFormat formatter) {
    082            super(labelFormat, formatter);
    083        }
    084
    085        /**
    086         * Creates a new generator with the specified date formatter.
    087         *
    088         * @param labelFormat  the label format string (<code>null</code> not
    089         *                     permitted).
    090         * @param formatter  the date formatter (<code>null</code> not permitted).
    091         */
    092        public StandardCategoryToolTipGenerator(String labelFormat,
    093                                                DateFormat formatter) {
    094            super(labelFormat, formatter);
    095        }
    096
    097        /**
    098         * Generates the tool tip text for an item in a dataset.  Note: in the
    099         * current dataset implementation, each row is a series, and each column
    100         * contains values for a particular category.
    101         *
    102         * @param dataset  the dataset (<code>null</code> not permitted).
    103         * @param row  the row index (zero-based).
    104         * @param column  the column index (zero-based).
    105         *
    106         * @return The tooltip text (possibly <code>null</code>).
    107         */
    108        public String generateToolTip(CategoryDataset dataset,
    109                                      int row, int column) {
    110            return generateLabelString(dataset, row, column);
    111        }
    112
    113        /**
    114         * Tests this generator for equality with an arbitrary object.
    115         *
    116         * @param obj  the object (<code>null</code> permitted).
    117         *
    118         * @return A boolean.
    119         */
    120        public boolean equals(Object obj) {
    121            if (obj == this) {
    122                return true;
    123            }
    124            if (!(obj instanceof StandardCategoryToolTipGenerator)) {
    125                return false;
    126            }
    127            return super.equals(obj);
    128        }
    129
    130    }