1 43 44 package org.jfree.chart.labels; 45 46 import java.io.Serializable ; 47 import java.text.DateFormat ; 48 import java.util.Date ; 49 50 import org.jfree.data.HighLowDataset; 51 import org.jfree.data.XYDataset; 52 import org.jfree.util.PublicCloneable; 53 54 59 public class HighLowToolTipGenerator implements XYToolTipGenerator, 60 Cloneable , PublicCloneable, 61 Serializable { 62 63 64 private DateFormat dateFormatter; 65 66 69 public HighLowToolTipGenerator() { 70 this(DateFormat.getInstance()); 71 } 72 73 78 public HighLowToolTipGenerator(DateFormat formatter) { 79 this.dateFormatter = formatter; 80 } 81 82 91 public String generateToolTip(XYDataset data, int series, int item) { 92 93 String result = null; 94 95 if (data instanceof HighLowDataset) { 96 HighLowDataset d = (HighLowDataset) data; 97 Number high = d.getHighValue(series, item); 98 Number low = d.getLowValue(series, item); 99 Number open = d.getOpenValue(series, item); 100 Number close = d.getCloseValue(series, item); 101 Number x = d.getXValue(series, item); 102 103 result = d.getSeriesName(series); 104 105 if (x != null) { 106 Date date = new Date (x.longValue()); 107 result = result + "--> Date=" + dateFormatter.format(date); 108 if (high != null) { 109 result = result + " High=" + high.toString(); 110 } 111 if (low != null) { 112 result = result + " Low=" + low.toString(); 113 } 114 if (open != null) { 115 result = result + " Open=" + open.toString(); 116 } 117 if (close != null) { 118 result = result + " Close=" + close.toString(); 119 } 120 } 121 122 } 123 124 return result; 125 126 } 127 128 135 public Object clone() throws CloneNotSupportedException { 136 137 HighLowToolTipGenerator clone = (HighLowToolTipGenerator) super.clone(); 138 139 if (this.dateFormatter != null) { 140 clone.dateFormatter = (DateFormat ) this.dateFormatter.clone(); 141 } 142 143 return clone; 144 145 } 146 147 154 public boolean equals(Object o) { 155 156 if (o == null) { 157 return false; 158 } 159 if (o == this) { 160 return true; 161 } 162 163 if (o instanceof HighLowToolTipGenerator) { 164 HighLowToolTipGenerator generator = (HighLowToolTipGenerator) o; 165 return this.dateFormatter.equals(generator.dateFormatter); 166 } 167 168 return false; 169 170 } 171 } 172 | Popular Tags |