1 42 43 package org.jfree.chart.labels; 44 45 import java.io.Serializable ; 46 import java.text.DateFormat ; 47 import java.text.MessageFormat ; 48 import java.text.NumberFormat ; 49 50 import org.jfree.data.xy.XYDataset; 51 import org.jfree.data.xy.XYZDataset; 52 import org.jfree.util.ObjectUtilities; 53 54 58 public class StandardXYZToolTipGenerator extends StandardXYToolTipGenerator 59 implements XYZToolTipGenerator, 60 Serializable { 61 62 63 private static final long serialVersionUID = -2961577421889473503L; 64 65 66 public static final String DEFAULT_TOOL_TIP_FORMAT = "{0}: ({1}, {2}, {3})"; 67 68 72 private NumberFormat zFormat; 73 74 78 private DateFormat zDateFormat; 79 80 84 public StandardXYZToolTipGenerator() { 85 this( 86 DEFAULT_TOOL_TIP_FORMAT, 87 NumberFormat.getNumberInstance(), 88 NumberFormat.getNumberInstance(), 89 NumberFormat.getNumberInstance() 90 ); 91 } 92 93 105 public StandardXYZToolTipGenerator(String formatString, 106 NumberFormat xFormat, 107 NumberFormat yFormat, 108 NumberFormat zFormat) { 109 super(formatString, xFormat, yFormat); 110 if (zFormat == null) { 111 throw new IllegalArgumentException ("Null 'zFormat' argument."); 112 } 113 this.zFormat = zFormat; 114 } 115 116 127 public StandardXYZToolTipGenerator(String formatString, 128 DateFormat xFormat, 129 DateFormat yFormat, 130 DateFormat zFormat) { 131 super(formatString, xFormat, yFormat); 132 if (zFormat == null) { 133 throw new IllegalArgumentException ("Null 'zFormat' argument."); 134 } 135 this.zDateFormat = zFormat; 136 } 137 138 140 145 public NumberFormat getZFormat() { 146 return this.zFormat; 147 } 148 149 154 public DateFormat getZDateFormat() { 155 return this.zDateFormat; 156 } 157 158 167 public String generateToolTip(XYZDataset dataset, int series, int item) { 168 return generateLabelString(dataset, series, item); 169 } 170 171 180 public String generateLabelString(XYDataset dataset, int series, int item) { 181 String result = null; 182 Object [] items = createItemArray((XYZDataset) dataset, series, item); 183 result = MessageFormat.format(getFormatString(), items); 184 return result; 185 } 186 187 197 protected Object [] createItemArray(XYZDataset dataset, 198 int series, int item) { 199 200 Object [] result = new Object [4]; 201 result[0] = dataset.getSeriesKey(series).toString(); 202 203 Number x = dataset.getX(series, item); 204 DateFormat xf = getXDateFormat(); 205 if (xf != null) { 206 result[1] = xf.format(x); 207 } 208 else { 209 result[1] = getXFormat().format(x); 210 } 211 212 Number y = dataset.getY(series, item); 213 DateFormat yf = getYDateFormat(); 214 if (yf != null) { 215 result[2] = yf.format(y); 216 } 217 else { 218 result[2] = getYFormat().format(y); 219 } 220 221 Number z = dataset.getZ(series, item); 222 if (this.zDateFormat != null) { 223 result[3] = this.zDateFormat.format(z); 224 } 225 else { 226 result[3] = this.zFormat.format(z); 227 } 228 229 return result; 230 231 } 232 233 240 public boolean equals(Object obj) { 241 if (obj == this) { 242 return true; 243 } 244 if (!(obj instanceof StandardXYZToolTipGenerator)) { 245 return false; 246 } 247 if (!super.equals(obj)) { 248 return false; 249 } 250 StandardXYZToolTipGenerator that = (StandardXYZToolTipGenerator) obj; 251 if (!ObjectUtilities.equal(this.zFormat, that.zFormat)) { 252 return false; 253 } 254 if (!ObjectUtilities.equal(this.zDateFormat, that.zDateFormat)) { 255 return false; 256 } 257 return true; 258 259 } 260 261 } 262 | Popular Tags |