Free cookie consent management tool by TermsFeed Policy Generator

source: branches/RefactorPluginInfrastructure-2522/HeuristicLab.PluginInfrastructure.UI/SplashScreen.cs @ 13353

Last change on this file since 13353 was 13353, checked in by gkronber, 8 years ago

#2522: added assembly attribute for release code name and updated AboutDialog as well as SplashScreen to show information of the EntryAssembly (in our case HeuristicLab-3.3.exe)

File size: 6.3 KB
RevLine 
[2]1#region License Information
2/* HeuristicLab
[12012]3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[2]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;
[4068]23using System.Linq;
24using System.Reflection;
[2]25using System.Windows.Forms;
[2481]26using HeuristicLab.PluginInfrastructure.Manager;
[2]27
[13338]28namespace HeuristicLab.PluginInfrastructure.UI {
[2504]29  internal partial class SplashScreen : Form {
[595]30    private const int FADE_INTERVAL = 50;
[2505]31    private Timer fadeTimer;
[596]32    private int initialInterval;
[4515]33    private PluginManager pluginManager;
[3777]34
[2504]35    internal SplashScreen() {
[2]36      InitializeComponent();
[2481]37    }
[2]38
[3113]39    internal SplashScreen(PluginManager manager, int initialInterval)
[2481]40      : this() {
41      this.initialInterval = initialInterval;
[4515]42      this.pluginManager = manager;
[2505]43
[13353]44      var entryAssembly = Assembly.GetEntryAssembly();
[4515]45      RegisterPluginManagerEventHandlers();
[2]46
[13353]47      versionLabel.Text = "Version " + entryAssembly.GetFileVersion() + " "
48        + entryAssembly.GetCustomAttributes().OfType<AssemblyInformationalVersionAttribute>().First().InformationalVersion; // code name
[2]49      infoLabel.Text = "";
50
[13353]51      var attr = entryAssembly.GetCustomAttributes().OfType<AssemblyCopyrightAttribute>().Single();
[2505]52      copyrightLabel.Text = "Copyright " + attr.Copyright;
[2]53
[2505]54      fadeTimer = new Timer();
55      fadeTimer.Tick += fadeTimer_Elapsed;
56      fadeTimer.Interval = initialInterval;
[2]57    }
58
[4515]59    #region events
60    private void RegisterPluginManagerEventHandlers() {
61      pluginManager.ApplicationStarted += new EventHandler<PluginInfrastructureEventArgs>(manager_ApplicationStarted);
62      pluginManager.ApplicationStarting += new EventHandler<PluginInfrastructureEventArgs>(manager_ApplicationStarting);
63      pluginManager.Initializing += new EventHandler<PluginInfrastructureEventArgs>(manager_Initializing);
64      pluginManager.Initialized += new EventHandler<PluginInfrastructureEventArgs>(manager_Initialized);
65      pluginManager.PluginLoaded += new EventHandler<PluginInfrastructureEventArgs>(manager_PluginLoaded);
66      pluginManager.PluginUnloaded += new EventHandler<PluginInfrastructureEventArgs>(manager_PluginUnloaded);
[2922]67    }
68
[4515]69    private void DeregisterPluginManagerEventHandlers() {
70      pluginManager.ApplicationStarted -= new EventHandler<PluginInfrastructureEventArgs>(manager_ApplicationStarted);
71      pluginManager.ApplicationStarting -= new EventHandler<PluginInfrastructureEventArgs>(manager_ApplicationStarting);
72      pluginManager.Initializing -= new EventHandler<PluginInfrastructureEventArgs>(manager_Initializing);
73      pluginManager.Initialized -= new EventHandler<PluginInfrastructureEventArgs>(manager_Initialized);
74      pluginManager.PluginLoaded -= new EventHandler<PluginInfrastructureEventArgs>(manager_PluginLoaded);
75      pluginManager.PluginUnloaded -= new EventHandler<PluginInfrastructureEventArgs>(manager_PluginUnloaded);
[2922]76    }
77
[4515]78    private void manager_PluginUnloaded(object sender, PluginInfrastructureEventArgs e) {
79      SafeUpdateMessage("Unloaded " + e.Entity);
[2922]80    }
81
[4515]82    private void manager_PluginLoaded(object sender, PluginInfrastructureEventArgs e) {
83      SafeUpdateMessage("Loaded " + e.Entity);
[2922]84    }
85
[4515]86    private void manager_Initialized(object sender, PluginInfrastructureEventArgs e) {
87      SafeUpdateMessage("Initialized");
[2922]88    }
89
[4515]90    private void manager_Initializing(object sender, PluginInfrastructureEventArgs e) {
91      SafeUpdateMessage("Initializing");
[2922]92    }
93
[4515]94    private void manager_ApplicationStarting(object sender, PluginInfrastructureEventArgs e) {
95      SafeUpdateMessage("Starting " + e.Entity);
96    }
97
98    private void manager_ApplicationStarted(object sender, PluginInfrastructureEventArgs e) {
99      SafeUpdateMessage("Started " + e.Entity);
100    }
101    // called from event handlers
102    private void SafeUpdateMessage(string msg) {
103      try {
104        Invoke((Action<string>)UpdateMessage, msg);
[13353]105      } catch (ObjectDisposedException) { }
[4515]106    }
107
108    // each tick of the timer reduce opacity and restart timer
109    private void fadeTimer_Elapsed(object sender, EventArgs e) {
110      // only called from local timer: no need to invoke here
111      FadeOut();
112    }
113    #endregion
114
[3113]115    public void Show(string initialText) {
116      if (InvokeRequired) Invoke((Action<string>)Show, initialText);
117      else {
118        Opacity = 1;
119        infoLabel.Text = initialText;
120        ResetFadeTimer();
121        Show();
122      }
123    }
124
[3697]125    public void Show(IWin32Window owner, string initialText) {
[4515]126      if (InvokeRequired) Invoke((Action<IWin32Window, string>)Show, owner, initialText);
[3697]127      else {
128        Opacity = 1;
129        infoLabel.Text = initialText;
130        ResetFadeTimer();
131        Show(owner);
132      }
133    }
134
[3113]135    private void ResetFadeTimer() {
136      // wait initialInterval again for the first tick
137      fadeTimer.Stop();
138      fadeTimer.Interval = initialInterval;
139      fadeTimer.Start();
140    }
141
[2922]142    private void UpdateMessage(string msg) {
[4515]143      ResetFadeTimer();
144      infoLabel.Text = msg;
145      Application.DoEvents(); // force immediate update of splash screen control
[2]146    }
147
[3113]148    // reduces opacity of the splashscreen one step and restarts the fade-timer
149    private void FadeOut() {
[2505]150      fadeTimer.Stop();
151      fadeTimer.Interval = FADE_INTERVAL;
152      if (this.Opacity > 0) {
153        Opacity -= 0.1;
154        fadeTimer.Start();
155      } else {
156        Opacity = 0;
157        fadeTimer.Stop();
[3113]158        Hide();
[2439]159      }
160    }
[4515]161
162    protected override void OnClosing(System.ComponentModel.CancelEventArgs e) {
163      // deregister events when form is closing
164      DeregisterPluginManagerEventHandlers();
165      base.OnClosing(e);
166    }
[2]167  }
168}
Note: See TracBrowser for help on using the repository browser.