Frames | No Frames |
1: /* =========================================================== 2: * JFreeChart : a free chart library for the Java(tm) platform 3: * =========================================================== 4: * 5: * (C) Copyright 2000-2006, 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: * StandardCategoryItemLabelGenerator.java 29: * --------------------------------------- 30: * (C) Copyright 2004-2006, by Object Refinery Limited. 31: * 32: * Original Author: David Gilbert (for Object Refinery Limited); 33: * Contributor(s): -; 34: * 35: * $Id: StandardCategoryItemLabelGenerator.java,v 1.2.2.3 2006/07/25 15:55:48 mungady Exp $ 36: * 37: * Changes 38: * ------- 39: * 11-May-2004 : Version 1 (DG); 40: * 20-Apr-2005 : Renamed StandardCategoryLabelGenerator 41: * --> StandardCategoryItemLabelGenerator (DG); 42: * ------------- JFREECHART 1.0.0 --------------------------------------------- 43: * 03-May-2005 : Added equals() implementation, to fix bug 1481087 (DG); 44: */ 45: 46: package org.jfree.chart.labels; 47: 48: import java.io.Serializable; 49: import java.text.DateFormat; 50: import java.text.NumberFormat; 51: 52: import org.jfree.data.category.CategoryDataset; 53: import org.jfree.util.PublicCloneable; 54: 55: /** 56: * A standard label generator that can be used with a 57: * {@link org.jfree.chart.renderer.category.CategoryItemRenderer}. 58: */ 59: public class StandardCategoryItemLabelGenerator 60: extends AbstractCategoryItemLabelGenerator 61: implements CategoryItemLabelGenerator, Cloneable, PublicCloneable, 62: Serializable { 63: 64: /** For serialization. */ 65: private static final long serialVersionUID = 3499701401211412882L; 66: 67: /** The default format string. */ 68: public static final String DEFAULT_LABEL_FORMAT_STRING = "{2}"; 69: 70: /** 71: * Creates a new generator with a default number formatter. 72: */ 73: public StandardCategoryItemLabelGenerator() { 74: super(DEFAULT_LABEL_FORMAT_STRING, NumberFormat.getInstance()); 75: } 76: 77: /** 78: * Creates a new generator with the specified number formatter. 79: * 80: * @param labelFormat the label format string (<code>null</code> not 81: * permitted). 82: * @param formatter the number formatter (<code>null</code> not permitted). 83: */ 84: public StandardCategoryItemLabelGenerator(String labelFormat, 85: NumberFormat formatter) { 86: super(labelFormat, formatter); 87: } 88: 89: /** 90: * Creates a new generator with the specified number formatter. 91: * 92: * @param labelFormat the label format string (<code>null</code> not 93: * permitted). 94: * @param formatter the number formatter (<code>null</code> not permitted). 95: * @param percentFormatter the percent formatter (<code>null</code> not 96: * permitted). 97: * 98: * @since 1.0.2 99: */ 100: public StandardCategoryItemLabelGenerator(String labelFormat, 101: NumberFormat formatter, NumberFormat percentFormatter) { 102: super(labelFormat, formatter, percentFormatter); 103: } 104: 105: /** 106: * Creates a new generator with the specified date formatter. 107: * 108: * @param labelFormat the label format string (<code>null</code> not 109: * permitted). 110: * @param formatter the date formatter (<code>null</code> not permitted). 111: */ 112: public StandardCategoryItemLabelGenerator(String labelFormat, 113: DateFormat formatter) { 114: super(labelFormat, formatter); 115: } 116: 117: /** 118: * Generates the label for an item in a dataset. Note: in the current 119: * dataset implementation, each row is a series, and each column contains 120: * values for a particular category. 121: * 122: * @param dataset the dataset (<code>null</code> not permitted). 123: * @param row the row index (zero-based). 124: * @param column the column index (zero-based). 125: * 126: * @return The label (possibly <code>null</code>). 127: */ 128: public String generateLabel(CategoryDataset dataset, int row, int column) { 129: return generateLabelString(dataset, row, column); 130: } 131: 132: /** 133: * Tests this generator for equality with an arbitrary object. 134: * 135: * @param obj the object (<code>null</code> permitted). 136: * 137: * @return <code>true</code> if this generator is equal to 138: * <code>obj</code>, and <code>false</code> otherwise. 139: */ 140: public boolean equals(Object obj) { 141: if (obj == this) { 142: return true; 143: } 144: if (!(obj instanceof StandardCategoryItemLabelGenerator)) { 145: return false; 146: } 147: return super.equals(obj); 148: } 149: }