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