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