/******************************************************************************
 * MarkForm.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.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace GODS
{
	using MarkData;
	using MarkGUI;

	/// <summary>
	/// Summary description for MarkForm.
	/// </summary>
	public class MarkForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.ComboBox cbBxMarkset;
		private System.Windows.Forms.Label lblMarkset;
		private System.Windows.Forms.Panel pnlMark;
		private ArrayList markViews;

		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public MarkForm()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MarkForm));
			this.cbBxMarkset = new System.Windows.Forms.ComboBox();
			this.lblMarkset = new System.Windows.Forms.Label();
			this.pnlMark = new System.Windows.Forms.Panel();
			this.SuspendLayout();
			// 
			// cbBxMarkset
			// 
			this.cbBxMarkset.ImeMode = System.Windows.Forms.ImeMode.Off;
			this.cbBxMarkset.Location = new System.Drawing.Point(87, 11);
			this.cbBxMarkset.Name = "cbBxMarkset";
			this.cbBxMarkset.Size = new System.Drawing.Size(161, 21);
			this.cbBxMarkset.TabIndex = 0;
			this.cbBxMarkset.SelectedIndexChanged += new System.EventHandler(this.cbBxMarkset_SelectedIndexChanged);
			// 
			// lblMarkset
			// 
			this.lblMarkset.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lblMarkset.Location = new System.Drawing.Point(16, 16);
			this.lblMarkset.Name = "lblMarkset";
			this.lblMarkset.Size = new System.Drawing.Size(64, 16);
			this.lblMarkset.TabIndex = 1;
			this.lblMarkset.Text = "Markset";
			// 
			// pnlMark
			// 
			this.pnlMark.AutoScroll = true;
			this.pnlMark.Location = new System.Drawing.Point(8, 48);
			this.pnlMark.Name = "pnlMark";
			this.pnlMark.Size = new System.Drawing.Size(248, 528);
			this.pnlMark.TabIndex = 2;
			// 
			// MarkForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(264, 582);
			this.ControlBox = false;
			this.Controls.Add(this.pnlMark);
			this.Controls.Add(this.lblMarkset);
			this.Controls.Add(this.cbBxMarkset);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.Name = "MarkForm";
			this.ShowInTaskbar = false;
			this.Text = "Marks";
			this.TopMost = true;
			this.ResumeLayout(false);

		}
		#endregion

		public void loadMarkset(int index)
		{
			this.cbBxMarkset.Items.Clear();
			this.cbBxMarkset.Items.AddRange(GODS.GODSMain.currCategory.Marksets.ToArray());
			this.cbBxMarkset.SelectedIndex = index;
			this.markViews = GODS.GODSMain.marksetHandler.loadMarkPanel(this.pnlMark, GODS.GODSMain.currMarkSet, null);
		}
        
		public void loadMarksetWithID(int marksetID)
		{
			for(int i=0; i<cbBxMarkset.Items.Count; i++)
			{
				if(((GODS.MarkData.MarkSet)(this.cbBxMarkset.Items[i])).MarkSetID == marksetID)
				{
					loadMarkset(i);
				}
			}
			
		}
		public void updateMarkForm(MarkSet ms, ArrayList marks)
		{
			// cause the markset change and load marks
			this.cbBxMarkset.SelectedIndex = GODS.GODSMain.currCategory.Marksets.IndexOf(ms);

			// change the values in some of the marks with preset-values
			foreach (MarkView mv in this.markViews)
			{
				if (mv.MyMark.HasPresetValues)
				{
					bool found = false;
					foreach (Mark markOnImage in marks)
					{
						if (mv.MyMark.Equals(markOnImage)) 
						{
							mv.setCurrentValueIndex(markOnImage.CurrentValueIndex);
							found = true;
						}
					}
					if (!found)
						mv.setCurrentValueIndex(0);
				}
			}
		}

		private void cbBxMarkset_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			this.markViews = GODS.GODSMain.marksetHandler.loadMarkPanel(this.pnlMark, (MarkSet) this.cbBxMarkset.SelectedItem, null);
			GODS.GODSMain.currMarkSet = (MarkSet) this.cbBxMarkset.SelectedItem;
		}
	}
}
