Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.0/sources/HeuristicLab.Core/VariableView.cs @ 7624

Last change on this file since 7624 was 2, checked in by swagner, 17 years ago

Added HeuristicLab 3.0 sources from former SVN repository at revision 52

File size: 3.7 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;
29
30namespace HeuristicLab.Core {
31  public partial class VariableView : ViewBase {
32    private ChooseItemDialog chooseItemDialog;
33
34    public IVariable Variable {
35      get { return (IVariable)Item; }
36      set { base.Item = value; }
37    }
38
39    public VariableView() {
40      InitializeComponent();
41      Caption = "Variable";
42    }
43    public VariableView(IVariable variable)
44      : this() {
45      Variable = variable;
46    }
47
48    protected override void RemoveItemEvents() {
49      Variable.NameChanged -= new EventHandler(Variable_NameChanged);
50      Variable.ValueChanged -= new EventHandler(Variable_ValueChanged);
51      base.RemoveItemEvents();
52    }
53    protected override void AddItemEvents() {
54      base.AddItemEvents();
55      Variable.NameChanged += new EventHandler(Variable_NameChanged);
56      Variable.ValueChanged += new EventHandler(Variable_ValueChanged);
57    }
58
59    protected override void UpdateControls() {
60      base.UpdateControls();
61      valueTextBox.Text = "-";
62      valueTextBox.Enabled = false;
63      editorGroupBox.Controls.Clear();
64      editorGroupBox.Enabled = false;
65      if (Variable == null) {
66        Caption = "Variable";
67        nameTextBox.Enabled = false;
68      } else {
69        Caption = Variable.Name + " (" + Variable.GetType().Name + ")";
70        nameTextBox.Text = Variable.Name;
71        nameTextBox.Enabled = true;
72        if (Variable.Value != null) {
73          valueTextBox.Text = Variable.Value.GetType().FullName;
74          valueTextBox.Enabled = true;
75          Control editor = (Control)Variable.Value.CreateView();
76          if (editor != null) {
77            editorGroupBox.Controls.Add(editor);
78            editor.Dock = DockStyle.Fill;
79            editorGroupBox.Enabled = true;
80          }
81        }
82      }
83    }
84
85    private void Variable_NameChanged(object sender, EventArgs e) {
86      UpdateText();
87    }
88    private void UpdateText() {
89      if (InvokeRequired)
90        Invoke(new MethodInvoker(UpdateText));
91      else
92        nameTextBox.Text = Variable.Name;
93    }
94    private void Variable_ValueChanged(object sender, EventArgs e) {
95      Refresh();
96    }
97
98    private void nameTextBox_Validating(object sender, CancelEventArgs e) {
99      Variable.Name = nameTextBox.Text;
100
101      // check if variable name was set successfully
102      e.Cancel = Variable.Name != nameTextBox.Text;
103    }
104
105    private void setVariableValueButton_Click(object sender, EventArgs e) {
106      if (chooseItemDialog == null) {
107        chooseItemDialog = new ChooseItemDialog();
108        chooseItemDialog.Caption = "Set Value";
109      }
110      if (chooseItemDialog.ShowDialog(this) == DialogResult.OK)
111        Variable.Value = chooseItemDialog.Item;
112    }
113  }
114}
Note: See TracBrowser for help on using the repository browser.