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 * StandardXYItemLabelGenerator.java
029 * ---------------------------------
030 * (C) Copyright 2001-present, by David Gilbert.
031 *
032 * Original Author:  David Gilbert;
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.xy.XYDataset;
045
046/**
047 * A standard item label generator for plots that use data from an
048 * {@link org.jfree.data.xy.XYDataset}.
049 */
050public class StandardXYItemLabelGenerator extends AbstractXYItemLabelGenerator
051            implements XYItemLabelGenerator, Cloneable, PublicCloneable,
052            Serializable {
053
054    /** For serialization. */
055    private static final long serialVersionUID = 7807668053171837925L;
056
057    /** The default item label format. */
058    public static final String DEFAULT_ITEM_LABEL_FORMAT = "{2}";
059
060    /**
061     * Creates an item label generator using default number formatters.
062     */
063    public StandardXYItemLabelGenerator() {
064        this(DEFAULT_ITEM_LABEL_FORMAT, NumberFormat.getNumberInstance(),
065                NumberFormat.getNumberInstance());
066    }
067
068    /**
069     * Creates an item label generator using the specified number formatters.
070     *
071     * @param formatString  the item label format string ({@code null} not
072     *                      permitted).
073     */
074    public StandardXYItemLabelGenerator(String formatString) {
075        this(formatString, NumberFormat.getNumberInstance(),
076                NumberFormat.getNumberInstance());
077    }
078
079    /**
080     * Creates an item label generator using the specified number formatters.
081     *
082     * @param formatString  the item label format string ({@code null} not
083     *                      permitted).
084     * @param xFormat  the format object for the x values ({@code null}
085     *                 not permitted).
086     * @param yFormat  the format object for the y values ({@code null}
087     *                 not permitted).
088     */
089    public StandardXYItemLabelGenerator(String formatString,
090            NumberFormat xFormat, NumberFormat yFormat) {
091
092        super(formatString, xFormat, yFormat);
093    }
094
095    /**
096     * Creates an item label generator using the specified formatters.
097     *
098     * @param formatString  the item label format string ({@code null}
099     *                      not permitted).
100     * @param xFormat  the format object for the x values ({@code null}
101     *                 not permitted).
102     * @param yFormat  the format object for the y values ({@code null}
103     *                 not permitted).
104     */
105    public StandardXYItemLabelGenerator(String formatString,
106            DateFormat xFormat, NumberFormat yFormat) {
107
108        super(formatString, xFormat, yFormat);
109    }
110
111    /**
112     * Creates an item label generator using the specified formatters (a
113     * number formatter for the x-values and a date formatter for the
114     * y-values).
115     *
116     * @param formatString  the item label format string ({@code null}
117     *                      not permitted).
118     * @param xFormat  the format object for the x values ({@code null}
119     *                 permitted).
120     * @param yFormat  the format object for the y values ({@code null}
121     *                 not permitted).
122     */
123    public StandardXYItemLabelGenerator(String formatString,
124            NumberFormat xFormat, DateFormat yFormat) {
125
126        super(formatString, xFormat, yFormat);
127    }
128
129    /**
130     * Creates a label generator using the specified date formatters.
131     *
132     * @param formatString  the label format string ({@code null} not
133     *                      permitted).
134     * @param xFormat  the format object for the x values ({@code null}
135     *                 not permitted).
136     * @param yFormat  the format object for the y values ({@code null}
137     *                 not permitted).
138     */
139    public StandardXYItemLabelGenerator(String formatString,
140            DateFormat xFormat, DateFormat yFormat) {
141
142        super(formatString, xFormat, yFormat);
143    }
144
145    /**
146     * Generates the item label text for an item in a dataset.
147     *
148     * @param dataset  the dataset ({@code null} not permitted).
149     * @param series  the series index (zero-based).
150     * @param item  the item index (zero-based).
151     *
152     * @return The label text (possibly {@code null}).
153     */
154    @Override
155    public String generateLabel(XYDataset dataset, int series, int item) {
156        return generateLabelString(dataset, series, item);
157    }
158
159    /**
160     * Returns an independent copy of the generator.
161     *
162     * @return A clone.
163     *
164     * @throws CloneNotSupportedException if cloning is not supported.
165     */
166    @Override
167    public Object clone() throws CloneNotSupportedException {
168        return super.clone();
169    }
170
171    /**
172     * Tests this object for equality with an arbitrary object.
173     *
174     * @param obj  the other object ({@code null} permitted).
175     *
176     * @return A boolean.
177     */
178    @Override
179    public boolean equals(Object obj) {
180        if (obj == this) {
181            return true;
182        }
183        if (!(obj instanceof StandardXYItemLabelGenerator)) {
184            return false;
185        }
186        return super.equals(obj);
187    }
188
189}