1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.ComponentModel;
|
---|
24 | using System.Windows.Forms;
|
---|
25 | using HeuristicLab.MainForm;
|
---|
26 | using HeuristicLab.MainForm.WindowsForms;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Data.Views {
|
---|
29 | [View("StringConvertibleValue View")]
|
---|
30 | [Content(typeof(IStringConvertibleValue), true)]
|
---|
31 | public partial class StringConvertibleValueView : AsynchronousContentView {
|
---|
32 | public new IStringConvertibleValue Content {
|
---|
33 | get { return (IStringConvertibleValue)base.Content; }
|
---|
34 | set { base.Content = value; }
|
---|
35 | }
|
---|
36 |
|
---|
37 | public StringConvertibleValueView() {
|
---|
38 | InitializeComponent();
|
---|
39 | Caption = "StringConvertibleValue View";
|
---|
40 | errorProvider.SetIconAlignment(valueTextBox, ErrorIconAlignment.MiddleLeft);
|
---|
41 | errorProvider.SetIconPadding(valueTextBox, 2);
|
---|
42 | }
|
---|
43 | public StringConvertibleValueView(IStringConvertibleValue content)
|
---|
44 | : this() {
|
---|
45 | Content = content;
|
---|
46 | }
|
---|
47 |
|
---|
48 | protected override void DeregisterContentEvents() {
|
---|
49 | Content.ValueChanged -= new EventHandler(Content_ValueChanged);
|
---|
50 | base.DeregisterContentEvents();
|
---|
51 | }
|
---|
52 |
|
---|
53 | protected override void RegisterContentEvents() {
|
---|
54 | base.RegisterContentEvents();
|
---|
55 | Content.ValueChanged += new EventHandler(Content_ValueChanged);
|
---|
56 | }
|
---|
57 |
|
---|
58 | protected override void OnContentChanged() {
|
---|
59 | base.OnContentChanged();
|
---|
60 | if (Content == null) {
|
---|
61 | Caption = "StringConvertibleValue View";
|
---|
62 | valueTextBox.Text = string.Empty;
|
---|
63 | valueTextBox.Enabled = false;
|
---|
64 | } else {
|
---|
65 | Caption = Content.GetValue() + " (" + Content.GetType().Name + ")";
|
---|
66 | valueTextBox.Text = Content.GetValue();
|
---|
67 | valueTextBox.Enabled = true;
|
---|
68 | }
|
---|
69 | }
|
---|
70 |
|
---|
71 | private void Content_ValueChanged(object sender, EventArgs e) {
|
---|
72 | if (InvokeRequired)
|
---|
73 | Invoke(new EventHandler(Content_ValueChanged), sender, e);
|
---|
74 | else
|
---|
75 | valueTextBox.Text = Content.GetValue();
|
---|
76 | }
|
---|
77 |
|
---|
78 | private void valueTextBox_KeyDown(object sender, KeyEventArgs e) {
|
---|
79 | if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
|
---|
80 | valueLabel.Focus(); // set focus on label to validate data
|
---|
81 | if (e.KeyCode == Keys.Escape) {
|
---|
82 | valueTextBox.Text = Content.GetValue();
|
---|
83 | valueLabel.Focus(); // set focus on label to validate data
|
---|
84 | }
|
---|
85 | }
|
---|
86 | private void valueTextBox_Validating(object sender, CancelEventArgs e) {
|
---|
87 | string errorMessage;
|
---|
88 | if (!Content.Validate(valueTextBox.Text, out errorMessage)) {
|
---|
89 | e.Cancel = true;
|
---|
90 | errorProvider.SetError(valueTextBox, errorMessage);
|
---|
91 | valueTextBox.SelectAll();
|
---|
92 | }
|
---|
93 | }
|
---|
94 | private void valueTextBox_Validated(object sender, EventArgs e) {
|
---|
95 | Content.SetValue(valueTextBox.Text);
|
---|
96 | errorProvider.SetError(valueTextBox, string.Empty);
|
---|
97 | }
|
---|
98 | }
|
---|
99 | }
|
---|