Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Optimization.Views/3.3/EngineAlgorithmView.cs @ 2900

Last change on this file since 2900 was 2864, checked in by swagner, 14 years ago

Operator architecture refactoring (#95)

  • worked on algorithms
File size: 3.9 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.Core;
25using HeuristicLab.Core.Views;
26using HeuristicLab.MainForm;
27
28namespace HeuristicLab.Optimization.Views {
29  /// <summary>
30  /// The base class for visual representations of items.
31  /// </summary>
32  [Content(typeof(EngineAlgorithm), true)]
33  public partial class EngineAlgorithmView : AlgorithmView {
34    private TypeSelectorDialog engineTypeSelectorDialog;
35
36    public new EngineAlgorithm Content {
37      get { return (EngineAlgorithm)base.Content; }
38      set { base.Content = value; }
39    }
40
41    /// <summary>
42    /// Initializes a new instance of <see cref="ItemBaseView"/>.
43    /// </summary>
44    public EngineAlgorithmView() {
45      InitializeComponent();
46    }
47    /// <summary>
48    /// Intializes a new instance of <see cref="ItemBaseView"/> with the given <paramref name="item"/>.
49    /// </summary>
50    /// <param name="item">The item that should be displayed.</param>
51    public EngineAlgorithmView(EngineAlgorithm content)
52      : this() {
53      Content = content;
54    }
55
56    protected override void DeregisterContentEvents() {
57      Content.EngineChanged -= new System.EventHandler(Content_EngineChanged);
58      base.DeregisterContentEvents();
59    }
60    protected override void RegisterContentEvents() {
61      base.RegisterContentEvents();
62      Content.EngineChanged += new System.EventHandler(Content_EngineChanged);
63    }
64
65    protected override void OnContentChanged() {
66      base.OnContentChanged();
67      if (Content == null) {
68        engineTextBox.Text = "-";
69        engineTextBox.Enabled = false;
70        setEngineButton.Enabled = false;
71      } else {
72        engineTextBox.Text = Content.Engine == null ? "-" : Content.Engine.ToString();
73        engineTextBox.Enabled = true;
74        setEngineButton.Enabled = true;
75      }
76    }
77
78    protected void Content_EngineChanged(object sender, System.EventArgs e) {
79      if (InvokeRequired)
80        Invoke(new EventHandler(Content_EngineChanged), sender, e);
81      else
82        engineTextBox.Text = Content.Engine == null ? "-" : Content.Engine.ToString();
83    }
84
85    protected void setEngineButton_Click(object sender, System.EventArgs e) {
86      if (engineTypeSelectorDialog == null) {
87        engineTypeSelectorDialog = new TypeSelectorDialog();
88        engineTypeSelectorDialog.Caption = "Select Engine";
89        engineTypeSelectorDialog.TypeSelector.Configure(typeof(IEngine), false, false);
90      }
91      if (engineTypeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
92        Content.Engine = (IEngine)engineTypeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
93      }
94    }
95
96    protected void engineTextBox_DoubleClick(object sender, System.EventArgs e) {
97      if (Content.Engine != null)
98        MainFormManager.CreateDefaultView(Content.Engine).Show();
99    }
100
101    protected void createUserDefinedAlgorithmButton_Click(object sender, EventArgs e) {
102      MainFormManager.CreateDefaultView(Content.CreateUserDefinedAlgorithm()).Show();
103    }
104  }
105}
Note: See TracBrowser for help on using the repository browser.