OSDN Git Service

1.1.0.2 マイナーチェンジ
[kybernetes/Kybernetes.git] / KyberNetes / view / BaseForm.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.Windows.Forms;\r
4 using com.andoutomo.kybernetes.control;\r
5 using com.andoutomo.kybernetes.data.DAO;\r
6 using System.Drawing;\r
7 \r
8 \r
9 namespace com.andoutomo.kybernetes.view\r
10 {\r
11     public partial class BaseForm : Form\r
12     {\r
13         public BaseForm()\r
14         {\r
15             InitializeComponent();\r
16 \r
17             List<string> initialText = new List<string>();\r
18             initialText.Add("#####################################################");\r
19             initialText.Add("# " + AppInfoContainer.Title + " " + AppInfoContainer.Description);\r
20             initialText.Add("# Version " + AppInfoContainer.VersionNo);\r
21             initialText.Add("# " + AppInfoContainer.CopyRight);\r
22             initialText.Add("# ");\r
23             initialText.Add("#####################################################");\r
24             addMultiText(initialText);\r
25 \r
26             addPrompt();\r
27             history = new CmdHistory();\r
28 \r
29             this.Text = AppInfoContainer.Title + " " + AppInfoContainer.Description;\r
30             Echo = true;\r
31             \r
32 \r
33         }\r
34         private CmdHistory history;\r
35 \r
36         /// <summary>\r
37         /// カテゴリ設定ダイアログを表示します。\r
38         /// </summary>\r
39         /// <param name="arg"></param>\r
40         internal void invokeCategSettingDialog(List<CategoryData> arg)\r
41         {\r
42             CategorySetting categSetting = new CategorySetting();\r
43             categSetting.StartPosition = FormStartPosition.CenterParent;\r
44             categSetting.setCategoryList(arg);\r
45             categSetting.ShowDialog();\r
46         }\r
47 \r
48         /// <summary>\r
49         /// バージョン情報を表示します\r
50         /// </summary>\r
51         internal void invokeCreditDialog()\r
52         {\r
53             Credit creditForm = new Credit();\r
54             creditForm.StartPosition = FormStartPosition.CenterParent;\r
55             \r
56             creditForm.ShowDialog();\r
57         }\r
58         /// <summary>\r
59         /// エクスポート用のファイルダイアログを開いて選択したファイルパスを返します。\r
60         /// </summary>\r
61         /// <returns></returns>\r
62         internal string invokeExpDialog()\r
63         {\r
64             DialogResult result =this.expData.ShowDialog();\r
65             if (result == DialogResult.OK)\r
66             {\r
67                 return this.expData.FileName;\r
68             }\r
69             else\r
70             {\r
71                 return string.Empty;\r
72             }\r
73         }\r
74         /// <summary>\r
75         /// ダンプ用のファイルダイアログを開いて選択したファイルパスを返します。\r
76         /// </summary>\r
77         /// <returns></returns>\r
78         internal string invokeDmpDialog()\r
79         {\r
80             DialogResult result = this.dmpData.ShowDialog();\r
81             if (result == DialogResult.OK)\r
82             {\r
83                 return this.dmpData.FileName;\r
84             }\r
85             return string.Empty;\r
86         }\r
87 \r
88         /// <summary>\r
89         /// タイムエリア設定画面を表示します。\r
90         /// </summary>\r
91         /// <param name="arg"></param>\r
92         internal void invokeTimeareaSettingDialog(List<TimeAreaData> arg)\r
93         {\r
94             TimeAreaSetting setting = new TimeAreaSetting();\r
95             setting.StartPosition = FormStartPosition.CenterParent;\r
96             setting.setTimeareaList(arg);\r
97             setting.ShowDialog();\r
98         }\r
99 \r
100         /// <summary>\r
101         /// コンソールに文字列を表示します。\r
102         /// </summary>\r
103         /// <param name="args">表示したい文字列</param>\r
104         internal void addText(string args)\r
105         {\r
106             rConsole.AppendText(args + System.Environment.NewLine);\r
107             KybernetesLogger.Log.trace(args);\r
108         }\r
109 \r
110         /// <summary>\r
111         /// コンソールに複数文章を追加します。\r
112         /// </summary>\r
113         /// <param name="messages">追加したい文章群</param>\r
114         internal void addMultiText(List<string> messages)\r
115         {\r
116             foreach (string message in messages)\r
117             {\r
118                 addText(message);\r
119             }\r
120             rConsole.AppendText(System.Environment.NewLine);\r
121         }\r
122         private void addPrompt()\r
123         {\r
124             rConsole.AppendText("> ");\r
125         }\r
126 \r
127         internal int getPanelSize()\r
128         {\r
129             return this.pnlTask.Width;\r
130         }\r
131         /// <summary>\r
132         /// コンソールをクリアします。\r
133         /// </summary>\r
134         internal void clearText()\r
135         {\r
136             rConsole.Clear();\r
137         }\r
138 \r
139         private bool exitSwitch = false;\r
140         internal bool ExitSwitch\r
141         {\r
142             set { exitSwitch = value; }\r
143         }\r
144 \r
145         private int lastRow=17;\r
146         /// <summary>\r
147         /// パネルを追加します。\r
148         /// </summary>\r
149         /// <param name="data"></param>\r
150         internal void addPanel(TaskData data)\r
151         {\r
152             Panel targetPanel = new PanelController(this).createRow(lastRow,data);\r
153             \r
154             pnlTask.Controls.Add(targetPanel);\r
155             lastRow += targetPanel.Height-1;\r
156         }\r
157 \r
158         /// <summary>\r
159         /// パネルがダブルクリックされた時に対応します。IDをテキストボックスに転記します。\r
160         /// </summary>\r
161         /// <param name="data"></param>\r
162         internal void AddIDToText(string data)\r
163         {\r
164             this.txtInput.Text += data + " ";\r
165             txtInput.Focus();\r
166             this.txtInput.Select(this.txtInput.Text.Length, 0);\r
167 \r
168         }\r
169 \r
170         /// <summary>\r
171         /// パネルをクリアします。\r
172         /// </summary>\r
173         internal void clearPanel()\r
174         {\r
175             pnlTask.Controls.Clear();\r
176             //先頭行は足す\r
177             pnlTask.Controls.Add(new CaptionPanelController().createRow(this.pnlTask.Width));\r
178             lastRow = 17;\r
179         }\r
180         /// <summary>\r
181         /// コマンド内容を表示するかどうかを決定します。\r
182         /// </summary>\r
183         internal bool Echo\r
184         {\r
185             get;\r
186             set;\r
187         }\r
188         /// <summary>\r
189         /// コマンド入力を受け付けます。\r
190         /// </summary>\r
191         /// <param name="sender"></param>\r
192         /// <param name="e"></param>\r
193         private void txtInput_KeyDown(object sender, KeyEventArgs e)\r
194         {\r
195             int currentYPosition;\r
196             switch (e.KeyCode)\r
197             {\r
198                 case Keys.Enter:\r
199                     e.SuppressKeyPress = true;\r
200                     doCommand();\r
201                     \r
202                     break;\r
203 \r
204                 case Keys.Space:\r
205                     if (e.Control)\r
206                     {\r
207                         e.SuppressKeyPress = true;\r
208                         if (txtInput.ImeMode == ImeMode.Off)\r
209                         {\r
210                             txtInput.ImeMode = ImeMode.On;\r
211                         }\r
212                         else\r
213                         {\r
214                             txtInput.ImeMode = ImeMode.Off;\r
215                         }\r
216                     }\r
217                     break;\r
218                 case Keys.Escape:\r
219                     e.SuppressKeyPress = true;\r
220                     history.resetPosition();\r
221                     txtInput.Clear();\r
222                     break;\r
223                 case Keys.Up:\r
224                     e.SuppressKeyPress = true;\r
225                     txtInput.Text = history.prevCommand();\r
226                     break;\r
227                 case Keys.Down:\r
228                     e.SuppressKeyPress = true;\r
229                     txtInput.Text = history.nextCommand();\r
230                     break;\r
231 \r
232                 case Keys.PageDown:\r
233                         currentYPosition = Math.Abs(this.pnlTask.AutoScrollPosition.Y);\r
234                         this.pnlTask.AutoScrollPosition = new Point(0, currentYPosition + 380);\r
235                     break;\r
236 \r
237                 case Keys.PageUp:\r
238                         currentYPosition = Math.Abs(this.pnlTask.AutoScrollPosition.Y);\r
239                         this.pnlTask.AutoScrollPosition = new Point(0, currentYPosition - 380);\r
240                     break;\r
241             }\r
242         }\r
243         /// <summary>\r
244         /// コマンドを実行します\r
245         /// </summary>\r
246         private void doCommand()\r
247         {\r
248             rConsole.Focus();\r
249             \r
250             if (Echo)\r
251             {\r
252                 addText(txtInput.Text);\r
253             }\r
254             KybernetesLogger.Log.trace("[dispatch]" + txtInput.Text);\r
255             CmdDispatcher dispatcher = CmdDispatcher.getDispatcher(this);\r
256             \r
257             string result = dispatcher.dispatch(txtInput.Text.Trim());\r
258             if (!string.IsNullOrEmpty(result))\r
259             {\r
260                 addText(result);\r
261             }\r
262 \r
263             addPrompt();\r
264             if (!string.IsNullOrEmpty(txtInput.Text))\r
265             {\r
266                 history.stackCmd(txtInput.Text);\r
267             }\r
268             txtInput.Clear();\r
269             txtInput.ImeMode = ImeMode.Off;\r
270 \r
271             if (exitSwitch == true)\r
272             {\r
273                 this.Close();\r
274             }\r
275             txtInput.Focus();\r
276         }\r
277 \r
278         /// <summary>\r
279         /// 文字入力ボックスを表示します。\r
280         /// </summary>\r
281         /// <param name="prompt"></param>\r
282         /// <returns></returns>\r
283         internal string showInputBox(string prompt)\r
284         {\r
285             return this.showInputBox(prompt, string.Empty);\r
286         }\r
287         /// <summary>\r
288         /// 文字入力ボックスを表示します。\r
289         /// </summary>\r
290         /// <param name="prompt"></param>\r
291         /// <param name="defaultData"></param>\r
292         /// <returns></returns>\r
293         internal string showInputBox(string prompt, string defaultData)\r
294         {\r
295             return showInputBox(prompt, defaultData, ImeMode.Off);\r
296         }\r
297         /// <summary>\r
298         /// 文字入力ボックスを表示します。\r
299         /// </summary>\r
300         /// <param name="prompt"></param>\r
301         /// <param name="defaultData"></param>\r
302         /// <param name="imeMode"></param>\r
303         /// <returns></returns>\r
304         internal string showInputBox(string prompt, string defaultData, ImeMode imeMode)\r
305         {\r
306             InputBox inputBox = new InputBox(prompt, defaultData);\r
307             inputBox.StartPosition = FormStartPosition.CenterParent;\r
308             inputBox.ImeMode = imeMode;\r
309             inputBox.Owner = this;\r
310 \r
311 \r
312             DialogResult res = inputBox.ShowDialog();\r
313             if (res == DialogResult.OK)\r
314             {\r
315                 return InputDialogData;\r
316             }\r
317             return null;\r
318         }\r
319         /// <summary>\r
320         /// 文字入力ボックスを表示します。\r
321         /// </summary>\r
322         /// <param name="prompt"></param>\r
323         /// <param name="imeMode"></param>\r
324         /// <returns></returns>\r
325         internal string showInputBox(string prompt, ImeMode imeMode)\r
326         {\r
327             return showInputBox(prompt, string.Empty, imeMode);\r
328         }\r
329 \r
330         /// <summary>\r
331         /// 文字入力ボックスを表示します。プロンプトなし版です。\r
332         /// </summary>\r
333         /// <returns></returns>\r
334         internal string showInputBox()\r
335         {\r
336             return showInputBox("");\r
337         }\r
338 \r
339 \r
340         /// <summary>\r
341         /// プロンプトで指定した値を(プロンプトがここに)格納します。\r
342         /// </summary>\r
343         internal string InputDialogData\r
344         {\r
345             private get;\r
346             set;\r
347         }\r
348 \r
349         /// <summary>\r
350         /// ドロップダウン式リストを表示します。\r
351         /// </summary>\r
352         /// <param name="prompt"></param>\r
353         /// <returns></returns>\r
354         internal string showDropBoxInputBox(List<SimpleDataBean> list,string prompt)\r
355         {\r
356             DropBoxInputBox inputBox = new DropBoxInputBox(prompt);\r
357             inputBox.StartPosition = FormStartPosition.CenterParent;\r
358             inputBox.setDropData(list);\r
359 \r
360             inputBox.Owner = this;\r
361 \r
362             DialogResult res = inputBox.ShowDialog();\r
363             if (res == DialogResult.OK)\r
364             {\r
365                 return InputDialogData;\r
366             }\r
367             return null;\r
368         }\r
369         /// <summary>\r
370         /// ドロップダウン式リストを表示します。デフォルト表示を追加しています。\r
371         /// </summary>\r
372         /// <param name="list"></param>\r
373         /// <param name="prompt"></param>\r
374         /// <param name="defaultData"></param>\r
375         /// <returns></returns>\r
376         internal string showDropBoxInputBox(List<SimpleDataBean> list, string prompt, string defaultData)\r
377         {\r
378             DropBoxInputBox inputBox = new DropBoxInputBox(prompt,defaultData);\r
379             inputBox.StartPosition = FormStartPosition.CenterParent;\r
380             inputBox.setDropData(list);\r
381 \r
382             inputBox.Owner = this;\r
383 \r
384             DialogResult res = inputBox.ShowDialog();\r
385             if (res == DialogResult.OK)\r
386             {\r
387                 return InputDialogData;\r
388             }\r
389             return null;\r
390         }\r
391 \r
392         /// <summary>\r
393         /// マウスでコンソールをドラッグした時に、選択対象を入力ボックスに追加します。\r
394         /// </summary>\r
395         /// <param name="sender"></param>\r
396         /// <param name="e"></param>\r
397         private void rConsole_MouseUp(object sender, MouseEventArgs e)\r
398         {\r
399             txtInput.Text += rConsole.SelectedText.Trim();\r
400             txtInput.Focus();\r
401             //選択状態を解除する\r
402             this.txtInput.Select(this.txtInput.Text.Length, 0);\r
403             \r
404         }\r
405     }\r
406 }\r