Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Parameters.Views/3.3/ScopeTreeLookupParameterView.cs @ 3714

Last change on this file since 3714 was 3659, checked in by swagner, 15 years ago

Worked on refactoring of algorithm analysis and tracing (#999)

  • removed SubScopesSubScopesLookupParameter
  • adapted SubScopesLookupParameter and renamed it into ScopeTreeLookupParameter
File size: 5.4 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.Windows.Forms;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Core.Views;
27using HeuristicLab.MainForm;
28
29namespace HeuristicLab.Parameters.Views {
30  /// <summary>
31  /// The visual representation of a <see cref="Parameter"/>.
32  /// </summary>
33  [View("ScopeTreeLookupParameter View")]
34  [Content(typeof(ScopeTreeLookupParameter<>), true)]
35  public partial class ScopeTreeLookupParameterView<T> : ParameterView where T : class, IItem {
36    /// <summary>
37    /// Gets or sets the variable to represent visually.
38    /// </summary>
39    /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
40    /// No own data storage present.</remarks>
41    public new ScopeTreeLookupParameter<T> Content {
42      get { return (ScopeTreeLookupParameter<T>)base.Content; }
43      set { base.Content = value; }
44    }
45
46    /// <summary>
47    /// Initializes a new instance of <see cref="VariableView"/> with caption "Variable".
48    /// </summary>
49    public ScopeTreeLookupParameterView() {
50      InitializeComponent();
51      Caption = "ScopeTreeLookupParameter";
52    }
53
54    /// <summary>
55    /// Removes the eventhandlers from the underlying <see cref="IVariable"/>.
56    /// </summary>
57    /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
58    protected override void DeregisterContentEvents() {
59      Content.ActualNameChanged -= new EventHandler(Content_ActualNameChanged);
60      Content.DepthChanged -= new EventHandler(Content_DepthChanged);
61      base.DeregisterContentEvents();
62    }
63
64    /// <summary>
65    /// Adds eventhandlers to the underlying <see cref="IVariable"/>.
66    /// </summary>
67    /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
68    protected override void RegisterContentEvents() {
69      base.RegisterContentEvents();
70      Content.ActualNameChanged += new EventHandler(Content_ActualNameChanged);
71      Content.DepthChanged += new EventHandler(Content_DepthChanged);
72    }
73
74    protected override void OnContentChanged() {
75      base.OnContentChanged();
76      if (Content == null) {
77        Caption = "ScopeTreeLookupParameter";
78        actualNameTextBox.Text = string.Empty;
79        depthTextBox.Text = string.Empty;
80      } else {
81        Caption = Content.Name + " (" + Content.GetType().Name + ")";
82        actualNameTextBox.Text = Content.ActualName;
83        depthTextBox.Text = Content.Depth.ToString();
84      }
85      SetEnabledStateOfControls();
86    }
87
88    protected override void OnReadOnlyChanged() {
89      base.OnReadOnlyChanged();
90      SetEnabledStateOfControls();
91    }
92
93    private void SetEnabledStateOfControls() {
94      actualNameTextBox.Enabled = Content != null;
95      actualNameTextBox.ReadOnly = ReadOnly;
96      depthTextBox.Enabled = Content != null;
97      depthTextBox.ReadOnly = ReadOnly;
98    }
99
100    protected virtual void Content_ActualNameChanged(object sender, EventArgs e) {
101      if (InvokeRequired)
102        Invoke(new EventHandler(Content_ActualNameChanged), sender, e);
103      else
104        actualNameTextBox.Text = Content.ActualName;
105    }
106    protected virtual void Content_DepthChanged(object sender, EventArgs e) {
107      if (InvokeRequired)
108        Invoke(new EventHandler(Content_DepthChanged), sender, e);
109      else
110        depthTextBox.Text = Content.Depth.ToString();
111    }
112
113    protected virtual void actualNameTextBox_Validated(object sender, EventArgs e) {
114      Content.ActualName = actualNameTextBox.Text;
115    }
116    protected virtual void depthTextBox_KeyDown(object sender, KeyEventArgs e) {
117      if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
118        depthLabel.Focus();  // set focus on label to validate data
119      if (e.KeyCode == Keys.Escape) {
120        depthTextBox.Text = Content.Depth.ToString();
121        depthLabel.Focus();  // set focus on label to validate data
122      }
123    }
124    protected virtual void depthTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
125      int val;
126      if (!int.TryParse(depthTextBox.Text, out val) || (val < 0)) {
127        e.Cancel = true;
128        errorProvider.SetError(depthTextBox, "Invalid Value (depth must be an integer number greater or equal to zero)");
129        depthTextBox.SelectAll();
130      }
131    }
132    protected virtual void depthTextBox_Validated(object sender, EventArgs e) {
133      Content.Depth = int.Parse(depthTextBox.Text);
134      errorProvider.SetError(depthTextBox, string.Empty);
135    }
136  }
137}
Note: See TracBrowser for help on using the repository browser.