/******************************************************************************
 * PreferenceDlg.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
{
	/// <summary>
	/// Summary description for Form2.
	/// </summary>
	public class PreferenceDlg: System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.CheckBox chkBxConfirmSave;
		private System.Windows.Forms.TextBox txtBxDefaultImg;
		private System.Windows.Forms.TextBox txtBxImgFolder;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Button button3;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public PreferenceDlg(bool showSaveDlg, string defaultImage)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			this.chkBxConfirmSave.Checked = showSaveDlg;
			this.txtBxImgFolder.Text = GODS.GODSMain.ImageDir;
			this.txtBxDefaultImg.Text = defaultImage;
			//
			// 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()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(PreferenceDlg));
			this.button1 = new System.Windows.Forms.Button();
			this.chkBxConfirmSave = new System.Windows.Forms.CheckBox();
			this.button2 = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			this.txtBxDefaultImg = new System.Windows.Forms.TextBox();
			this.txtBxImgFolder = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.button3 = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// button1
			// 
			this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.button1.Location = new System.Drawing.Point(56, 224);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(64, 24);
			this.button1.TabIndex = 1;
			this.button1.Text = "OK";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// chkBxConfirmSave
			// 
			this.chkBxConfirmSave.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.chkBxConfirmSave.Location = new System.Drawing.Point(16, 16);
			this.chkBxConfirmSave.Name = "chkBxConfirmSave";
			this.chkBxConfirmSave.Size = new System.Drawing.Size(264, 40);
			this.chkBxConfirmSave.TabIndex = 2;
			this.chkBxConfirmSave.Text = " Show confirmation dialog after save.";
			// 
			// button2
			// 
			this.button2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.button2.Location = new System.Drawing.Point(152, 224);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(64, 24);
			this.button2.TabIndex = 3;
			this.button2.Text = "Cancel";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// label1
			// 
			this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label1.Location = new System.Drawing.Point(16, 144);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(104, 16);
			this.label1.TabIndex = 4;
			this.label1.Text = "Default Image:";
			// 
			// txtBxDefaultImg
			// 
			this.txtBxDefaultImg.Enabled = false;
			this.txtBxDefaultImg.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtBxDefaultImg.Location = new System.Drawing.Point(16, 168);
			this.txtBxDefaultImg.Name = "txtBxDefaultImg";
			this.txtBxDefaultImg.Size = new System.Drawing.Size(256, 22);
			this.txtBxDefaultImg.TabIndex = 5;
			this.txtBxDefaultImg.Text = "";
			// 
			// txtBxImgFolder
			// 
			this.txtBxImgFolder.Enabled = false;
			this.txtBxImgFolder.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtBxImgFolder.Location = new System.Drawing.Point(17, 96);
			this.txtBxImgFolder.Name = "txtBxImgFolder";
			this.txtBxImgFolder.Size = new System.Drawing.Size(215, 22);
			this.txtBxImgFolder.TabIndex = 7;
			this.txtBxImgFolder.Text = "";
			// 
			// label2
			// 
			this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label2.Location = new System.Drawing.Point(17, 72);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(104, 16);
			this.label2.TabIndex = 6;
			this.label2.Text = "Image Folder:";
			// 
			// button3
			// 
			this.button3.Location = new System.Drawing.Point(248, 96);
			this.button3.Name = "button3";
			this.button3.Size = new System.Drawing.Size(24, 24);
			this.button3.TabIndex = 8;
			this.button3.Text = "...";
			this.button3.Click += new System.EventHandler(this.button3_Click);
			// 
			// PreferenceDlg
			// 
			this.AcceptButton = this.button1;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(290, 264);
			this.Controls.Add(this.button3);
			this.Controls.Add(this.txtBxImgFolder);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.txtBxDefaultImg);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.chkBxConfirmSave);
			this.Controls.Add(this.button1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "PreferenceDlg";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Preference";
			this.ResumeLayout(false);

		}
		#endregion		

		private void button1_Click(object sender, System.EventArgs e)
		{
			GODS.GODSMain.showSaveConfirmDlg = this.chkBxConfirmSave.Checked;
			GODS.GODSMain.ImageDir = this.txtBxImgFolder.Text;
			string oimagePath = GODS.GODSMain.ImageDir+@"\oimage";
			string aimagePath = GODS.GODSMain.ImageDir+@"\aimage";
			if (!System.IO.Directory.Exists(oimagePath))
				System.IO.Directory.CreateDirectory(oimagePath);
			if (!System.IO.Directory.Exists(aimagePath))
				System.IO.Directory.CreateDirectory(aimagePath);
			this.Close();
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void button3_Click(object sender, System.EventArgs e)
		{
			FolderBrowserDialog dialog = new FolderBrowserDialog();
			dialog.ShowNewFolderButton = true;
			dialog.SelectedPath = this.txtBxImgFolder.Text;
			if (dialog.ShowDialog() == DialogResult.OK)
				this.txtBxImgFolder.Text = dialog.SelectedPath;
		}
	}
}
