// Copyright (C) 2005 panacorn <panacoran@users.sourceforge.jp>
// 
// This program is part of Protra.
//
// Protra is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
// 
// $Id: ApplicationError.cs,v 1.5 2007-12-27 08:34:39 panacoran Exp $

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace Protra.Lib.Dialogs
{
	/// <summary>
	/// 例外発生時に表示するダイアログです。
	/// </summary>
	public class ApplicationError : System.Windows.Forms.Form
	{
		/// <summary>
		/// 必要なデザイナ変数です。
		/// </summary>
		private System.ComponentModel.Container components = null;

		/// <summary>
		/// コンストラクタです。
		/// </summary>
		public ApplicationError()
		{
			//
			// Windows フォーム デザイナ サポートに必要です。
			//
			InitializeComponent();
		}

		/// <summary>
		/// 使用されているリソースに後処理を実行します。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows フォーム デザイナで生成されたコード 
		/// <summary>
		/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
		/// コード エディタで変更しないでください。
		/// </summary>
		private void InitializeComponent()
		{
			this.messageLabel = new System.Windows.Forms.Label();
			this.exitButton = new System.Windows.Forms.Button();
			this.messageText = new System.Windows.Forms.TextBox();
			this.SuspendLayout();
			// 
			// messageLabel
			// 
			this.messageLabel.Location = new System.Drawing.Point(8, 16);
			this.messageLabel.Name = "messageLabel";
			this.messageLabel.Size = new System.Drawing.Size(296, 16);
			this.messageLabel.TabIndex = 0;
			this.messageLabel.Text = "アプリケーション内部でエラーが発生しました";
			// 
			// exitButton
			// 
			this.exitButton.DialogResult = System.Windows.Forms.DialogResult.OK;
			this.exitButton.Location = new System.Drawing.Point(320, 160);
			this.exitButton.Name = "exitButton";
			this.exitButton.TabIndex = 1;
			this.exitButton.Text = "終了";
			// 
			// messageText
			// 
			this.messageText.AutoSize = false;
			this.messageText.Location = new System.Drawing.Point(8, 40);
			this.messageText.Multiline = true;
			this.messageText.Name = "messageText";
			this.messageText.ReadOnly = true;
			this.messageText.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
			this.messageText.Size = new System.Drawing.Size(384, 112);
			this.messageText.TabIndex = 2;
			this.messageText.Text = "";
			// 
			// ApplicationError
			// 
			this.AcceptButton = this.exitButton;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
			this.ClientSize = new System.Drawing.Size(400, 190);
			this.ControlBox = false;
			this.Controls.Add(this.messageText);
			this.Controls.Add(this.exitButton);
			this.Controls.Add(this.messageLabel);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.Name = "ApplicationError";
			this.Text = "エラーの発生";
			this.ResumeLayout(false);

		}
		#endregion

		private System.Windows.Forms.Label messageLabel;
		private System.Windows.Forms.Button exitButton;
		private System.Windows.Forms.TextBox messageText;

		
		/// <summary>
		/// エラーの種類を表す列挙型です。
		/// </summary>
		public enum ErrorType
		{
			/// <summary>
			/// 回復可能なエラー。
			/// </summary>
			Recoverable,
			/// <summary>
			/// 致命的なエラー。
			/// </summary>
			Fatal
		}
		private ErrorType mode;

		/// <summary>
		/// エラーの種類です。
		/// </summary>
		public ErrorType Mode
		{
			get
			{
				return mode;
			}
			set
			{
				mode = value;
				if (value == ErrorType.Fatal)
					this.exitButton.Text = "終了";
				else
					this.exitButton.Text = "無視";
			}
		}

		/// <summary>
		/// 表示するエラーメッセージです。
		/// </summary>
		public string ErrorMessage
		{
			set
			{
				messageText.Lines = value.Split(new Char[] {'\n'});
			}
		}
	}
}
