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