Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/OptimizableView.cs @ 5533

Last change on this file since 5533 was 5087, checked in by cneumuel, 14 years ago

#1215

  • enabled multiple problems
  • enabled n repetitions
  • improved results output
  • reduced memory footprint significantly
  • removed viewhost icons for less screen space waste
File size: 3.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Data;
6using System.Linq;
7using System.Text;
8using HeuristicLab.Core.Views;
9using HeuristicLab.MainForm;
10using HeuristicLab.Parameters;
11using HeuristicLab.Core;
12using HeuristicLab.Data;
13
14namespace HeuristicLab.Problems.MetaOptimization.Views.ValueConfigurationViews {
15  [View("IOptimizable View")]
16  [Content(typeof(IOptimizable), IsDefaultView = false)]
17  [Content(typeof(ParameterConfiguration), IsDefaultView = true)]
18  [Content(typeof(ValueConfiguration), IsDefaultView = true)]
19  public sealed partial class OptimizableView : ItemView {
20    public new IOptimizable Content {
21      get { return (IOptimizable)base.Content; }
22      set { base.Content = value; }
23    }
24
25    public OptimizableView() {
26      InitializeComponent();
27    }
28
29    protected override void DeregisterContentEvents() {
30      Content.OptimizeChanged -= new EventHandler(Content_OptimizeChanged);
31      Content.IsOptimizableChanged -= new EventHandler(Content_IsOptimizabeChanged);
32      base.DeregisterContentEvents();
33    }
34
35    protected override void RegisterContentEvents() {
36      base.RegisterContentEvents();
37      Content.IsOptimizableChanged += new EventHandler(Content_IsOptimizabeChanged);
38      Content.OptimizeChanged += new EventHandler(Content_OptimizeChanged);
39    }
40
41    #region Event Handlers (Content)
42    void Content_OptimizeChanged(object sender, EventArgs e) {
43      if (InvokeRequired) {
44        Invoke(new EventHandler(Content_OptimizeChanged), sender, e);
45      } else {
46        this.optimizeCheckBox.Checked = Content.Optimize;
47        if (Content.Optimize) {
48          this.viewHost.ViewType = null;
49          if (Content is IParameterConfiguration) {
50            this.viewHost.Content = ((IParameterConfiguration)Content).ValueConfigurations;
51          } else if (Content is IValueConfiguration) {
52            if (Content.ActualValue.ValueDataType == typeof(IntValue) ||
53                Content.ActualValue.ValueDataType == typeof(DoubleValue) ||
54                Content.ActualValue.ValueDataType == typeof(PercentValue)) {
55              this.viewHost.ViewsLabelVisible = true;
56              this.viewHost.Content = ((IValueConfiguration)Content).RangeConstraint;
57            } else if(Content.ActualValue.ValueDataType == typeof(BoolValue)) {
58              this.viewHost.Content = null; // no configuration required
59            } else {
60              this.viewHost.ViewsLabelVisible = false;
61              this.viewHost.Content = ((IValueConfiguration)Content).ParameterConfigurations;
62            }
63          } else {
64            throw new NotSupportedException("Only IParameterConfiguration and IValueConfiguration types are allowed.");
65          }
66        } else {
67          this.viewHost.ViewsLabelVisible = false;
68          this.viewHost.Content = Content.ActualValue;
69        }
70      }
71      SetEnabledStateOfControls();
72    }
73    void Content_IsOptimizabeChanged(object sender, EventArgs e) {
74      if (InvokeRequired) {
75        Invoke(new EventHandler(Content_IsOptimizabeChanged), sender, e);
76      } else {
77        SetEnabledStateOfControls();
78      }
79    }
80    #endregion
81
82    protected override void OnContentChanged() {
83      base.OnContentChanged();
84      if (Content != null) {
85        Content_OptimizeChanged(this, EventArgs.Empty);
86      } else {
87        this.viewHost.Content = null;
88      }
89    }
90
91    protected override void SetEnabledStateOfControls() {
92      base.SetEnabledStateOfControls();
93      if (Content != null) {
94        this.optimizeCheckBox.Enabled = !this.ReadOnly && Content.IsOptimizable;
95      }
96    }
97
98    #region Event Handlers (child controls)
99    private void optimizeCheckBox_CheckedChanged(object sender, EventArgs e) {
100      Content.Optimize = optimizeCheckBox.Checked;
101    }
102    #endregion
103  }
104}
Note: See TracBrowser for help on using the repository browser.