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 * StandardCategoryItemLabelGenerator.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;
042import org.jfree.chart.util.PublicCloneable;
043
044import org.jfree.data.category.CategoryDataset;
045
046/**
047 * A standard label generator that can be used with a
048 * {@link org.jfree.chart.renderer.category.CategoryItemRenderer}.
049 */
050public class StandardCategoryItemLabelGenerator
051    extends AbstractCategoryItemLabelGenerator
052    implements CategoryItemLabelGenerator, Cloneable, PublicCloneable,
053               Serializable {
054
055    /** For serialization. */
056    private static final long serialVersionUID = 3499701401211412882L;
057
058    /** The default format string. */
059    public static final String DEFAULT_LABEL_FORMAT_STRING = "{2}";
060
061    /**
062     * Creates a new generator with a default number formatter.
063     */
064    public StandardCategoryItemLabelGenerator() {
065        super(DEFAULT_LABEL_FORMAT_STRING, NumberFormat.getInstance());
066    }
067
068    /**
069     * Creates a new generator with the specified number formatter.
070     *
071     * @param labelFormat  the label format string ({@code null} not
072     *                     permitted).
073     * @param formatter  the number formatter ({@code null} not permitted).
074     */
075    public StandardCategoryItemLabelGenerator(String labelFormat,
076                                              NumberFormat formatter) {
077        super(labelFormat, formatter);
078    }
079
080    /**
081     * Creates a new generator with the specified number formatter.
082     *
083     * @param labelFormat  the label format string ({@code null} not
084     *                     permitted).
085     * @param formatter  the number formatter ({@code null} not permitted).
086     * @param percentFormatter  the percent formatter ({@code null} not
087     *     permitted).
088     */
089    public StandardCategoryItemLabelGenerator(String labelFormat,
090            NumberFormat formatter, NumberFormat percentFormatter) {
091        super(labelFormat, formatter, percentFormatter);
092    }
093
094    /**
095     * Creates a new generator with the specified date formatter.
096     *
097     * @param labelFormat  the label format string ({@code null} not
098     *                     permitted).
099     * @param formatter  the date formatter ({@code null} not permitted).
100     */
101    public StandardCategoryItemLabelGenerator(String labelFormat,
102                                              DateFormat formatter) {
103        super(labelFormat, formatter);
104    }
105
106    /**
107     * Generates the label for an item in a dataset.  Note: in the current
108     * dataset implementation, each row is a series, and each column contains
109     * values for a particular category.
110     *
111     * @param dataset  the dataset ({@code null} not permitted).
112     * @param row  the row index (zero-based).
113     * @param column  the column index (zero-based).
114     *
115     * @return The label (possibly {@code null}).
116     */
117    @Override
118    public String generateLabel(CategoryDataset dataset, int row, int column) {
119        return generateLabelString(dataset, row, column);
120    }
121
122    /**
123     * Tests this generator for equality with an arbitrary object.
124     *
125     * @param obj  the object ({@code null} permitted).
126     *
127     * @return {@code true} if this generator is equal to
128     *     {@code obj}, and {@code false} otherwise.
129     */
130    @Override
131    public boolean equals(Object obj) {
132        if (obj == this) {
133            return true;
134        }
135        if (!(obj instanceof StandardCategoryItemLabelGenerator)) {
136            return false;
137        }
138        StandardCategoryItemLabelGenerator that = (StandardCategoryItemLabelGenerator) obj;
139        if (!that.canEqual(this)) {
140            return false;
141        }
142        return super.equals(obj);
143    }
144    @Override
145    public boolean canEqual(Object other) {
146        // fix the "equals not symmetric" problem
147        return (other instanceof StandardCategoryItemLabelGenerator);
148    }
149
150    @Override
151    public int hashCode() {
152        int hash = super.hashCode();
153        return hash;
154    }
155
156}