// trackerConfigForm.cs: set tracker attributes
// --------------------------------------------------------
// July 20,2004 
// By Xiaotao Shu.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

using TrackingController;

namespace tools
{
	/// <summary>
	/// Summary description for trackerConfigForm.
	/// </summary>
	public class trackerConfigForm : System.Windows.Forms.Form
	{
		private Controller m_controller;
		private Font m_font;               //font of current tracker 
		private Color m_color;			   //color of current tracker
		private Color m_labelColor;        //label color of current tracker 


		private System.Windows.Forms.GroupBox AddGroupBox;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.GroupBox TrackingGroupBox;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Button button3;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Button CloseButton;
		private System.Windows.Forms.Button button4;
		private System.Windows.Forms.ListView TrackingList;
		private System.Windows.Forms.ColumnHeader ID;
		private System.Windows.Forms.ColumnHeader Label;
		private System.Windows.Forms.ColumnHeader TrackerColor;
		private System.Windows.Forms.ColumnHeader LabelFont;
		private System.Windows.Forms.ColumnHeader LabelColor;
		private System.Windows.Forms.DataGrid dataGrid1;
		private System.Windows.Forms.TextBox textLabelColor;
		private System.Windows.Forms.TextBox textFont;
		private System.Windows.Forms.TextBox textColor;
		private System.Windows.Forms.TextBox textId;
		private System.Windows.Forms.TextBox textLabel;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public trackerConfigForm(Controller aController)
		{
			InitializeComponent();
			TrackingList.MultiSelect = false;
			 m_controller = aController;
			
			//init list
			TrackeeServant aTrackee = null;
			for (int i=0; i <m_controller.Trackees.Count; i++)
			{
				if(this.m_controller.Trackees[i] != null)
				{
					aTrackee = (TrackeeServant)m_controller.Trackees[i];
					ListViewItem aRow = new ListViewItem(aTrackee.ID, 0);
					aRow.SubItems.Add(aTrackee.Label);
					aRow.SubItems.Add(aTrackee.Color.ToString());
					aRow.SubItems.Add(aTrackee.Font.ToString());
					aRow.SubItems.Add(aTrackee.LabelColor.ToString());
					TrackingList.Items.Add(aRow);
				}
			}
		}

