1 44 45 package org.jfree.chart.labels; 46 47 import java.io.Serializable ; 48 import java.text.DecimalFormat ; 49 import java.text.SimpleDateFormat ; 50 import java.util.Date ; 51 52 import org.jfree.data.contour.ContourDataset; 53 54 60 public class StandardContourToolTipGenerator implements ContourToolTipGenerator, 61 Serializable { 62 63 64 private static final long serialVersionUID = -1881659351247502711L; 65 66 67 private DecimalFormat valueForm = new DecimalFormat ("##.###"); 68 69 77 public String generateToolTip(ContourDataset data, int item) { 78 79 double x = data.getXValue(0, item); 80 double y = data.getYValue(0, item); 81 double z = data.getZValue(0, item); 82 String xString = null; 83 84 if (data.isDateAxis(0)) { 85 SimpleDateFormat formatter 86 = new java.text.SimpleDateFormat ("MM/dd/yyyy hh:mm:ss"); 87 StringBuffer strbuf = new StringBuffer (); 88 strbuf = formatter.format( 89 new Date ((long) x), strbuf, new java.text.FieldPosition (0) 90 ); 91 xString = strbuf.toString(); 92 } 93 else { 94 xString = this.valueForm.format(x); 95 } 96 if (!Double.isNaN(z)) { 97 return "X: " + xString 98 + ", Y: " + this.valueForm.format(y) 99 + ", Z: " + this.valueForm.format(z); 100 } 101 else { 102 return "X: " + xString 103 + ", Y: " + this.valueForm.format(y) 104 + ", Z: no data"; 105 } 106 107 } 108 109 116 public boolean equals(Object obj) { 117 118 if (obj == this) { 119 return true; 120 } 121 122 if (!(obj instanceof StandardContourToolTipGenerator)) { 123 return false; 124 } 125 StandardContourToolTipGenerator that 126 = (StandardContourToolTipGenerator) obj; 127 if (this.valueForm != null) { 128 return this.valueForm.equals(that.valueForm); 129 } 130 return false; 131 132 } 133 134 } 135 | Popular Tags |