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


using CategoryTheory;
using DiagramUI;
using Motion6D;

namespace MotionUI
{
    public partial class FormPositionsIndicatror : Form, IUpdatableForm, IRedraw
    {
        private PositionCollectionIndicator indicator;
        private IPointsIndicator pIndicator;
        private IObjectLabel label;
        private FormPositionsIndicatror()
        {
            InitializeComponent();
        }
        public FormPositionsIndicatror(IObjectLabel label)
        {
            InitializeComponent();
            ResourceService.Resources.LoadControlResources(this);
            this.label = label;
            indicator = label.Object as PositionCollectionIndicator;
            string[] s = SimplePointsIdicator.Indicator[indicator];
            DefaultForm.FillCombo(comboBoxType, s);
            Text = label.Name;
        }

        #region IUpdatableForm Members

        void IUpdatableForm.UpdateFormUI()
        {
            Text = label.Name;
        }

        #endregion

        private void comboBoxType_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                string s = comboBoxType.SelectedItem + "";
                if (s.Length == null)
                {
                    return;
                }
                if (pIndicator != null)
                {
                    Control cont = pIndicator as Control;
                    panelChart.Controls.Remove(cont);
                }
                pIndicator = SimplePointsIdicator.Indicator[s];
                pIndicator.Positions = indicator;
                Control c = pIndicator as Control;
                panelChart.Controls.Add(c);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        #region IRedraw Members

        void IRedraw.Redraw()
        {
            if (pIndicator != null)
            {
                if (pIndicator is IRedraw)
                {
                    IRedraw r = pIndicator as IRedraw;
                    r.Redraw();
                }
            }
        }

        #endregion
    }
}