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;

namespace ImageNavigation
{
    public partial class FormBitmapSelection : Form, IUpdatableForm
    {
        private IObjectLabel label;
        private BitmapSelection selection;

        private Bitmap bmp;

        
        private FormBitmapSelection()
        {
            InitializeComponent();
        }

        public FormBitmapSelection(IObjectLabel label)
            : this()
        {
            ResourceService.Resources.LoadControlResources(this);
            this.label = label;
            UpdateFormUI();
            selection = label.Object as BitmapSelection;
        }

        #region IUpdatableForm Members

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

        #endregion

        private void panelImage_Paint(object sender, PaintEventArgs e)
        {
            if (bmp == null)
            {
                return;
            }
            e.Graphics.DrawImage(bmp, 0, 0);

        }

        private void refreshImage()
        {
            bmp = selection.EdgeBitmap;
            Refresh();
        }

        private void buttonUpdate_Click(object sender, EventArgs e)
        {
            refreshImage();
        }

        void open()
        {
            try
            {
                if (openFileDialogBitmap.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }
                Bitmap bmp = new Bitmap(openFileDialogBitmap.FileName);
                selection.Bitmap = bmp;
                refreshImage();
            }
            catch (Exception ex)
            {
                DefaultForm.ShowError(this, ex);
            }
        }

        private void openToolStripButton_Click(object sender, EventArgs e)
        {
            open();
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            open();
        }

    }
}