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