1 41 42 package org.jfree.chart.labels; 43 44 import java.io.Serializable ; 45 import java.text.DateFormat ; 46 import java.text.DecimalFormat ; 47 import java.text.NumberFormat ; 48 import java.text.SimpleDateFormat ; 49 import java.util.Date ; 50 51 import org.jfree.data.XYDataset; 52 import org.jfree.util.PublicCloneable; 53 54 59 public class TimeSeriesToolTipGenerator implements XYToolTipGenerator, 60 Cloneable , PublicCloneable, 61 Serializable { 62 63 64 private DateFormat dateFormat; 65 66 67 private NumberFormat numberFormat; 68 69 72 public TimeSeriesToolTipGenerator() { 73 74 this(DateFormat.getInstance(), NumberFormat.getNumberInstance()); 75 76 } 77 78 84 public TimeSeriesToolTipGenerator(String dateFormat, String valueFormat) { 85 this(new SimpleDateFormat (dateFormat), new DecimalFormat (valueFormat)); 86 } 87 88 94 public TimeSeriesToolTipGenerator(DateFormat dateFormat, NumberFormat numberFormat) { 95 this.dateFormat = dateFormat; 96 this.numberFormat = numberFormat; 97 } 98 99 104 public DateFormat getDateFormat() { 105 return this.dateFormat; 106 } 107 108 113 public NumberFormat getNumberFormat() { 114 return this.numberFormat; 115 } 116 117 126 public String generateToolTip(XYDataset data, int series, int item) { 127 128 String result = ""; 129 String seriesName = data.getSeriesName(series); 130 if (seriesName != null) { 131 result += seriesName + ": "; 132 } 133 long x = data.getXValue(series, item).longValue(); 134 result = result + "date = " + this.dateFormat.format(new Date (x)); 135 136 Number y = data.getYValue(series, item); 137 if (y != null) { 138 result = result + ", value = " + this.numberFormat.format(y); 139 } 140 else { 141 result = result + ", value = null"; 142 } 143 144 return result; 145 } 146 147 154 public Object clone() throws CloneNotSupportedException { 155 156 TimeSeriesToolTipGenerator clone = (TimeSeriesToolTipGenerator) super.clone(); 157 158 if (this.dateFormat != null) { 159 clone.dateFormat = (DateFormat ) this.dateFormat.clone(); 160 } 161 162 if (this.numberFormat != null) { 163 clone.numberFormat = (NumberFormat ) this.numberFormat.clone(); 164 } 165 166 return clone; 167 168 } 169 170 177 public boolean equals(Object o) { 178 179 if (o == null) { 180 return false; 181 } 182 if (o == this) { 183 return true; 184 } 185 186 if (o instanceof TimeSeriesToolTipGenerator) { 187 TimeSeriesToolTipGenerator generator = (TimeSeriesToolTipGenerator) o; 188 return (this.dateFormat.equals(generator.getDateFormat()) 189 && this.numberFormat.equals(generator.getNumberFormat())); 190 } 191 return false; 192 193 } 194 195 } 196 | Popular Tags |