using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;


using DataPerformer;
using DiagramUI;

namespace MotionUI
{
    public partial class SimpleChooser : UserControl, IPositionCollectionMeasureChooser
    {

        static private IPositionCollectionMeasureChooser chooser = new SimpleChooser();

        private ComboBox[] boxes;

        #region Ctor

        public SimpleChooser()
        {
            InitializeComponent();
            ResourceService.Resources.LoadControlResources(this);
            boxes = new ComboBox[] { comboBoxX, comboBoxY, comboBoxZ };
        }

        #endregion


        #region Specific Members

        static public IPositionCollectionMeasureChooser Chooser
        {
            get
            {
                return chooser;
            }
            set
            {
                chooser = value;
            }
        }

        #endregion

        #region IPositionCollectionMeasureChooser Members

        List<string> IPositionCollectionMeasureChooser.Meausements
        {
            get
            {
                List<string> l = new List<string>();
                foreach (ComboBox box in boxes)
                {
                    string s = box.SelectedItem + "";
                    if (s.Length == 0)
                    {
                        throw new Exception("Variales shortage");
                    }
                    l.Add(s);
                }
                return l;
            }
            set
            {
                for (int i = 0; i < boxes.Length; i++)
                {
                    if (i >= value.Count)
                    {
                        break;
                    }
                    DefaultForm.SelectCombo(boxes[i], value[i]);
                }
            }
        }

        IDataConsumer IPositionCollectionMeasureChooser.Consumer
        {
            get
            {
                return null;
            }
            set
            {
                Double a = 0;
                List<string> l = DataConsumer.GetAllMeasurements(value, a);
                foreach (ComboBox box in boxes)
                {
                    DefaultForm.FillCombo(box, l);
                }
            }
        }

        IPositionCollectionMeasureChooser IPositionCollectionMeasureChooser.this[Motion6D.IPositionFactory factory]
        {
            get
            {
                return new SimpleChooser();
            }
        }

        #endregion
    }
}
