Free cookie consent management tool by TermsFeed Policy Generator

source: branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape.Views/ScopePathLookupParameterView.cs @ 14781

Last change on this file since 14781 was 7128, checked in by epitzer, 13 years ago

#1696 Integrate fitness landscape analysis plugins from Heureka! repository.

File size: 5.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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.Core;
25using HeuristicLab.Core.Views;
26using HeuristicLab.MainForm;
27
28namespace HeuristicLab.Parameters.Views {
29  /// <summary>
30  /// The visual representation of a <see cref="Parameter"/>.
31  /// </summary>
32  [View("ScopePathLookupParameter View")]
33  [Content(typeof(ScopePathLookupParameter<>), true)]
34  public partial class ScopePathLookupParameterView<T> : ParameterView where T : class, IItem {
35    /// <summary>
36    /// Gets or sets the variable to represent visually.
37    /// </summary>
38    /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
39    /// No own data storage present.</remarks>
40    public new ScopePathLookupParameter<T> Content {
41      get { return (ScopePathLookupParameter<T>)base.Content; }
42      set { base.Content = value; }
43    }
44
45    /// <summary>
46    /// Initializes a new instance of <see cref="VariableView"/> with caption "Variable".
47    /// </summary>
48    public ScopePathLookupParameterView() {
49      InitializeComponent();
50    }
51
52    /// <summary>
53    /// Removes the eventhandlers from the underlying <see cref="IVariable"/>.
54    /// </summary>
55    /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
56    protected override void DeregisterContentEvents() {
57      Content.ActualNameChanged -= new EventHandler(Content_ActualNameChanged);
58      Content.PathChanged -= new EventHandler(Content_PathChanged);
59      base.DeregisterContentEvents();
60    }
61
62    /// <summary>
63    /// Adds eventhandlers to the underlying <see cref="IVariable"/>.
64    /// </summary>
65    /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
66    protected override void RegisterContentEvents() {
67      base.RegisterContentEvents();
68      Content.ActualNameChanged += new EventHandler(Content_ActualNameChanged);
69      Content.PathChanged += new EventHandler(Content_PathChanged);
70    }
71
72    protected override void OnContentChanged() {
73      base.OnContentChanged();
74      if (Content == null) {
75        actualNameTextBox.Text = string.Empty;
76        pathTextBox.Text = string.Empty;
77      } else {
78        actualNameTextBox.Text = Content.ActualName;
79        pathTextBox.Text = Content.Path;
80      }
81    }
82
83    protected override void SetEnabledStateOfControls() {
84      base.SetEnabledStateOfControls();
85      actualNameTextBox.Enabled = Content != null;
86      actualNameTextBox.ReadOnly = ReadOnly;
87      pathTextBox.Enabled = Content != null;
88      pathTextBox.ReadOnly = ReadOnly;
89    }
90
91    protected virtual void Content_ActualNameChanged(object sender, EventArgs e) {
92      if (InvokeRequired)
93        Invoke(new EventHandler(Content_ActualNameChanged), sender, e);
94      else
95        actualNameTextBox.Text = Content.ActualName;
96    }
97    protected virtual void Content_PathChanged(object sender, EventArgs e) {
98      if (InvokeRequired)
99        Invoke(new EventHandler(Content_PathChanged), sender, e);
100      else
101        pathTextBox.Text = Content.Path;
102    }
103
104    protected virtual void actualNameTextBox_Validated(object sender, EventArgs e) {
105      Content.ActualName = actualNameTextBox.Text;
106    }
107    protected virtual void pathTextBox_KeyDown(object sender, KeyEventArgs e) {
108      if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
109        pathLabel.Focus();  // set focus on label to validate data
110      if (e.KeyCode == Keys.Escape) {
111        pathTextBox.Text = Content.Path;
112        pathLabel.Focus();  // set focus on label to validate data
113      }
114    }
115    protected virtual void pathTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
116      if (!ScopePathLookupParameter<T>.ValidPathRegex.IsMatch(pathTextBox.Text)) {
117        e.Cancel = true;
118        errorProvider.SetError(pathTextBox, "Invalid Path");
119        pathTextBox.SelectAll();
120      }
121    }
122    protected virtual void pathTextBox_Validated(object sender, EventArgs e) {
123      Content.Path = pathTextBox.Text;
124      errorProvider.SetError(pathTextBox, string.Empty);
125    }
126  }
127}
Note: See TracBrowser for help on using the repository browser.