Source for org.jfree.chart.labels.StandardXYItemLabelGenerator

   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:  * StandardXYItemLabelGenerator.java
  29:  * ---------------------------------
  30:  * (C) Copyright 2001-2007, by Object Refinery Limited.
  31:  *
  32:  * Original Author:  David Gilbert (for Object Refinery Limited);
  33:  * Contributor(s):   -;
  34:  *
  35:  * $Id: StandardXYItemLabelGenerator.java,v 1.2.2.3 2007/02/02 11:07:00 mungady Exp $
  36:  *
  37:  * Changes
  38:  * -------
  39:  * 13-Dec-2001 : Version 1 (DG);
  40:  * 16-Jan-2002 : Completed Javadocs (DG);
  41:  * 02-Apr-2002 : Modified to handle null y-values (DG);
  42:  * 09-Apr-2002 : Added formatting objects for the x and y values (DG);
  43:  * 30-May-2002 : Added series name to standard tool tip (DG);
  44:  * 26-Sep-2002 : Fixed errors reported by Checkstyle (DG);
  45:  * 23-Mar-2003 : Implemented Serializable (DG);
  46:  * 13-Aug-2003 : Implemented Cloneable (DG);
  47:  * 17-Nov-2003 : Implemented PublicCloneable (DG);
  48:  * 25-Feb-2004 : Renamed XYToolTipGenerator --> XYItemLabelGenerator and
  49:  *               StandardXYToolTipGenerator --> 
  50:  *               StandardXYItemLabelGenerator (DG);
  51:  * 26-Feb-2004 : Modified to use MessageFormat (DG);
  52:  * 27-Feb-2004 : Added abstract superclass (DG);
  53:  * 11-May-2004 : Split into StandardXYToolTipGenerator and 
  54:  *               StandardXYLabelGenerator (DG);
  55:  * 20-Apr-2005 : Renamed StandardXYLabelGenerator 
  56:  *               --> StandardXYItemLabelGenerator (DG);
  57:  * ------------- JFREECHART 1.0.x ---------------------------------------------
  58:  * 25-Jan-2007 : Added new constructor - see bug 1624067 (DG);
  59:  * 
  60:  */
  61: 
  62: package org.jfree.chart.labels;
  63: 
  64: import java.io.Serializable;
  65: import java.text.DateFormat;
  66: import java.text.NumberFormat;
  67: 
  68: import org.jfree.data.xy.XYDataset;
  69: import org.jfree.util.PublicCloneable;
  70: 
  71: /**
  72:  * A standard item label generator for plots that use data from an 
  73:  * {@link org.jfree.data.xy.XYDataset}.
  74:  */
  75: public class StandardXYItemLabelGenerator extends AbstractXYItemLabelGenerator  
  76:                                           implements XYItemLabelGenerator, 
  77:                                                      Cloneable, 
  78:                                                      PublicCloneable,
  79:                                                      Serializable {
  80: 
  81:     /** For serialization. */
  82:     private static final long serialVersionUID = 7807668053171837925L;
  83:     
  84:     /** The default item label format. */
  85:     public static final String DEFAULT_ITEM_LABEL_FORMAT = "{2}";
  86: 
  87:     /**
  88:      * Creates an item label generator using default number formatters.
  89:      */
  90:     public StandardXYItemLabelGenerator() {
  91:         this(DEFAULT_ITEM_LABEL_FORMAT, NumberFormat.getNumberInstance(), 
  92:                 NumberFormat.getNumberInstance());
  93:     }
  94: 
  95: 
  96:     /**
  97:      * Creates an item label generator using the specified number formatters.
  98:      *
  99:      * @param formatString  the item label format string (<code>null</code> not 
 100:      *                      permitted).
 101:      * @param xFormat  the format object for the x values (<code>null</code> 
 102:      *                 not permitted).
 103:      * @param yFormat  the format object for the y values (<code>null</code> 
 104:      *                 not permitted).
 105:      */
 106:     public StandardXYItemLabelGenerator(String formatString,
 107:             NumberFormat xFormat, NumberFormat yFormat) {
 108:         
 109:         super(formatString, xFormat, yFormat);
 110:     }
 111: 
 112:     /**
 113:      * Creates an item label generator using the specified formatters.
 114:      *
 115:      * @param formatString  the item label format string (<code>null</code> 
 116:      *                      not permitted).
 117:      * @param xFormat  the format object for the x values (<code>null</code> 
 118:      *                 not permitted).
 119:      * @param yFormat  the format object for the y values (<code>null</code> 
 120:      *                 not permitted).
 121:      */
 122:     public StandardXYItemLabelGenerator(String formatString,
 123:             DateFormat xFormat, NumberFormat yFormat) {
 124:         
 125:         super(formatString, xFormat, yFormat);
 126:     }
 127: 
 128:     /**
 129:      * Creates an item label generator using the specified formatters (a 
 130:      * number formatter for the x-values and a date formatter for the 
 131:      * y-values).
 132:      *
 133:      * @param formatString  the item label format string (<code>null</code> 
 134:      *                      not permitted).
 135:      * @param xFormat  the format object for the x values (<code>null</code> 
 136:      *                 permitted).
 137:      * @param yFormat  the format object for the y values (<code>null</code> 
 138:      *                 not permitted).
 139:      *                 
 140:      * @since 1.0.4
 141:      */
 142:     public StandardXYItemLabelGenerator(String formatString, 
 143:             NumberFormat xFormat, DateFormat yFormat) {
 144:         
 145:         super(formatString, xFormat, yFormat);
 146:     }
 147: 
 148:     /**
 149:      * Creates a label generator using the specified date formatters.
 150:      *
 151:      * @param formatString  the label format string (<code>null</code> not 
 152:      *                      permitted).
 153:      * @param xFormat  the format object for the x values (<code>null</code> 
 154:      *                 not permitted).
 155:      * @param yFormat  the format object for the y values (<code>null</code> 
 156:      *                 not permitted).
 157:      */
 158:     public StandardXYItemLabelGenerator(String formatString,
 159:             DateFormat xFormat, DateFormat yFormat) {
 160:         
 161:         super(formatString, xFormat, yFormat);
 162:     }
 163: 
 164:     /**
 165:      * Generates the item label text for an item in a dataset.
 166:      *
 167:      * @param dataset  the dataset (<code>null</code> not permitted).
 168:      * @param series  the series index (zero-based).
 169:      * @param item  the item index (zero-based).
 170:      *
 171:      * @return The label text (possibly <code>null</code>).
 172:      */
 173:     public String generateLabel(XYDataset dataset, int series, int item) {
 174:         return generateLabelString(dataset, series, item);
 175:     }
 176: 
 177:     /**
 178:      * Returns an independent copy of the generator.
 179:      * 
 180:      * @return A clone.
 181:      * 
 182:      * @throws CloneNotSupportedException if cloning is not supported.
 183:      */
 184:     public Object clone() throws CloneNotSupportedException { 
 185:         return super.clone();
 186:     }
 187:     
 188:     /**
 189:      * Tests this object for equality with an arbitrary object.
 190:      *
 191:      * @param obj  the other object (<code>null</code> permitted).
 192:      *
 193:      * @return A boolean.
 194:      */
 195:     public boolean equals(Object obj) {
 196:         if (obj == this) {
 197:             return true;
 198:         }
 199:         if (!(obj instanceof StandardXYItemLabelGenerator)) {
 200:             return false;
 201:         }
 202:         return super.equals(obj);
 203:     }
 204: 
 205: }