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 |
|
---|
22 | using System;
|
---|
23 | using HeuristicLab.MainForm;
|
---|
24 |
|
---|
25 | namespace HeuristicLab.Core.Views {
|
---|
26 | /// <summary>
|
---|
27 | /// Base class for editors of engines.
|
---|
28 | /// </summary>
|
---|
29 | [View("Engine View")]
|
---|
30 | [Content(typeof(Engine), true)]
|
---|
31 | [Content(typeof(IEngine), false)]
|
---|
32 | public partial class EngineView : ItemView {
|
---|
33 | /// <summary>
|
---|
34 | /// Gets or sets the current engine.
|
---|
35 | /// </summary>
|
---|
36 | /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="EditorBase"/>.</remarks>
|
---|
37 | public new IEngine Content {
|
---|
38 | get { return (IEngine)base.Content; }
|
---|
39 | set { base.Content = value; }
|
---|
40 | }
|
---|
41 |
|
---|
42 | /// <summary>
|
---|
43 | /// Initializes a new instance of <see cref="EngineBaseEditor"/>.
|
---|
44 | /// </summary>
|
---|
45 | public EngineView() {
|
---|
46 | InitializeComponent();
|
---|
47 | }
|
---|
48 | public EngineView(IEngine content)
|
---|
49 | : this() {
|
---|
50 | Content = content;
|
---|
51 | }
|
---|
52 |
|
---|
53 | /// <summary>
|
---|
54 | /// Removes the event handlers from the underlying <see cref="IEngine"/>.
|
---|
55 | /// </summary>
|
---|
56 | /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
|
---|
57 | protected override void DeregisterContentEvents() {
|
---|
58 | Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged);
|
---|
59 | base.DeregisterContentEvents();
|
---|
60 | }
|
---|
61 |
|
---|
62 | /// <summary>
|
---|
63 | /// Adds event handlers to the underlying <see cref="IEngine"/>.
|
---|
64 | /// </summary>
|
---|
65 | /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
|
---|
66 | protected override void RegisterContentEvents() {
|
---|
67 | base.RegisterContentEvents();
|
---|
68 | Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged);
|
---|
69 | }
|
---|
70 |
|
---|
71 | /// <summary>
|
---|
72 | /// Updates all controls with the latest data of the model.
|
---|
73 | /// </summary>
|
---|
74 | /// <remarks>Calls <see cref="EditorBase.UpdateControls"/> of base class <see cref="EditorBase"/>.</remarks>
|
---|
75 | protected override void OnContentChanged() {
|
---|
76 | base.OnContentChanged();
|
---|
77 | if (Content == null) {
|
---|
78 | logView.Content = null;
|
---|
79 | logView.Enabled = false;
|
---|
80 | executionTimeTextBox.Text = "-";
|
---|
81 | executionTimeTextBox.Enabled = false;
|
---|
82 | } else {
|
---|
83 | logView.Content = Content.Log;
|
---|
84 | logView.Enabled = true;
|
---|
85 | executionTimeTextBox.Text = Content.ExecutionTime.ToString();
|
---|
86 | executionTimeTextBox.Enabled = true;
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 | protected virtual void Content_ExecutionTimeChanged(object sender, EventArgs e) {
|
---|
91 | if (InvokeRequired)
|
---|
92 | Invoke(new EventHandler(Content_ExecutionTimeChanged), sender, e);
|
---|
93 | else
|
---|
94 | executionTimeTextBox.Text = Content.ExecutionTime.ToString();
|
---|
95 | }
|
---|
96 | }
|
---|
97 | }
|
---|