Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2457_ExpertSystem/HeuristicLab.OptimizationExpertSystem/3.3/OptimizationKnowledgeCenter.cs @ 17099

Last change on this file since 17099 was 16958, checked in by abeham, 6 years ago

#2457: adapted to trunk

File size: 3.9 KB
RevLine 
[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
[16958]22using System;
23using System.Windows.Forms;
[13720]24using HeuristicLab.Common;
25using HeuristicLab.MainForm;
[13667]26using HeuristicLab.MainForm.WindowsForms;
27using HeuristicLab.OptimizationExpertSystem.Common;
28
29namespace 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;
[16958]47      e.Value.MessageChanged += OnProgressStatusChanged;
[13720]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;
[16958]57      if (progress.ProgressState == ProgressState.CancelRequested
[13720]58          || progress.ProgressState == ProgressState.Finished) {
59        progress.ProgressStateChanged -= OnProgressStateChanged;
60        progress.ProgressValueChanged -= OnProgressValueChanged;
[16958]61        progress.MessageChanged -= OnProgressStatusChanged;
[13720]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;
[16958]76      progressLabel.Text = progress.Message.Replace(Environment.NewLine, "   ");
[13720]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}
Note: See TracBrowser for help on using the repository browser.