/******************************************************************************
 * MarkSetConfiguration.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;
using GODS.MarkData;
using GODS.MarkGUI;

namespace GODS.MarkConfig
{
	/// <summary>
	/// Summary description for MarkSetConfiguration.
	/// </summary>
	public class MarkSetConfiguration : System.Windows.Forms.Form
	{
		private System.Windows.Forms.GroupBox previewGBox;
		private System.Windows.Forms.Panel previewPanel;
		private System.Windows.Forms.GroupBox marksetGBox;
		private System.Windows.Forms.Label lblCategory;
		private System.Windows.Forms.Button btnRmCat;
		private System.Windows.Forms.Button btnEditCat;
		private System.Windows.Forms.Button btnAddCat;
		private System.Windows.Forms.ComboBox cBoxCategory;
		private System.Windows.Forms.Button btnRmMarkset;
		private System.Windows.Forms.Button btnEditMarkset;
		private System.Windows.Forms.Button btnAddMarkset;
		private System.Windows.Forms.ComboBox cBoxMarkset;
		private System.Windows.Forms.Label lblMarkset;
		private System.Windows.Forms.GroupBox gBoxMarkGroup;
		private System.Windows.Forms.Button btnSaveMarkset;
		private System.Windows.Forms.Button btnHelp;
		private System.Windows.Forms.Button btnExit;
		private System.Windows.Forms.Button btnRmGroup;
		private System.Windows.Forms.Button btnEditGroup;
		private System.Windows.Forms.Button btnAddGroup;
		private System.Windows.Forms.ComboBox cBoxGroup;
		private System.Windows.Forms.Label lblGroup;
		private System.Windows.Forms.Label lblMark;
		private System.Windows.Forms.TextBox txtBoxMarkName;
		private System.Windows.Forms.GroupBox gBoxMark;
		private System.Windows.Forms.Label lblMarkDesc;
		private System.Windows.Forms.RichTextBox txtBoxDesc;
		private System.Windows.Forms.Label lblMarkImage;
		private System.Windows.Forms.Button btnBrowseImage;
		private System.Windows.Forms.TextBox txtBoxImage;
		private System.Windows.Forms.Label lblTxtValues;
		private System.Windows.Forms.ListBox lBoxTextValues;
		private System.Windows.Forms.Button btnAddValue;
		private System.Windows.Forms.Button btnEditValue;
		private System.Windows.Forms.Button btnRmValue;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		
		private MarkView currentMarkView;
		private InputDialog inputDialog;
		private OpenFileDialog openFileDialog;
		private ArrayList categories;
		private MarkCategory currCategory;
		private MarkSet currMarkSet;
		private MarkGroup currMarkGroup;
		private System.Windows.Forms.Button btnReset;
		private System.Windows.Forms.Button btnAddMark;
		private System.Windows.Forms.Button btnSaveMark;
		private System.Windows.Forms.Button btnDelMark;

		//enableing thumnail viewing of mark images
		private FileDialogExtender _extender = new FileDialogExtender(FileDialogExtender.DialogViewTypes.Thumbnails,true); 

		public MarkSetConfiguration()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			this.inputDialog = new InputDialog();
			this.openFileDialog = new OpenFileDialog();
			this.openFileDialog.Filter="Image files (*.bmp, *.jpg, *.gif, *.ico)|*.BMP;*.JPG;*.GIF;*.ICO";
			this.loadCategories();
		}

		private void loadCategories()
		{
			GODS.GODSMain.marksetHandler.loadAllCategories();
			this.categories = GODS.GODSMain.marksetHandler.Categories;
			if(categories != null && categories.Count > 0)
			{
				this.cBoxCategory.Items.Add( new MarkCategory(" "));
				this.cBoxCategory.Items.AddRange(this.categories.ToArray());
				this.cBoxCategory.SelectedIndex = 0;
			}
		}
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{   
			
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		//
		//This will enable the thumb nail viewing of the image possible
		//
		protected override void WndProc(ref Message m)
		{
			base.WndProc(ref m);
			_extender.WndProc(ref m);
		}

 
		#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(MarkSetConfiguration));
			this.previewGBox = new System.Windows.Forms.GroupBox();
			this.previewPanel = new System.Windows.Forms.Panel();
			this.marksetGBox = new System.Windows.Forms.GroupBox();
			this.btnExit = new System.Windows.Forms.Button();
			this.btnHelp = new System.Windows.Forms.Button();
			this.btnSaveMarkset = new System.Windows.Forms.Button();
			this.gBoxMarkGroup = new System.Windows.Forms.GroupBox();
			this.gBoxMark = new System.Windows.Forms.GroupBox();
			this.btnSaveMark = new System.Windows.Forms.Button();
			this.btnReset = new System.Windows.Forms.Button();
			this.btnAddMark = new System.Windows.Forms.Button();
			this.btnDelMark = new System.Windows.Forms.Button();
			this.btnRmValue = new System.Windows.Forms.Button();
			this.btnEditValue = new System.Windows.Forms.Button();
			this.btnAddValue = new System.Windows.Forms.Button();
			this.lBoxTextValues = new System.Windows.Forms.ListBox();
			this.lblTxtValues = new System.Windows.Forms.Label();
			this.btnBrowseImage = new System.Windows.Forms.Button();
			this.txtBoxImage = new System.Windows.Forms.TextBox();
			this.lblMarkImage = new System.Windows.Forms.Label();
			this.txtBoxDesc = new System.Windows.Forms.RichTextBox();
			this.lblMarkDesc = new System.Windows.Forms.Label();
			this.lblMark = new System.Windows.Forms.Label();
			this.txtBoxMarkName = new System.Windows.Forms.TextBox();
			this.btnRmGroup = new System.Windows.Forms.Button();
			this.btnEditGroup = new System.Windows.Forms.Button();
			this.btnAddGroup = new System.Windows.Forms.Button();
			this.cBoxGroup = new System.Windows.Forms.ComboBox();
			this.lblGroup = new System.Windows.Forms.Label();
			this.btnRmMarkset = new System.Windows.Forms.Button();
			this.btnEditMarkset = new System.Windows.Forms.Button();
			this.btnAddMarkset = new System.Windows.Forms.Button();
			this.cBoxMarkset = new System.Windows.Forms.ComboBox();
			this.lblMarkset = new System.Windows.Forms.Label();
			this.lblCategory = new System.Windows.Forms.Label();
			this.btnRmCat = new System.Windows.Forms.Button();
			this.btnEditCat = new System.Windows.Forms.Button();
			this.btnAddCat = new System.Windows.Forms.Button();
			this.cBoxCategory = new System.Windows.Forms.ComboBox();
			this.previewGBox.SuspendLayout();
			this.marksetGBox.SuspendLayout();
			this.gBoxMarkGroup.SuspendLayout();
			this.gBoxMark.SuspendLayout();
			this.SuspendLayout();
			// 
			// previewGBox
			// 
			this.previewGBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.previewGBox.Controls.Add(this.previewPanel);
			this.previewGBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.previewGBox.Location = new System.Drawing.Point(504, 56);
			this.previewGBox.Name = "previewGBox";
			this.previewGBox.Size = new System.Drawing.Size(285, 488);
			this.previewGBox.TabIndex = 23;
			this.previewGBox.TabStop = false;
			this.previewGBox.Text = "Preview";
			// 
			// previewPanel
			// 
			this.previewPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.previewPanel.AutoScroll = true;
			this.previewPanel.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.previewPanel.Location = new System.Drawing.Point(13, 17);
			this.previewPanel.Name = "previewPanel";
			this.previewPanel.Size = new System.Drawing.Size(256, 456);
			this.previewPanel.TabIndex = 0;
			// 
			// marksetGBox
			// 
			this.marksetGBox.Controls.Add(this.btnExit);
			this.marksetGBox.Controls.Add(this.btnHelp);
			this.marksetGBox.Controls.Add(this.btnSaveMarkset);
			this.marksetGBox.Controls.Add(this.gBoxMarkGroup);
			this.marksetGBox.Controls.Add(this.btnRmMarkset);
			this.marksetGBox.Controls.Add(this.btnEditMarkset);
			this.marksetGBox.Controls.Add(this.btnAddMarkset);
			this.marksetGBox.Controls.Add(this.cBoxMarkset);
			this.marksetGBox.Controls.Add(this.lblMarkset);
			this.marksetGBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.marksetGBox.Location = new System.Drawing.Point(16, 56);
			this.marksetGBox.Name = "marksetGBox";
			this.marksetGBox.Size = new System.Drawing.Size(480, 488);
			this.marksetGBox.TabIndex = 24;
			this.marksetGBox.TabStop = false;
			this.marksetGBox.Text = "Mark Set";
			// 
			// btnExit
			// 
			this.btnExit.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnExit.Location = new System.Drawing.Point(352, 456);
			this.btnExit.Name = "btnExit";
			this.btnExit.Size = new System.Drawing.Size(104, 23);
			this.btnExit.TabIndex = 39;
			this.btnExit.Text = "Exit";
			this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
			// 
			// btnHelp
			// 
			this.btnHelp.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnHelp.Location = new System.Drawing.Point(216, 456);
			this.btnHelp.Name = "btnHelp";
			this.btnHelp.Size = new System.Drawing.Size(104, 23);
			this.btnHelp.TabIndex = 38;
			this.btnHelp.Text = "Help";
			this.btnHelp.Click += new System.EventHandler(this.btnHelp_Click);
			// 
			// btnSaveMarkset
			// 
			this.btnSaveMarkset.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnSaveMarkset.Location = new System.Drawing.Point(80, 456);
			this.btnSaveMarkset.Name = "btnSaveMarkset";
			this.btnSaveMarkset.Size = new System.Drawing.Size(104, 23);
			this.btnSaveMarkset.TabIndex = 36;
			this.btnSaveMarkset.Text = "Save Mark Set";
			this.btnSaveMarkset.Click += new System.EventHandler(this.btnSaveMarkset_Click);
			// 
			// gBoxMarkGroup
			// 
			this.gBoxMarkGroup.Controls.Add(this.gBoxMark);
			this.gBoxMarkGroup.Controls.Add(this.btnRmGroup);
			this.gBoxMarkGroup.Controls.Add(this.btnEditGroup);
			this.gBoxMarkGroup.Controls.Add(this.btnAddGroup);
			this.gBoxMarkGroup.Controls.Add(this.cBoxGroup);
			this.gBoxMarkGroup.Controls.Add(this.lblGroup);
			this.gBoxMarkGroup.Location = new System.Drawing.Point(16, 64);
			this.gBoxMarkGroup.Name = "gBoxMarkGroup";
			this.gBoxMarkGroup.Size = new System.Drawing.Size(456, 384);
			this.gBoxMarkGroup.TabIndex = 35;
			this.gBoxMarkGroup.TabStop = false;
			this.gBoxMarkGroup.Text = "Mark Group";
			// 
			// gBoxMark
			// 
			this.gBoxMark.Controls.Add(this.btnSaveMark);
			this.gBoxMark.Controls.Add(this.btnReset);
			this.gBoxMark.Controls.Add(this.btnAddMark);
			this.gBoxMark.Controls.Add(this.btnDelMark);
			this.gBoxMark.Controls.Add(this.btnRmValue);
			this.gBoxMark.Controls.Add(this.btnEditValue);
			this.gBoxMark.Controls.Add(this.btnAddValue);
			this.gBoxMark.Controls.Add(this.lBoxTextValues);
			this.gBoxMark.Controls.Add(this.lblTxtValues);
			this.gBoxMark.Controls.Add(this.btnBrowseImage);
			this.gBoxMark.Controls.Add(this.txtBoxImage);
			this.gBoxMark.Controls.Add(this.lblMarkImage);
			this.gBoxMark.Controls.Add(this.txtBoxDesc);
			this.gBoxMark.Controls.Add(this.lblMarkDesc);
			this.gBoxMark.Controls.Add(this.lblMark);
			this.gBoxMark.Controls.Add(this.txtBoxMarkName);
			this.gBoxMark.Location = new System.Drawing.Point(16, 64);
			this.gBoxMark.Name = "gBoxMark";
			this.gBoxMark.Size = new System.Drawing.Size(424, 304);
			this.gBoxMark.TabIndex = 42;
			this.gBoxMark.TabStop = false;
			this.gBoxMark.Text = "Mark";
			// 
			// btnSaveMark
			// 
			this.btnSaveMark.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnSaveMark.Location = new System.Drawing.Point(136, 256);
			this.btnSaveMark.Name = "btnSaveMark";
			this.btnSaveMark.Size = new System.Drawing.Size(75, 32);
			this.btnSaveMark.TabIndex = 61;
			this.btnSaveMark.Text = "Save Mark";
			this.btnSaveMark.Click += new System.EventHandler(this.btnSaveMark_Click);
			// 
			// btnReset
			// 
			this.btnReset.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnReset.Location = new System.Drawing.Point(40, 256);
			this.btnReset.Name = "btnReset";
			this.btnReset.Size = new System.Drawing.Size(72, 32);
			this.btnReset.TabIndex = 59;
			this.btnReset.Text = "Clear";
			this.btnReset.Click += new System.EventHandler(this.btnReset_Click);
			// 
			// btnAddMark
			// 
			this.btnAddMark.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnAddMark.Location = new System.Drawing.Point(224, 256);
			this.btnAddMark.Name = "btnAddMark";
			this.btnAddMark.Size = new System.Drawing.Size(96, 32);
			this.btnAddMark.TabIndex = 58;
			this.btnAddMark.Text = "Save, Add Another Mark";
			this.btnAddMark.Click += new System.EventHandler(this.btnAddMark_Click);
			// 
			// btnDelMark
			// 
			this.btnDelMark.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnDelMark.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(0)), ((System.Byte)(0)));
			this.btnDelMark.Location = new System.Drawing.Point(344, 256);
			this.btnDelMark.Name = "btnDelMark";
			this.btnDelMark.Size = new System.Drawing.Size(72, 32);
			this.btnDelMark.TabIndex = 60;
			this.btnDelMark.Text = "Delete Mark";
			this.btnDelMark.Click += new System.EventHandler(this.btnDelMark_Click);
			// 
			// btnRmValue
			// 
			this.btnRmValue.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnRmValue.Location = new System.Drawing.Point(336, 220);
			this.btnRmValue.Name = "btnRmValue";
			this.btnRmValue.Size = new System.Drawing.Size(72, 22);
			this.btnRmValue.TabIndex = 51;
			this.btnRmValue.Text = "Remove";
			this.btnRmValue.Click += new System.EventHandler(this.btnRmValue_Click);
			// 
			// btnEditValue
			// 
			this.btnEditValue.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnEditValue.Location = new System.Drawing.Point(336, 190);
			this.btnEditValue.Name = "btnEditValue";
			this.btnEditValue.Size = new System.Drawing.Size(72, 22);
			this.btnEditValue.TabIndex = 50;
			this.btnEditValue.Text = "Edit";
			this.btnEditValue.Click += new System.EventHandler(this.btnEditValue_Click);
			// 
			// btnAddValue
			// 
			this.btnAddValue.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnAddValue.Location = new System.Drawing.Point(336, 160);
			this.btnAddValue.Name = "btnAddValue";
			this.btnAddValue.Size = new System.Drawing.Size(72, 22);
			this.btnAddValue.TabIndex = 49;
			this.btnAddValue.Text = "Add";
			this.btnAddValue.Click += new System.EventHandler(this.btnAddValue_Click);
			// 
			// lBoxTextValues
			// 
			this.lBoxTextValues.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lBoxTextValues.Location = new System.Drawing.Point(128, 160);
			this.lBoxTextValues.Name = "lBoxTextValues";
			this.lBoxTextValues.Size = new System.Drawing.Size(200, 56);
			this.lBoxTextValues.TabIndex = 48;
			// 
			// lblTxtValues
			// 
			this.lblTxtValues.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lblTxtValues.Location = new System.Drawing.Point(16, 160);
			this.lblTxtValues.Name = "lblTxtValues";
			this.lblTxtValues.Size = new System.Drawing.Size(80, 24);
			this.lblTxtValues.TabIndex = 47;
			this.lblTxtValues.Text = "Pulldown List Values :";
			this.lblTxtValues.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// btnBrowseImage
			// 
			this.btnBrowseImage.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnBrowseImage.Location = new System.Drawing.Point(336, 119);
			this.btnBrowseImage.Name = "btnBrowseImage";
			this.btnBrowseImage.Size = new System.Drawing.Size(72, 22);
			this.btnBrowseImage.TabIndex = 46;
			this.btnBrowseImage.Text = "Browse";
			this.btnBrowseImage.Click += new System.EventHandler(this.btnBrowseImage_Click);
			// 
			// txtBoxImage
			// 
			this.txtBoxImage.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtBoxImage.Location = new System.Drawing.Point(128, 120);
			this.txtBoxImage.Name = "txtBoxImage";
			this.txtBoxImage.ReadOnly = true;
			this.txtBoxImage.Size = new System.Drawing.Size(200, 19);
			this.txtBoxImage.TabIndex = 45;
			this.txtBoxImage.Text = "";
			// 
			// lblMarkImage
			// 
			this.lblMarkImage.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lblMarkImage.Location = new System.Drawing.Point(16, 117);
			this.lblMarkImage.Name = "lblMarkImage";
			this.lblMarkImage.Size = new System.Drawing.Size(80, 24);
			this.lblMarkImage.TabIndex = 44;
			this.lblMarkImage.Text = "Image :";
			this.lblMarkImage.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// txtBoxDesc
			// 
			this.txtBoxDesc.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtBoxDesc.Location = new System.Drawing.Point(128, 64);
			this.txtBoxDesc.MaxLength = 100;
			this.txtBoxDesc.Name = "txtBoxDesc";
			this.txtBoxDesc.Size = new System.Drawing.Size(200, 40);
			this.txtBoxDesc.TabIndex = 43;
			this.txtBoxDesc.Text = "";
			// 
			// lblMarkDesc
			// 
			this.lblMarkDesc.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lblMarkDesc.Location = new System.Drawing.Point(16, 64);
			this.lblMarkDesc.Name = "lblMarkDesc";
			this.lblMarkDesc.Size = new System.Drawing.Size(96, 24);
			this.lblMarkDesc.TabIndex = 42;
			this.lblMarkDesc.Text = "Text :";
			this.lblMarkDesc.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// lblMark
			// 
			this.lblMark.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lblMark.Location = new System.Drawing.Point(16, 32);
			this.lblMark.Name = "lblMark";
			this.lblMark.Size = new System.Drawing.Size(80, 24);
			this.lblMark.TabIndex = 40;
			this.lblMark.Text = "Name :";
			this.lblMark.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// txtBoxMarkName
			// 
			this.txtBoxMarkName.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtBoxMarkName.Location = new System.Drawing.Point(128, 32);
			this.txtBoxMarkName.MaxLength = 50;
			this.txtBoxMarkName.Name = "txtBoxMarkName";
			this.txtBoxMarkName.Size = new System.Drawing.Size(200, 19);
			this.txtBoxMarkName.TabIndex = 41;
			this.txtBoxMarkName.Text = "";
			// 
			// btnRmGroup
			// 
			this.btnRmGroup.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnRmGroup.Location = new System.Drawing.Point(392, 24);
			this.btnRmGroup.Name = "btnRmGroup";
			this.btnRmGroup.Size = new System.Drawing.Size(56, 20);
			this.btnRmGroup.TabIndex = 39;
			this.btnRmGroup.Text = "Remove";
			this.btnRmGroup.Visible = false;
			this.btnRmGroup.Click += new System.EventHandler(this.btnRmGroup_Click);
			// 
			// btnEditGroup
			// 
			this.btnEditGroup.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnEditGroup.Location = new System.Drawing.Point(352, 24);
			this.btnEditGroup.Name = "btnEditGroup";
			this.btnEditGroup.Size = new System.Drawing.Size(33, 20);
			this.btnEditGroup.TabIndex = 38;
			this.btnEditGroup.Text = "Edit";
			this.btnEditGroup.Click += new System.EventHandler(this.btnEditGroup_Click);
			// 
			// btnAddGroup
			// 
			this.btnAddGroup.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnAddGroup.Location = new System.Drawing.Point(312, 24);
			this.btnAddGroup.Name = "btnAddGroup";
			this.btnAddGroup.Size = new System.Drawing.Size(32, 20);
			this.btnAddGroup.TabIndex = 37;
			this.btnAddGroup.Text = "Add";
			this.btnAddGroup.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.btnAddGroup.Click += new System.EventHandler(this.btnAddGroup_Click);
			// 
			// cBoxGroup
			// 
			this.cBoxGroup.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cBoxGroup.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.cBoxGroup.Location = new System.Drawing.Point(96, 24);
			this.cBoxGroup.MaxDropDownItems = 50;
			this.cBoxGroup.Name = "cBoxGroup";
			this.cBoxGroup.Size = new System.Drawing.Size(200, 21);
			this.cBoxGroup.TabIndex = 36;
			this.cBoxGroup.SelectedIndexChanged += new System.EventHandler(this.cBoxGroup_SelectedIndexChanged);
			// 
			// lblGroup
			// 
			this.lblGroup.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lblGroup.Location = new System.Drawing.Point(16, 24);
			this.lblGroup.Name = "lblGroup";
			this.lblGroup.Size = new System.Drawing.Size(80, 24);
			this.lblGroup.TabIndex = 35;
			this.lblGroup.Text = "Group Name :";
			this.lblGroup.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// btnRmMarkset
			// 
			this.btnRmMarkset.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnRmMarkset.Location = new System.Drawing.Point(408, 24);
			this.btnRmMarkset.Name = "btnRmMarkset";
			this.btnRmMarkset.Size = new System.Drawing.Size(56, 20);
			this.btnRmMarkset.TabIndex = 34;
			this.btnRmMarkset.Text = "Remove";
			this.btnRmMarkset.Visible = false;
			this.btnRmMarkset.Click += new System.EventHandler(this.btnRmMarkset_Click);
			// 
			// btnEditMarkset
			// 
			this.btnEditMarkset.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnEditMarkset.Location = new System.Drawing.Point(368, 24);
			this.btnEditMarkset.Name = "btnEditMarkset";
			this.btnEditMarkset.Size = new System.Drawing.Size(33, 20);
			this.btnEditMarkset.TabIndex = 33;
			this.btnEditMarkset.Text = "Edit";
			this.btnEditMarkset.Click += new System.EventHandler(this.btnEditMarkset_Click);
			// 
			// btnAddMarkset
			// 
			this.btnAddMarkset.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnAddMarkset.Location = new System.Drawing.Point(328, 24);
			this.btnAddMarkset.Name = "btnAddMarkset";
			this.btnAddMarkset.Size = new System.Drawing.Size(32, 20);
			this.btnAddMarkset.TabIndex = 32;
			this.btnAddMarkset.Text = "Add";
			this.btnAddMarkset.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.btnAddMarkset.Click += new System.EventHandler(this.btnAddMarkset_Click);
			// 
			// cBoxMarkset
			// 
			this.cBoxMarkset.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cBoxMarkset.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.cBoxMarkset.Location = new System.Drawing.Point(80, 24);
			this.cBoxMarkset.MaxDropDownItems = 50;
			this.cBoxMarkset.Name = "cBoxMarkset";
			this.cBoxMarkset.Size = new System.Drawing.Size(232, 21);
			this.cBoxMarkset.TabIndex = 31;
			this.cBoxMarkset.SelectedIndexChanged += new System.EventHandler(this.cBoxMarkset_SelectedIndexChanged);
			// 
			// lblMarkset
			// 
			this.lblMarkset.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lblMarkset.Location = new System.Drawing.Point(16, 24);
			this.lblMarkset.Name = "lblMarkset";
			this.lblMarkset.Size = new System.Drawing.Size(56, 24);
			this.lblMarkset.TabIndex = 30;
			this.lblMarkset.Text = "Mark Set :";
			this.lblMarkset.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// lblCategory
			// 
			this.lblCategory.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lblCategory.Location = new System.Drawing.Point(16, 16);
			this.lblCategory.Name = "lblCategory";
			this.lblCategory.Size = new System.Drawing.Size(72, 24);
			this.lblCategory.TabIndex = 25;
			this.lblCategory.Text = "Category :";
			this.lblCategory.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// btnRmCat
			// 
			this.btnRmCat.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnRmCat.Location = new System.Drawing.Point(424, 17);
			this.btnRmCat.Name = "btnRmCat";
			this.btnRmCat.Size = new System.Drawing.Size(56, 20);
			this.btnRmCat.TabIndex = 29;
			this.btnRmCat.Text = "Remove";
			this.btnRmCat.Visible = false;
			this.btnRmCat.Click += new System.EventHandler(this.btnRmCat_Click);
			// 
			// btnEditCat
			// 
			this.btnEditCat.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnEditCat.Location = new System.Drawing.Point(384, 17);
			this.btnEditCat.Name = "btnEditCat";
			this.btnEditCat.Size = new System.Drawing.Size(33, 20);
			this.btnEditCat.TabIndex = 28;
			this.btnEditCat.Text = "Edit";
			this.btnEditCat.Click += new System.EventHandler(this.btnEditCat_Click);
			// 
			// btnAddCat
			// 
			this.btnAddCat.Location = new System.Drawing.Point(344, 17);
			this.btnAddCat.Name = "btnAddCat";
			this.btnAddCat.Size = new System.Drawing.Size(32, 20);
			this.btnAddCat.TabIndex = 27;
			this.btnAddCat.Text = "Add";
			this.btnAddCat.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.btnAddCat.Click += new System.EventHandler(this.btnAddCat_Click);
			// 
			// cBoxCategory
			// 
			this.cBoxCategory.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cBoxCategory.Location = new System.Drawing.Point(88, 17);
			this.cBoxCategory.MaxDropDownItems = 50;
			this.cBoxCategory.Name = "cBoxCategory";
			this.cBoxCategory.Size = new System.Drawing.Size(240, 21);
			this.cBoxCategory.TabIndex = 26;
			this.cBoxCategory.SelectedIndexChanged += new System.EventHandler(this.cBoxCategory_SelectedIndexChanged);
			// 
			// MarkSetConfiguration
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(804, 565);
			this.Controls.Add(this.btnRmCat);
			this.Controls.Add(this.btnEditCat);
			this.Controls.Add(this.btnAddCat);
			this.Controls.Add(this.cBoxCategory);
			this.Controls.Add(this.lblCategory);
			this.Controls.Add(this.marksetGBox);
			this.Controls.Add(this.previewGBox);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.MinimumSize = new System.Drawing.Size(812, 593);
			this.Name = "MarkSetConfiguration";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Edit Mark Set";
			this.previewGBox.ResumeLayout(false);
			this.marksetGBox.ResumeLayout(false);
			this.gBoxMarkGroup.ResumeLayout(false);
			this.gBoxMark.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private string getUserInput(string title, string origValue)
		{
			this.inputDialog.ShowDialog(title, origValue);
			return this.inputDialog.Input;
		}

		//helper method for modify combo box item
		private void addComboBoxItem(ComboBox b, Object item, string typeName)
		{
			if (!b.Items.Contains(item)) 
			{
				b.Items.Add(item);
				b.SelectedItem = item;
			}
			else 
			{
				MessageBox.Show(this, typeName + " with that name already exists.", "Error");
			}
		}

		//helper method for modify combo box item
		private void editComboBoxItems(ComboBox b, object item)
		{
			int index = b.SelectedIndex;
			b.Items.Remove(item);
			b.Items.Insert(index, item);
			b.SelectedIndex = index;
		}
		
		private void updateMarkSetComboBox(MarkCategory cat)
		{
			this.cBoxMarkset.Items.Clear();
			this.cBoxMarkset.Items.Add(new MarkSet(null," "));
			if (cat == null)
				this.currMarkSet = null;
			else
			{
				this.cBoxMarkset.Items.AddRange(cat.Marksets.ToArray());
				if (this.cBoxMarkset.Items.Count > 0) 
				{
					this.cBoxMarkset.SelectedIndex = 0;
					this.currMarkSet = (MarkSet) this.cBoxMarkset.SelectedItem;
				}
				else
					this.currMarkSet = null;
			}
			// update the mark group for the new mark set
			this.updateMarkGroupComboBox(this.currMarkSet);
		}

		private void updateMarkGroupComboBox(MarkSet ms)
		{
			this.cBoxGroup.Items.Clear();
			this.cBoxGroup.Items.Add( new MarkGroup(null," "));
			if (ms == null)
				this.currMarkGroup = null;
			else
			{
				this.cBoxGroup.Items.AddRange(ms.MarkGroups.ToArray());
				if (this.cBoxGroup.Items.Count > 0)
				{
					this.cBoxGroup.SelectedIndex = 0;
					this.currMarkGroup = (MarkGroup) this.cBoxGroup.SelectedItem;
				}
				else
					this.currMarkGroup = null;
			}

			this.updatePreviewPanel();
		}

		//method to update mark panel preview
		private void updatePreviewPanel()
		{
			//update preview panel
			if (this.currMarkSet != null)
			{
				GODS.GODSMain.marksetHandler.loadMarkPanel
					(this.previewPanel, this.currMarkSet, new EventHandler(this.selectMarkview));
			}
		}

		private void btnAddCat_Click(object sender, System.EventArgs e)
		{
			string input = this.getUserInput("New Catagory Name", "");
			if (input != null)
			{
				MarkCategory cat = new MarkCategory(input);
				this.categories.Add(cat);
				this.currCategory = cat;
				this.addComboBoxItem(this.cBoxCategory, cat, "Category");
				// update the mark set for the new category, will set the current mark set
				this.updateMarkSetComboBox(this.currCategory);
			}
		}

		private void btnEditCat_Click(object sender, System.EventArgs e)
		{
			if (this.currCategory == null) 
			{
				MessageBox.Show("No mark category is selected");
				return;
			}
			string input = this.getUserInput("Edit Catagory Name", this.currCategory.CategoryName);
			if (input != null)
			{
				this.currCategory.CategoryName = input;
				this.editComboBoxItems(this.cBoxCategory, this.currCategory);
			}
		}

		private void btnRmCat_Click(object sender, System.EventArgs e)
		{
			if (this.currCategory != null && this.currCategory.Removable) 
			{
				this.categories.Remove(this.currCategory);
				this.cBoxCategory.Items.Remove(this.currCategory);
				if (this.cBoxCategory.Items.Count > 0) 
					this.cBoxCategory.SelectedIndex = 0;
				else
					this.currCategory = null;
			
				// update the mark set for the new category, will set the current mark set
				this.updateMarkSetComboBox(this.currCategory);
			}
		}

		private void cBoxCategory_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			this.currCategory = (MarkCategory) this.cBoxCategory.SelectedItem;
			// update the mark set for the new category, will set the current mark set
			this.updateMarkSetComboBox(this.currCategory);
		}

		private void btnAddMarkset_Click(object sender, System.EventArgs e)
		{
			if (this.currCategory == null) 
			{
				MessageBox.Show("You must select a category for this mark set.");
				return;
			}

			string input = this.getUserInput("New Mark Set Name", "");
			if (input != null) 
			{
				MarkSet ms = new MarkSet(this.currCategory, input);
				MarkSet markset = this.currCategory.getMarkSet(ms.MarksetName);
				if (markset != null) 
				{				
					MessageBox.Show("Can't add the mark set as it has duplicate names.","Warning");
					return;
				}
				this.currCategory.addMarkSet(ms);
				this.currMarkSet = ms;
				this.addComboBoxItem(this.cBoxMarkset, ms, "Mark Set");
				// update the groups for the new mark set
				this.updateMarkGroupComboBox(this.currMarkSet);
			}
		}

		private void btnEditMarkset_Click(object sender, System.EventArgs e)
		{
			if (this.currMarkSet == null) 
			{
				MessageBox.Show("No mark set is selected");
				return;
			}

			string input = this.getUserInput("Edit Mark Set Name", this.currMarkSet.MarksetName);
			if (input != null)
			{
				MarkSet markset = this.currCategory.getMarkSet(input);
				if (markset != null) 
				{				
					MessageBox.Show("Duplicate mark set name.","Warning");
					return;
				}
				this.currMarkSet.MarksetName = input;
				this.editComboBoxItems(this.cBoxMarkset, this.currMarkSet);
			}
		}

		private void btnRmMarkset_Click(object sender, System.EventArgs e)
		{
			if (this.currMarkSet != null && this.currMarkSet.Removable) 
			{
				this.currCategory.removeMarkSet(this.currMarkSet);
				this.cBoxMarkset.Items.Remove(this.currMarkSet);
				if (this.cBoxMarkset.Items.Count > 0)
					this.cBoxMarkset.SelectedIndex = 0;
				else
					this.currMarkSet = null;
				// update the groups for the new mark set
				this.updateMarkGroupComboBox(this.currMarkSet);
			}
		}

		private void cBoxMarkset_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			this.currMarkSet = (MarkSet) this.cBoxMarkset.SelectedItem;
			this.updateMarkGroupComboBox(this.currMarkSet);
			this.btnReset_Click(null,null);
		}

		private void cBoxGroup_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			this.currMarkGroup = (MarkGroup) this.cBoxGroup.SelectedItem;
		}

		private void btnAddGroup_Click(object sender, System.EventArgs e)
		{
			if (this.currMarkSet == null) 
			{
				MessageBox.Show("You must select a mark set for this mark group.");
				return;
			}

			string input = this.getUserInput("New Mark Group Name", "");
			if (input != null) 
			{
				MarkGroup mg = new MarkGroup(this.currMarkSet, input);
				this.currMarkSet.addMarkGroup(mg);
				this.currMarkGroup = mg;
				this.addComboBoxItem(this.cBoxGroup, mg, "Mark Group");
			}
		}

		private void btnEditGroup_Click(object sender, System.EventArgs e)
		{
			if (this.currMarkGroup == null) 
			{
				MessageBox.Show("No mark group is selected");
				return;
			}

			string input = this.getUserInput("Edit Mark Group Name", this.currMarkGroup.GroupName);
			if (input != null)
			{
				this.currMarkGroup.GroupName = input;
				this.editComboBoxItems(this.cBoxGroup, this.currMarkGroup);
			    this.updatePreviewPanel();
				this.CurrMarkSetHasChanged();
			}	
		}
		
		private void btnRmGroup_Click(object sender, System.EventArgs e)
		{
			if (this.currMarkGroup != null && this.currMarkGroup.Removable) 
			{
				this.cBoxGroup.Items.Remove(this.currMarkGroup);
				this.currMarkSet.removeMarkGroup(this.currMarkGroup);
				if (this.cBoxGroup.Items.Count > 0)
					this.cBoxGroup.SelectedIndex = 0;
				else
					this.currMarkGroup = null;
			}
		}

		private void btnBrowseImage_Click(object sender, System.EventArgs e)
		{
			string imagepath = "";
			if (this.openFileDialog.ShowDialog() == DialogResult.OK)
			{
				imagepath = this.openFileDialog.FileName;
			}
			this.txtBoxImage.Text = imagepath;
		}

		private void btnAddValue_Click(object sender, System.EventArgs e)
		{
			if (this.currMarkGroup == null) 
			{
				MessageBox.Show("You must select a mark group for this mark.");
				return;
			}

			string input = this.getUserInput("New Preset Value", "");
			if (input != null)
			{
				if (this.lBoxTextValues.Items.Contains(input))
					MessageBox.Show(this, "Value already exists.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
				else
					this.lBoxTextValues.Items.Add(input);
			} 
		}

		private void btnEditValue_Click(object sender, System.EventArgs e)
		{
			if (this.lBoxTextValues.SelectedIndex == -1) 
			{
				MessageBox.Show("No preset value is selected");
				return;
			}

			string input = this.getUserInput("Edit Preset Value", (string) this.lBoxTextValues.SelectedItem);
			if (input != null)
			{
				int index = this.lBoxTextValues.SelectedIndex;
				this.lBoxTextValues.Items.RemoveAt(index);
				this.lBoxTextValues.Items.Insert(index, input);
			}		
		}

		private void btnRmValue_Click(object sender, System.EventArgs e)
		{
			if(this.lBoxTextValues.Items.Count >0)
			 this.lBoxTextValues.Items.RemoveAt(this.lBoxTextValues.SelectedIndex);
		}

		private void btnAddMark_Click(object sender, System.EventArgs e)
		{
			btnSaveMark_Click(sender, e);
			this.btnReset_Click(null,null);
			this.currentMarkView = null;
			
		}

		//method to validate input from user
		private void validateInput(string input, string fieldName)
		{
			if (input == null || input.Trim().Equals(""))
				throw new System.Exception("Missing " + fieldName);
		}

		//reset all mark entry form
		private void btnReset_Click(object sender, System.EventArgs e)
		{
			this.txtBoxMarkName.Text = "";
			this.txtBoxDesc.Text = "";
			this.txtBoxImage.Text = "";
			this.lBoxTextValues.Items.Clear();
			this.currentMarkView = null;
		}

		private void btnDelMark_Click(object sender, System.EventArgs e)
		{
			Mark mark =  (this.currentMarkView != null)?this.currentMarkView.MyMark:null;
			
			//don't delete if already in MarkSet
			if(mark != null && mark.MarkID >-1)
			{
				MessageBox.Show("Can't delete the mark as it's already in database.","Warning");
				return;
			}

			//check if there is any mark selected --fix the null point exception when 
			//delete mark is clicked without selecting mark
			if(this.currentMarkView != null && this.currentMarkView.IsSelectOn)
			{
				MarkGroup group = mark.Markgroup;
				group.removeMark(mark);
				this.currentMarkView = null;
				this.updatePreviewPanel();
				this.CurrMarkSetHasChanged();
				this.btnReset_Click(null, null);
			}
			else
			{
				MessageBox.Show("No mark selected!");
			}
		}

		//event handler for the mark view selection
		//will be called when user click on the mark on marks preview panel
		private void selectMarkview(object sender, System.EventArgs e)
		{
			//rest old selected markview
			if(this.currentMarkView != null)
				this.currentMarkView.selectOff();

			//set current select mark
			this.currentMarkView = (MarkView) sender;
			this.currentMarkView.selectOn();

			//fill in selected markinformation on form
			this.setSelectedMarkInfo(this.currentMarkView.MyMark);
		}

		//this method is not working correctly....
		private void setSelectedMarkInfo(Mark mark)
		{
			this.cBoxCategory.SelectedItem = mark.Markset.Category;
			this.cBoxMarkset.SelectedItem = mark.Markset;
			this.cBoxGroup.SelectedItem = mark.Markgroup;
			this.txtBoxMarkName.Text = mark.MarkName;
			this.txtBoxDesc.Text = mark.Description;
			this.txtBoxImage.Text = mark.ImagePath;
			this.lBoxTextValues.Items.Clear();
			if (mark.HasPresetValues)
				this.lBoxTextValues.Items.AddRange(mark.PresetValues.ToArray());
		}

		private void btnSaveMarkset_Click(object sender, System.EventArgs e)
		{
			if (this.currMarkSet != null)
			{
				if((currMarkSet.AllMarks==null)||(currMarkSet.AllMarks.Count==0))
				{
					MessageBox.Show("Can't save the mark set as it has no marks.","Warning");
					return;
				}
				else if(!currMarkSet.HasChanged)
				{
					MessageBox.Show("The mark set hasn't changed since the last save","Warning");
					return;
				}
                
				if(getConfirmation("Save the current mark set?"))
				{
					this.currMarkSet.HasChanged=false;
					GODS.GODSMain.marksetHandler.saveMarkSetInfo(this.currMarkSet);
					MessageBox.Show(
						this, 
						"Mark set " + this.currMarkSet.MarksetName + " saved." + System.Environment.NewLine +
						"This change will take effect when next time you start up GODS.", 
						"Mark set saved",
						MessageBoxButtons.OK,
						MessageBoxIcon.Information);
				}
			}
		}

		private void btnSaveMark_Click(object sender, System.EventArgs e)
		{
			// validate inputs
			MarkSet ms = (MarkSet)this.cBoxMarkset.SelectedItem;
			MarkCategory mcat = (MarkCategory)this.cBoxCategory.SelectedItem;
			MarkGroup group = (MarkGroup)this.cBoxGroup.SelectedItem;

			string mName = this.txtBoxMarkName.Text.Trim();
			string mDesc = this.txtBoxDesc.Text.Trim();
			string imagePath = this.txtBoxImage.Text.Trim();
			string markSetName =  (ms!= null)?ms.ToString():null;
			string catName =  (mcat!= null)?mcat.ToString():null;
			string gName =  (group != null)?group.ToString():null;

			try
			{  
				this.validateInput(catName,"Category Name");
				this.validateInput(markSetName,"mark set Name");
				this.validateInput(gName,"Group Name");
				this.validateInput(mName, "mark name");
				this.validateInput(mDesc,"mark description");
			}
			catch (Exception ex)
			{
				MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
				return;
			}

			//insert into buffer
			ArrayList pValues = null;
			if (this.lBoxTextValues.Items.Count > 0) 
			{
				pValues = new ArrayList();
				if(!this.lBoxTextValues.Items.Contains(" "))
                  pValues.Add(" ");

				pValues.AddRange(this.lBoxTextValues.Items);
			}
			if(this.currentMarkView == null )
			{
				this.currMarkGroup.addMark(new Mark(this.currMarkSet, this.currMarkGroup, mName, imagePath, mDesc,pValues));
			}
			else
			{
				this.currentMarkView.ViewMark.Markset = this.currMarkSet;
				this.currentMarkView.ViewMark.Markgroup = this.currMarkGroup;
				this.currentMarkView.ViewMark.MarkName = mName;
				if(this.currentMarkView.ViewMark.ImagePath!= imagePath)
				{
					this.currentMarkView.ViewMark.ImagePath=imagePath;
					this.currentMarkView.ViewMark.SetMarkImage(imagePath);
				}
				this.currentMarkView.ViewMark.Description = mDesc;
				this.currentMarkView.ViewMark.PresetValues = pValues;
			}
			this.updatePreviewPanel();
			this.CurrMarkSetHasChanged();
			
		}

		private void btnExit_Click(object sender, System.EventArgs e)
		{
			//check if user has forgoten to save and ask to confirm
			if(this.currMarkSet.HasChanged)
				this.btnSaveMarkset_Click(null,null);
			GODSMain.application.reloadMarkForm();
			this.Close();
		}

		protected override void OnClosing(CancelEventArgs e)		 
		{   
			base.OnClosing (e);
		}

		//method to get confirmation from user if OKreturn true othersie false
		//a dialog with a message will be display where user will clikc YES or NO
		private bool getConfirmation(string msg)
		{   
			// Initializes the variables to pass to the MessageBox.Show method.
			string message = msg;
			string caption = "Confirmation";
			MessageBoxButtons buttons = MessageBoxButtons.YesNo;
			DialogResult result;

			// Displays the MessageBox.
			result = MessageBox.Show(this, message, caption, buttons,
				MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, 
				MessageBoxOptions.RightAlign);

			return(result == DialogResult.Yes);
			
		}

		//method to set the current mark as eligible to save
		private void CurrMarkSetHasChanged()
		{
			if(this.currMarkSet != null)
				this.currMarkSet.HasChanged=true;
		}

		private void btnHelp_Click(object sender, System.EventArgs e)
		{   
			string helpfile = GODSMain.ExecDir+"markConfHelp.hlp";
			Help.ShowHelp(this,helpfile);
		  
		}

	}
}
