1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2018 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.ComponentModel;
|
---|
24 | using System.Windows.Forms;
|
---|
25 | using HeuristicLab.Core.Views;
|
---|
26 | using HeuristicLab.MainForm;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Problems.ExternalEvaluation.Views {
|
---|
29 |
|
---|
30 | [View("EvaluationCacheView")]
|
---|
31 | [Content(typeof(EvaluationCache), IsDefaultView = true)]
|
---|
32 | public sealed partial class EvaluationCacheView : ParameterizedNamedItemView {
|
---|
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() {
|
---|
44 | Content.Changed -= new System.EventHandler(Content_StatusChanged);
|
---|
45 | base.DeregisterContentEvents();
|
---|
46 | }
|
---|
47 |
|
---|
48 | protected override void RegisterContentEvents() {
|
---|
49 | base.RegisterContentEvents();
|
---|
50 | Content.Changed += new System.EventHandler(Content_StatusChanged);
|
---|
51 | }
|
---|
52 |
|
---|
53 | #region Event Handlers (Content)
|
---|
54 | void Content_StatusChanged(object sender, EventArgs e) {
|
---|
55 | if (InvokeRequired)
|
---|
56 | Invoke(new EventHandler(Content_StatusChanged), sender, e);
|
---|
57 | else
|
---|
58 | hits_sizeTextBox.Text = string.Format("{0}/{1} ({2} active)", Content.Hits, Content.Size, Content.ActiveEvaluations);
|
---|
59 | }
|
---|
60 |
|
---|
61 | #endregion
|
---|
62 |
|
---|
63 | protected override void OnContentChanged() {
|
---|
64 | base.OnContentChanged();
|
---|
65 | if (Content == null) {
|
---|
66 | hits_sizeTextBox.Text = "#/#";
|
---|
67 | } else {
|
---|
68 | Content_StatusChanged(this, EventArgs.Empty);
|
---|
69 | }
|
---|
70 | }
|
---|
71 |
|
---|
72 | protected override void SetEnabledStateOfControls() {
|
---|
73 | base.SetEnabledStateOfControls();
|
---|
74 | clearButton.Enabled = !ReadOnly && Content != null;
|
---|
75 | saveButton.Enabled = !ReadOnly && Content != null;
|
---|
76 | }
|
---|
77 |
|
---|
78 | #region Event Handlers (child controls)
|
---|
79 | private void clearButton_Click(object sender, EventArgs e) {
|
---|
80 | Content.Reset();
|
---|
81 | }
|
---|
82 | #endregion
|
---|
83 |
|
---|
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 | }
|
---|
96 | }
|
---|
97 | }
|
---|
98 | }
|
---|