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