1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2008 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.Collections.Generic;
|
---|
24 | using System.ComponentModel;
|
---|
25 | using System.Drawing;
|
---|
26 | using System.Data;
|
---|
27 | using System.Text;
|
---|
28 | using System.Windows.Forms;
|
---|
29 | using HeuristicLab.Core;
|
---|
30 | using HeuristicLab.Core.Views;
|
---|
31 | using HeuristicLab.MainForm;
|
---|
32 |
|
---|
33 | namespace HeuristicLab.Data.Views {
|
---|
34 | [Content(typeof(IStringConvertibleData), true)]
|
---|
35 | public partial class StringConvertibleDataView : ObjectView {
|
---|
36 | public IStringConvertibleData StringConvertibleData {
|
---|
37 | get { return (IStringConvertibleData)Object; }
|
---|
38 | set { base.Object = value; }
|
---|
39 | }
|
---|
40 |
|
---|
41 | public StringConvertibleDataView() {
|
---|
42 | InitializeComponent();
|
---|
43 | Caption = "StringConvertibleData View";
|
---|
44 | errorProvider.SetIconAlignment(valueTextBox, ErrorIconAlignment.MiddleLeft);
|
---|
45 | errorProvider.SetIconPadding(valueTextBox, 2);
|
---|
46 | }
|
---|
47 | public StringConvertibleDataView(IStringConvertibleData stringConvertibleData)
|
---|
48 | : this() {
|
---|
49 | StringConvertibleData = stringConvertibleData;
|
---|
50 | }
|
---|
51 |
|
---|
52 | protected override void DeregisterObjectEvents() {
|
---|
53 | StringConvertibleData.Changed -= new ChangedEventHandler(StringConvertibleData_Changed);
|
---|
54 | base.DeregisterObjectEvents();
|
---|
55 | }
|
---|
56 |
|
---|
57 | protected override void RegisterObjectEvents() {
|
---|
58 | base.RegisterObjectEvents();
|
---|
59 | StringConvertibleData.Changed += new ChangedEventHandler(StringConvertibleData_Changed);
|
---|
60 | }
|
---|
61 |
|
---|
62 | protected override void OnObjectChanged() {
|
---|
63 | base.OnObjectChanged();
|
---|
64 | if (StringConvertibleData == null) {
|
---|
65 | Caption = "StringConvertibleData View";
|
---|
66 | valueTextBox.Text = string.Empty;
|
---|
67 | valueTextBox.Enabled = false;
|
---|
68 | } else {
|
---|
69 | Caption = StringConvertibleData.GetValue() + " (" + StringConvertibleData.GetType().Name + ")";
|
---|
70 | valueTextBox.Text = StringConvertibleData.GetValue();
|
---|
71 | valueTextBox.Enabled = true;
|
---|
72 | }
|
---|
73 | }
|
---|
74 |
|
---|
75 | private void StringConvertibleData_Changed(object sender, ChangedEventArgs e) {
|
---|
76 | if (InvokeRequired)
|
---|
77 | Invoke(new ChangedEventHandler(StringConvertibleData_Changed), sender, e);
|
---|
78 | else
|
---|
79 | valueTextBox.Text = StringConvertibleData.GetValue();
|
---|
80 | }
|
---|
81 |
|
---|
82 | private void valueTextBox_KeyDown(object sender, KeyEventArgs e) {
|
---|
83 | if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
|
---|
84 | valueLabel.Focus(); // set focus on label to validate data
|
---|
85 | if (e.KeyCode == Keys.Escape) {
|
---|
86 | valueTextBox.Text = StringConvertibleData.GetValue();
|
---|
87 | valueLabel.Focus(); // set focus on label to validate data
|
---|
88 | }
|
---|
89 | }
|
---|
90 | private void valueTextBox_Validating(object sender, CancelEventArgs e) {
|
---|
91 | string errorMessage;
|
---|
92 | if (!StringConvertibleData.Validate(valueTextBox.Text, out errorMessage)) {
|
---|
93 | e.Cancel = true;
|
---|
94 | errorProvider.SetError(valueTextBox, errorMessage);
|
---|
95 | valueTextBox.SelectAll();
|
---|
96 | }
|
---|
97 | }
|
---|
98 | private void valueTextBox_Validated(object sender, EventArgs e) {
|
---|
99 | StringConvertibleData.SetValue(valueTextBox.Text);
|
---|
100 | errorProvider.SetError(valueTextBox, string.Empty);
|
---|
101 | }
|
---|
102 | }
|
---|
103 | }
|
---|