/******************************************************************************
 * ThumbnailsForm.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 DBHandler;
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class ThumbnailsForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.ImageList imageList1;
		private System.ComponentModel.IContainer components;
		private System.Windows.Forms.ListView Imgs4Mrn;
		private ImageData[] imageData;
		private BrowseForm parent;
		private int selectedIndex = -1;
		protected internal int SelectedIndex
		{
			get
			{
				return selectedIndex;	    
			}
		}
		public ThumbnailsForm(ImageData[] data,string mrn,BrowseForm p)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			this.Text = "Annotated images for MRN:"+mrn;
			imageData = data;
			parent = p;
			if (imageData==null)
				return;
			for(int i =0;i<imageData.Length;i++)
			{
				imageList1.Images.Add(
					Image.FromFile(imageData[i].AnnotImgPath));
				Imgs4Mrn.Items.Add(new ListViewItem(imageData[i].AppDate.ToString(), i));

			}
			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <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()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(ThumbnailsForm));
			this.Imgs4Mrn = new System.Windows.Forms.ListView();
			this.imageList1 = new System.Windows.Forms.ImageList(this.components);
			this.SuspendLayout();
			// 
			// Imgs4Mrn
			// 
			this.Imgs4Mrn.Dock = System.Windows.Forms.DockStyle.Fill;
			this.Imgs4Mrn.LargeImageList = this.imageList1;
			this.Imgs4Mrn.Location = new System.Drawing.Point(0, 0);
			this.Imgs4Mrn.Name = "Imgs4Mrn";
			this.Imgs4Mrn.Size = new System.Drawing.Size(432, 266);
			this.Imgs4Mrn.TabIndex = 0;
			this.Imgs4Mrn.DoubleClick += new System.EventHandler(this.Imgs4Mrn_DoubleClick);
			// 
			// imageList1
			// 
			this.imageList1.ImageSize = new System.Drawing.Size(100, 80);
			this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// ThumbnailsForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(432, 266);
			this.Controls.Add(this.Imgs4Mrn);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "ThumbnailsForm";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "Form1";
			this.ResumeLayout(false);

		}
		#endregion

		private void Imgs4Mrn_DoubleClick(object sender, System.EventArgs e)
		{
		    Close();
			parent.Close();				
			//if(!this.mainApp.activateAnnoForm(iData.ImageId ))
			//								this.mainApp.LoadFromDB(iData);
			if(!GODSMain.application.activateAnnoForm(imageData[Imgs4Mrn.SelectedIndices[0]].ImageId ))
											
			GODSMain.application.LoadFromDB(imageData[Imgs4Mrn.SelectedIndices[0]]);	
		}

		/*private void Imgs4Mrn_Click(object sender, System.EventArgs e)
		{   
		    selectedIndex = Imgs4Mrn.SelectedIndices[0];
            Close();
		}*/
	}
}
