- Timestamp:
- 08/01/11 17:48:53 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GP.Grammar.Editor/HeuristicLab.Optimization.Views/3.3/AlgorithmView.cs
r5837 r6618 31 31 32 32 namespace HeuristicLab.Optimization.Views { 33 /// <summary>34 /// The base class for visual representations of algorithms.35 /// </summary>36 33 [View("Algorithm View")] 37 34 [Content(typeof(Algorithm), true)] 38 35 [Content(typeof(IAlgorithm), false)] 39 public partial class AlgorithmView : NamedItemView {36 public partial class AlgorithmView : IOptimizerView { 40 37 private TypeSelectorDialog problemTypeSelectorDialog; 38 public AlgorithmView() { 39 InitializeComponent(); 40 } 41 41 42 42 public new IAlgorithm Content { 43 43 get { return (IAlgorithm)base.Content; } 44 44 set { base.Content = value; } 45 }46 47 /// <summary>48 /// Initializes a new instance of <see cref="ItemBaseView"/>.49 /// </summary>50 public AlgorithmView() {51 InitializeComponent();52 45 } 53 46 … … 75 68 76 69 protected override void DeregisterContentEvents() { 77 Content.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);78 Content.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged);79 Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged);80 Content.Prepared -= new EventHandler(Content_Prepared);81 Content.Started -= new EventHandler(Content_Started);82 Content.Paused -= new EventHandler(Content_Paused);83 Content.Stopped -= new EventHandler(Content_Stopped);84 70 Content.ProblemChanged -= new EventHandler(Content_ProblemChanged); 85 71 Content.StoreAlgorithmInEachRunChanged -= new EventHandler(Content_StoreAlgorithmInEachRunChanged); … … 88 74 protected override void RegisterContentEvents() { 89 75 base.RegisterContentEvents(); 90 Content.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);91 Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged);92 Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged);93 Content.Prepared += new EventHandler(Content_Prepared);94 Content.Started += new EventHandler(Content_Started);95 Content.Paused += new EventHandler(Content_Paused);96 Content.Stopped += new EventHandler(Content_Stopped);97 76 Content.ProblemChanged += new EventHandler(Content_ProblemChanged); 98 77 Content.StoreAlgorithmInEachRunChanged += new EventHandler(Content_StoreAlgorithmInEachRunChanged); … … 107 86 runsView.Content = null; 108 87 storeAlgorithmInEachRunCheckBox.Checked = true; 109 executionTimeTextBox.Text = "-";110 88 } else { 111 Locked = ReadOnly = Content.ExecutionState == ExecutionState.Started;112 89 parameterCollectionView.Content = Content.Parameters; 113 90 problemViewHost.ViewType = null; … … 116 93 runsView.Content = Content.Runs; 117 94 storeAlgorithmInEachRunCheckBox.Checked = Content.StoreAlgorithmInEachRun; 118 executionTimeTextBox.Text = Content.ExecutionTime.ToString();119 95 } 120 96 } … … 129 105 runsView.Enabled = Content != null; 130 106 storeAlgorithmInEachRunCheckBox.Enabled = Content != null && !ReadOnly; 131 executionTimeTextBox.Enabled = Content != null;132 SetEnabledStateOfExecutableButtons();133 107 } 134 108 … … 146 120 147 121 #region Content Events 122 protected override void Content_Prepared(object sender, EventArgs e) { 123 if (InvokeRequired) 124 Invoke(new EventHandler(Content_Prepared), sender, e); 125 else { 126 base.Content_Prepared(sender, e); 127 resultsView.Content = Content.Results.AsReadOnly(); 128 } 129 } 130 148 131 protected virtual void Content_ProblemChanged(object sender, EventArgs e) { 149 132 if (InvokeRequired) … … 154 137 } 155 138 } 156 protected virtual void Content_ExecutionStateChanged(object sender, EventArgs e) {157 if (InvokeRequired)158 Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);159 else160 startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;161 }162 protected virtual void Content_ExecutionTimeChanged(object sender, EventArgs e) {163 if (InvokeRequired)164 Invoke(new EventHandler(Content_ExecutionTimeChanged), sender, e);165 else166 executionTimeTextBox.Text = Content == null ? "-" : Content.ExecutionTime.ToString();167 }168 139 protected virtual void Content_StoreAlgorithmInEachRunChanged(object sender, EventArgs e) { 169 140 if (InvokeRequired) … … 171 142 else 172 143 storeAlgorithmInEachRunCheckBox.Checked = Content.StoreAlgorithmInEachRun; 173 }174 protected virtual void Content_Prepared(object sender, EventArgs e) {175 if (InvokeRequired)176 Invoke(new EventHandler(Content_Prepared), sender, e);177 else {178 resultsView.Content = Content.Results.AsReadOnly();179 ReadOnly = Locked = false;180 SetEnabledStateOfExecutableButtons();181 }182 }183 protected virtual void Content_Started(object sender, EventArgs e) {184 if (InvokeRequired)185 Invoke(new EventHandler(Content_Started), sender, e);186 else {187 ReadOnly = Locked = true;188 SetEnabledStateOfExecutableButtons();189 }190 }191 protected virtual void Content_Paused(object sender, EventArgs e) {192 if (InvokeRequired)193 Invoke(new EventHandler(Content_Paused), sender, e);194 else {195 ReadOnly = Locked = false;196 SetEnabledStateOfExecutableButtons();197 }198 }199 protected virtual void Content_Stopped(object sender, EventArgs e) {200 if (InvokeRequired)201 Invoke(new EventHandler(Content_Stopped), sender, e);202 else {203 ReadOnly = Locked = false;204 SetEnabledStateOfExecutableButtons();205 }206 }207 protected virtual void Content_ExceptionOccurred(object sender, EventArgs<Exception> e) {208 if (InvokeRequired)209 Invoke(new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred), sender, e);210 else211 ErrorHandling.ShowErrorDialog(this, e.Value);212 144 } 213 145 #endregion … … 264 196 if (Content != null) Content.StoreAlgorithmInEachRun = storeAlgorithmInEachRunCheckBox.Checked; 265 197 } 266 protected virtual void startButton_Click(object sender, EventArgs e) {267 Content.Start();268 }269 protected virtual void pauseButton_Click(object sender, EventArgs e) {270 Content.Pause();271 }272 protected virtual void stopButton_Click(object sender, EventArgs e) {273 Content.Stop();274 }275 protected virtual void resetButton_Click(object sender, EventArgs e) {276 Content.Prepare(false);277 }278 198 protected virtual void problemTabPage_DragEnterOver(object sender, DragEventArgs e) { 279 199 e.Effect = DragDropEffects.None; … … 294 214 } 295 215 #endregion 296 297 #region Helpers298 private void SetEnabledStateOfExecutableButtons() {299 if (Content == null) {300 startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;301 } else {302 startButton.Enabled = (Content.ExecutionState == ExecutionState.Prepared) || (Content.ExecutionState == ExecutionState.Paused);303 pauseButton.Enabled = Content.ExecutionState == ExecutionState.Started;304 stopButton.Enabled = (Content.ExecutionState == ExecutionState.Started) || (Content.ExecutionState == ExecutionState.Paused);305 resetButton.Enabled = Content.ExecutionState != ExecutionState.Started;306 }307 }308 #endregion309 216 } 310 217 }
Note: See TracChangeset
for help on using the changeset viewer.