KickJava   Java API By Example, From Geeks To Geeks.

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


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  * TaskSeries.java
28  * ---------------
29  * (C) Copyright 2002-2004, by Object Refinery Limited.
30  *
31  * Original Author: David Gilbert (for Object Refinery Limited);
32  * Contributor(s): -;
33  *
34  * $Id: TaskSeries.java,v 1.3 2005/03/29 12:56:57 mungady Exp $
35  *
36  * Changes
37  * -------
38  * 06-Jun-2002 : Version 1 (DG);
39  * 07-Oct-2002 : Fixed errors reported by Checkstyle (DG);
40  * 24-Oct-2002 : Added methods to get TimeAllocation by task index (DG);
41  * 10-Jan-2003 : Renamed GanttSeries --> TaskSeries (DG);
42  * 30-Jul-2004 : Added equals() method (DG);
43  *
44  */

45
46 package org.jfree.data.gantt;
47
48 import java.util.Collections JavaDoc;
49 import java.util.List JavaDoc;
50
51 import org.jfree.data.general.Series;
52
53 /**
54  * A series that contains zero, one or many {@link Task} objects.
55  * <P>
56  * This class is used as a building block for the {@link TaskSeriesCollection}
57  * class that can be used to construct basic Gantt charts.
58  */

59 public class TaskSeries extends Series {
60
61     /** Storage for the tasks in the series. */
62     private List JavaDoc tasks;
63
64     /**
65      * Constructs a new series with the specified name.
66      *
67      * @param name the series name (<code>null</code> not permitted).
68      */

69     public TaskSeries(String JavaDoc name) {
70         super(name);
71         this.tasks = new java.util.ArrayList JavaDoc();
72     }
73
74     /**
75      * Adds a task to the series and sends a
76      * {@link org.jfree.data.general.SeriesChangeEvent} to all registered
77      * listeners.
78      *
79      * @param task the task (<code>null</code> not permitted).
80      */

81     public void add(Task task) {
82         if (task == null) {
83             throw new IllegalArgumentException JavaDoc("Null 'task' argument.");
84         }
85         this.tasks.add(task);
86         fireSeriesChanged();
87     }
88
89     /**
90      * Removes a task from the series and sends
91      * a {@link org.jfree.data.general.SeriesChangeEvent}
92      * to all registered listeners.
93      *
94      * @param task the task.
95      */

96     public void remove(Task task) {
97         this.tasks.remove(task);
98         fireSeriesChanged();
99     }
100
101     /**
102      * Removes all tasks from the series and sends
103      * a {@link org.jfree.data.general.SeriesChangeEvent}
104      * to all registered listeners.
105      */

106     public void removeAll() {
107         this.tasks.clear();
108         fireSeriesChanged();
109     }
110
111     /**
112      * Returns the number of items in the series.
113      *
114      * @return The item count.
115      */

116     public int getItemCount() {
117         return this.tasks.size();
118     }
119
120     /**
121      * Returns a task from the series.
122      *
123      * @param index the task index (zero-based).
124      *
125      * @return The task.
126      */

127     public Task get(int index) {
128         return (Task) this.tasks.get(index);
129     }
130     
131     /**
132      * Returns the task in the series that has the specified description.
133      *
134      * @param description the name (<code>null</code> not permitted).
135      *
136      * @return The task (possibly <code>null</code>).
137      */

138     public Task get(String JavaDoc description) {
139         Task result = null;
140         int count = this.tasks.size();
141         for (int i = 0; i < count; i++) {
142             Task t = (Task) this.tasks.get(i);
143             if (t.getDescription().equals(description)) {
144                 result = t;
145                 break;
146             }
147         }
148         return result;
149     }
150
151     /**
152      * Returns an unmodifialble list of the tasks in the series.
153      *
154      * @return The tasks.
155      */

156     public List JavaDoc getTasks() {
157         return Collections.unmodifiableList(this.tasks);
158     }
159
160     /**
161      * Tests this object for equality with an arbitrary object.
162      *
163      * @param obj the object to test against (<code>null</code> permitted).
164      *
165      * @return A boolean.
166      */

167     public boolean equals(Object JavaDoc obj) {
168         if (obj == this) {
169             return true;
170         }
171         if (!(obj instanceof TaskSeries)) {
172             return false;
173         }
174         if (!super.equals(obj)) {
175             return false;
176         }
177         TaskSeries that = (TaskSeries) obj;
178         if (!this.tasks.equals(that.tasks)) {
179             return false;
180         }
181         return true;
182     }
183     
184 }
185
Popular Tags