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: * StandardXYItemLabelGenerator.java
029: * ---------------------------------
030: * (C) Copyright 2001-2007, by Object Refinery Limited.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: StandardXYItemLabelGenerator.java,v 1.2.2.3 2007/02/02 11:07:00 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 13-Dec-2001 : Version 1 (DG);
040: * 16-Jan-2002 : Completed Javadocs (DG);
041: * 02-Apr-2002 : Modified to handle null y-values (DG);
042: * 09-Apr-2002 : Added formatting objects for the x and y values (DG);
043: * 30-May-2002 : Added series name to standard tool tip (DG);
044: * 26-Sep-2002 : Fixed errors reported by Checkstyle (DG);
045: * 23-Mar-2003 : Implemented Serializable (DG);
046: * 13-Aug-2003 : Implemented Cloneable (DG);
047: * 17-Nov-2003 : Implemented PublicCloneable (DG);
048: * 25-Feb-2004 : Renamed XYToolTipGenerator --> XYItemLabelGenerator and
049: * StandardXYToolTipGenerator -->
050: * StandardXYItemLabelGenerator (DG);
051: * 26-Feb-2004 : Modified to use MessageFormat (DG);
052: * 27-Feb-2004 : Added abstract superclass (DG);
053: * 11-May-2004 : Split into StandardXYToolTipGenerator and
054: * StandardXYLabelGenerator (DG);
055: * 20-Apr-2005 : Renamed StandardXYLabelGenerator
056: * --> StandardXYItemLabelGenerator (DG);
057: * ------------- JFREECHART 1.0.x ---------------------------------------------
058: * 25-Jan-2007 : Added new constructor - see bug 1624067 (DG);
059: *
060: */
061:
062: package org.jfree.chart.labels;
063:
064: import java.io.Serializable;
065: import java.text.DateFormat;
066: import java.text.NumberFormat;
067:
068: import org.jfree.data.xy.XYDataset;
069: import org.jfree.util.PublicCloneable;
070:
071: /**
072: * A standard item label generator for plots that use data from an
073: * {@link org.jfree.data.xy.XYDataset}.
074: */
075: public class StandardXYItemLabelGenerator extends
076: AbstractXYItemLabelGenerator implements XYItemLabelGenerator,
077: Cloneable, PublicCloneable, Serializable {
078:
079: /** For serialization. */
080: private static final long serialVersionUID = 7807668053171837925L;
081:
082: /** The default item label format. */
083: public static final String DEFAULT_ITEM_LABEL_FORMAT = "{2}";
084:
085: /**
086: * Creates an item label generator using default number formatters.
087: */
088: public StandardXYItemLabelGenerator() {
089: this (DEFAULT_ITEM_LABEL_FORMAT, NumberFormat
090: .getNumberInstance(), NumberFormat.getNumberInstance());
091: }
092:
093: /**
094: * Creates an item label generator using the specified number formatters.
095: *
096: * @param formatString the item label format string (<code>null</code> not
097: * permitted).
098: * @param xFormat the format object for the x values (<code>null</code>
099: * not permitted).
100: * @param yFormat the format object for the y values (<code>null</code>
101: * not permitted).
102: */
103: public StandardXYItemLabelGenerator(String formatString,
104: NumberFormat xFormat, NumberFormat yFormat) {
105:
106: super (formatString, xFormat, yFormat);
107: }
108:
109: /**
110: * Creates an item label generator using the specified formatters.
111: *
112: * @param formatString the item label format string (<code>null</code>
113: * not permitted).
114: * @param xFormat the format object for the x values (<code>null</code>
115: * not permitted).
116: * @param yFormat the format object for the y values (<code>null</code>
117: * not permitted).
118: */
119: public StandardXYItemLabelGenerator(String formatString,
120: DateFormat xFormat, NumberFormat yFormat) {
121:
122: super (formatString, xFormat, yFormat);
123: }
124:
125: /**
126: * Creates an item label generator using the specified formatters (a
127: * number formatter for the x-values and a date formatter for the
128: * y-values).
129: *
130: * @param formatString the item label format string (<code>null</code>
131: * not permitted).
132: * @param xFormat the format object for the x values (<code>null</code>
133: * permitted).
134: * @param yFormat the format object for the y values (<code>null</code>
135: * not permitted).
136: *
137: * @since 1.0.4
138: */
139: public StandardXYItemLabelGenerator(String formatString,
140: NumberFormat xFormat, DateFormat yFormat) {
141:
142: super (formatString, xFormat, yFormat);
143: }
144:
145: /**
146: * Creates a label generator using the specified date formatters.
147: *
148: * @param formatString the label format string (<code>null</code> not
149: * permitted).
150: * @param xFormat the format object for the x values (<code>null</code>
151: * not permitted).
152: * @param yFormat the format object for the y values (<code>null</code>
153: * not permitted).
154: */
155: public StandardXYItemLabelGenerator(String formatString,
156: DateFormat xFormat, DateFormat yFormat) {
157:
158: super (formatString, xFormat, yFormat);
159: }
160:
161: /**
162: * Generates the item label text for an item in a dataset.
163: *
164: * @param dataset the dataset (<code>null</code> not permitted).
165: * @param series the series index (zero-based).
166: * @param item the item index (zero-based).
167: *
168: * @return The label text (possibly <code>null</code>).
169: */
170: public String generateLabel(XYDataset dataset, int series, int item) {
171: return generateLabelString(dataset, series, item);
172: }
173:
174: /**
175: * Returns an independent copy of the generator.
176: *
177: * @return A clone.
178: *
179: * @throws CloneNotSupportedException if cloning is not supported.
180: */
181: public Object clone() throws CloneNotSupportedException {
182: return super .clone();
183: }
184:
185: /**
186: * Tests this object for equality with an arbitrary object.
187: *
188: * @param obj the other object (<code>null</code> permitted).
189: *
190: * @return A boolean.
191: */
192: public boolean equals(Object obj) {
193: if (obj == this ) {
194: return true;
195: }
196: if (!(obj instanceof StandardXYItemLabelGenerator)) {
197: return false;
198: }
199: return super.equals(obj);
200: }
201:
202: }
|