1 43 44 package org.jfree.chart.labels; 45 46 import java.io.Serializable ; 47 import java.text.NumberFormat ; 48 49 import org.jfree.data.PieDataset; 50 import org.jfree.util.ObjectUtils; 51 52 59 public class StandardPieToolTipGenerator implements PieItemLabelGenerator, 60 Cloneable , 61 Serializable { 62 63 64 private NumberFormat numberFormat; 65 66 69 public StandardPieToolTipGenerator() { 70 this(NumberFormat.getInstance()); 71 } 72 73 78 public StandardPieToolTipGenerator(NumberFormat formatter) { 79 this.numberFormat = formatter; 80 } 81 82 87 public NumberFormat getNumberFormat() { 88 return this.numberFormat; 89 } 90 91 100 public String generateToolTip(PieDataset data, Comparable key, int pieIndex) { 101 102 String result = null; 103 Number value = data.getValue(key); 104 if (value != null) { 105 String sectionLabel = key.toString(); 106 result = sectionLabel + " = " + this.numberFormat.format(value); 107 } 108 109 return result; 110 111 } 112 113 120 public Object clone() throws CloneNotSupportedException { 121 122 StandardPieToolTipGenerator clone = (StandardPieToolTipGenerator) super.clone(); 123 124 if (this.numberFormat != null) { 125 clone.numberFormat = (NumberFormat ) this.numberFormat.clone(); 126 } 127 128 return clone; 129 130 } 131 132 139 public boolean equals(Object o) { 140 141 if (o == null) { 142 return false; 143 } 144 if (o == this) { 145 return true; 146 } 147 148 if (o instanceof StandardPieToolTipGenerator) { 149 StandardPieToolTipGenerator generator = (StandardPieToolTipGenerator) o; 150 return ObjectUtils.equal(this.numberFormat, generator.getNumberFormat()); 151 } 152 return false; 153 154 } 155 156 } 157 | Popular Tags |