Source for org.jfree.chart.labels.StandardCategoryToolTipGenerator

   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:  * StandardCategoryToolTipGenerator.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:  * Changes
  36:  * -------
  37:  * 11-May-2004 : Version 1 (DG);
  38:  * ------------- JFREECHART 1.0.x ---------------------------------------------
  39:  * 03-May-2006 : Added equals() method to fix bug 1481087 (DG);
  40:  *
  41:  */
  42: 
  43: package org.jfree.chart.labels;
  44: 
  45: import java.io.Serializable;
  46: import java.text.DateFormat;
  47: import java.text.NumberFormat;
  48: 
  49: import org.jfree.data.category.CategoryDataset;
  50: 
  51: /**
  52:  * A standard tool tip generator that can be used with a 
  53:  * {@link org.jfree.chart.renderer.category.CategoryItemRenderer}.
  54:  */
  55: public class StandardCategoryToolTipGenerator 
  56:         extends AbstractCategoryItemLabelGenerator 
  57:         implements CategoryToolTipGenerator, Serializable {
  58: 
  59:     /** For serialization. */
  60:     private static final long serialVersionUID = -6768806592218710764L;
  61:     
  62:     /** The default format string. */
  63:     public static final String DEFAULT_TOOL_TIP_FORMAT_STRING 
  64:             = "({0}, {1}) = {2}";
  65:     
  66:     /**
  67:      * Creates a new generator with a default number formatter.
  68:      */
  69:     public StandardCategoryToolTipGenerator() {
  70:         super(DEFAULT_TOOL_TIP_FORMAT_STRING, NumberFormat.getInstance());
  71:     }
  72: 
  73:     /**
  74:      * Creates a new generator with the specified number formatter.
  75:      *
  76:      * @param labelFormat  the label format string (<code>null</code> not 
  77:      *                     permitted).
  78:      * @param formatter  the number formatter (<code>null</code> not permitted).
  79:      */
  80:     public StandardCategoryToolTipGenerator(String labelFormat, 
  81:                                             NumberFormat formatter) {
  82:         super(labelFormat, formatter);
  83:     }
  84:     
  85:     /**
  86:      * Creates a new generator with the specified date formatter.
  87:      *
  88:      * @param labelFormat  the label format string (<code>null</code> not 
  89:      *                     permitted).
  90:      * @param formatter  the date formatter (<code>null</code> not permitted).
  91:      */
  92:     public StandardCategoryToolTipGenerator(String labelFormat, 
  93:                                             DateFormat formatter) {
  94:         super(labelFormat, formatter);
  95:     }
  96:     
  97:     /**
  98:      * Generates the tool tip text for an item in a dataset.  Note: in the 
  99:      * current dataset implementation, each row is a series, and each column 
 100:      * contains values for a particular category.
 101:      *
 102:      * @param dataset  the dataset (<code>null</code> not permitted).
 103:      * @param row  the row index (zero-based).
 104:      * @param column  the column index (zero-based).
 105:      *
 106:      * @return The tooltip text (possibly <code>null</code>).
 107:      */
 108:     public String generateToolTip(CategoryDataset dataset, 
 109:                                   int row, int column) {
 110:         return generateLabelString(dataset, row, column);
 111:     }
 112:     
 113:     /**
 114:      * Tests this generator for equality with an arbitrary object.
 115:      * 
 116:      * @param obj  the object (<code>null</code> permitted).
 117:      * 
 118:      * @return A boolean.
 119:      */
 120:     public boolean equals(Object obj) {
 121:         if (obj == this) {
 122:             return true;
 123:         }
 124:         if (!(obj instanceof StandardCategoryToolTipGenerator)) {
 125:             return false;
 126:         }
 127:         return super.equals(obj);
 128:     }
 129: 
 130: }