Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/OptimizationExpertSystem.cs @ 13720

Last change on this file since 13720 was 13720, checked in by abeham, 8 years ago

#2457: worked on expert-system

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