1 38 39 package org.jfree.data; 40 41 import java.util.List ; 42 43 49 public class CategoryToPieDataset extends AbstractDataset 50 implements PieDataset, DatasetChangeListener { 51 52 53 public static final int ROW = 0; 54 55 56 public static final int COLUMN = 1; 57 58 59 private CategoryDataset source; 60 61 62 private int extract; 63 64 65 private int index; 66 67 75 public CategoryToPieDataset(CategoryDataset source, int extract, int index) { 76 this.source = source; 77 this.source.addChangeListener(this); 78 this.extract = extract; 79 this.index = index; 80 } 81 82 87 public int getItemCount() { 88 89 int result = 0; 90 switch (this.extract) { 91 case (ROW) : 92 result = source.getColumnCount(); 93 break; 94 case (COLUMN) : 95 result = source.getRowCount(); 96 break; 97 default : } 99 return result; 100 } 101 102 109 public Number getValue(int item) { 110 111 Number result = null; 112 switch (this.extract) { 113 case (ROW) : 114 result = source.getValue(this.index, item); 115 break; 116 case (COLUMN) : 117 result = source.getValue(item, this.index); 118 break; 119 default : } 121 return result; 122 123 } 124 125 132 public Comparable getKey(int index) { 133 134 Comparable result = null; 135 switch (this.extract) { 136 case (ROW) : 137 result = source.getColumnKey(index); 138 break; 139 case (COLUMN) : 140 result = source.getRowKey(index); 141 break; 142 default : } 144 return result; 145 146 } 147 148 155 public int getIndex(Comparable key) { 156 157 int result = -1; 158 switch (this.extract) { 159 case (ROW) : 160 result = source.getColumnIndex(key); 161 break; 162 case (COLUMN) : 163 result = source.getRowIndex(key); 164 break; 165 default : } 167 return result; 168 169 } 170 171 176 public List getKeys() { 177 178 List result = null; 179 switch (this.extract) { 180 case (ROW) : 181 result = source.getColumnKeys(); 182 break; 183 case (COLUMN) : 184 result = source.getRowKeys(); 185 break; 186 default : } 188 return result; 189 190 } 191 192 201 public Number getValue(Comparable key) { 202 203 Number result = null; 204 int keyIndex = getIndex(key); 205 switch (this.extract) { 206 case (ROW) : 207 result = source.getValue(this.index, keyIndex); 208 break; 209 case (COLUMN) : 210 result = source.getValue(keyIndex, this.index); 211 break; 212 default : } 214 return result; 215 216 } 217 218 223 public void datasetChanged (DatasetChangeEvent event) { 224 fireDatasetChanged (); 225 } 226 227 } 228 | Popular Tags |