001 /* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2007, 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 * TaskSeries.java 029 * --------------- 030 * (C) Copyright 2002-2007, by Object Refinery Limited. 031 * 032 * Original Author: David Gilbert (for Object Refinery Limited); 033 * Contributor(s): -; 034 * 035 * Changes 036 * ------- 037 * 06-Jun-2002 : Version 1 (DG); 038 * 07-Oct-2002 : Fixed errors reported by Checkstyle (DG); 039 * 24-Oct-2002 : Added methods to get TimeAllocation by task index (DG); 040 * 10-Jan-2003 : Renamed GanttSeries --> TaskSeries (DG); 041 * 30-Jul-2004 : Added equals() method (DG); 042 * 043 */ 044 045 package org.jfree.data.gantt; 046 047 import java.util.Collections; 048 import java.util.List; 049 050 import org.jfree.data.general.Series; 051 052 /** 053 * A series that contains zero, one or many {@link Task} objects. 054 * <P> 055 * This class is used as a building block for the {@link TaskSeriesCollection} 056 * class that can be used to construct basic Gantt charts. 057 */ 058 public class TaskSeries extends Series { 059 060 /** Storage for the tasks in the series. */ 061 private List tasks; 062 063 /** 064 * Constructs a new series with the specified name. 065 * 066 * @param name the series name (<code>null</code> not permitted). 067 */ 068 public TaskSeries(String name) { 069 super(name); 070 this.tasks = new java.util.ArrayList(); 071 } 072 073 /** 074 * Adds a task to the series and sends a 075 * {@link org.jfree.data.general.SeriesChangeEvent} to all registered 076 * listeners. 077 * 078 * @param task the task (<code>null</code> not permitted). 079 */ 080 public void add(Task task) { 081 if (task == null) { 082 throw new IllegalArgumentException("Null 'task' argument."); 083 } 084 this.tasks.add(task); 085 fireSeriesChanged(); 086 } 087 088 /** 089 * Removes a task from the series and sends 090 * a {@link org.jfree.data.general.SeriesChangeEvent} 091 * to all registered listeners. 092 * 093 * @param task the task. 094 */ 095 public void remove(Task task) { 096 this.tasks.remove(task); 097 fireSeriesChanged(); 098 } 099 100 /** 101 * Removes all tasks from the series and sends 102 * a {@link org.jfree.data.general.SeriesChangeEvent} 103 * to all registered listeners. 104 */ 105 public void removeAll() { 106 this.tasks.clear(); 107 fireSeriesChanged(); 108 } 109 110 /** 111 * Returns the number of items in the series. 112 * 113 * @return The item count. 114 */ 115 public int getItemCount() { 116 return this.tasks.size(); 117 } 118 119 /** 120 * Returns a task from the series. 121 * 122 * @param index the task index (zero-based). 123 * 124 * @return The task. 125 */ 126 public Task get(int index) { 127 return (Task) this.tasks.get(index); 128 } 129 130 /** 131 * Returns the task in the series that has the specified description. 132 * 133 * @param description the name (<code>null</code> not permitted). 134 * 135 * @return The task (possibly <code>null</code>). 136 */ 137 public Task get(String description) { 138 Task result = null; 139 int count = this.tasks.size(); 140 for (int i = 0; i < count; i++) { 141 Task t = (Task) this.tasks.get(i); 142 if (t.getDescription().equals(description)) { 143 result = t; 144 break; 145 } 146 } 147 return result; 148 } 149 150 /** 151 * Returns an unmodifialble list of the tasks in the series. 152 * 153 * @return The tasks. 154 */ 155 public List getTasks() { 156 return Collections.unmodifiableList(this.tasks); 157 } 158 159 /** 160 * Tests this object for equality with an arbitrary object. 161 * 162 * @param obj the object to test against (<code>null</code> permitted). 163 * 164 * @return A boolean. 165 */ 166 public boolean equals(Object obj) { 167 if (obj == this) { 168 return true; 169 } 170 if (!(obj instanceof TaskSeries)) { 171 return false; 172 } 173 if (!super.equals(obj)) { 174 return false; 175 } 176 TaskSeries that = (TaskSeries) obj; 177 if (!this.tasks.equals(that.tasks)) { 178 return false; 179 } 180 return true; 181 } 182 183 }