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

using DiagramUI;

using Motion6D;

namespace MotionUI
{
    public partial class ColoredChooser : UserControl, IPositionCollectionMeasureChooser
    {
        private ComboBox[] boxes;

        public static readonly ColoredChooser Object = new ColoredChooser();

        internal ColoredChooser()
        {
            InitializeComponent();
            boxes = new ComboBox[] { comboBoxX, comboBoxY, comboBoxZ, comboBoxR, comboBoxG, comboBoxB, comboBoxS };
        }

        #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("Undefined measure");
                    }
                    l.Add(s);
                }
                return l;
            }
            set
            {
                for (int i = 0; i < value.Count & i < boxes.Length; i++)
                {
                    DefaultForm.SelectCombo(boxes[i], value[i]);
                }
            }
        }

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

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

        #endregion
    }
}
