001/* ===========================================================
002 * JFreeChart : a free chart library for the Java(tm) platform
003 * ===========================================================
004 *
005 * (C) Copyright 2000-present, by David Gilbert 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 * StandardCategoryToolTipGenerator.java
029 * -------------------------------------
030 * (C) Copyright 2004-present, by David Gilbert.
031 *
032 * Original Author:  David Gilbert;
033 * Contributor(s):   Tracy Hiltbrand (equals/hashCode comply with EqualsVerifier);
034 *
035 */
036
037package org.jfree.chart.labels;
038
039import java.io.Serializable;
040import java.text.DateFormat;
041import java.text.NumberFormat;
042
043import org.jfree.data.category.CategoryDataset;
044
045/**
046 * A standard tool tip generator that can be used with a
047 * {@link org.jfree.chart.renderer.category.CategoryItemRenderer}.
048 */
049public class StandardCategoryToolTipGenerator
050        extends AbstractCategoryItemLabelGenerator
051        implements CategoryToolTipGenerator, Serializable {
052
053    /** For serialization. */
054    private static final long serialVersionUID = -6768806592218710764L;
055
056    /** The default format string. */
057    public static final String DEFAULT_TOOL_TIP_FORMAT_STRING
058            = "({0}, {1}) = {2}";
059
060    /**
061     * Creates a new generator with a default number formatter.
062     */
063    public StandardCategoryToolTipGenerator() {
064        super(DEFAULT_TOOL_TIP_FORMAT_STRING, NumberFormat.getInstance());
065    }
066
067    /**
068     * Creates a new generator with the specified number formatter.
069     *
070     * @param labelFormat  the label format string ({@code null} not
071     *                     permitted).
072     * @param formatter  the number formatter ({@code null} not permitted).
073     */
074    public StandardCategoryToolTipGenerator(String labelFormat,
075                                            NumberFormat formatter) {
076        super(labelFormat, formatter);
077    }
078
079    /**
080     * Creates a new generator with the specified date formatter.
081     *
082     * @param labelFormat  the label format string ({@code null} not
083     *                     permitted).
084     * @param formatter  the date formatter ({@code null} not permitted).
085     */
086    public StandardCategoryToolTipGenerator(String labelFormat,
087                                            DateFormat formatter) {
088        super(labelFormat, formatter);
089    }
090
091    /**
092     * Generates the tool tip text for an item in a dataset.  Note: in the
093     * current dataset implementation, each row is a series, and each column
094     * contains values for a particular category.
095     *
096     * @param dataset  the dataset ({@code null} not permitted).
097     * @param row  the row index (zero-based).
098     * @param column  the column index (zero-based).
099     *
100     * @return The tooltip text (possibly {@code null}).
101     */
102    @Override
103    public String generateToolTip(CategoryDataset dataset,
104                                  int row, int column) {
105        return generateLabelString(dataset, row, column);
106    }
107
108    /**
109     * Tests this generator for equality with an arbitrary object.
110     *
111     * @param obj  the object ({@code null} permitted).
112     *
113     * @return A boolean.
114     */
115    @Override
116    public boolean equals(Object obj) {
117        if (obj == this) {
118            return true;
119        }
120        if (!(obj instanceof StandardCategoryToolTipGenerator)) {
121            return false;
122        }
123        StandardCategoryToolTipGenerator that = (StandardCategoryToolTipGenerator) obj;
124        if (!that.canEqual(this)) {
125            return false;
126        }
127        return super.equals(obj);
128    }
129
130    /**
131     * Ensures symmetry between super/subclass implementations of equals. For
132     * more detail, see http://jqno.nl/equalsverifier/manual/inheritance.
133     *
134     * @param other Object
135     * 
136     * @return true ONLY if the parameter is THIS class type
137     */
138    @Override
139    public boolean canEqual(Object other) {
140        // fix the "equals not symmetric" problem
141        return (other instanceof StandardCategoryToolTipGenerator);
142    }
143
144    @Override
145    public int hashCode() {
146        int hash = super.hashCode(); // equals calls superclass, hashCode must also
147        return hash;
148    }
149
150}