Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/OptimizationKnowledgeCenter.cs @ 14680

Last change on this file since 14680 was 13748, checked in by abeham, 9 years ago

#2457: Added toolbar, fixed some bugs

File size: 3.8 KB
Line 
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
22using HeuristicLab.Common;
23using HeuristicLab.MainForm;
24using HeuristicLab.MainForm.WindowsForms;
25using HeuristicLab.OptimizationExpertSystem.Common;
26using System;
27using System.Windows.Forms;
28
29namespace HeuristicLab.OptimizationExpertSystem {
30  public partial class OptimizationKnowledgeCenter : DockingMainForm {
31    private ToolStripProgressBar progressBar;
32    private ToolStripLabel progressLabel;
33
34    public KnowledgeCenter ExpertSystem { get; private set; }
35   
36    public OptimizationKnowledgeCenter(Type userInterfaceType) : base(userInterfaceType) {
37      InitializeComponent();
38      ExpertSystem = new KnowledgeCenter();
39      ExpertSystem.DownloadStarted += ExpertSystemOnDownloadStarted;
40      ShowContentInViewHost = false;
41    }
42
43    private void ExpertSystemOnDownloadStarted(object sender, EventArgs<IProgress> e) {
44      if (InvokeRequired) { Invoke((Action<object, EventArgs<IProgress>>)ExpertSystemOnDownloadStarted, sender, e); return; }
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) {
55      if (InvokeRequired) { Invoke((Action<object, EventArgs>)OnProgressStateChanged, sender, e); return; }
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) {
68      if (InvokeRequired) { Invoke((Action<object, EventArgs>)OnProgressValueChanged, sender, e); return; }
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) {
74      if (InvokeRequired) { Invoke((Action<object, EventArgs>)OnProgressStatusChanged, sender, e); return; }
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
87    private void OptimizationExpertSystem_Load(object sender, EventArgs e) {
88      ShowContent(ExpertSystem.Problem);
89    }
90  }
91}
Note: See TracBrowser for help on using the repository browser.