1 44 45 package org.jfree.chart.labels; 46 47 import java.io.Serializable ; 48 import java.text.MessageFormat ; 49 50 import org.jfree.data.category.CategoryDataset; 51 import org.jfree.util.PublicCloneable; 52 53 57 public class StandardCategorySeriesLabelGenerator implements 58 CategorySeriesLabelGenerator, Cloneable , PublicCloneable, Serializable { 59 60 61 private static final long serialVersionUID = 4630760091523940820L; 62 63 64 public static final String DEFAULT_LABEL_FORMAT = "{0}"; 65 66 67 private String formatPattern; 68 69 73 public StandardCategorySeriesLabelGenerator() { 74 this(DEFAULT_LABEL_FORMAT); 75 } 76 77 82 public StandardCategorySeriesLabelGenerator(String format) { 83 if (format == null) { 84 throw new IllegalArgumentException ("Null 'format' argument."); 85 } 86 this.formatPattern = format; 87 } 88 89 97 public String generateLabel(CategoryDataset dataset, int series) { 98 if (dataset == null) { 99 throw new IllegalArgumentException ("Null 'dataset' argument."); 100 } 101 String label = MessageFormat.format(this.formatPattern, 102 createItemArray(dataset, series)); 103 return label; 104 } 105 106 115 protected Object [] createItemArray(CategoryDataset dataset, int series) { 116 Object [] result = new Object [1]; 117 result[0] = dataset.getRowKey(series).toString(); 118 return result; 119 } 120 121 128 public Object clone() throws CloneNotSupportedException { 129 return super.clone(); 130 } 131 132 139 public boolean equals(Object obj) { 140 if (obj == this) { 141 return true; 142 } 143 if (!(obj instanceof StandardCategorySeriesLabelGenerator)) { 144 return false; 145 } 146 StandardCategorySeriesLabelGenerator that 147 = (StandardCategorySeriesLabelGenerator) obj; 148 if (!this.formatPattern.equals(that.formatPattern)) { 149 return false; 150 } 151 return true; 152 } 153 154 } 155 | Popular Tags |