1 37 38 package org.jfree.data; 39 40 import java.io.Serializable ; 41 import java.util.List ; 42 43 import org.jfree.util.ObjectUtils; 44 45 52 public class MatrixSeriesCollection extends AbstractSeriesDataset 53 implements XYZDataset, Serializable { 54 55 private List m_data; 56 57 60 public MatrixSeriesCollection() { 61 this(null); 62 } 63 64 65 70 public MatrixSeriesCollection(MatrixSeries series) { 71 this.m_data = new java.util.ArrayList (); 72 73 if (series != null) { 74 m_data.add(series); 75 series.addChangeListener(this); 76 } 77 } 78 79 86 public int getItemCount(int seriesIndex) { 87 return getSeries(seriesIndex).getItemCount(); 88 } 89 90 91 100 public MatrixSeries getSeries(int seriesIndex) { 101 if ((seriesIndex < 0) || (seriesIndex > getSeriesCount())) { 102 throw new IllegalArgumentException ( 103 "MatrixSeriesCollection.getSeries(...): index outside valid range."); 104 } 105 106 MatrixSeries series = (MatrixSeries) m_data.get(seriesIndex); 107 108 return series; 109 } 110 111 112 117 public int getSeriesCount() { 118 return this.m_data.size(); 119 } 120 121 122 129 public String getSeriesName(int seriesIndex) { 130 return getSeries(seriesIndex).getName(); 131 } 132 133 134 145 public Number getXValue(int seriesIndex, int itemIndex) { 146 MatrixSeries series = (MatrixSeries) m_data.get(seriesIndex); 147 int x = series.getItemColumn(itemIndex); 148 149 return new Integer (x); } 151 152 153 164 public Number getYValue(int seriesIndex, int itemIndex) { 165 MatrixSeries series = (MatrixSeries) m_data.get(seriesIndex); 166 int y = series.getItemRow(itemIndex); 167 168 return new Integer (y); } 170 171 172 183 public Number getZValue(int seriesIndex, int itemIndex) { 184 MatrixSeries series = (MatrixSeries) m_data.get(seriesIndex); 185 Number z = series.getItem(itemIndex); 186 187 return z; 188 } 189 190 191 201 public void addSeries(MatrixSeries series) { 202 if (series == null) { 204 throw new IllegalArgumentException ( 205 "MatrixSeriesCollection.addSeries(...): cannot add null series."); 206 } 207 208 m_data.add(series); 210 series.addChangeListener(this); 211 fireDatasetChanged(); 212 } 213 214 215 222 public boolean equals(Object obj) { 223 if (obj == null) { 224 return false; 225 } 226 227 if (obj == this) { 228 return true; 229 } 230 231 if (obj instanceof MatrixSeriesCollection) { 232 MatrixSeriesCollection c = (MatrixSeriesCollection) obj; 233 234 return ObjectUtils.equal(m_data, c.m_data); 235 } 236 237 return false; 238 } 239 240 241 247 public void removeAllSeries() { 248 for (int i = 0; i < this.m_data.size(); i++) { 250 MatrixSeries series = (MatrixSeries) m_data.get(i); 251 series.removeChangeListener(this); 252 } 253 254 m_data.clear(); 256 fireDatasetChanged(); 257 } 258 259 260 270 public void removeSeries(MatrixSeries series) { 271 if (series == null) { 273 throw new IllegalArgumentException ( 274 "MatrixSeriesCollection.removeSeries(...): cannot remove null series."); 275 } 276 277 if (m_data.contains(series)) { 279 series.removeChangeListener(this); 280 m_data.remove(series); 281 fireDatasetChanged(); 282 } 283 } 284 285 286 296 public void removeSeries(int seriesIndex) { 297 if ((seriesIndex < 0) || (seriesIndex > getSeriesCount())) { 299 throw new IllegalArgumentException ( 300 "MatrixSeriesCollection.removeSeries(...): index outside valid range."); 301 } 302 303 MatrixSeries series = (MatrixSeries) m_data.get(seriesIndex); 305 series.removeChangeListener(this); 306 m_data.remove(seriesIndex); 307 fireDatasetChanged(); 308 } 309 310 } 311 | Popular Tags |