1 48 49 package org.jfree.data.gantt; 50 51 import java.io.Serializable ; 52 import java.util.Iterator ; 53 import java.util.List ; 54 55 import org.jfree.data.general.AbstractSeriesDataset; 56 import org.jfree.data.general.SeriesChangeEvent; 57 import org.jfree.data.time.TimePeriod; 58 import org.jfree.util.ObjectUtilities; 59 import org.jfree.util.PublicCloneable; 60 61 65 public class TaskSeriesCollection extends AbstractSeriesDataset 66 implements GanttCategoryDataset, 67 Cloneable , PublicCloneable, 68 Serializable { 69 70 71 private static final long serialVersionUID = -2065799050738449903L; 72 73 77 private List keys; 78 79 80 private List data; 81 82 85 public TaskSeriesCollection() { 86 this.keys = new java.util.ArrayList (); 87 this.data = new java.util.ArrayList (); 88 } 89 90 95 public int getSeriesCount() { 96 return getRowCount(); 97 } 98 99 106 public Comparable getSeriesKey(int series) { 107 TaskSeries ts = (TaskSeries) this.data.get(series); 108 return ts.getKey(); 109 } 110 111 116 public int getRowCount() { 117 return this.data.size(); 118 } 119 120 125 public List getRowKeys() { 126 return this.data; 127 } 128 129 134 public int getColumnCount() { 135 return this.keys.size(); 136 } 137 138 143 public List getColumnKeys() { 144 return this.keys; 145 } 146 147 154 public Comparable getColumnKey(int index) { 155 return (Comparable ) this.keys.get(index); 156 } 157 158 165 public int getColumnIndex(Comparable columnKey) { 166 return this.keys.indexOf(columnKey); 167 } 168 169 176 public int getRowIndex(Comparable rowKey) { 177 int result = -1; 178 int count = this.data.size(); 179 for (int i = 0; i < count; i++) { 180 TaskSeries s = (TaskSeries) this.data.get(i); 181 if (s.getKey().equals(rowKey)) { 182 result = i; 183 break; 184 } 185 } 186 return result; 187 } 188 189 196 public Comparable getRowKey(int index) { 197 TaskSeries series = (TaskSeries) this.data.get(index); 198 return series.getKey(); 199 } 200 201 208 public void add(TaskSeries series) { 209 if (series == null) { 210 throw new IllegalArgumentException ("Null 'series' argument."); 211 } 212 this.data.add(series); 213 series.addChangeListener(this); 214 215 Iterator iterator = series.getTasks().iterator(); 217 while (iterator.hasNext()) { 218 Task task = (Task) iterator.next(); 219 String key = task.getDescription(); 220 int index = this.keys.indexOf(key); 221 if (index < 0) { 222 this.keys.add(key); 223 } 224 } 225 fireDatasetChanged(); 226 } 227 228 235 public void remove(TaskSeries series) { 236 if (series == null) { 237 throw new IllegalArgumentException ("Null 'series' argument."); 238 } 239 if (this.data.contains(series)) { 240 series.removeChangeListener(this); 241 this.data.remove(series); 242 fireDatasetChanged(); 243 } 244 } 245 246 253 public void remove(int series) { 254 if ((series < 0) || (series > getSeriesCount())) { 255 throw new IllegalArgumentException ( 256 "TaskSeriesCollection.remove(): index outside valid range."); 257 } 258 259 TaskSeries ts = (TaskSeries) this.data.get(series); 261 ts.removeChangeListener(this); 262 this.data.remove(series); 263 fireDatasetChanged(); 264 265 } 266 267 272 public void removeAll() { 273 274 Iterator iterator = this.data.iterator(); 277 while (iterator.hasNext()) { 278 TaskSeries series = (TaskSeries) iterator.next(); 279 series.removeChangeListener(this); 280 } 281 282 this.data.clear(); 284 fireDatasetChanged(); 285 286 } 287 288 296 public Number getValue(Comparable rowKey, Comparable columnKey) { 297 return getStartValue(rowKey, columnKey); 298 } 299 300 308 public Number getValue(int row, int column) { 309 return getStartValue(row, column); 310 } 311 312 320 public Number getStartValue(Comparable rowKey, Comparable columnKey) { 321 Number result = null; 322 int row = getRowIndex(rowKey); 323 TaskSeries series = (TaskSeries) this.data.get(row); 324 Task task = series.get(columnKey.toString()); 325 if (task != null) { 326 TimePeriod duration = task.getDuration(); 327 result = new Long (duration.getStart().getTime()); 328 } 329 return result; 330 } 331 332 340 public Number getStartValue(int row, int column) { 341 Comparable rowKey = getRowKey(row); 342 Comparable columnKey = getColumnKey(column); 343 return getStartValue(rowKey, columnKey); 344 } 345 346 354 public Number getEndValue(Comparable rowKey, Comparable columnKey) { 355 Number result = null; 356 int row = getRowIndex(rowKey); 357 TaskSeries series = (TaskSeries) this.data.get(row); 358 Task task = series.get(columnKey.toString()); 359 if (task != null) { 360 TimePeriod duration = task.getDuration(); 361 result = new Long (duration.getEnd().getTime()); 362 } 363 return result; 364 } 365 366 374 public Number getEndValue(int row, int column) { 375 Comparable rowKey = getRowKey(row); 376 Comparable columnKey = getColumnKey(column); 377 return getEndValue(rowKey, columnKey); 378 } 379 380 388 public Number getPercentComplete(int row, int column) { 389 Comparable rowKey = getRowKey(row); 390 Comparable columnKey = getColumnKey(column); 391 return getPercentComplete(rowKey, columnKey); 392 } 393 394 402 public Number getPercentComplete(Comparable rowKey, Comparable columnKey) { 403 Number result = null; 404 int row = getRowIndex(rowKey); 405 TaskSeries series = (TaskSeries) this.data.get(row); 406 Task task = series.get(columnKey.toString()); 407 if (task != null) { 408 result = task.getPercentComplete(); 409 } 410 return result; 411 } 412 413 421 public int getSubIntervalCount(int row, int column) { 422 Comparable rowKey = getRowKey(row); 423 Comparable columnKey = getColumnKey(column); 424 return getSubIntervalCount(rowKey, columnKey); 425 } 426 427 435 public int getSubIntervalCount(Comparable rowKey, Comparable columnKey) { 436 int result = 0; 437 int row = getRowIndex(rowKey); 438 TaskSeries series = (TaskSeries) this.data.get(row); 439 Task task = series.get(columnKey.toString()); 440 if (task != null) { 441 result = task.getSubtaskCount(); 442 } 443 return result; 444 } 445 446 455 public Number getStartValue(int row, int column, int subinterval) { 456 Comparable rowKey = getRowKey(row); 457 Comparable columnKey = getColumnKey(column); 458 return getStartValue(rowKey, columnKey, subinterval); 459 } 460 461 470 public Number getStartValue(Comparable rowKey, Comparable columnKey, 471 int subinterval) { 472 Number result = null; 473 int row = getRowIndex(rowKey); 474 TaskSeries series = (TaskSeries) this.data.get(row); 475 Task task = series.get(columnKey.toString()); 476 if (task != null) { 477 Task sub = task.getSubtask(subinterval); 478 if (sub != null) { 479 TimePeriod duration = sub.getDuration(); 480 result = new Long (duration.getStart().getTime()); 481 } 482 } 483 return result; 484 } 485 486 495 public Number getEndValue(int row, int column, int subinterval) { 496 Comparable rowKey = getRowKey(row); 497 Comparable columnKey = getColumnKey(column); 498 return getEndValue(rowKey, columnKey, subinterval); 499 } 500 501 510 public Number getEndValue(Comparable rowKey, Comparable columnKey, 511 int subinterval) { 512 Number result = null; 513 int row = getRowIndex(rowKey); 514 TaskSeries series = (TaskSeries) this.data.get(row); 515 Task task = series.get(columnKey.toString()); 516 if (task != null) { 517 Task sub = task.getSubtask(subinterval); 518 if (sub != null) { 519 TimePeriod duration = sub.getDuration(); 520 result = new Long (duration.getEnd().getTime()); 521 } 522 } 523 return result; 524 } 525 526 535 public Number getPercentComplete(int row, int column, int subinterval) { 536 Comparable rowKey = getRowKey(row); 537 Comparable columnKey = getColumnKey(column); 538 return getPercentComplete(rowKey, columnKey, subinterval); 539 } 540 541 550 public Number getPercentComplete(Comparable rowKey, Comparable columnKey, 551 int subinterval) { 552 Number result = null; 553 int row = getRowIndex(rowKey); 554 TaskSeries series = (TaskSeries) this.data.get(row); 555 Task task = series.get(columnKey.toString()); 556 if (task != null) { 557 Task sub = task.getSubtask(subinterval); 558 if (sub != null) { 559 result = sub.getPercentComplete(); 560 } 561 } 562 return result; 563 } 564 565 570 public void seriesChanged(SeriesChangeEvent event) { 571 refreshKeys(); 572 fireDatasetChanged(); 573 } 574 575 578 private void refreshKeys() { 579 580 this.keys.clear(); 581 for (int i = 0; i < getSeriesCount(); i++) { 582 TaskSeries series = (TaskSeries) this.data.get(i); 583 Iterator iterator = series.getTasks().iterator(); 585 while (iterator.hasNext()) { 586 Task task = (Task) iterator.next(); 587 String key = task.getDescription(); 588 int index = this.keys.indexOf(key); 589 if (index < 0) { 590 this.keys.add(key); 591 } 592 } 593 } 594 595 } 596 597 604 public boolean equals(Object obj) { 605 if (obj == this) { 606 return true; 607 } 608 if (!(obj instanceof TaskSeriesCollection)) { 609 return false; 610 } 611 TaskSeriesCollection that = (TaskSeriesCollection) obj; 612 if (!ObjectUtilities.equal(this.data, that.data)) { 613 return false; 614 } 615 return true; 616 } 617 618 } 619 | Popular Tags |