001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jfreechart/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * ---------
028: * Task.java
029: * ---------
030: * (C) Copyright 2003, 2004, by Object Refinery Limited.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: Task.java,v 1.4.2.1 2005/10/25 21:31:44 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 10-Jan-2003 : Version 1 (DG);
040: * 16-Sep-2003 : Added percentage complete (DG);
041: * 30-Jul-2004 : Added clone() and equals() methods and implemented
042: * Serializable (DG);
043: *
044: */
045:
046: package org.jfree.data.gantt;
047:
048: import java.io.Serializable;
049: import java.util.Date;
050: import java.util.List;
051:
052: import org.jfree.data.time.SimpleTimePeriod;
053: import org.jfree.data.time.TimePeriod;
054: import org.jfree.util.ObjectUtilities;
055: import org.jfree.util.PublicCloneable;
056:
057: /**
058: * A simple representation of a task. The task has a description and a
059: * duration. You can add sub-tasks to the task.
060: */
061: public class Task implements Cloneable, PublicCloneable, Serializable {
062:
063: /** For serialization. */
064: private static final long serialVersionUID = 1094303785346988894L;
065:
066: /** The task description. */
067: private String description;
068:
069: /** The time period for the task (estimated or actual). */
070: private TimePeriod duration;
071:
072: /** The percent complete (<code>null</code> is permitted). */
073: private Double percentComplete;
074:
075: /** Storage for the sub-tasks (if any). */
076: private List subtasks;
077:
078: /**
079: * Creates a new task.
080: *
081: * @param description the task description (<code>null</code> not
082: * permitted).
083: * @param duration the task duration (<code>null</code> permitted).
084: */
085: public Task(String description, TimePeriod duration) {
086: if (description == null) {
087: throw new IllegalArgumentException(
088: "Null 'description' argument.");
089: }
090: this .description = description;
091: this .duration = duration;
092: this .percentComplete = null;
093: this .subtasks = new java.util.ArrayList();
094: }
095:
096: /**
097: * Creates a new task.
098: *
099: * @param description the task description (<code>null</code> not
100: * permitted).
101: * @param start the start date (<code>null</code> not permitted).
102: * @param end the end date (<code>null</code> not permitted).
103: */
104: public Task(String description, Date start, Date end) {
105: this (description, new SimpleTimePeriod(start, end));
106: }
107:
108: /**
109: * Returns the task description.
110: *
111: * @return The task description (never <code>null</code>).
112: */
113: public String getDescription() {
114: return this .description;
115: }
116:
117: /**
118: * Sets the task description.
119: *
120: * @param description the description (<code>null</code> not permitted).
121: */
122: public void setDescription(String description) {
123: if (description == null) {
124: throw new IllegalArgumentException(
125: "Null 'description' argument.");
126: }
127: this .description = description;
128: }
129:
130: /**
131: * Returns the duration (actual or estimated) of the task.
132: *
133: * @return The task duration (possibly <code>null</code>).
134: */
135: public TimePeriod getDuration() {
136: return this .duration;
137: }
138:
139: /**
140: * Sets the task duration (actual or estimated).
141: *
142: * @param duration the duration (<code>null</code> permitted).
143: */
144: public void setDuration(TimePeriod duration) {
145: this .duration = duration;
146: }
147:
148: /**
149: * Returns the percentage complete for this task.
150: *
151: * @return The percentage complete (possibly <code>null</code>).
152: */
153: public Double getPercentComplete() {
154: return this .percentComplete;
155: }
156:
157: /**
158: * Sets the percentage complete for the task.
159: *
160: * @param percent the percentage (<code>null</code> permitted).
161: */
162: public void setPercentComplete(Double percent) {
163: this .percentComplete = percent;
164: }
165:
166: /**
167: * Sets the percentage complete for the task.
168: *
169: * @param percent the percentage.
170: */
171: public void setPercentComplete(double percent) {
172: setPercentComplete(new Double(percent));
173: }
174:
175: /**
176: * Adds a sub-task to the task.
177: *
178: * @param subtask the subtask (<code>null</code> not permitted).
179: */
180: public void addSubtask(Task subtask) {
181: if (subtask == null) {
182: throw new IllegalArgumentException(
183: "Null 'subtask' argument.");
184: }
185: this .subtasks.add(subtask);
186: }
187:
188: /**
189: * Removes a sub-task from the task.
190: *
191: * @param subtask the subtask.
192: */
193: public void removeSubtask(Task subtask) {
194: this .subtasks.remove(subtask);
195: }
196:
197: /**
198: * Returns the sub-task count.
199: *
200: * @return The sub-task count.
201: */
202: public int getSubtaskCount() {
203: return this .subtasks.size();
204: }
205:
206: /**
207: * Returns a sub-task.
208: *
209: * @param index the index.
210: *
211: * @return The sub-task.
212: */
213: public Task getSubtask(int index) {
214: return (Task) this .subtasks.get(index);
215: }
216:
217: /**
218: * Tests this object for equality with an arbitrary object.
219: *
220: * @param object the other object (<code>null</code> permitted).
221: *
222: * @return A boolean.
223: */
224: public boolean equals(Object object) {
225: if (object == this ) {
226: return true;
227: }
228: if (!(object instanceof Task)) {
229: return false;
230: }
231: Task that = (Task) object;
232: if (!ObjectUtilities.equal(this .description, that.description)) {
233: return false;
234: }
235: if (!ObjectUtilities.equal(this .duration, that.duration)) {
236: return false;
237: }
238: if (!ObjectUtilities.equal(this .percentComplete,
239: that.percentComplete)) {
240: return false;
241: }
242: if (!ObjectUtilities.equal(this .subtasks, that.subtasks)) {
243: return false;
244: }
245: return true;
246: }
247:
248: /**
249: * Returns a clone of the task.
250: *
251: * @return A clone.
252: *
253: * @throws CloneNotSupportedException never thrown by this class, but
254: * subclasses may not support cloning.
255: */
256: public Object clone() throws CloneNotSupportedException {
257: Task clone = (Task) super.clone();
258: return clone;
259: }
260:
261: }
|