KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > data > gantt > Task


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 License
20  * along with this library; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
24  * in the United States and other countries.]
25  *
26  * ---------
27  * Task.java
28  * ---------
29  * (C) Copyright 2003, 2004, by Object Refinery Limited.
30  *
31  * Original Author: David Gilbert (for Object Refinery Limited);
32  * Contributor(s): -;
33  *
34  * $Id: Task.java,v 1.4 2005/05/19 10:34:07 mungady Exp $
35  *
36  * Changes
37  * -------
38  * 10-Jan-2003 : Version 1 (DG);
39  * 16-Sep-2003 : Added percentage complete (DG);
40  * 30-Jul-2004 : Added clone() and equals() methods and implemented
41  * Serializable (DG);
42  *
43  */

44
45 package org.jfree.data.gantt;
46
47 import java.io.Serializable JavaDoc;
48 import java.util.Date JavaDoc;
49 import java.util.List JavaDoc;
50
51 import org.jfree.data.time.SimpleTimePeriod;
52 import org.jfree.data.time.TimePeriod;
53 import org.jfree.util.ObjectUtilities;
54 import org.jfree.util.PublicCloneable;
55
56 /**
57  * A simple representation of a task. The task has a description and a
58  * duration. You can add sub-tasks to the task.
59  */

60 public class Task implements Cloneable JavaDoc, PublicCloneable, Serializable JavaDoc {
61
62     /** For serialization. */
63     private static final long serialVersionUID = 1094303785346988894L;
64     
65     /** The task description. */
66     private String JavaDoc description;
67
68     /** The time period for the task (estimated or actual). */
69     private TimePeriod duration;
70     
71     /** The percent complete (<code>null</code> is permitted). */
72     private Double JavaDoc percentComplete;
73
74     /** Storage for the sub-tasks (if any). */
75     private List JavaDoc subtasks;
76
77     /**
78      * Creates a new task.
79      *
80      * @param description the task description (<code>null</code> not
81      * permitted).
82      * @param duration the task duration (<code>null</code> permitted).
83      */

84     public Task(String JavaDoc description, TimePeriod duration) {
85         if (description == null) {
86             throw new IllegalArgumentException JavaDoc("Null 'description' argument.");
87         }
88         this.description = description;
89         this.duration = duration;
90         this.percentComplete = null;
91         this.subtasks = new java.util.ArrayList JavaDoc();
92     }
93     
94     /**
95      * Creates a new task.
96      *
97      * @param description the task description (<code>null</code> not
98      * permitted).
99      * @param start the start date (<code>null</code> not permitted).
100      * @param end the end date (<code>null</code> not permitted).
101      */

102     public Task(String JavaDoc description, Date JavaDoc start, Date JavaDoc end) {
103         this(description, new SimpleTimePeriod(start, end));
104     }
105
106     /**
107      * Returns the task description.
108      *
109      * @return The task description (never <code>null</code>).
110      */

111     public String JavaDoc getDescription() {
112         return this.description;
113     }
114
115     /**
116      * Sets the task description.
117      *
118      * @param description the description (<code>null</code> not permitted).
119      */

120     public void setDescription(String JavaDoc description) {
121         if (description == null) {
122             throw new IllegalArgumentException JavaDoc("Null 'description' argument.");
123         }
124         this.description = description;
125     }
126
127     /**
128      * Returns the duration (actual or estimated) of the task.
129      *
130      * @return The task duration (possibly <code>null</code>).
131      */

132     public TimePeriod getDuration() {
133         return this.duration;
134     }
135
136     /**
137      * Sets the task duration (actual or estimated).
138      *
139      * @param duration the duration (<code>null</code> permitted).
140      */

141     public void setDuration(TimePeriod duration) {
142         this.duration = duration;
143     }
144     
145     /**
146      * Returns the percentage complete for this task.
147      *
148      * @return The percentage complete (possibly <code>null</code>).
149      */

150     public Double JavaDoc getPercentComplete() {
151         return this.percentComplete;
152     }
153     
154     /**
155      * Sets the percentage complete for the task.
156      *
157      * @param percent the percentage (<code>null</code> permitted).
158      */

159     public void setPercentComplete(Double JavaDoc percent) {
160         this.percentComplete = percent;
161     }
162
163     /**
164      * Sets the percentage complete for the task.
165      *
166      * @param percent the percentage.
167      */

168     public void setPercentComplete(double percent) {
169         setPercentComplete(new Double JavaDoc(percent));
170     }
171     
172     /**
173      * Adds a sub-task to the task.
174      *
175      * @param subtask the subtask (<code>null</code> not permitted).
176      */

177     public void addSubtask(Task subtask) {
178         if (subtask == null) {
179             throw new IllegalArgumentException JavaDoc("Null 'subtask' argument.");
180         }
181         this.subtasks.add(subtask);
182     }
183
184     /**
185      * Removes a sub-task from the task.
186      *
187      * @param subtask the subtask.
188      */

189     public void removeSubtask(Task subtask) {
190         this.subtasks.remove(subtask);
191     }
192
193     /**
194      * Returns the sub-task count.
195      *
196      * @return The sub-task count.
197      */

198     public int getSubtaskCount() {
199         return this.subtasks.size();
200     }
201
202     /**
203      * Returns a sub-task.
204      *
205      * @param index the index.
206      *
207      * @return The sub-task.
208      */

209     public Task getSubtask(int index) {
210         return (Task) this.subtasks.get(index);
211     }
212     
213     /**
214      * Tests this object for equality with an arbitrary object.
215      *
216      * @param object the other object (<code>null</code> permitted).
217      *
218      * @return A boolean.
219      */

220     public boolean equals(Object JavaDoc object) {
221         if (object == this) {
222             return true;
223         }
224         if (!(object instanceof Task)) {
225             return false;
226         }
227         Task that = (Task) object;
228         if (!ObjectUtilities.equal(this.description, that.description)) {
229             return false;
230         }
231         if (!ObjectUtilities.equal(this.duration, that.duration)) {
232             return false;
233         }
234         if (!ObjectUtilities.equal(this.percentComplete,
235                 that.percentComplete)) {
236             return false;
237         }
238         if (!ObjectUtilities.equal(this.subtasks, that.subtasks)) {
239             return false;
240         }
241         return true;
242     }
243
244     /**
245      * Returns a clone of the task.
246      *
247      * @return A clone.
248      *
249      * @throws CloneNotSupportedException never thrown by this class, but
250      * subclasses may not support cloning.
251      */

252     public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
253         Task clone = (Task) super.clone();
254         return clone;
255     }
256
257 }
258
Popular Tags