Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/16/11 10:56:26 (13 years ago)
Author:
mkommend
Message:

#1555: Refactored optimizer views to derive from common base class IOptimizerView.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/AlgorithmView.cs

    r5837 r6425  
    3131
    3232namespace HeuristicLab.Optimization.Views {
    33   /// <summary>
    34   /// The base class for visual representations of algorithms.
    35   /// </summary>
    3633  [View("Algorithm View")]
    3734  [Content(typeof(Algorithm), true)]
    3835  [Content(typeof(IAlgorithm), false)]
    39   public partial class AlgorithmView : NamedItemView {
     36  public partial class AlgorithmView : IOptimizerView {
    4037    private TypeSelectorDialog problemTypeSelectorDialog;
     38    public AlgorithmView() {
     39      InitializeComponent();
     40    }
    4141
    4242    public new IAlgorithm Content {
    4343      get { return (IAlgorithm)base.Content; }
    4444      set { base.Content = value; }
    45     }
    46 
    47     /// <summary>
    48     /// Initializes a new instance of <see cref="ItemBaseView"/>.
    49     /// </summary>
    50     public AlgorithmView() {
    51       InitializeComponent();
    5245    }
    5346
     
    7568
    7669    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);
    8470      Content.ProblemChanged -= new EventHandler(Content_ProblemChanged);
    8571      Content.StoreAlgorithmInEachRunChanged -= new EventHandler(Content_StoreAlgorithmInEachRunChanged);
     
    8874    protected override void RegisterContentEvents() {
    8975      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);
    9776      Content.ProblemChanged += new EventHandler(Content_ProblemChanged);
    9877      Content.StoreAlgorithmInEachRunChanged += new EventHandler(Content_StoreAlgorithmInEachRunChanged);
     
    10786        runsView.Content = null;
    10887        storeAlgorithmInEachRunCheckBox.Checked = true;
    109         executionTimeTextBox.Text = "-";
    11088      } else {
    111         Locked = ReadOnly = Content.ExecutionState == ExecutionState.Started;
    11289        parameterCollectionView.Content = Content.Parameters;
    11390        problemViewHost.ViewType = null;
     
    11693        runsView.Content = Content.Runs;
    11794        storeAlgorithmInEachRunCheckBox.Checked = Content.StoreAlgorithmInEachRun;
    118         executionTimeTextBox.Text = Content.ExecutionTime.ToString();
    11995      }
    12096    }
     
    129105      runsView.Enabled = Content != null;
    130106      storeAlgorithmInEachRunCheckBox.Enabled = Content != null && !ReadOnly;
    131       executionTimeTextBox.Enabled = Content != null;
    132       SetEnabledStateOfExecutableButtons();
    133107    }
    134108
     
    146120
    147121    #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
    148131    protected virtual void Content_ProblemChanged(object sender, EventArgs e) {
    149132      if (InvokeRequired)
     
    154137      }
    155138    }
    156     protected virtual void Content_ExecutionStateChanged(object sender, EventArgs e) {
    157       if (InvokeRequired)
    158         Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);
    159       else
    160         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       else
    166         executionTimeTextBox.Text = Content == null ? "-" : Content.ExecutionTime.ToString();
    167     }
    168139    protected virtual void Content_StoreAlgorithmInEachRunChanged(object sender, EventArgs e) {
    169140      if (InvokeRequired)
     
    171142      else
    172143        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       else
    211         ErrorHandling.ShowErrorDialog(this, e.Value);
    212144    }
    213145    #endregion
     
    264196      if (Content != null) Content.StoreAlgorithmInEachRun = storeAlgorithmInEachRunCheckBox.Checked;
    265197    }
    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     }
    278198    protected virtual void problemTabPage_DragEnterOver(object sender, DragEventArgs e) {
    279199      e.Effect = DragDropEffects.None;
     
    294214    }
    295215    #endregion
    296 
    297     #region Helpers
    298     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     #endregion
    309216  }
    310217}
Note: See TracChangeset for help on using the changeset viewer.