Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Parameters.Views/3.3/LookupParameterView.cs @ 2790

Last change on this file since 2790 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: 4.1 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.Collections.Generic;
24using System.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Text;
28using System.Windows.Forms;
29using HeuristicLab.Core;
30using HeuristicLab.Core.Views;
31using HeuristicLab.MainForm;
32
33namespace HeuristicLab.Parameters.Views {
34  /// <summary>
35  /// The visual representation of a <see cref="Parameter"/>.
36  /// </summary>
37  [Content(typeof(LookupParameter<>), true)]
38  [Content(typeof(SubScopesLookupParameter<>), true)]
39  [Content(typeof(ILookupParameter<>), false)]
40  public partial class LookupParameterView<T> : ParameterView where T : class, IItem {
41    /// <summary>
42    /// Gets or sets the variable to represent visually.
43    /// </summary>
44    /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
45    /// No own data storage present.</remarks>
46    public new ILookupParameter<T> Content {
47      get { return (ILookupParameter<T>)base.Content; }
48      set { base.Content = value; }
49    }
50
51    /// <summary>
52    /// Initializes a new instance of <see cref="VariableView"/> with caption "Variable".
53    /// </summary>
54    public LookupParameterView() {
55      InitializeComponent();
56      Caption = "LookupParameter";
57    }
58    /// <summary>
59    /// Initializes a new instance of <see cref="VariableView"/> with the given <paramref name="variable"/>.
60    /// </summary>
61    /// <remarks>Calls <see cref="VariableView()"/>.</remarks>
62    /// <param name="variable">The variable to represent visually.</param>
63    public LookupParameterView(ILookupParameter<T> content)
64      : this() {
65      Content = content;
66    }
67
68    /// <summary>
69    /// Removes the eventhandlers from the underlying <see cref="IVariable"/>.
70    /// </summary>
71    /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
72    protected override void DeregisterContentEvents() {
73      Content.ActualNameChanged -= new EventHandler(Content_ActualNameChanged);
74      base.DeregisterContentEvents();
75    }
76
77    /// <summary>
78    /// Adds eventhandlers to the underlying <see cref="IVariable"/>.
79    /// </summary>
80    /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
81    protected override void RegisterContentEvents() {
82      base.RegisterContentEvents();
83      Content.ActualNameChanged += new EventHandler(Content_ActualNameChanged);
84    }
85
86    protected override void OnContentChanged() {
87      base.OnContentChanged();
88      if (Content == null) {
89        Caption = "LookupParameter";
90        actualNameTextBox.Text = "-";
91        actualNameTextBox.Enabled = false;
92      } else {
93        Caption = Content.Name + " (" + Content.GetType().Name + ")";
94        actualNameTextBox.Text = Content.ActualName;
95        actualNameTextBox.Enabled = true;
96      }
97    }
98
99    protected virtual void Content_ActualNameChanged(object sender, EventArgs e) {
100      if (InvokeRequired)
101        Invoke(new EventHandler(Content_ActualNameChanged), sender, e);
102      else
103        actualNameTextBox.Text = Content.ActualName;
104    }
105
106    protected virtual void actualNameTextBox_Validated(object sender, EventArgs e) {
107      Content.ActualName = actualNameTextBox.Text;
108    }
109  }
110}
Note: See TracBrowser for help on using the repository browser.