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