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 System.Windows.Forms;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Core.Views;
|
---|
27 | using HeuristicLab.MainForm;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.Optimization.Views {
|
---|
30 | /// <summary>
|
---|
31 | /// The base class for visual representations of items.
|
---|
32 | /// </summary>
|
---|
33 | [View("Experiment View")]
|
---|
34 | [Content(typeof(Experiment), true)]
|
---|
35 | public sealed partial class ExperimentView : NamedItemView {
|
---|
36 | public new Experiment Content {
|
---|
37 | get { return (Experiment)base.Content; }
|
---|
38 | set { base.Content = value; }
|
---|
39 | }
|
---|
40 |
|
---|
41 | /// <summary>
|
---|
42 | /// Initializes a new instance of <see cref="ItemBaseView"/>.
|
---|
43 | /// </summary>
|
---|
44 | public ExperimentView() {
|
---|
45 | InitializeComponent();
|
---|
46 | }
|
---|
47 |
|
---|
48 | protected override void DeregisterContentEvents() {
|
---|
49 | Content.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
|
---|
50 | Content.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged);
|
---|
51 | Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged);
|
---|
52 | base.DeregisterContentEvents();
|
---|
53 | }
|
---|
54 | protected override void RegisterContentEvents() {
|
---|
55 | base.RegisterContentEvents();
|
---|
56 | Content.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
|
---|
57 | Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged);
|
---|
58 | Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged);
|
---|
59 | }
|
---|
60 |
|
---|
61 | protected override void OnContentChanged() {
|
---|
62 | base.OnContentChanged();
|
---|
63 | if (Content == null) {
|
---|
64 | optimizerListView.Content = null;
|
---|
65 | runsViewHost.Content = null;
|
---|
66 | executionTimeTextBox.Text = "-";
|
---|
67 | } else {
|
---|
68 | optimizerListView.Content = Content.Optimizers;
|
---|
69 | runsViewHost.Content = Content.Runs;
|
---|
70 | executionTimeTextBox.Text = Content.ExecutionTime.ToString();
|
---|
71 | }
|
---|
72 | SetEnableStateOfControls();
|
---|
73 | }
|
---|
74 |
|
---|
75 | protected override void OnReadOnlyChanged() {
|
---|
76 | base.OnReadOnlyChanged();
|
---|
77 | SetEnableStateOfControls();
|
---|
78 | }
|
---|
79 | private void SetEnableStateOfControls() {
|
---|
80 | optimizerListView.Enabled = Content != null;
|
---|
81 | runsViewHost.Enabled = Content != null;
|
---|
82 | executionTimeTextBox.Enabled = Content != null;
|
---|
83 | SetEnabledStateOfExecutableButtons();
|
---|
84 | }
|
---|
85 |
|
---|
86 | protected override void OnClosed(FormClosedEventArgs e) {
|
---|
87 | if ((Content != null) && (Content.ExecutionState == ExecutionState.Started)) Content.Stop();
|
---|
88 | base.OnClosed(e);
|
---|
89 | }
|
---|
90 |
|
---|
91 | #region Content Events
|
---|
92 | private void Content_ExecutionStateChanged(object sender, EventArgs e) {
|
---|
93 | if (InvokeRequired)
|
---|
94 | Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);
|
---|
95 | else {
|
---|
96 | nameTextBox.Enabled = Content.ExecutionState != ExecutionState.Started;
|
---|
97 | descriptionTextBox.Enabled = Content.ExecutionState != ExecutionState.Started;
|
---|
98 | Locked = Content.ExecutionState == ExecutionState.Started;
|
---|
99 | SetEnabledStateOfExecutableButtons();
|
---|
100 | }
|
---|
101 | }
|
---|
102 | private void Content_ExecutionTimeChanged(object sender, EventArgs e) {
|
---|
103 | if (InvokeRequired)
|
---|
104 | Invoke(new EventHandler(Content_ExecutionTimeChanged), sender, e);
|
---|
105 | else
|
---|
106 | executionTimeTextBox.Text = Content.ExecutionTime.ToString();
|
---|
107 | }
|
---|
108 | private void Content_ExceptionOccurred(object sender, EventArgs<Exception> e) {
|
---|
109 | if (InvokeRequired)
|
---|
110 | Invoke(new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred), sender, e);
|
---|
111 | else
|
---|
112 | Auxiliary.ShowErrorMessageBox(e.Value);
|
---|
113 | }
|
---|
114 | #endregion
|
---|
115 |
|
---|
116 | #region Control events
|
---|
117 | private void startButton_Click(object sender, EventArgs e) {
|
---|
118 | Content.Start();
|
---|
119 | }
|
---|
120 | private void pauseButton_Click(object sender, EventArgs e) {
|
---|
121 | Content.Pause();
|
---|
122 | }
|
---|
123 | private void stopButton_Click(object sender, EventArgs e) {
|
---|
124 | Content.Stop();
|
---|
125 | }
|
---|
126 | private void resetButton_Click(object sender, EventArgs e) {
|
---|
127 | Content.Prepare(false);
|
---|
128 | }
|
---|
129 | #endregion
|
---|
130 |
|
---|
131 | #region Helpers
|
---|
132 | private void SetEnabledStateOfExecutableButtons() {
|
---|
133 | if (Content == null) {
|
---|
134 | startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;
|
---|
135 | } else {
|
---|
136 | startButton.Enabled = (Content.ExecutionState == ExecutionState.Prepared) || (Content.ExecutionState == ExecutionState.Paused);
|
---|
137 | pauseButton.Enabled = Content.ExecutionState == ExecutionState.Started;
|
---|
138 | stopButton.Enabled = (Content.ExecutionState == ExecutionState.Started) || (Content.ExecutionState == ExecutionState.Paused);
|
---|
139 | resetButton.Enabled = Content.ExecutionState != ExecutionState.Started;
|
---|
140 | }
|
---|
141 | }
|
---|
142 | #endregion
|
---|
143 | }
|
---|
144 | }
|
---|