/******************************************************************************
 * MarkCategory.cs 
 * 
 * <Copyright and License> 
 * 
 * This file is part of GODS, a package for annotating medical images. 
 * 
 * Copyright (C) 2004 
 * Xuedong Chen 
 * Heri Mariwa 
 * Kimmy (Hsiang-ling) Lin 
 * Rui Yu 
 * 
 * This program is free software; you can redistribute it and/or 
 * modify it under the terms of the GNU General Public License 
 * as published by the Free Software Foundation; either version 2 
 * of the License, or (at your option) any later version. 
 * 
 * This program is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
 * GNU General Public License for more details. 
 * 
 * You should have received a copy of the GNU General Public License 
 * along with this program; if not, write to the Free Software 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
 *  
 * For further questions about this file, please send email to 
 * gods@cs.umb.edu or visit us at http://gods.sourceforge.net.  
 ******************************************************************************/

using System;
using System.Collections;

namespace GODS.MarkData
{
	/// <summary>
	/// Summary description for MarkCategory.
	/// </summary>
	public class MarkCategory
	{
		private ArrayList markSetList;
		private string name;
		private bool removable = true;

		public MarkCategory(string name)
		{
			this.name = name;
			markSetList = new ArrayList();
		}

		public string CategoryName
		{
			get 
			{
				return name;
			}
			set
			{
				name = value;
			}
		}

		public ArrayList Marksets
		{
			get 
			{
				return this.markSetList;
			}
		}

		public bool Removable
		{
			get 
			{
				return this.removable;
			}
		}

		public void addMarkSet(MarkSet newMarkset)
		{
			MarkSet markset = this.getMarkSet(newMarkset.MarksetName);
			if (markset == null) 
			{
				this.markSetList.Add(newMarkset);
			}
			else
			{
				throw new System.Exception("Duplicate markset: Markset with the same name already exists.");
			}
		}

		public void removeMarkSet(MarkSet markset)
		{
			this.markSetList.Remove(markset);
		}

		internal MarkSet getMarkSet(string msName)
		{
			foreach (MarkSet markset in this.markSetList)
			{
				if (msName.Equals(markset.MarksetName))
					return markset;
			}
			return null;
		}

		public MarkSet getMarkSet(int id)
		{
			foreach (MarkSet markset in this.markSetList)
			{
				if (markset.MarkSetID == id)
					return markset;
			}
			return null;
		}

		public override string ToString()
		{
			return this.name;
		}

		public override bool Equals(object obj)
		{
			return (obj.GetType().Equals(this.GetType()) &&
				 ((MarkCategory) obj).name.Equals(this.name));
		}

		public override int GetHashCode()
		{
			return base.GetHashCode ();
		}


	}
}

