1 53 54 package org.jfree.chart.labels; 55 56 import java.io.Serializable ; 57 import java.text.DateFormat ; 58 import java.text.NumberFormat ; 59 import java.util.Date ; 60 61 import org.jfree.data.xy.OHLCDataset; 62 import org.jfree.data.xy.XYDataset; 63 import org.jfree.util.PublicCloneable; 64 65 69 public class HighLowItemLabelGenerator implements XYItemLabelGenerator, 70 XYToolTipGenerator, 71 Cloneable , 72 PublicCloneable, 73 Serializable { 74 75 76 private static final long serialVersionUID = 5617111754832211830L; 77 78 79 private DateFormat dateFormatter; 80 81 82 private NumberFormat numberFormatter; 83 84 88 public HighLowItemLabelGenerator() { 89 this(DateFormat.getInstance(), NumberFormat.getInstance()); 90 } 91 92 100 public HighLowItemLabelGenerator(DateFormat dateFormatter, 101 NumberFormat numberFormatter) { 102 if (dateFormatter == null) { 103 throw new IllegalArgumentException ( 104 "Null 'dateFormatter' argument." 105 ); 106 } 107 if (numberFormatter == null) { 108 throw new IllegalArgumentException ( 109 "Null 'numberFormatter' argument." 110 ); 111 } 112 this.dateFormatter = dateFormatter; 113 this.numberFormatter = numberFormatter; 114 } 115 116 125 public String generateToolTip(XYDataset dataset, int series, int item) { 126 127 String result = null; 128 129 if (dataset instanceof OHLCDataset) { 130 OHLCDataset d = (OHLCDataset) dataset; 131 Number high = d.getHigh(series, item); 132 Number low = d.getLow(series, item); 133 Number open = d.getOpen(series, item); 134 Number close = d.getClose(series, item); 135 Number x = d.getX(series, item); 136 137 result = d.getSeriesKey(series).toString(); 138 139 if (x != null) { 140 Date date = new Date (x.longValue()); 141 result = result + "--> Date=" + this.dateFormatter.format(date); 142 if (high != null) { 143 result = result + " High=" 144 + this.numberFormatter.format(high.doubleValue()); 145 } 146 if (low != null) { 147 result = result + " Low=" 148 + this.numberFormatter.format(low.doubleValue()); 149 } 150 if (open != null) { 151 result = result + " Open=" 152 + this.numberFormatter.format(open.doubleValue()); 153 } 154 if (close != null) { 155 result = result + " Close=" 156 + this.numberFormatter.format(close.doubleValue()); 157 } 158 } 159 160 } 161 162 return result; 163 164 } 165 166 176 public String generateLabel(XYDataset dataset, int series, int category) { 177 return null; } 179 180 187 public Object clone() throws CloneNotSupportedException { 188 189 HighLowItemLabelGenerator clone 190 = (HighLowItemLabelGenerator) super.clone(); 191 192 if (this.dateFormatter != null) { 193 clone.dateFormatter = (DateFormat ) this.dateFormatter.clone(); 194 } 195 if (this.numberFormatter != null) { 196 clone.numberFormatter = (NumberFormat ) this.numberFormatter.clone(); 197 } 198 199 return clone; 200 201 } 202 203 210 public boolean equals(Object obj) { 211 if (obj == this) { 212 return true; 213 } 214 if (!(obj instanceof HighLowItemLabelGenerator)) { 215 return false; 216 } 217 HighLowItemLabelGenerator generator = (HighLowItemLabelGenerator) obj; 218 if (!this.dateFormatter.equals(generator.dateFormatter)) { 219 return false; 220 } 221 if (!this.numberFormatter.equals(generator.numberFormatter)) { 222 return false; 223 } 224 return true; 225 } 226 227 } 228 | Popular Tags |