Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Core.Views/3.3/IntDataView.cs @ 2655

Last change on this file since 2655 was 2655, checked in by swagner, 14 years ago

Committing first results of the refactoring of HeuristicLab.Core and related plugins (#95)

File size: 3.2 KB
Line 
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
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Text;
28using System.Windows.Forms;
29using HeuristicLab.MainForm;
30
31namespace HeuristicLab.Core.Views {
32  /// <summary>
33  /// The visual representation of a <see cref="Variable"/>.
34  /// </summary>
35  [Content(typeof(IntData), true)]
36  public partial class IntDataView : ItemViewBase {
37    public IntData IntData {
38      get { return (IntData)Item; }
39      set { base.Item = value; }
40    }
41
42    public IntDataView() {
43      InitializeComponent();
44      Caption = "IntData";
45    }
46    public IntDataView(IntData intData)
47      : this() {
48      IntData = intData;
49    }
50
51    protected override void DeregisterObjectEvents() {
52      IntData.ValueChanged -= new EventHandler(IntData_ValueChanged);
53      base.DeregisterObjectEvents();
54    }
55
56    protected override void RegisterObjectEvents() {
57      base.RegisterObjectEvents();
58      IntData.ValueChanged += new EventHandler(IntData_ValueChanged);
59    }
60
61    protected override void OnObjectChanged() {
62      base.OnObjectChanged();
63      if (IntData == null) {
64        Caption = "IntData";
65        valueTextBox.Text = "-";
66        valueTextBox.Enabled = false;
67      } else {
68        Caption = IntData.Value.ToString() + " (" + IntData.GetType().Name + ")";
69        valueTextBox.Text = IntData.Value.ToString();
70        valueTextBox.Enabled = true;
71      }
72    }
73
74    private void IntData_ValueChanged(object sender, EventArgs e) {
75      if (InvokeRequired)
76        Invoke(new EventHandler(IntData_ValueChanged), sender, e);
77      else
78        valueTextBox.Text = IntData.Value.ToString();
79    }
80
81    private void valueTextBox_Validating(object sender, CancelEventArgs e) {
82      int oldValue = IntData.Value;
83      int value;
84      e.Cancel = !int.TryParse(valueTextBox.Text, out value);
85      if (e.Cancel) {
86        MessageBox.Show(this, "\"" + valueTextBox.Text + "\" is not a valid integer value.", "Invalid Value", MessageBoxButtons.OK, MessageBoxIcon.Error);
87        valueTextBox.Text = oldValue.ToString();
88        valueTextBox.SelectAll();
89        valueTextBox.Focus();
90      }
91    }
92    private void valueTextBox_Validated(object sender, EventArgs e) {
93      IntData.Value = int.Parse(valueTextBox.Text);
94    }
95  }
96}
Note: See TracBrowser for help on using the repository browser.