		/// <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.AddGroupBox = new System.Windows.Forms.GroupBox();
			this.button4 = new System.Windows.Forms.Button();
			this.button3 = new System.Windows.Forms.Button();
			this.textLabelColor = new System.Windows.Forms.TextBox();
			this.label5 = new System.Windows.Forms.Label();
			this.button2 = new System.Windows.Forms.Button();
			this.textFont = new System.Windows.Forms.TextBox();
			this.label4 = new System.Windows.Forms.Label();
			this.button1 = new System.Windows.Forms.Button();
			this.textColor = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.textLabel = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.textId = new System.Windows.Forms.TextBox();
			this.TrackingGroupBox = new System.Windows.Forms.GroupBox();
			this.TrackingList = new System.Windows.Forms.ListView();
			this.ID = new System.Windows.Forms.ColumnHeader();
			this.Label = new System.Windows.Forms.ColumnHeader();
			this.TrackerColor = new System.Windows.Forms.ColumnHeader();
			this.LabelFont = new System.Windows.Forms.ColumnHeader();
			this.LabelColor = new System.Windows.Forms.ColumnHeader();
			this.dataGrid1 = new System.Windows.Forms.DataGrid();
			this.CloseButton = new System.Windows.Forms.Button();
			this.AddGroupBox.SuspendLayout();
			this.TrackingGroupBox.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
			this.SuspendLayout();
			// 
			// AddGroupBox
			// 
			this.AddGroupBox.Anchor = System.Windows.Forms.AnchorStyles.None;
			this.AddGroupBox.Controls.Add(this.button4);
			this.AddGroupBox.Controls.Add(this.button3);
			this.AddGroupBox.Controls.Add(this.textLabelColor);
			this.AddGroupBox.Controls.Add(this.label5);
			this.AddGroupBox.Controls.Add(this.button2);
			this.AddGroupBox.Controls.Add(this.textFont);
			this.AddGroupBox.Controls.Add(this.label4);
			this.AddGroupBox.Controls.Add(this.button1);
			this.AddGroupBox.Controls.Add(this.textColor);
			this.AddGroupBox.Controls.Add(this.label3);
			this.AddGroupBox.Controls.Add(this.textLabel);
			this.AddGroupBox.Controls.Add(this.label2);
			this.AddGroupBox.Controls.Add(this.label1);
			this.AddGroupBox.Controls.Add(this.textId);
			this.AddGroupBox.Location = new System.Drawing.Point(472, 16);
			this.AddGroupBox.Name = "AddGroupBox";
			this.AddGroupBox.Size = new System.Drawing.Size(280, 224);
			this.AddGroupBox.TabIndex = 15;
			this.AddGroupBox.TabStop = false;
			this.AddGroupBox.Text = "Edit a Tracker";
			// 
			// button4
			// 
			this.button4.Anchor = System.Windows.Forms.AnchorStyles.None;
			this.button4.DialogResult = System.Windows.Forms.DialogResult.OK;
			this.button4.Location = new System.Drawing.Point(8, 184);
			this.button4.Name = "button4";
			this.button4.TabIndex = 20;
			this.button4.Text = "OK";
			this.button4.Click += new System.EventHandler(this.button4_Click);
			// 
			// button3
			// 
			this.button3.Anchor = System.Windows.Forms.AnchorStyles.None;
			this.button3.Location = new System.Drawing.Point(208, 152);
			this.button3.Name = "button3";
			this.button3.Size = new System.Drawing.Size(48, 23);
			this.button3.TabIndex = 18;
			this.button3.Text = "Color";
			this.button3.Click += new System.EventHandler(this.button3_Click);
			// 
			// textLabelColor
			// 
			this.textLabelColor.Anchor = System.Windows.Forms.AnchorStyles.None;
			this.textLabelColor.Enabled = false;
			this.textLabelColor.Location = new System.Drawing.Point(88, 152);
			this.textLabelColor.Name = "textLabelColor";
			this.textLabelColor.Size = new System.Drawing.Size(128, 20);
			this.textLabelColor.TabIndex = 17;
			this.textLabelColor.Text = "";
			// 
			// label5
			// 
			this.label5.Anchor = System.Windows.Forms.AnchorStyles.None;
			this.label5.Location = new System.Drawing.Point(8, 152);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(88, 16);
			this.label5.TabIndex = 16;
			this.label5.Text = "LabelColor:";
			// 
			// button2
			// 
			this.button2.Anchor = System.Windows.Forms.AnchorStyles.None;
			this.button2.Location = new System.Drawing.Point(208, 120);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(48, 23);
			this.button2.TabIndex = 15;
			this.button2.Text = "Font";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// textFont
			// 
			this.textFont.Anchor = System.Windows.Forms.AnchorStyles.None;
			this.textFont.Enabled = false;
			this.textFont.Location = new System.Drawing.Point(88, 120);
			this.textFont.Name = "textFont";
			this.textFont.Size = new System.Drawing.Size(128, 20);
			this.textFont.TabIndex = 14;
			this.textFont.Text = "";
			// 
			// label4
			// 
			this.label4.Anchor = System.Windows.Forms.AnchorStyles.None;
			this.label4.Location = new System.Drawing.Point(8, 120);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(88, 16);
			this.label4.TabIndex = 13;
			this.label4.Text = "LabelFont:";
			// 
			// button1
			// 
			this.button1.Anchor = System.Windows.Forms.AnchorStyles.None;
			this.button1.Location = new System.Drawing.Point(208, 88);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(48, 23);
			this.button1.TabIndex = 12;
			this.button1.Text = "Color";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// textColor
			// 
			this.textColor.Anchor = System.Windows.Forms.AnchorStyles.None;
			this.textColor.Enabled = false;
			this.textColor.Location = new System.Drawing.Point(88, 88);
			this.textColor.Name = "textColor";
			this.textColor.Size = new System.Drawing.Size(128, 20);
			this.textColor.TabIndex = 11;
			this.textColor.Text = "";
			// 
			// label3
			// 
			this.label3.Anchor = System.Windows.Forms.AnchorStyles.None;
			this.label3.Location = new System.Drawing.Point(8, 88);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(96, 16);
			this.label3.TabIndex = 10;
			this.label3.Text = "TrackerColor:";
			// 
			// textLabel
			// 
			this.textLabel.Anchor = System.Windows.Forms.AnchorStyles.None;
			this.textLabel.Location = new System.Drawing.Point(88, 56);
			this.textLabel.Name = "textLabel";
			this.textLabel.Size = new System.Drawing.Size(176, 20);
			this.textLabel.TabIndex = 9;
			this.textLabel.Text = "";
			// 
			// label2
			// 
			this.label2.Anchor = System.Windows.Forms.AnchorStyles.None;
			this.label2.Location = new System.Drawing.Point(8, 56);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(64, 16);
			this.label2.TabIndex = 8;
			this.label2.Text = "Label:";
			// 
			// label1
			// 
			this.label1.Anchor = System.Windows.Forms.AnchorStyles.None;
			this.label1.Location = new System.Drawing.Point(8, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(72, 16);
			this.label1.TabIndex = 5;
			this.label1.Text = "Tracker ID:";
			// 
			// textId
			// 
			this.textId.Anchor = System.Windows.Forms.AnchorStyles.None;
			this.textId.Location = new System.Drawing.Point(88, 24);
			this.textId.Name = "textId";
			this.textId.Size = new System.Drawing.Size(176, 20);
			this.textId.TabIndex = 6;
			this.textId.Text = "";
			// 
			// TrackingGroupBox
			// 
			this.TrackingGroupBox.Anchor = System.Windows.Forms.AnchorStyles.None;
			this.TrackingGroupBox.Controls.Add(this.TrackingList);
			this.TrackingGroupBox.Controls.Add(this.dataGrid1);
			this.TrackingGroupBox.Location = new System.Drawing.Point(-8, 8);
			this.TrackingGroupBox.Name = "TrackingGroupBox";
			this.TrackingGroupBox.Size = new System.Drawing.Size(472, 248);
			this.TrackingGroupBox.TabIndex = 14;
			this.TrackingGroupBox.TabStop = false;
			this.TrackingGroupBox.Text = "Tracker configuration:";
			// 
			// TrackingList
			// 
			this.TrackingList.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.TrackingList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
																						   this.ID,
																						   this.Label,
																						   this.TrackerColor,
																						   this.LabelFont,
																						   this.LabelColor});
			this.TrackingList.FullRowSelect = true;
			this.TrackingList.Location = new System.Drawing.Point(16, 24);
			this.TrackingList.MultiSelect = false;
			this.TrackingList.Name = "TrackingList";
			this.TrackingList.Size = new System.Drawing.Size(440, 212);
			this.TrackingList.Sorting = System.Windows.Forms.SortOrder.Ascending;
			this.TrackingList.TabIndex = 2;
			this.TrackingList.View = System.Windows.Forms.View.Details;
			this.TrackingList.SelectedIndexChanged += new System.EventHandler(this.TrackingList_SelectedIndexChanged);
			// 
			// ID
			// 
			this.ID.Text = "Tracker Number";
			this.ID.Width = 100;
			// 
			// Label
			// 
			this.Label.Text = "Label";
			this.Label.Width = 100;
			// 
			// TrackerColor
			// 
			this.TrackerColor.Text = "Color";
			// 
			// LabelFont
			// 
			this.LabelFont.Text = "Font";
			this.LabelFont.Width = 80;
			// 
			// LabelColor
			// 
			this.LabelColor.Text = "LabelColor";
			this.LabelColor.Width = 80;
			// 
			// dataGrid1
			// 
			this.dataGrid1.DataMember = "";
			this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGrid1.Location = new System.Drawing.Point(48, 152);
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.TabIndex = 18;
			// 
			// CloseButton
			// 
			this.CloseButton.Anchor = System.Windows.Forms.AnchorStyles.None;
			this.CloseButton.DialogResult = System.Windows.Forms.DialogResult.OK;
			this.CloseButton.Location = new System.Drawing.Point(672, 248);
			this.CloseButton.Name = "CloseButton";
			this.CloseButton.TabIndex = 17;
			this.CloseButton.Text = "Close";
			this.CloseButton.Click += new System.EventHandler(this.CloseButton_Click);
			// 
			// trackerConfigForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(762, 279);
			this.Controls.Add(this.CloseButton);
			this.Controls.Add(this.AddGroupBox);
			this.Controls.Add(this.TrackingGroupBox);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.Name = "trackerConfigForm";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "trackerConfigForm";
			this.AddGroupBox.ResumeLayout(false);
			this.TrackingGroupBox.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void TrackingList_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			textId.Text = TrackingList.SelectedItems[0].SubItems[0].Text;
			textLabel.Text = TrackingList.SelectedItems[0].SubItems[1].Text;
			textColor.Text = TrackingList.SelectedItems[0].SubItems[2].Text;
			textFont.Text = TrackingList.SelectedItems[0].SubItems[3].Text;
			textLabelColor.Text = TrackingList.SelectedItems[0].SubItems[4].Text;
			m_color=Color.Empty;
			m_font=null;
			m_labelColor=Color.Empty;
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			ColorDialog cd = new ColorDialog();
			if (cd.ShowDialog() == DialogResult.OK)
			{
				m_color = cd.Color;
				textColor.Text = m_color.ToString();
			}
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			FontDialog fd = new FontDialog();
			if (fd.ShowDialog() == DialogResult.OK)
			{
				m_font = fd.Font;
				textFont.Text = m_font.ToString();
			}
		}

		private void button3_Click(object sender, System.EventArgs e)
		{
			ColorDialog cd = new ColorDialog();
			if (cd.ShowDialog() == DialogResult.OK)
			{
				m_labelColor = cd.Color;
				textLabelColor.Text = m_labelColor.ToString();
			}
		}

		private void button4_Click(object sender, System.EventArgs e)
		{	
			if ( TrackingList.SelectedIndices.Count == 0 )
				return;
			TrackeeServant aTrackee = (TrackeeServant)m_controller.Trackees[TrackingList.SelectedIndices[0]];
			aTrackee.Label = textLabel.Text;
			if ( m_color!=Color.Empty )
				aTrackee.Color = m_color;
			if ( m_font != null )
				aTrackee.Font = m_font;
			if ( m_labelColor != Color.Empty )
				aTrackee.LabelColor = m_labelColor;
		}

		private void CloseButton_Click(object sender, System.EventArgs e)
		{
			m_controller.update();
		}
	}
}
