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

namespace EvoXP
{
	/// <summary>
	/// Summary description for SelectRoute.
	/// </summary>
	public class SelectRoute : System.Windows.Forms.Form
	{
		private System.Windows.Forms.ListBox listBoxRoutes;
		private System.Windows.Forms.Button buttonOK;
		private System.Windows.Forms.Button buttonCancel;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public SelectRoute(WaypointRepository WR)
		{
			InitializeComponent();
			for(int i=0;i<WR._Routes.Count;i++)
			{
				LocalRoute LR = WR._Routes.GetByIndex(i) as LocalRoute;
				listBoxRoutes.Items.Add(LR._name);
			}
		}

		public static bool canShow(WaypointRepository WR)
		{
			return WR._Routes.Count > 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 );
		}

		#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.listBoxRoutes = new System.Windows.Forms.ListBox();
			this.buttonOK = new System.Windows.Forms.Button();
			this.buttonCancel = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// listBoxRoutes
			// 
			this.listBoxRoutes.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.listBoxRoutes.ColumnWidth = 75;
			this.listBoxRoutes.Location = new System.Drawing.Point(8, 8);
			this.listBoxRoutes.MultiColumn = true;
			this.listBoxRoutes.Name = "listBoxRoutes";
			this.listBoxRoutes.Size = new System.Drawing.Size(328, 223);
			this.listBoxRoutes.TabIndex = 4;
			this.listBoxRoutes.SelectedIndexChanged += new System.EventHandler(this.listBoxRoutes_SelectedIndexChanged);
			// 
			// buttonOK
			// 
			this.buttonOK.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
			this.buttonOK.Location = new System.Drawing.Point(352, 8);
			this.buttonOK.Name = "buttonOK";
			this.buttonOK.Size = new System.Drawing.Size(56, 24);
			this.buttonOK.TabIndex = 5;
			this.buttonOK.Text = "Ok!";
			this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
			// 
			// buttonCancel
			// 
			this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.buttonCancel.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
			this.buttonCancel.Location = new System.Drawing.Point(352, 40);
			this.buttonCancel.Name = "buttonCancel";
			this.buttonCancel.Size = new System.Drawing.Size(56, 24);
			this.buttonCancel.TabIndex = 6;
			this.buttonCancel.Text = "Cancel";
			this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
			// 
			// SelectRoute
			// 
			this.AcceptButton = this.buttonOK;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.CancelButton = this.buttonCancel;
			this.ClientSize = new System.Drawing.Size(418, 237);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.buttonCancel,
																		  this.buttonOK,
																		  this.listBoxRoutes});
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.Name = "SelectRoute";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "Select A Route";
			this.ResumeLayout(false);

		}
		#endregion


		public string _Route;

		private void buttonOK_Click(object sender, System.EventArgs e)
		{
			_Route = listBoxRoutes.SelectedItem as string;
			 this.Close();
		}

		private void buttonCancel_Click(object sender, System.EventArgs e)
		{
			_Route = null;
			this.Close();
		}

		private void listBoxRoutes_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if(listBoxRoutes.SelectedIndex >= 0)
			{
				buttonOK.Enabled = true;
			}
			else
			{
				buttonOK.Enabled = false;
			}
		}

	}
}
