Frames | No Frames |
1: /* =========================================================== 2: * JFreeChart : a free chart library for the Java(tm) platform 3: * =========================================================== 4: * 5: * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. 6: * 7: * Project Info: http://www.jfree.org/jfreechart/index.html 8: * 9: * This library is free software; you can redistribute it and/or modify it 10: * under the terms of the GNU Lesser General Public License as published by 11: * the Free Software Foundation; either version 2.1 of the License, or 12: * (at your option) any later version. 13: * 14: * This library is distributed in the hope that it will be useful, but 15: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17: * License for more details. 18: * 19: * You should have received a copy of the GNU Lesser General Public 20: * License along with this library; if not, write to the Free Software 21: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22: * USA. 23: * 24: * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 25: * in the United States and other countries.] 26: * 27: * --------------- 28: * TaskSeries.java 29: * --------------- 30: * (C) Copyright 2002-2007, by Object Refinery Limited. 31: * 32: * Original Author: David Gilbert (for Object Refinery Limited); 33: * Contributor(s): -; 34: * 35: * Changes 36: * ------- 37: * 06-Jun-2002 : Version 1 (DG); 38: * 07-Oct-2002 : Fixed errors reported by Checkstyle (DG); 39: * 24-Oct-2002 : Added methods to get TimeAllocation by task index (DG); 40: * 10-Jan-2003 : Renamed GanttSeries --> TaskSeries (DG); 41: * 30-Jul-2004 : Added equals() method (DG); 42: * 43: */ 44: 45: package org.jfree.data.gantt; 46: 47: import java.util.Collections; 48: import java.util.List; 49: 50: import org.jfree.data.general.Series; 51: 52: /** 53: * A series that contains zero, one or many {@link Task} objects. 54: * <P> 55: * This class is used as a building block for the {@link TaskSeriesCollection} 56: * class that can be used to construct basic Gantt charts. 57: */ 58: public class TaskSeries extends Series { 59: 60: /** Storage for the tasks in the series. */ 61: private List tasks; 62: 63: /** 64: * Constructs a new series with the specified name. 65: * 66: * @param name the series name (<code>null</code> not permitted). 67: */ 68: public TaskSeries(String name) { 69: super(name); 70: this.tasks = new java.util.ArrayList(); 71: } 72: 73: /** 74: * Adds a task to the series and sends a 75: * {@link org.jfree.data.general.SeriesChangeEvent} to all registered 76: * listeners. 77: * 78: * @param task the task (<code>null</code> not permitted). 79: */ 80: public void add(Task task) { 81: if (task == null) { 82: throw new IllegalArgumentException("Null 'task' argument."); 83: } 84: this.tasks.add(task); 85: fireSeriesChanged(); 86: } 87: 88: /** 89: * Removes a task from the series and sends 90: * a {@link org.jfree.data.general.SeriesChangeEvent} 91: * to all registered listeners. 92: * 93: * @param task the task. 94: */ 95: public void remove(Task task) { 96: this.tasks.remove(task); 97: fireSeriesChanged(); 98: } 99: 100: /** 101: * Removes all tasks from the series and sends 102: * a {@link org.jfree.data.general.SeriesChangeEvent} 103: * to all registered listeners. 104: */ 105: public void removeAll() { 106: this.tasks.clear(); 107: fireSeriesChanged(); 108: } 109: 110: /** 111: * Returns the number of items in the series. 112: * 113: * @return The item count. 114: */ 115: public int getItemCount() { 116: return this.tasks.size(); 117: } 118: 119: /** 120: * Returns a task from the series. 121: * 122: * @param index the task index (zero-based). 123: * 124: * @return The task. 125: */ 126: public Task get(int index) { 127: return (Task) this.tasks.get(index); 128: } 129: 130: /** 131: * Returns the task in the series that has the specified description. 132: * 133: * @param description the name (<code>null</code> not permitted). 134: * 135: * @return The task (possibly <code>null</code>). 136: */ 137: public Task get(String description) { 138: Task result = null; 139: int count = this.tasks.size(); 140: for (int i = 0; i < count; i++) { 141: Task t = (Task) this.tasks.get(i); 142: if (t.getDescription().equals(description)) { 143: result = t; 144: break; 145: } 146: } 147: return result; 148: } 149: 150: /** 151: * Returns an unmodifialble list of the tasks in the series. 152: * 153: * @return The tasks. 154: */ 155: public List getTasks() { 156: return Collections.unmodifiableList(this.tasks); 157: } 158: 159: /** 160: * Tests this object for equality with an arbitrary object. 161: * 162: * @param obj the object to test against (<code>null</code> permitted). 163: * 164: * @return A boolean. 165: */ 166: public boolean equals(Object obj) { 167: if (obj == this) { 168: return true; 169: } 170: if (!(obj instanceof TaskSeries)) { 171: return false; 172: } 173: if (!super.equals(obj)) { 174: return false; 175: } 176: TaskSeries that = (TaskSeries) obj; 177: if (!this.tasks.equals(that.tasks)) { 178: return false; 179: } 180: return true; 181: } 182: 183: }