Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 4047 was 3777, checked in by swagner, 15 years ago

Updated HeuristicLab logos and adapted SplashScreen (#989)

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