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