Frames | No Frames |
1: /* =========================================================== 2: * JFreeChart : a free chart library for the Java(tm) platform 3: * =========================================================== 4: * 5: * (C) Copyright 2000-2005, 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: * Task.java 29: * --------- 30: * (C) Copyright 2003, 2004, by Object Refinery Limited. 31: * 32: * Original Author: David Gilbert (for Object Refinery Limited); 33: * Contributor(s): -; 34: * 35: * $Id: Task.java,v 1.4.2.1 2005/10/25 21:31:44 mungady Exp $ 36: * 37: * Changes 38: * ------- 39: * 10-Jan-2003 : Version 1 (DG); 40: * 16-Sep-2003 : Added percentage complete (DG); 41: * 30-Jul-2004 : Added clone() and equals() methods and implemented 42: * Serializable (DG); 43: * 44: */ 45: 46: package org.jfree.data.gantt; 47: 48: import java.io.Serializable; 49: import java.util.Date; 50: import java.util.List; 51: 52: import org.jfree.data.time.SimpleTimePeriod; 53: import org.jfree.data.time.TimePeriod; 54: import org.jfree.util.ObjectUtilities; 55: import org.jfree.util.PublicCloneable; 56: 57: /** 58: * A simple representation of a task. The task has a description and a 59: * duration. You can add sub-tasks to the task. 60: */ 61: public class Task implements Cloneable, PublicCloneable, Serializable { 62: 63: /** For serialization. */ 64: private static final long serialVersionUID = 1094303785346988894L; 65: 66: /** The task description. */ 67: private String description; 68: 69: /** The time period for the task (estimated or actual). */ 70: private TimePeriod duration; 71: 72: /** The percent complete (<code>null</code> is permitted). */ 73: private Double percentComplete; 74: 75: /** Storage for the sub-tasks (if any). */ 76: private List subtasks; 77: 78: /** 79: * Creates a new task. 80: * 81: * @param description the task description (<code>null</code> not 82: * permitted). 83: * @param duration the task duration (<code>null</code> permitted). 84: */ 85: public Task(String description, TimePeriod duration) { 86: if (description == null) { 87: throw new IllegalArgumentException("Null 'description' argument."); 88: } 89: this.description = description; 90: this.duration = duration; 91: this.percentComplete = null; 92: this.subtasks = new java.util.ArrayList(); 93: } 94: 95: /** 96: * Creates a new task. 97: * 98: * @param description the task description (<code>null</code> not 99: * permitted). 100: * @param start the start date (<code>null</code> not permitted). 101: * @param end the end date (<code>null</code> not permitted). 102: */ 103: public Task(String description, Date start, Date end) { 104: this(description, new SimpleTimePeriod(start, end)); 105: } 106: 107: /** 108: * Returns the task description. 109: * 110: * @return The task description (never <code>null</code>). 111: */ 112: public String getDescription() { 113: return this.description; 114: } 115: 116: /** 117: * Sets the task description. 118: * 119: * @param description the description (<code>null</code> not permitted). 120: */ 121: public void setDescription(String description) { 122: if (description == null) { 123: throw new IllegalArgumentException("Null 'description' argument."); 124: } 125: this.description = description; 126: } 127: 128: /** 129: * Returns the duration (actual or estimated) of the task. 130: * 131: * @return The task duration (possibly <code>null</code>). 132: */ 133: public TimePeriod getDuration() { 134: return this.duration; 135: } 136: 137: /** 138: * Sets the task duration (actual or estimated). 139: * 140: * @param duration the duration (<code>null</code> permitted). 141: */ 142: public void setDuration(TimePeriod duration) { 143: this.duration = duration; 144: } 145: 146: /** 147: * Returns the percentage complete for this task. 148: * 149: * @return The percentage complete (possibly <code>null</code>). 150: */ 151: public Double getPercentComplete() { 152: return this.percentComplete; 153: } 154: 155: /** 156: * Sets the percentage complete for the task. 157: * 158: * @param percent the percentage (<code>null</code> permitted). 159: */ 160: public void setPercentComplete(Double percent) { 161: this.percentComplete = percent; 162: } 163: 164: /** 165: * Sets the percentage complete for the task. 166: * 167: * @param percent the percentage. 168: */ 169: public void setPercentComplete(double percent) { 170: setPercentComplete(new Double(percent)); 171: } 172: 173: /** 174: * Adds a sub-task to the task. 175: * 176: * @param subtask the subtask (<code>null</code> not permitted). 177: */ 178: public void addSubtask(Task subtask) { 179: if (subtask == null) { 180: throw new IllegalArgumentException("Null 'subtask' argument."); 181: } 182: this.subtasks.add(subtask); 183: } 184: 185: /** 186: * Removes a sub-task from the task. 187: * 188: * @param subtask the subtask. 189: */ 190: public void removeSubtask(Task subtask) { 191: this.subtasks.remove(subtask); 192: } 193: 194: /** 195: * Returns the sub-task count. 196: * 197: * @return The sub-task count. 198: */ 199: public int getSubtaskCount() { 200: return this.subtasks.size(); 201: } 202: 203: /** 204: * Returns a sub-task. 205: * 206: * @param index the index. 207: * 208: * @return The sub-task. 209: */ 210: public Task getSubtask(int index) { 211: return (Task) this.subtasks.get(index); 212: } 213: 214: /** 215: * Tests this object for equality with an arbitrary object. 216: * 217: * @param object the other object (<code>null</code> permitted). 218: * 219: * @return A boolean. 220: */ 221: public boolean equals(Object object) { 222: if (object == this) { 223: return true; 224: } 225: if (!(object instanceof Task)) { 226: return false; 227: } 228: Task that = (Task) object; 229: if (!ObjectUtilities.equal(this.description, that.description)) { 230: return false; 231: } 232: if (!ObjectUtilities.equal(this.duration, that.duration)) { 233: return false; 234: } 235: if (!ObjectUtilities.equal(this.percentComplete, 236: that.percentComplete)) { 237: return false; 238: } 239: if (!ObjectUtilities.equal(this.subtasks, that.subtasks)) { 240: return false; 241: } 242: return true; 243: } 244: 245: /** 246: * Returns a clone of the task. 247: * 248: * @return A clone. 249: * 250: * @throws CloneNotSupportedException never thrown by this class, but 251: * subclasses may not support cloning. 252: */ 253: public Object clone() throws CloneNotSupportedException { 254: Task clone = (Task) super.clone(); 255: return clone; 256: } 257: 258: }