Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 2803 was 2790, checked in by swagner, 14 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
RevLine 
[2665]1#region License Information
2/* HeuristicLab
[2790]3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[2665]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;
[2669]29using HeuristicLab.Core;
[2665]30using HeuristicLab.Core.Views;
31using HeuristicLab.MainForm;
[2713]32using HeuristicLab.MainForm.WindowsForms;
[2665]33
34namespace HeuristicLab.Data.Views {
35  [Content(typeof(IStringConvertibleData), true)]
[2713]36  public partial class StringConvertibleDataView : ContentView {
37    public new IStringConvertibleData Content {
38      get { return (IStringConvertibleData)base.Content; }
39      set { base.Content = value; }
[2665]40    }
41
42    public StringConvertibleDataView() {
43      InitializeComponent();
44      Caption = "StringConvertibleData View";
[2676]45      errorProvider.SetIconAlignment(valueTextBox, ErrorIconAlignment.MiddleLeft);
46      errorProvider.SetIconPadding(valueTextBox, 2);
[2665]47    }
[2727]48    public StringConvertibleDataView(IStringConvertibleData content)
[2665]49      : this() {
[2727]50      Content = content;
[2665]51    }
52
[2713]53    protected override void DeregisterContentEvents() {
54      Content.Changed -= new ChangedEventHandler(Content_Changed);
55      base.DeregisterContentEvents();
[2665]56    }
57
[2713]58    protected override void RegisterContentEvents() {
59      base.RegisterContentEvents();
60      Content.Changed += new ChangedEventHandler(Content_Changed);
[2665]61    }
62
[2713]63    protected override void OnContentChanged() {
64      base.OnContentChanged();
65      if (Content == null) {
[2665]66        Caption = "StringConvertibleData View";
[2669]67        valueTextBox.Text = string.Empty;
[2665]68        valueTextBox.Enabled = false;
69      } else {
[2713]70        Caption = Content.GetValue() + " (" + Content.GetType().Name + ")";
71        valueTextBox.Text = Content.GetValue();
[2665]72        valueTextBox.Enabled = true;
73      }
74    }
75
[2713]76    private void Content_Changed(object sender, ChangedEventArgs e) {
[2665]77      if (InvokeRequired)
[2713]78        Invoke(new ChangedEventHandler(Content_Changed), sender, e);
[2665]79      else
[2713]80        valueTextBox.Text = Content.GetValue();
[2665]81    }
82
[2676]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) {
[2713]87        valueTextBox.Text = Content.GetValue();
[2676]88        valueLabel.Focus();  // set focus on label to validate data
89      }
90    }
[2665]91    private void valueTextBox_Validating(object sender, CancelEventArgs e) {
[2694]92      string errorMessage;
[2713]93      if (!Content.Validate(valueTextBox.Text, out errorMessage)) {
[2676]94        e.Cancel = true;
[2694]95        errorProvider.SetError(valueTextBox, errorMessage);
[2665]96        valueTextBox.SelectAll();
97      }
98    }
99    private void valueTextBox_Validated(object sender, EventArgs e) {
[2713]100      Content.SetValue(valueTextBox.Text);
[2676]101      errorProvider.SetError(valueTextBox, string.Empty);
[2665]102    }
103  }
104}
Note: See TracBrowser for help on using the repository browser.