Source for 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
  20:  * License along with this library; if not, write to the Free Software
  21:  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
  22:  * USA.  
  23:  *
  24:  * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
  25:  * in the United States and other countries.]
  26:  *
  27:  * ---------------
  28:  * TaskSeries.java
  29:  * ---------------
  30:  * (C) Copyright 2002-2004, by Object Refinery Limited.
  31:  *
  32:  * Original Author:  David Gilbert (for Object Refinery Limited);
  33:  * Contributor(s):   -;
  34:  *
  35:  * $Id: TaskSeries.java,v 1.3.2.1 2005/10/25 21:31:43 mungady Exp $
  36:  *
  37:  * Changes
  38:  * -------
  39:  * 06-Jun-2002 : Version 1 (DG);
  40:  * 07-Oct-2002 : Fixed errors reported by Checkstyle (DG);
  41:  * 24-Oct-2002 : Added methods to get TimeAllocation by task index (DG);
  42:  * 10-Jan-2003 : Renamed GanttSeries --> TaskSeries (DG);
  43:  * 30-Jul-2004 : Added equals() method (DG);
  44:  *
  45:  */
  46: 
  47: package org.jfree.data.gantt;
  48: 
  49: import java.util.Collections;
  50: import java.util.List;
  51: 
  52: import org.jfree.data.general.Series;
  53: 
  54: /**
  55:  * A series that contains zero, one or many {@link Task} objects.
  56:  * <P>
  57:  * This class is used as a building block for the {@link TaskSeriesCollection}
  58:  * class that can be used to construct basic Gantt charts.
  59:  */
  60: public class TaskSeries extends Series {
  61: 
  62:     /** Storage for the tasks in the series. */
  63:     private List tasks;
  64: 
  65:     /**
  66:      * Constructs a new series with the specified name.
  67:      *
  68:      * @param name  the series name (<code>null</code> not permitted).
  69:      */
  70:     public TaskSeries(String name) {
  71:         super(name);
  72:         this.tasks = new java.util.ArrayList();
  73:     }
  74: 
  75:     /**
  76:      * Adds a task to the series and sends a 
  77:      * {@link org.jfree.data.general.SeriesChangeEvent} to all registered 
  78:      * listeners.
  79:      *
  80:      * @param task  the task (<code>null</code> not permitted).
  81:      */
  82:     public void add(Task task) {
  83:         if (task == null) {
  84:             throw new IllegalArgumentException("Null 'task' argument.");
  85:         }
  86:         this.tasks.add(task);
  87:         fireSeriesChanged();
  88:     }
  89: 
  90:     /**
  91:      * Removes a task from the series and sends 
  92:      * a {@link org.jfree.data.general.SeriesChangeEvent} 
  93:      * to all registered listeners.
  94:      *
  95:      * @param task  the task.
  96:      */
  97:     public void remove(Task task) {
  98:         this.tasks.remove(task);
  99:         fireSeriesChanged();
 100:     }
 101: 
 102:     /**
 103:      * Removes all tasks from the series and sends 
 104:      * a {@link org.jfree.data.general.SeriesChangeEvent} 
 105:      * to all registered listeners.
 106:      */
 107:     public void removeAll() {
 108:         this.tasks.clear();
 109:         fireSeriesChanged();
 110:     }
 111: 
 112:     /**
 113:      * Returns the number of items in the series.
 114:      *
 115:      * @return The item count.
 116:      */
 117:     public int getItemCount() {
 118:         return this.tasks.size();
 119:     }
 120: 
 121:     /**
 122:      * Returns a task from the series.
 123:      *
 124:      * @param index  the task index (zero-based).
 125:      *
 126:      * @return The task.
 127:      */
 128:     public Task get(int index) {
 129:         return (Task) this.tasks.get(index);
 130:     }
 131:     
 132:     /**
 133:      * Returns the task in the series that has the specified description.
 134:      * 
 135:      * @param description  the name (<code>null</code> not permitted).
 136:      * 
 137:      * @return The task (possibly <code>null</code>).
 138:      */
 139:     public Task get(String description) {
 140:         Task result = null;
 141:         int count = this.tasks.size();
 142:         for (int i = 0; i < count; i++) {
 143:             Task t = (Task) this.tasks.get(i);
 144:             if (t.getDescription().equals(description)) {
 145:                 result = t;
 146:                 break;
 147:             }
 148:         }
 149:         return result;
 150:     }
 151: 
 152:     /**
 153:      * Returns an unmodifialble list of the tasks in the series.
 154:      *
 155:      * @return The tasks.
 156:      */
 157:     public List getTasks() {
 158:         return Collections.unmodifiableList(this.tasks);
 159:     }
 160: 
 161:     /**
 162:      * Tests this object for equality with an arbitrary object.
 163:      * 
 164:      * @param obj  the object to test against (<code>null</code> permitted).
 165:      * 
 166:      * @return A boolean.
 167:      */
 168:     public boolean equals(Object obj) {
 169:         if (obj == this) {
 170:             return true;
 171:         }
 172:         if (!(obj instanceof TaskSeries)) {
 173:             return false;
 174:         }
 175:         if (!super.equals(obj)) {
 176:             return false;
 177:         }
 178:         TaskSeries that = (TaskSeries) obj;
 179:         if (!this.tasks.equals(that.tasks)) {
 180:             return false;
 181:         }
 182:         return true;
 183:     }
 184:     
 185: }