Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 4179 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

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