Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 4482 was 4482, checked in by gkronber, 14 years ago

Preparations for next HL release. #1203

File size: 5.1 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.Diagnostics;
24using System.Linq;
25using System.Reflection;
26using System.Windows.Forms;
27using HeuristicLab.PluginInfrastructure.Manager;
28
29namespace HeuristicLab.PluginInfrastructure.Starter {
30  internal partial class SplashScreen : Form {
31    private const int FADE_INTERVAL = 50;
32    private Timer fadeTimer;
33    private int initialInterval;
34
35    internal SplashScreen() {
36      InitializeComponent();
37    }
38
39    internal SplashScreen(PluginManager manager, int initialInterval)
40      : this() {
41      this.initialInterval = initialInterval;
42
43      manager.ApplicationStarted += new EventHandler<PluginInfrastructureEventArgs>(manager_ApplicationStarted);
44      manager.ApplicationStarting += new EventHandler<PluginInfrastructureEventArgs>(manager_ApplicationStarting);
45      manager.Initializing += new EventHandler<PluginInfrastructureEventArgs>(manager_Initializing);
46      manager.Initialized += new EventHandler<PluginInfrastructureEventArgs>(manager_Initialized);
47      manager.PluginLoaded += new EventHandler<PluginInfrastructureEventArgs>(manager_PluginLoaded);
48      manager.PluginUnloaded += new EventHandler<PluginInfrastructureEventArgs>(manager_PluginUnloaded);
49
50      FileVersionInfo pluginInfrastructureVersion = FileVersionInfo.GetVersionInfo(GetType().Assembly.Location);
51      versionLabel.Text = "Version " + pluginInfrastructureVersion.FileVersion;
52      infoLabel.Text = "";
53
54      var attr = (AssemblyCopyrightAttribute)this.GetType().Assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false).Single();
55      copyrightLabel.Text = "Copyright " + attr.Copyright;
56
57      fadeTimer = new Timer();
58      fadeTimer.Tick += fadeTimer_Elapsed;
59      fadeTimer.Interval = initialInterval;
60    }
61
62    void manager_PluginUnloaded(object sender, PluginInfrastructureEventArgs e) {
63      UpdateMessage("Unloaded " + e.Entity);
64    }
65
66    void manager_PluginLoaded(object sender, PluginInfrastructureEventArgs e) {
67      UpdateMessage("Loaded " + e.Entity);
68    }
69
70    void manager_Initialized(object sender, PluginInfrastructureEventArgs e) {
71      UpdateMessage("Initialized");
72    }
73
74    void manager_Initializing(object sender, PluginInfrastructureEventArgs e) {
75      UpdateMessage("Initializing");
76    }
77
78    void manager_ApplicationStarting(object sender, PluginInfrastructureEventArgs e) {
79      UpdateMessage("Starting " + e.Entity);
80    }
81
82    void manager_ApplicationStarted(object sender, PluginInfrastructureEventArgs e) {
83      UpdateMessage("Started " + e.Entity);
84    }
85
86    public void Show(string initialText) {
87      if (InvokeRequired) Invoke((Action<string>)Show, initialText);
88      else {
89        Opacity = 1;
90        infoLabel.Text = initialText;
91        ResetFadeTimer();
92        Show();
93      }
94    }
95
96    public void Show(IWin32Window owner, string initialText) {
97      if (InvokeRequired) Invoke((Action<string>)Show, initialText);
98      else {
99        Opacity = 1;
100        infoLabel.Text = initialText;
101        ResetFadeTimer();
102        Show(owner);
103      }
104    }
105
106    private void ResetFadeTimer() {
107      // wait initialInterval again for the first tick
108      fadeTimer.Stop();
109      fadeTimer.Interval = initialInterval;
110      fadeTimer.Start();
111    }
112
113
114    private void SetInfoText(string text) {
115      if (InvokeRequired) Invoke((Action<string>)SetInfoText, text);
116      else {
117        infoLabel.Text = text;
118      }
119    }
120
121    private void UpdateMessage(string msg) {
122      if (InvokeRequired) {
123        Invoke((Action<string>)UpdateMessage, msg);
124      } else {
125        ResetFadeTimer();
126        SetInfoText(msg);
127        Application.DoEvents(); // force immediate update of splash screen control
128      }
129    }
130
131    // each tick of the timer reduce opacity and restart timer
132    private void fadeTimer_Elapsed(object sender, EventArgs e) {
133      FadeOut();
134    }
135
136    // reduces opacity of the splashscreen one step and restarts the fade-timer
137    private void FadeOut() {
138      fadeTimer.Stop();
139      fadeTimer.Interval = FADE_INTERVAL;
140      if (this.Opacity > 0) {
141        Opacity -= 0.1;
142        fadeTimer.Start();
143      } else {
144        Opacity = 0;
145        fadeTimer.Stop();
146        Hide();
147      }
148    }
149  }
150}
Note: See TracBrowser for help on using the repository browser.