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

using DataPerformer;
using DiagramUI;

using ToolBox;
using Chart;


namespace DataPerformerUI
{
    public partial class FormSeriesIterator : Form, IUpdatableForm
    {
        private IObjectLabel label;
        private SeriesIterator series;
        private ChartPerformer performer;
        private OfficePickers.ColorPicker.ToolStripColorPicker pic = 
            new OfficePickers.ColorPicker.ToolStripColorPicker();
        private FormSeriesIterator()
        {
            InitializeComponent();
        }

        public FormSeriesIterator(IObjectLabel label)
        {
            InitializeComponent();
            ResourceService.Resources.LoadControlResources(this);
            this.label = label;
            series = label.Object as SeriesIterator;
            Text = label.Name;

            PanelChart panel = new PanelChart(new int[,] { { 80, 20 }, { 30, 40 } });
            panel.Width = panelGraph.Width - 100;
            panel.Height = panelGraph.Height - 100;
            panel.Top = 50;
            panel.Left = 50;
            panel.Dock = DockStyle.Fill;
            performer = panel.Performer;
            performer.Resize();
            panelGraph.Controls.Add(panel);
            ArrayList comments = series.Comments;
            ControlPanel.LoadControls(panelGraph, comments);
            SimpleCoordinator coordinator = new SimpleCoordinator(5, 5, performer);
            performer.Coordinator = coordinator;
            //performer.AddSeries(ser, Color.Magenta);
            //performer.RefreshAll();
            fill();
            if (series != null)
            {
                labelConstStep.Text = series.HasEqualSteps;
            }
            //if (EMDatabaseInterface.DatabaseClient.Service == null)
            //	{
            //menuItemLoadFromDatabase.Visible = false;
            //	}

            pic.Text = ResourceService.Resources.GetControlResource("Color");
            pic.Width = 70;
            toolStripMain.Items.Add(pic);

        }

        #region IUpdatableForm Members

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

        #endregion


        void fill()
        {
            List<string> l = series.AllMeasurements;
            DefaultForm.FillCombo(toolStripButtonX, l);
            DefaultForm.FillCombo(toolStripButtonY, l);
            DefaultForm.SelectCombo(toolStripButtonX, series.X);
            DefaultForm.SelectCombo(toolStripButtonY, series.Y);
            FormSeries.FillTypeCombo(toolStripButtonType);
        }

        private void toolStripButtonRefresh_Click(object sender, EventArgs e)
        {
            string x = toolStripButtonX.SelectedItem + "";
            string y = toolStripButtonY.SelectedItem + "";
            series.Set(x, y);
            string mode = toolStripButtonType.SelectedItem + "";
            show(mode, pic.Color);

        }

        private void show(string mode, Color color)
        {
            ISeriesPainter painter = FormSeries.SelectPainter(toolStripButtonType.SelectedItem + "", pic.Color, performer);
            ISeries s = new SeriesGraph(series);
            performer.AddSeries(s, painter);
            performer.RefreshAll();
            Refresh();
        }
    }
}