Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.PluginInfrastructure/Starter/SplashScreen.cs @ 2876

Last change on this file since 2876 was 2790, checked in by swagner, 15 years ago

Operator architecture refactoring (#95)

  • implemented reviewers' comments
  • added additional plugins HeuristicLab.Evolutionary, HeuristicLab.Permutation, HeuristicLab.Selection, and HeuristicLab.Routing.TSP
File size: 3.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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 System;
23using System.Collections.Generic;
24using System.Data;
25using System.Drawing;
26using System.Windows.Forms;
27using System.Reflection;
28using System.Linq;
29using HeuristicLab.PluginInfrastructure;
30using HeuristicLab.PluginInfrastructure.Manager;
31
32namespace HeuristicLab.PluginInfrastructure.Starter {
33  internal partial class SplashScreen : Form {
34    private const int FADE_INTERVAL = 50;
35    private Timer fadeTimer;
36    private int initialInterval;
37    private PluginManager manager;
38
39    internal SplashScreen() {
40      InitializeComponent();
41    }
42
43    internal SplashScreen(PluginManager manager, int initialInterval, string initialText)
44      : this() {
45      this.initialInterval = initialInterval;
46      this.manager = manager;
47
48      manager.Action += managerActionEventHandler;
49
50      infoLabel.Text = initialText;
51      titleLabel.Text = Application.ProductName;
52      versionLabel.Text = "Version " + Application.ProductVersion;
53      infoLabel.Text = "";
54
55      var attr = (AssemblyCopyrightAttribute)this.GetType().Assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false).Single();
56      copyrightLabel.Text = "Copyright " + attr.Copyright;
57
58      string user = HeuristicLab.PluginInfrastructure.Properties.Settings.Default.User;
59      string company = HeuristicLab.PluginInfrastructure.Properties.Settings.Default.Organization;
60
61      userNameLabel.Text = string.IsNullOrEmpty(user) ? "-" : user;
62      companyLabel.Text = string.IsNullOrEmpty(company) ? "-" : company;
63
64      fadeTimer = new Timer();
65      fadeTimer.Tick += fadeTimer_Elapsed;
66      fadeTimer.Interval = initialInterval;
67    }
68
69    private void SetInfoText(string text) {
70      if (InvokeRequired) Invoke((Action<string>)SetInfoText, text);
71      else {
72        infoLabel.Text = text;
73      }
74    }
75
76    private void managerActionEventHandler(object sender, PluginInfrastructureEventArgs e) {
77      if (InvokeRequired) {
78        Invoke((EventHandler<PluginInfrastructureEventArgs>)managerActionEventHandler, sender, e);
79      } else {
80        ResetFadeTimer();
81        string info = e.Action + ": " + e.Entity;
82        SetInfoText(info);
83        Application.DoEvents(); // force immediate update of splash screen control
84      }
85    }
86
87    private void ResetFadeTimer() {
88      fadeTimer.Stop(); fadeTimer.Start();
89    }
90
91    private void fadeTimer_Elapsed(object sender, EventArgs e) {
92      FadeOutAndClose();
93    }
94
95    private void FadeOutAndClose() {
96      fadeTimer.Stop();
97      fadeTimer.Interval = FADE_INTERVAL;
98      if (this.Opacity > 0) {
99        Opacity -= 0.1;
100        fadeTimer.Start();
101      } else {
102        Opacity = 0;
103        fadeTimer.Stop();
104        fadeTimer.Dispose();
105        manager.Action -= managerActionEventHandler; // remove event before calling close
106        Close();
107      }
108    }
109
110    private void closeButton_Click(object sender, EventArgs e) {
111      FadeOutAndClose();
112    }
113  }
114}
Note: See TracBrowser for help on using the repository browser.