Frames | No Frames |
1: /* =========================================================== 2: * JFreeChart : a free chart library for the Java(tm) platform 3: * =========================================================== 4: * 5: * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. 6: * 7: * Project Info: http://www.jfree.org/jfreechart/index.html 8: * 9: * This library is free software; you can redistribute it and/or modify it 10: * under the terms of the GNU Lesser General Public License as published by 11: * the Free Software Foundation; either version 2.1 of the License, or 12: * (at your option) any later version. 13: * 14: * This library is distributed in the hope that it will be useful, but 15: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17: * License for more details. 18: * 19: * You should have received a copy of the GNU Lesser General Public 20: * License along with this library; if not, write to the Free Software 21: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22: * USA. 23: * 24: * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 25: * in the United States and other countries.] 26: * 27: * ------------------------------- 28: * StandardXYToolTipGenerator.java 29: * ------------------------------- 30: * (C) Copyright 2004-2007, by Object Refinery Limited. 31: * 32: * Original Author: David Gilbert (for Object Refinery Limited); 33: * Contributor(s): -; 34: * 35: * $Id: StandardXYToolTipGenerator.java,v 1.3.2.3 2007/02/02 11:07:00 mungady Exp $ 36: * 37: * Changes 38: * ------- 39: * 12-May-2004 : Version 1 (DG); 40: * ------------- JFREECHART 1.0.x --------------------------------------------- 41: * 25-Jan-2007 : Added new constructor - see bug 1624067 (DG); 42: * 43: */ 44: 45: package org.jfree.chart.labels; 46: 47: import java.io.Serializable; 48: import java.text.DateFormat; 49: import java.text.NumberFormat; 50: 51: import org.jfree.data.xy.XYDataset; 52: import org.jfree.util.PublicCloneable; 53: 54: /** 55: * A standard tool tip generator for use with an 56: * {@link org.jfree.chart.renderer.xy.XYItemRenderer}. 57: */ 58: public class StandardXYToolTipGenerator extends AbstractXYItemLabelGenerator 59: implements XYToolTipGenerator, 60: Cloneable, 61: PublicCloneable, 62: Serializable { 63: 64: /** For serialization. */ 65: private static final long serialVersionUID = -3564164459039540784L; 66: 67: /** The default tooltip format. */ 68: public static final String DEFAULT_TOOL_TIP_FORMAT = "{0}: ({1}, {2})"; 69: 70: /** 71: * Returns a tool tip generator that formats the x-values as dates and the 72: * y-values as numbers. 73: * 74: * @return A tool tip generator (never <code>null</code>). 75: */ 76: public static StandardXYToolTipGenerator getTimeSeriesInstance() { 77: return new StandardXYToolTipGenerator(DEFAULT_TOOL_TIP_FORMAT, 78: DateFormat.getInstance(), NumberFormat.getInstance()); 79: } 80: 81: /** 82: * Creates a tool tip generator using default number formatters. 83: */ 84: public StandardXYToolTipGenerator() { 85: this(DEFAULT_TOOL_TIP_FORMAT, NumberFormat.getNumberInstance(), 86: NumberFormat.getNumberInstance()); 87: } 88: 89: /** 90: * Creates a tool tip generator using the specified number formatters. 91: * 92: * @param formatString the item label format string (<code>null</code> not 93: * permitted). 94: * @param xFormat the format object for the x values (<code>null</code> 95: * not permitted). 96: * @param yFormat the format object for the y values (<code>null</code> 97: * not permitted). 98: */ 99: public StandardXYToolTipGenerator(String formatString, NumberFormat xFormat, 100: NumberFormat yFormat) { 101: 102: super(formatString, xFormat, yFormat); 103: 104: } 105: 106: /** 107: * Creates a tool tip generator using the specified number formatters. 108: * 109: * @param formatString the label format string (<code>null</code> not 110: * permitted). 111: * @param xFormat the format object for the x values (<code>null</code> 112: * not permitted). 113: * @param yFormat the format object for the y values (<code>null</code> 114: * not permitted). 115: */ 116: public StandardXYToolTipGenerator(String formatString, DateFormat xFormat, 117: NumberFormat yFormat) { 118: 119: super(formatString, xFormat, yFormat); 120: 121: } 122: 123: /** 124: * Creates a tool tip generator using the specified formatters (a 125: * number formatter for the x-values and a date formatter for the 126: * y-values). 127: * 128: * @param formatString the item label format string (<code>null</code> 129: * not permitted). 130: * @param xFormat the format object for the x values (<code>null</code> 131: * permitted). 132: * @param yFormat the format object for the y values (<code>null</code> 133: * not permitted). 134: * 135: * @since 1.0.4 136: */ 137: public StandardXYToolTipGenerator(String formatString, 138: NumberFormat xFormat, DateFormat yFormat) { 139: 140: super(formatString, xFormat, yFormat); 141: } 142: /** 143: * Creates a tool tip generator using the specified date formatters. 144: * 145: * @param formatString the label format string (<code>null</code> not 146: * permitted). 147: * @param xFormat the format object for the x values (<code>null</code> 148: * not permitted). 149: * @param yFormat the format object for the y values (<code>null</code> 150: * not permitted). 151: */ 152: public StandardXYToolTipGenerator(String formatString, 153: DateFormat xFormat, DateFormat yFormat) { 154: 155: super(formatString, xFormat, yFormat); 156: 157: } 158: 159: /** 160: * Generates the tool tip text for an item in a dataset. 161: * 162: * @param dataset the dataset (<code>null</code> not permitted). 163: * @param series the series index (zero-based). 164: * @param item the item index (zero-based). 165: * 166: * @return The tooltip text (possibly <code>null</code>). 167: */ 168: public String generateToolTip(XYDataset dataset, int series, 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: }