Free cookie consent management tool by TermsFeed Policy Generator

source: branches/TimeLimitRunOptimizer/HeuristicLab.Optimization.Views/3.3/IOptimizerView.cs @ 10662

Last change on this file since 10662 was 7259, checked in by swagner, 13 years ago

Updated year of copyrights to 2012 (#1716)

File size: 6.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Core.Views;
27using HeuristicLab.MainForm;
28using HeuristicLab.PluginInfrastructure;
29
30namespace HeuristicLab.Optimization.Views {
31  [View("IOptimizer View")]
32  [Content(typeof(IOptimizer), false)]
33  public partial class IOptimizerView : NamedItemView {
34    public IOptimizerView() {
35      InitializeComponent();
36    }
37
38    public new IOptimizer Content {
39      get { return (IOptimizer)base.Content; }
40      set { base.Content = value; }
41    }
42
43    protected override void DeregisterContentEvents() {
44      Content.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
45      Content.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged);
46      Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged);
47      Content.Prepared -= new EventHandler(Content_Prepared);
48      Content.Started -= new EventHandler(Content_Started);
49      Content.Paused -= new EventHandler(Content_Paused);
50      Content.Stopped -= new EventHandler(Content_Stopped);
51      base.DeregisterContentEvents();
52    }
53    protected override void RegisterContentEvents() {
54      base.RegisterContentEvents();
55      Content.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
56      Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged);
57      Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged);
58      Content.Prepared += new EventHandler(Content_Prepared);
59      Content.Started += new EventHandler(Content_Started);
60      Content.Paused += new EventHandler(Content_Paused);
61      Content.Stopped += new EventHandler(Content_Stopped);
62    }
63
64    protected override void OnContentChanged() {
65      base.OnContentChanged();
66      if (Content == null) {
67        executionTimeTextBox.Text = "-";
68      } else {
69        Locked = ReadOnly = Content.ExecutionState == ExecutionState.Started;
70        executionTimeTextBox.Text = Content.ExecutionTime.ToString();
71      }
72    }
73
74    protected override void SetEnabledStateOfControls() {
75      base.SetEnabledStateOfControls();
76      executionTimeTextBox.Enabled = Content != null;
77      SetEnabledStateOfExecutableButtons();
78    }
79
80    #region Content Events
81    protected virtual void Content_ExecutionStateChanged(object sender, EventArgs e) {
82      if (InvokeRequired)
83        Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);
84      else
85        startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;
86    }
87    protected virtual void Content_Prepared(object sender, EventArgs e) {
88      if (InvokeRequired)
89        Invoke(new EventHandler(Content_Prepared), sender, e);
90      else {
91        nameTextBox.Enabled = infoLabel.Enabled = true;
92        ReadOnly = Locked = false;
93        SetEnabledStateOfExecutableButtons();
94      }
95    }
96    protected virtual void Content_Started(object sender, EventArgs e) {
97      if (InvokeRequired)
98        Invoke(new EventHandler(Content_Started), sender, e);
99      else {
100        nameTextBox.Enabled = infoLabel.Enabled = false;
101        ReadOnly = Locked = true;
102        SetEnabledStateOfExecutableButtons();
103      }
104    }
105    protected virtual void Content_Paused(object sender, EventArgs e) {
106      if (InvokeRequired)
107        Invoke(new EventHandler(Content_Paused), sender, e);
108      else {
109        nameTextBox.Enabled = infoLabel.Enabled = true;
110        ReadOnly = Locked = false;
111        SetEnabledStateOfExecutableButtons();
112      }
113    }
114    protected virtual void Content_Stopped(object sender, EventArgs e) {
115      if (InvokeRequired)
116        Invoke(new EventHandler(Content_Stopped), sender, e);
117      else {
118        nameTextBox.Enabled = infoLabel.Enabled = true;
119        ReadOnly = Locked = false;
120        SetEnabledStateOfExecutableButtons();
121      }
122    }
123    protected virtual void Content_ExecutionTimeChanged(object sender, EventArgs e) {
124      if (InvokeRequired)
125        Invoke(new EventHandler(Content_ExecutionTimeChanged), sender, e);
126      else
127        executionTimeTextBox.Text = Content == null ? "-" : Content.ExecutionTime.ToString();
128    }
129    protected virtual void Content_ExceptionOccurred(object sender, EventArgs<Exception> e) {
130      if (InvokeRequired)
131        Invoke(new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred), sender, e);
132      else
133        ErrorHandling.ShowErrorDialog(this, e.Value);
134    }
135    #endregion
136
137    #region Control events
138    protected virtual void startButton_Click(object sender, EventArgs e) {
139      Content.Start();
140    }
141    protected virtual void pauseButton_Click(object sender, EventArgs e) {
142      Content.Pause();
143    }
144    protected virtual void stopButton_Click(object sender, EventArgs e) {
145      Content.Stop();
146    }
147    protected virtual void resetButton_Click(object sender, EventArgs e) {
148      Content.Prepare(false);
149    }
150    #endregion
151
152    #region Helpers
153    protected virtual void SetEnabledStateOfExecutableButtons() {
154      if (Content == null) {
155        startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;
156      } else {
157        startButton.Enabled = (Content.ExecutionState == ExecutionState.Prepared) || (Content.ExecutionState == ExecutionState.Paused);
158        pauseButton.Enabled = Content.ExecutionState == ExecutionState.Started;
159        stopButton.Enabled = (Content.ExecutionState == ExecutionState.Started) || (Content.ExecutionState == ExecutionState.Paused);
160        resetButton.Enabled = Content.ExecutionState != ExecutionState.Started;
161      }
162    }
163    #endregion
164  }
165}
Note: See TracBrowser for help on using the repository browser.