1. /* ===========================================================
  2. * JFreeChart : a free chart library for the Java(tm) platform
  3. * ===========================================================
  4. *
  5. * (C) Copyright 2000-2004, 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 under the terms
  10. * of the GNU Lesser General Public License as published by the Free Software Foundation;
  11. * either version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  14. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. * See the GNU Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License along with this
  18. * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  19. * Boston, MA 02111-1307, USA.
  20. *
  21. * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  22. * in the United States and other countries.]
  23. *
  24. * ---------------
  25. * TaskSeries.java
  26. * ---------------
  27. * (C) Copyright 2002-2004, by Object Refinery Limited.
  28. *
  29. * Original Author: David Gilbert (for Object Refinery Limited);
  30. * Contributor(s): -;
  31. *
  32. * $Id: TaskSeries.java,v 1.2 2004/11/29 15:18:37 mungady Exp $
  33. *
  34. * Changes
  35. * -------
  36. * 06-Jun-2002 : Version 1 (DG);
  37. * 07-Oct-2002 : Fixed errors reported by Checkstyle (DG);
  38. * 24-Oct-2002 : Added methods to get TimeAllocation by task index (DG);
  39. * 10-Jan-2003 : Renamed GanttSeries --> TaskSeries (DG);
  40. * 30-Jul-2004 : Added equals() method (DG);
  41. *
  42. */
  43. package org.jfree.data.gantt;
  44. import java.util.Collections;
  45. import java.util.List;
  46. import org.jfree.data.general.Series;
  47. /**
  48. * A series that contains zero, one or many {@link Task} objects.
  49. * <P>
  50. * This class is used as a building block for the {@link TaskSeriesCollection} class that
  51. * can be used to construct basic Gantt charts.
  52. */
  53. public class TaskSeries extends Series {
  54. /** Storage for the tasks in the series. */
  55. private List tasks;
  56. /**
  57. * Constructs a new series with the specified name.
  58. *
  59. * @param name the series name (<code>null</code> not permitted).
  60. */
  61. public TaskSeries(String name) {
  62. super(name);
  63. this.tasks = new java.util.ArrayList();
  64. }
  65. /**
  66. * Adds a task to the series and sends a {@link org.jfree.data.general.SeriesChangeEvent}
  67. * to all registered listeners.
  68. *
  69. * @param task the task (<code>null</code> not permitted).
  70. */
  71. public void add(Task task) {
  72. if (task == null) {
  73. throw new IllegalArgumentException("Null 'task' argument.");
  74. }
  75. this.tasks.add(task);
  76. fireSeriesChanged();
  77. }
  78. /**
  79. * Removes a task from the series and sends
  80. * a {@link org.jfree.data.general.SeriesChangeEvent}
  81. * to all registered listeners.
  82. *
  83. * @param task the task.
  84. */
  85. public void remove(Task task) {
  86. this.tasks.remove(task);
  87. fireSeriesChanged();
  88. }
  89. /**
  90. * Removes all tasks from the series and sends
  91. * a {@link org.jfree.data.general.SeriesChangeEvent}
  92. * to all registered listeners.
  93. */
  94. public void removeAll() {
  95. this.tasks.clear();
  96. fireSeriesChanged();
  97. }
  98. /**
  99. * Returns the number of items in the series.
  100. *
  101. * @return The item count.
  102. */
  103. public int getItemCount() {
  104. return this.tasks.size();
  105. }
  106. /**
  107. * Returns a task from the series.
  108. *
  109. * @param index the task index (zero-based).
  110. *
  111. * @return The task.
  112. */
  113. public Task get(int index) {
  114. return (Task) this.tasks.get(index);
  115. }
  116. /**
  117. * Returns the task in the series that has the specified description.
  118. *
  119. * @param description the name (<code>null</code> not permitted).
  120. *
  121. * @return The task (possibly <code>null</code>).
  122. */
  123. public Task get(String description) {
  124. Task result = null;
  125. int count = this.tasks.size();
  126. for (int i = 0; i < count; i++) {
  127. Task t = (Task) this.tasks.get(i);
  128. if (t.getDescription().equals(description)) {
  129. result = t;
  130. break;
  131. }
  132. }
  133. return result;
  134. }
  135. /**
  136. * Returns an unmodifialble list of the tasks in the series.
  137. *
  138. * @return The tasks.
  139. */
  140. public List getTasks() {
  141. return Collections.unmodifiableList(this.tasks);
  142. }
  143. /**
  144. * Tests this object for equality with an arbitrary object.
  145. *
  146. * @param obj the object to test against (<code>null</code> permitted).
  147. *
  148. * @return A boolean.
  149. */
  150. public boolean equals(Object obj) {
  151. if (obj == this) {
  152. return true;
  153. }
  154. if (!(obj instanceof TaskSeries)) {
  155. return false;
  156. }
  157. if (!super.equals(obj)) {
  158. return false;
  159. }
  160. TaskSeries that = (TaskSeries) obj;
  161. if (!this.tasks.equals(that.tasks)) {
  162. return false;
  163. }
  164. return true;
  165. }
  166. }