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

namespace GMLC01HerramientasCad.Logica
{
    public partial class SeleccionFontForm : BaseForm
    {
        /// <summary>
        /// Constructor de la clase
        /// </summary>
        public SeleccionFontForm(CriterioEtiquetado criterio)
        {
            try
            {
                Criterio = criterio;

                InitializeComponent();
            }
            catch (Exception e)
            {
                Log.RegisterError(e);
                throw new ExcepcionGMLC(e.Message, e);
            }
        }

        public CriterioEtiquetado Criterio { get; set; }

        private void SeleccionFontFormLoad(object sender, EventArgs e)
        {
            System.Drawing.Text.InstalledFontCollection font = new System.Drawing.Text.InstalledFontCollection();

            foreach (FontFamily fFamily in font.Families)
                fontComboBox.Items.Add(fFamily.Name);

            fontComboBox.SelectedItem = Criterio.Font;
            alturaTextBox.Text = Criterio.Altura.ToString(CultureInfo.InvariantCulture);
            negritaCheckBox.Checked = Criterio.Negrita;
            cursivaCheckBox.Checked = Criterio.Cursiva;
            subCheckBox.Checked = Criterio.Subrayado;
            colorButton.BackColor = Criterio.Color;
        }

        private void ColorButtonClick(object sender, EventArgs e)
        {
            colorDialog.ShowDialog();
            ((Button)sender).BackColor = colorDialog.Color;
        }

        private void AceptarButtonClick(object sender, EventArgs e)
        {
            try
            {
                Criterio.Font = fontComboBox.Text;
                Criterio.Altura = Convert.ToDouble(alturaTextBox.Text.Replace(',','.'), CultureInfo.InvariantCulture);
                Criterio.Negrita = negritaCheckBox.Checked;
                Criterio.Cursiva = cursivaCheckBox.Checked;
                Criterio.Subrayado = subCheckBox.Checked;
                Criterio.Color = colorButton.BackColor;
            }
            catch (FormatException ex)
            {
                throw new ExcepcionGMLC(ex.Message);
            }
            catch (OverflowException ex)
            {
                throw new ExcepcionGMLC(ex.Message);
            }

            this.Close();
        }

        private void CancelarButtonClick(object sender, EventArgs e)
        {
            this.Close();
        }


        /// <summary>
        /// 
        /// </summary>
        public override void ActualizarIdiomaInterfaz()
        {
            try
            {
                base.ActualizarIdiomaInterfaz();

                this.toolTip1.SetToolTip(this.cancelarButton, Properties.Resources.CancelarElFormulario);
                this.toolTip1.SetToolTip(this.aceptarButton, Properties.Resources.AceptarLaFontSeleccionada);
                this.toolTip1.SetToolTip(this.alturaTextBox, Properties.Resources.AlturaEnMetrosDelTexto);
                this.toolTip1.SetToolTip(this.colorButton, Properties.Resources.SeleccionDeColor);
                this.toolTip1.SetToolTip(this.subCheckBox, Properties.Resources.SeleccionDeTextoSubrayado);
                this.toolTip1.SetToolTip(this.cursivaCheckBox, Properties.Resources.SeleccionDeTextoSubrayado);
                this.toolTip1.SetToolTip(this.negritaCheckBox, Properties.Resources.SeleccionDeTextoEnNegrita);
                this.toolTip1.SetToolTip(this.fontComboBox, Properties.Resources.FontAUtilizar);
                this.Text = Properties.Resources.SeleccionDeFont;
            }
            catch (Exception e)
            {
                Log.RegisterError(e);
                throw new ExcepcionGMLC(e.Message, e);
            }
        }
    }
}
