Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.ExternalEvaluation.Views/3.4/EvaluationCacheView.cs @ 15428

Last change on this file since 15428 was 14185, checked in by swagner, 8 years ago

#2526: Updated year of copyrights in license headers

File size: 3.2 KB
RevLine 
[6519]1#region License Information
2/* HeuristicLab
[14185]3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[6519]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.ComponentModel;
[6169]24using System.Windows.Forms;
[6140]25using HeuristicLab.Core.Views;
26using HeuristicLab.MainForm;
27
[6169]28namespace HeuristicLab.Problems.ExternalEvaluation.Views {
29
[6140]30  [View("EvaluationCacheView")]
31  [Content(typeof(EvaluationCache), IsDefaultView = true)]
[6169]32  public sealed partial class EvaluationCacheView : ParameterizedNamedItemView {
[6140]33
34    public new EvaluationCache Content {
35      get { return (EvaluationCache)base.Content; }
36      set { base.Content = value; }
37    }
38
39    public EvaluationCacheView() {
40      InitializeComponent();
41    }
42
43    protected override void DeregisterContentEvents() {
[6291]44      Content.Changed -= new System.EventHandler(Content_StatusChanged);
[6140]45      base.DeregisterContentEvents();
46    }
47
48    protected override void RegisterContentEvents() {
49      base.RegisterContentEvents();
[6291]50      Content.Changed += new System.EventHandler(Content_StatusChanged);
[6140]51    }
52
53    #region Event Handlers (Content)
[6169]54    void Content_StatusChanged(object sender, EventArgs e) {
55      if (InvokeRequired)
56        Invoke(new EventHandler(Content_StatusChanged), sender, e);
57      else
[6183]58        hits_sizeTextBox.Text = string.Format("{0}/{1} ({2} active)", Content.Hits, Content.Size, Content.ActiveEvaluations);
[6140]59    }
60
61    #endregion
62
63    protected override void OnContentChanged() {
64      base.OnContentChanged();
65      if (Content == null) {
[6169]66        hits_sizeTextBox.Text = "#/#";
[6140]67      } else {
[6169]68        Content_StatusChanged(this, EventArgs.Empty);
[6140]69      }
70    }
71
72    protected override void SetEnabledStateOfControls() {
73      base.SetEnabledStateOfControls();
74      clearButton.Enabled = !ReadOnly && Content != null;
[6265]75      saveButton.Enabled = !ReadOnly && Content != null;
[6140]76    }
77
78    #region Event Handlers (child controls)
[6169]79    private void clearButton_Click(object sender, EventArgs e) {
[6140]80      Content.Reset();
81    }
82    #endregion
[6519]83
[6265]84    private void saveButton_Click(object sender, EventArgs e) {
85      if (saveFileDialog.ShowDialog() == DialogResult.OK) {
86        saveButton.Enabled = false;
87        BackgroundWorker worker = new BackgroundWorker();
88        worker.DoWork += (s, a) => {
89          Content.Save((string)a.Argument);
90        };
91        worker.RunWorkerCompleted += (s, a) => {
92          SetEnabledStateOfControls();
93        };
94        worker.RunWorkerAsync(saveFileDialog.FileName);
95      }
[6519]96    }
[6140]97  }
98}
Note: See TracBrowser for help on using the repository browser.