Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Optimization.Views/3.3/ResultView.cs @ 3500

Last change on this file since 3500 was 3455, checked in by swagner, 15 years ago

Removed manual propagation of ReadOnly property (#973)

File size: 4.2 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.Views;
26using HeuristicLab.MainForm;
27
28namespace HeuristicLab.Optimization.Views {
29  /// <summary>
30  /// The visual representation of a <see cref="Variable"/>.
31  /// </summary>
32  [View("Result View")]
33  [Content(typeof(Result), true)]
34  [Content(typeof(IResult), false)]
35  public sealed partial class ResultView : NamedItemView {
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 IResult Content {
42      get { return (IResult)base.Content; }
43      set { base.Content = value; }
44    }
45
46    public override bool ReadOnly {
47      get { return base.ReadOnly; }
48      set { /*not needed because results are always readonly */}
49    }
50
51    /// <summary>
52    /// Initializes a new instance of <see cref="VariableView"/> with caption "Variable".
53    /// </summary>
54    public ResultView() {
55      InitializeComponent();
56      Caption = "Result";
57      base.ReadOnly = true;
58    }
59    /// <summary>
60    /// Initializes a new instance of <see cref="VariableView"/> with the given <paramref name="variable"/>.
61    /// </summary>
62    /// <remarks>Calls <see cref="VariableView()"/>.</remarks>
63    /// <param name="variable">The variable to represent visually.</param>
64    public ResultView(IResult content)
65      : this() {
66      Content = content;
67    }
68
69    /// <summary>
70    /// Removes the eventhandlers from the underlying <see cref="Variable"/>.
71    /// </summary>
72    /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
73    protected override void DeregisterContentEvents() {
74      Content.ValueChanged -= new EventHandler(Content_ValueChanged);
75      base.DeregisterContentEvents();
76    }
77
78    /// <summary>
79    /// Adds eventhandlers to the underlying <see cref="Variable"/>.
80    /// </summary>
81    /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
82    protected override void RegisterContentEvents() {
83      base.RegisterContentEvents();
84      Content.ValueChanged += new EventHandler(Content_ValueChanged);
85    }
86
87    protected override void OnContentChanged() {
88      base.OnContentChanged();
89      if (Content == null) {
90        Caption = "Result";
91        dataTypeTextBox.Text = "-";
92        viewHost.Content = null;
93      } else {
94        Caption = Content.Name + " (" + Content.GetType().Name + ")";
95        dataTypeTextBox.Text = Content.DataType.GetPrettyName();
96        viewHost.ViewType = null;
97        viewHost.Content = Content.Value;
98      }
99      SetEnabledStateOfControls();
100    }
101    protected override void OnReadOnlyChanged() {
102      base.OnReadOnlyChanged();
103      SetEnabledStateOfControls();
104    }
105    private void SetEnabledStateOfControls() {
106      dataTypeTextBox.Enabled = Content != null;
107      viewHost.Enabled = Content != null;
108    }
109
110    private void Content_ValueChanged(object sender, EventArgs e) {
111      if (InvokeRequired)
112        Invoke(new EventHandler(Content_ValueChanged), sender, e);
113      else {
114        viewHost.ViewType = null;
115        viewHost.Content = Content.Value;
116      }
117    }
118  }
119}
Note: See TracBrowser for help on using the repository browser.