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.Views;
|
---|
30 | using HeuristicLab.MainForm;
|
---|
31 |
|
---|
32 | namespace HeuristicLab.Data.Views {
|
---|
33 | [Content(typeof(IStringConvertibleData), true)]
|
---|
34 | public partial class StringConvertibleDataView : ObjectView {
|
---|
35 | public IStringConvertibleData StringConvertibleData {
|
---|
36 | get { return (IStringConvertibleData)Object; }
|
---|
37 | set { base.Object = value; }
|
---|
38 | }
|
---|
39 |
|
---|
40 | public StringConvertibleDataView() {
|
---|
41 | InitializeComponent();
|
---|
42 | Caption = "StringConvertibleData View";
|
---|
43 | }
|
---|
44 | public StringConvertibleDataView(IStringConvertibleData stringConvertibleData)
|
---|
45 | : this() {
|
---|
46 | StringConvertibleData = stringConvertibleData;
|
---|
47 | }
|
---|
48 |
|
---|
49 | protected override void DeregisterObjectEvents() {
|
---|
50 | StringConvertibleData.ValueChanged -= new EventHandler(StringConvertibleData_ValueChanged);
|
---|
51 | base.DeregisterObjectEvents();
|
---|
52 | }
|
---|
53 |
|
---|
54 | protected override void RegisterObjectEvents() {
|
---|
55 | base.RegisterObjectEvents();
|
---|
56 | StringConvertibleData.ValueChanged += new EventHandler(StringConvertibleData_ValueChanged);
|
---|
57 | }
|
---|
58 |
|
---|
59 | protected override void OnObjectChanged() {
|
---|
60 | base.OnObjectChanged();
|
---|
61 | if (StringConvertibleData == null) {
|
---|
62 | Caption = "StringConvertibleData View";
|
---|
63 | valueTextBox.Text = "-";
|
---|
64 | valueTextBox.Enabled = false;
|
---|
65 | } else {
|
---|
66 | Caption = StringConvertibleData.GetValue() + " (" + StringConvertibleData.GetType().Name + ")";
|
---|
67 | valueTextBox.Text = StringConvertibleData.GetValue();
|
---|
68 | valueTextBox.Enabled = true;
|
---|
69 | }
|
---|
70 | }
|
---|
71 |
|
---|
72 | private void StringConvertibleData_ValueChanged(object sender, EventArgs e) {
|
---|
73 | if (InvokeRequired)
|
---|
74 | Invoke(new EventHandler(StringConvertibleData_ValueChanged), sender, e);
|
---|
75 | else
|
---|
76 | valueTextBox.Text = StringConvertibleData.GetValue();
|
---|
77 | }
|
---|
78 |
|
---|
79 | private void valueTextBox_Validating(object sender, CancelEventArgs e) {
|
---|
80 | e.Cancel = !StringConvertibleData.SetValue(valueTextBox.Text);
|
---|
81 | if (e.Cancel) {
|
---|
82 | MessageBox.Show(this, "\"" + valueTextBox.Text + "\" is not a valid value.", "Invalid Value", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
83 | valueTextBox.SelectAll();
|
---|
84 | valueTextBox.Focus();
|
---|
85 | }
|
---|
86 | }
|
---|
87 | private void valueTextBox_Validated(object sender, EventArgs e) {
|
---|
88 | valueTextBox.Text = StringConvertibleData.GetValue();
|
---|
89 | }
|
---|
90 | }
|
---|
91 | }
|
---|