Free cookie consent management tool by TermsFeed Policy Generator

source: tags/3.3.0/HeuristicLab.Problems.OneMax.Views/3.3/OneMaxSolutionView.cs @ 9708

Last change on this file since 9708 was 3667, checked in by svonolfe, 14 years ago
  • Updated OneMax analyzer
  • Updated Knapsack analyzer
  • Fixed bug in OneMax and TF analyzer views

(#999)

File size: 3.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.Drawing;
24using System.Windows.Forms;
25using HeuristicLab.Core.Views;
26using HeuristicLab.MainForm;
27using HeuristicLab.Problems.OneMax;
28using HeuristicLab.Data;
29using System.Collections.Generic;
30
31namespace HeuristicLab.Problems.OneMax.Views {
32  /// <summary>
33  /// A view for a OneMax solution.
34  /// </summary>
35  [View("OneMax View")]
36  [Content(typeof(OneMaxSolution), true)]
37  public partial class OneMaxSolutionView : HeuristicLab.Core.Views.ItemView {
38    public new OneMaxSolution Content {
39      get { return (OneMaxSolution)base.Content; }
40      set { base.Content = value; }
41    }
42   
43    public OneMaxSolutionView() {
44      InitializeComponent();
45
46      qualityView.ReadOnly = true;
47      binaryVectorView.ReadOnly = true;
48    }
49
50    protected override void DeregisterContentEvents() {
51      Content.BinaryVectorChanged -= new EventHandler(Content_BinaryVectorChanged);
52      Content.QualityChanged -= new EventHandler(Content_QualityChanged);
53      base.DeregisterContentEvents();
54    }
55    protected override void RegisterContentEvents() {
56      base.RegisterContentEvents();
57      Content.BinaryVectorChanged += new EventHandler(Content_BinaryVectorChanged);
58      Content.QualityChanged += new EventHandler(Content_QualityChanged);
59    }
60
61    void Content_QualityChanged(object sender, EventArgs e) {
62      if (InvokeRequired)
63        Invoke(new EventHandler(Content_QualityChanged), sender, e);
64      else {
65        qualityView.Content = Content.Quality;
66      }
67    }
68
69    void Content_BinaryVectorChanged(object sender, EventArgs e) {
70      if (InvokeRequired)
71        Invoke(new EventHandler(Content_BinaryVectorChanged), sender, e);
72      else {
73        binaryVectorView.Content = Content.BinaryVector;
74      }
75    }
76
77    protected override void OnContentChanged() {
78      base.OnContentChanged();
79
80      if (Content == null) {
81        qualityView.Content = null;
82        binaryVectorView.Content = null;
83      } else {
84        qualityView.Content = Content.Quality;
85        binaryVectorView.Content = Content.BinaryVector;
86      }
87
88      SetEnabledStateOfControls();
89    }
90
91    private void SetEnabledStateOfControls() {
92      qualityView.Enabled = Content != null;
93      binaryVectorView.Enabled = Content != null;
94    }
95  }
96}
Note: See TracBrowser for help on using the repository browser.