1 50 51 package org.jfree.chart.labels; 52 53 import java.io.Serializable ; 54 import java.text.DateFormat ; 55 import java.text.MessageFormat ; 56 import java.text.NumberFormat ; 57 import java.util.Date ; 58 59 import org.jfree.data.statistics.BoxAndWhiskerXYDataset; 60 import org.jfree.data.xy.XYDataset; 61 62 82 public class BoxAndWhiskerXYToolTipGenerator extends StandardXYToolTipGenerator 83 implements XYToolTipGenerator, 84 Cloneable , 85 Serializable { 86 87 88 private static final long serialVersionUID = -2648775791161459710L; 89 90 91 public static final String DEFAULT_TOOL_TIP_FORMAT 92 = "X: {1} Mean: {2} Median: {3} Min: {4} Max: {5} Q1: {6} Q3: {7} "; 93 94 97 public BoxAndWhiskerXYToolTipGenerator() { 98 super( 99 DEFAULT_TOOL_TIP_FORMAT, 100 NumberFormat.getInstance(), NumberFormat.getInstance() 101 ); 102 } 103 104 114 public BoxAndWhiskerXYToolTipGenerator(String toolTipFormat, 115 DateFormat dateFormat, 116 NumberFormat numberFormat) { 117 118 super(toolTipFormat, dateFormat, numberFormat); 119 120 } 121 122 132 protected Object [] createItemArray(XYDataset dataset, int series, 133 int item) { 134 Object [] result = new Object [8]; 135 result[0] = dataset.getSeriesKey(series).toString(); 136 Number x = dataset.getX(series, item); 137 if (getXDateFormat() != null) { 138 result[1] = getXDateFormat().format(new Date (x.longValue())); 139 } 140 else { 141 result[1] = getXFormat().format(x); 142 } 143 NumberFormat formatter = getYFormat(); 144 145 if (dataset instanceof BoxAndWhiskerXYDataset) { 146 BoxAndWhiskerXYDataset d = (BoxAndWhiskerXYDataset) dataset; 147 result[2] = formatter.format(d.getMeanValue(series, item)); 148 result[3] = formatter.format(d.getMedianValue(series, item)); 149 result[4] = formatter.format(d.getMinRegularValue(series, item)); 150 result[5] = formatter.format(d.getMaxRegularValue(series, item)); 151 result[6] = formatter.format(d.getQ1Value(series, item)); 152 result[7] = formatter.format(d.getQ3Value(series, item)); 153 } 154 return result; 155 } 156 157 164 public boolean equals(Object obj) { 165 if (obj == this) { 166 return true; 167 } 168 if (!(obj instanceof BoxAndWhiskerXYToolTipGenerator)) { 169 return false; 170 } 171 return super.equals(obj); 172 } 173 174 } 175 | Popular Tags |