[13667] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2016 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 |
|
---|
[13720] | 22 | using HeuristicLab.Common;
|
---|
| 23 | using HeuristicLab.MainForm;
|
---|
[13667] | 24 | using HeuristicLab.MainForm.WindowsForms;
|
---|
| 25 | using HeuristicLab.OptimizationExpertSystem.Common;
|
---|
| 26 | using System;
|
---|
[13720] | 27 | using System.Windows.Forms;
|
---|
[13667] | 28 |
|
---|
| 29 | namespace HeuristicLab.OptimizationExpertSystem {
|
---|
[13722] | 30 | public partial class OptimizationKnowledgeCenter : DockingMainForm {
|
---|
[13720] | 31 | private ToolStripProgressBar progressBar;
|
---|
| 32 | private ToolStripLabel progressLabel;
|
---|
[13667] | 33 |
|
---|
[13722] | 34 | public KnowledgeCenter ExpertSystem { get; private set; }
|
---|
[13720] | 35 |
|
---|
[13722] | 36 | public OptimizationKnowledgeCenter(Type userInterfaceType) : base(userInterfaceType) {
|
---|
[13667] | 37 | InitializeComponent();
|
---|
[13722] | 38 | ExpertSystem = new KnowledgeCenter();
|
---|
[13720] | 39 | ExpertSystem.DownloadStarted += ExpertSystemOnDownloadStarted;
|
---|
| 40 | ShowContentInViewHost = false;
|
---|
[13667] | 41 | }
|
---|
| 42 |
|
---|
[13720] | 43 | private void ExpertSystemOnDownloadStarted(object sender, EventArgs<IProgress> e) {
|
---|
[13748] | 44 | if (InvokeRequired) { Invoke((Action<object, EventArgs<IProgress>>)ExpertSystemOnDownloadStarted, sender, e); return; }
|
---|
[13720] | 45 | e.Value.ProgressStateChanged += OnProgressStateChanged;
|
---|
| 46 | e.Value.ProgressValueChanged += OnProgressValueChanged;
|
---|
| 47 | e.Value.StatusChanged += OnProgressStatusChanged;
|
---|
| 48 | progressBar.Value = progressBar.Minimum;
|
---|
| 49 | progressLabel.Text = string.Empty;
|
---|
| 50 | progressBar.Visible = true;
|
---|
| 51 | progressLabel.Visible = true;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | private void OnProgressStateChanged(object sender, EventArgs e) {
|
---|
[13748] | 55 | if (InvokeRequired) { Invoke((Action<object, EventArgs>)OnProgressStateChanged, sender, e); return; }
|
---|
[13720] | 56 | var progress = (IProgress)sender;
|
---|
| 57 | if (progress.ProgressState == ProgressState.Canceled
|
---|
| 58 | || progress.ProgressState == ProgressState.Finished) {
|
---|
| 59 | progress.ProgressStateChanged -= OnProgressStateChanged;
|
---|
| 60 | progress.ProgressValueChanged -= OnProgressValueChanged;
|
---|
| 61 | progress.StatusChanged -= OnProgressStatusChanged;
|
---|
| 62 | progressBar.Visible = false;
|
---|
| 63 | progressLabel.Visible = false;
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | private void OnProgressValueChanged(object sender, EventArgs e) {
|
---|
[13748] | 68 | if (InvokeRequired) { Invoke((Action<object, EventArgs>)OnProgressValueChanged, sender, e); return; }
|
---|
[13720] | 69 | var progress = (IProgress)sender;
|
---|
| 70 | progressBar.Value = Math.Max(progressBar.Minimum, Math.Min(progressBar.Maximum, (int)(progress.ProgressValue * 100)));
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | private void OnProgressStatusChanged(object sender, EventArgs e) {
|
---|
[13748] | 74 | if (InvokeRequired) { Invoke((Action<object, EventArgs>)OnProgressStatusChanged, sender, e); return; }
|
---|
[13720] | 75 | var progress = (IProgress)sender;
|
---|
| 76 | progressLabel.Text = progress.Status.Replace(Environment.NewLine, " ");
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | protected override void AdditionalCreationOfGuiElements() {
|
---|
| 80 | base.AdditionalCreationOfGuiElements();
|
---|
| 81 | progressBar = new ToolStripProgressBar();
|
---|
| 82 | statusStrip.Items.Add(progressBar);
|
---|
| 83 | progressLabel = new ToolStripLabel();
|
---|
| 84 | statusStrip.Items.Add(progressLabel);
|
---|
| 85 | }
|
---|
| 86 |
|
---|
[13667] | 87 | private void OptimizationExpertSystem_Load(object sender, EventArgs e) {
|
---|
[13720] | 88 | ShowContent(ExpertSystem.Problem);
|
---|
[13667] | 89 | }
|
---|
| 90 | }
|
---|
| 91 | }
|
---|