using System;
using System.ComponentModel;
using System.Threading;
using System.Windows.Forms;

namespace PinyinModel
{
    public partial class FormWelcome : Form
    {
        public FormWelcome()
        {
			this.Font = View.GetFont();
            InitializeComponent();
            this.Text = this.labelTitle.Text;
        }

        PinyinModel pinyin_model;

        private void initializer_DoWork(object sender, DoWorkEventArgs e)
        {
            pinyin_model = new PinyinModel();

            initializer.ReportProgress(0);
            pinyin_model.initializeSyllable();
			
            initializer.ReportProgress(1);
            pinyin_model.initializeLexicon();

            initializer.ReportProgress(2);
            pinyin_model.initializeSLM();
        }

        private void FormWelcome_Load(object sender, EventArgs e)
        {
            initializer.RunWorkerAsync();
        }

        private void initializer_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            this.Hide();
            FormMain frmMain = new FormMain(pinyin_model);
            frmMain.ShowDialog();
            this.Dispose();
        }

        private void initializer_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            if (e.ProgressPercentage == 0)
            {
                this.labelStatus.Text = "正在初始化拼音音節...";
            }
            else if (e.ProgressPercentage == 1)
            {
                this.labelStatus.Text = "正在初始化詞庫...";
            }
            else if (e.ProgressPercentage == 2)
            {
                this.labelStatus.Text = "正在初始化語言模型...";
            }
        }

        private void linkLabelURL_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start(linkLabelURL.Text);
        }
    }
}
