using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Configuration;

namespace HearingAidLab
{
	/// <summary>
	/// Summary description for ChirpParams.
	/// </summary>
	public class ChirpParams : System.Windows.Forms.Form
	{
		public System.Windows.Forms.TextBox MaxIn;
		public System.Windows.Forms.TextBox MaxOut;
		public System.Windows.Forms.TextBox MaxInt;
		public System.Windows.Forms.TextBox Level;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label3;
		public System.Windows.Forms.ComboBox Mic;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label1;
		private ApplicationSettings applicationSettings;
		private System.Windows.Forms.Button btnSave;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

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

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
			applicationSettings = new ApplicationSettings();
		}

		/// <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(ChirpParams));
			this.MaxIn = new System.Windows.Forms.TextBox();
			this.MaxOut = new System.Windows.Forms.TextBox();
			this.MaxInt = new System.Windows.Forms.TextBox();
			this.Level = new System.Windows.Forms.TextBox();
			this.label5 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.Mic = new System.Windows.Forms.ComboBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.btnSave = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// MaxIn
			// 
			this.MaxIn.Location = new System.Drawing.Point(168, 112);
			this.MaxIn.Name = "MaxIn";
			this.MaxIn.Size = new System.Drawing.Size(121, 20);
			this.MaxIn.TabIndex = 25;
			this.MaxIn.Text = "10.20";
			// 
			// MaxOut
			// 
			this.MaxOut.Location = new System.Drawing.Point(168, 88);
			this.MaxOut.Name = "MaxOut";
			this.MaxOut.Size = new System.Drawing.Size(121, 20);
			this.MaxOut.TabIndex = 24;
			this.MaxOut.Text = "4.85";
			// 
			// MaxInt
			// 
			this.MaxInt.Location = new System.Drawing.Point(168, 64);
			this.MaxInt.Name = "MaxInt";
			this.MaxInt.Size = new System.Drawing.Size(121, 20);
			this.MaxInt.TabIndex = 23;
			this.MaxInt.Text = "24";
			// 
			// Level
			// 
			this.Level.Location = new System.Drawing.Point(168, 40);
			this.Level.Name = "Level";
			this.Level.Size = new System.Drawing.Size(121, 20);
			this.Level.TabIndex = 20;
			this.Level.Text = "0.25";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(24, 112);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(136, 23);
			this.label5.TabIndex = 28;
			this.label5.Text = "Max Input Voltage (pk):";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(24, 88);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(136, 23);
			this.label4.TabIndex = 27;
			this.label4.Text = "Max Output Voltage (pk):";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(24, 64);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(136, 23);
			this.label3.TabIndex = 26;
			this.label3.Text = "DAC/ADC Bit Resolution:";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// Mic
			// 
			this.Mic.Items.AddRange(new object[] {
													 "0",
													 "20",
													 "40"});
			this.Mic.Location = new System.Drawing.Point(168, 16);
			this.Mic.Name = "Mic";
			this.Mic.Size = new System.Drawing.Size(121, 21);
			this.Mic.TabIndex = 19;
			this.Mic.Text = "0";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(24, 40);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(136, 23);
			this.label2.TabIndex = 22;
			this.label2.Text = "Peak Stimulus Voltage:";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 16);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(144, 23);
			this.label1.TabIndex = 21;
			this.label1.Text = "Microphone (uV = 0dbSPL):";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// btnSave
			// 
			this.btnSave.Location = new System.Drawing.Point(240, 144);
			this.btnSave.Name = "btnSave";
			this.btnSave.Size = new System.Drawing.Size(48, 24);
			this.btnSave.TabIndex = 29;
			this.btnSave.Text = "Save";
			this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
			// 
			// ChirpParams
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(304, 174);
			this.Controls.Add(this.btnSave);
			this.Controls.Add(this.MaxIn);
			this.Controls.Add(this.MaxOut);
			this.Controls.Add(this.MaxInt);
			this.Controls.Add(this.Level);
			this.Controls.Add(this.label5);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.Mic);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "ChirpParams";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Soundcard Parameters";
			this.Load += new System.EventHandler(this.ChirpParams_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private void ChirpParams_Load(object sender, System.EventArgs e)
		{
			//WAP to read these from resources
			// If the LoadAppSettings method is successful, assign the 
			// ApplicationSettings properties to their corresponding form properties.
			if(this.applicationSettings.LoadAppSettings() )
			{
				// Create a Color from the integer (ARGB) value.
				this.Mic.Text = applicationSettings.Mic;
				this.Level.Text =applicationSettings.Level;
				this.MaxIn.Text = applicationSettings.MaxIn;
				this.MaxOut.Text = applicationSettings.MaxOut;
				this.MaxInt.Text = applicationSettings.MaxInt;
			}
			else //if load fails, give default values
			{
				this.Mic.Text = "20";
				this.Level.Text = "0.25";
				this.MaxIn.Text = "10.20";
				this.MaxInt.Text = "24";
				this.MaxOut.Text = "4.85";
			}

		}

		private void btnSave_Click(object sender, System.EventArgs e)
		{	
			applicationSettings.Mic = this.Mic.Text;
			applicationSettings.Level = this.Level.Text;
			applicationSettings.MaxIn = this.MaxIn.Text;
			applicationSettings.MaxInt = this.MaxInt.Text;
			applicationSettings.MaxOut = this.MaxOut.Text;

			applicationSettings.SaveAppSettings();
			this.Hide();
		}

	}
}
