1 42 43 package org.jfree.chart.labels; 44 45 import java.io.Serializable ; 46 import java.text.DateFormat ; 47 import java.text.NumberFormat ; 48 49 import org.jfree.data.category.CategoryDataset; 50 import org.jfree.data.category.IntervalCategoryDataset; 51 import org.jfree.util.PublicCloneable; 52 53 57 public class IntervalCategoryToolTipGenerator 58 extends StandardCategoryToolTipGenerator 59 implements CategoryToolTipGenerator, PublicCloneable, Cloneable , 60 Serializable { 61 62 63 private static final long serialVersionUID = -3853824986520333437L; 64 65 66 public static final String DEFAULT_TOOL_TIP_FORMAT_STRING 67 = "({0}, {1}) = {3} - {4}"; 68 69 72 public IntervalCategoryToolTipGenerator() { 73 super(DEFAULT_TOOL_TIP_FORMAT_STRING, NumberFormat.getInstance()); 74 } 75 76 83 public IntervalCategoryToolTipGenerator(String labelFormat, 84 NumberFormat formatter) { 85 super(labelFormat, formatter); 86 } 87 88 95 public IntervalCategoryToolTipGenerator(String labelFormat, 96 DateFormat formatter) { 97 super(labelFormat, formatter); 98 } 99 100 110 protected Object [] createItemArray(CategoryDataset dataset, 111 int row, int column) { 112 Object [] result = new Object [5]; 113 result[0] = dataset.getRowKey(row).toString(); 114 result[1] = dataset.getColumnKey(column).toString(); 115 Number value = dataset.getValue(row, column); 116 if (getNumberFormat() != null) { 117 result[2] = getNumberFormat().format(value); 118 } 119 else if (getDateFormat() != null) { 120 result[2] = getDateFormat().format(value); 121 } 122 123 if (dataset instanceof IntervalCategoryDataset) { 124 IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset; 125 Number start = icd.getStartValue(row, column); 126 Number end = icd.getEndValue(row, column); 127 if (getNumberFormat() != null) { 128 result[3] = getNumberFormat().format(start); 129 result[4] = getNumberFormat().format(end); 130 } 131 else if (getDateFormat() != null) { 132 result[3] = getDateFormat().format(start); 133 result[4] = getDateFormat().format(end); 134 } 135 } 136 return result; 137 } 138 139 } 140 | Popular Tags |