Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Data.Views/3.3/StringConvertibleDataView.cs @ 2915

Last change on this file since 2915 was 2790, checked in by swagner, 15 years ago

Operator architecture refactoring (#95)

  • implemented reviewers' comments
  • added additional plugins HeuristicLab.Evolutionary, HeuristicLab.Permutation, HeuristicLab.Selection, and HeuristicLab.Routing.TSP
File size: 3.7 KB
Line 
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
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Text;
28using System.Windows.Forms;
29using HeuristicLab.Core;
30using HeuristicLab.Core.Views;
31using HeuristicLab.MainForm;
32using HeuristicLab.MainForm.WindowsForms;
33
34namespace HeuristicLab.Data.Views {
35  [Content(typeof(IStringConvertibleData), true)]
36  public partial class StringConvertibleDataView : ContentView {
37    public new IStringConvertibleData Content {
38      get { return (IStringConvertibleData)base.Content; }
39      set { base.Content = value; }
40    }
41
42    public StringConvertibleDataView() {
43      InitializeComponent();
44      Caption = "StringConvertibleData View";
45      errorProvider.SetIconAlignment(valueTextBox, ErrorIconAlignment.MiddleLeft);
46      errorProvider.SetIconPadding(valueTextBox, 2);
47    }
48    public StringConvertibleDataView(IStringConvertibleData content)
49      : this() {
50      Content = content;
51    }
52
53    protected override void DeregisterContentEvents() {
54      Content.Changed -= new ChangedEventHandler(Content_Changed);
55      base.DeregisterContentEvents();
56    }
57
58    protected override void RegisterContentEvents() {
59      base.RegisterContentEvents();
60      Content.Changed += new ChangedEventHandler(Content_Changed);
61    }
62
63    protected override void OnContentChanged() {
64      base.OnContentChanged();
65      if (Content == null) {
66        Caption = "StringConvertibleData View";
67        valueTextBox.Text = string.Empty;
68        valueTextBox.Enabled = false;
69      } else {
70        Caption = Content.GetValue() + " (" + Content.GetType().Name + ")";
71        valueTextBox.Text = Content.GetValue();
72        valueTextBox.Enabled = true;
73      }
74    }
75
76    private void Content_Changed(object sender, ChangedEventArgs e) {
77      if (InvokeRequired)
78        Invoke(new ChangedEventHandler(Content_Changed), sender, e);
79      else
80        valueTextBox.Text = Content.GetValue();
81    }
82
83    private void valueTextBox_KeyDown(object sender, KeyEventArgs e) {
84      if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
85        valueLabel.Focus();  // set focus on label to validate data
86      if (e.KeyCode == Keys.Escape) {
87        valueTextBox.Text = Content.GetValue();
88        valueLabel.Focus();  // set focus on label to validate data
89      }
90    }
91    private void valueTextBox_Validating(object sender, CancelEventArgs e) {
92      string errorMessage;
93      if (!Content.Validate(valueTextBox.Text, out errorMessage)) {
94        e.Cancel = true;
95        errorProvider.SetError(valueTextBox, errorMessage);
96        valueTextBox.SelectAll();
97      }
98    }
99    private void valueTextBox_Validated(object sender, EventArgs e) {
100      Content.SetValue(valueTextBox.Text);
101      errorProvider.SetError(valueTextBox, string.Empty);
102    }
103  }
104}
Note: See TracBrowser for help on using the repository browser.