001/* ===========================================================
002 * JFreeChart : a free chart library for the Java(tm) platform
003 * ===========================================================
004 *
005 * (C) Copyright 2000-2020, 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 * StandardCategoryItemLabelGenerator.java
029 * ---------------------------------------
030 * (C) Copyright 2004-2020, by Object Refinery Limited.
031 *
032 * Original Author:  David Gilbert (for Object Refinery Limited);
033 * Contributor(s):   -;
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     * @since 1.0.2
090     */
091    public StandardCategoryItemLabelGenerator(String labelFormat,
092            NumberFormat formatter, NumberFormat percentFormatter) {
093        super(labelFormat, formatter, percentFormatter);
094    }
095
096    /**
097     * Creates a new generator with the specified date formatter.
098     *
099     * @param labelFormat  the label format string ({@code null} not
100     *                     permitted).
101     * @param formatter  the date formatter ({@code null} not permitted).
102     */
103    public StandardCategoryItemLabelGenerator(String labelFormat,
104                                              DateFormat formatter) {
105        super(labelFormat, formatter);
106    }
107
108    /**
109     * Generates the label for an item in a dataset.  Note: in the current
110     * dataset implementation, each row is a series, and each column contains
111     * values for a particular category.
112     *
113     * @param dataset  the dataset ({@code null} not permitted).
114     * @param row  the row index (zero-based).
115     * @param column  the column index (zero-based).
116     *
117     * @return The label (possibly {@code null}).
118     */
119    @Override
120    public String generateLabel(CategoryDataset dataset, int row, int column) {
121        return generateLabelString(dataset, row, column);
122    }
123
124    /**
125     * Tests this generator for equality with an arbitrary object.
126     *
127     * @param obj  the object ({@code null} permitted).
128     *
129     * @return {@code true} if this generator is equal to
130     *     {@code obj}, and {@code false} otherwise.
131     */
132    @Override
133    public boolean equals(Object obj) {
134        if (obj == this) {
135            return true;
136        }
137        if (!(obj instanceof StandardCategoryItemLabelGenerator)) {
138            return false;
139        }
140        return super.equals(obj);
141    }
142}