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