[6618] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2011 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;
|
---|
[6169] | 24 | using System.Windows.Forms;
|
---|
[6140] | 25 | using HeuristicLab.Core.Views;
|
---|
| 26 | using HeuristicLab.MainForm;
|
---|
| 27 |
|
---|
[6169] | 28 | namespace 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() {
|
---|
[6377] | 44 | Content.Changed -= new System.EventHandler(Content_StatusChanged);
|
---|
[6140] | 45 | base.DeregisterContentEvents();
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | protected override void RegisterContentEvents() {
|
---|
| 49 | base.RegisterContentEvents();
|
---|
[6377] | 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
|
---|
[6618] | 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 | }
|
---|
[6618] | 96 | }
|
---|
[6140] | 97 | }
|
---|
| 98 | }
|
---|