Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Operators.Views/3.3/OperatorView.cs @ 3634

Last change on this file since 3634 was 3566, checked in by mkommend, 15 years ago

removed ctors with contents in all views (ticket #972)

File size: 3.3 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 HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Core.Views;
25using HeuristicLab.MainForm;
26using System;
27
28namespace HeuristicLab.Operators.Views {
29  /// <summary>
30  /// The base class for visual representations of items.
31  /// </summary>
32  [View("Operator View (Default)")]
33  [Content(typeof(Operator), true)]
34  [Content(typeof(IOperator), false)]
35  public partial class OperatorView : ParameterizedNamedItemView {
36    public new IOperator Content {
37      get { return (IOperator)base.Content; }
38      set { base.Content = value; }
39    }
40
41    /// <summary>
42    /// Initializes a new instance of <see cref="ItemBaseView"/>.
43    /// </summary>
44    public OperatorView() {
45      InitializeComponent();
46    }
47
48    /// <summary>
49    /// Removes the eventhandlers from the underlying <see cref="IOperatorGraph"/>.
50    /// </summary>
51    /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
52    protected override void DeregisterContentEvents() {
53      Content.BreakpointChanged -= new EventHandler(Content_BreakpointChanged);
54      base.DeregisterContentEvents();
55    }
56
57    /// <summary>
58    /// Adds eventhandlers to the underlying <see cref="IOperatorGraph"/>.
59    /// </summary>
60    /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
61    protected override void RegisterContentEvents() {
62      base.RegisterContentEvents();
63      Content.BreakpointChanged += new EventHandler(Content_BreakpointChanged);
64    }
65
66    protected override void OnContentChanged() {
67      base.OnContentChanged();
68      if (Content == null) {
69        breakpointCheckBox.Checked = false;
70      } else {
71        breakpointCheckBox.Checked = Content.Breakpoint;
72      }
73      SetEnabledStateOfControls();
74    }
75
76    protected override void OnReadOnlyChanged() {
77      base.OnReadOnlyChanged();
78      SetEnabledStateOfControls();
79    }
80
81    private void SetEnabledStateOfControls() {
82      breakpointCheckBox.Enabled = Content != null && !ReadOnly;
83    }
84
85    protected void Content_BreakpointChanged(object sender, EventArgs e) {
86      if (InvokeRequired)
87        Invoke(new EventHandler(Content_DescriptionChanged), sender, e);
88      else
89        breakpointCheckBox.Checked = Content.Breakpoint;
90    }
91
92    protected void breakpointCheckBox_CheckedChanged(object sender, System.EventArgs e) {
93      if (Content != null) Content.Breakpoint = breakpointCheckBox.Checked;
94    }
95  }
96}
Note: See TracBrowser for help on using the repository browser.