#region License Information
/* HeuristicLab
* Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
using HeuristicLab.PluginInfrastructure.Manager;
namespace HeuristicLab.PluginInfrastructure.Starter {
internal partial class SplashScreen : Form {
private const int FADE_INTERVAL = 50;
private Timer fadeTimer;
private int initialInterval;
private PluginManager manager;
internal SplashScreen() {
InitializeComponent();
}
internal SplashScreen(PluginManager manager, int initialInterval)
: this() {
this.initialInterval = initialInterval;
this.manager = manager;
manager.ApplicationStarted += new EventHandler(manager_ApplicationStarted);
manager.ApplicationStarting += new EventHandler(manager_ApplicationStarting);
manager.Initializing += new EventHandler(manager_Initializing);
manager.Initialized += new EventHandler(manager_Initialized);
manager.PluginLoaded += new EventHandler(manager_PluginLoaded);
manager.PluginUnloaded += new EventHandler(manager_PluginUnloaded);
FileVersionInfo pluginInfrastructureVersion = FileVersionInfo.GetVersionInfo(GetType().Assembly.Location);
versionLabel.Text = "Version " + pluginInfrastructureVersion.FileVersion;
infoLabel.Text = "";
var attr = (AssemblyCopyrightAttribute)this.GetType().Assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false).Single();
copyrightLabel.Text = "Copyright " + attr.Copyright;
fadeTimer = new Timer();
fadeTimer.Tick += fadeTimer_Elapsed;
fadeTimer.Interval = initialInterval;
}
void manager_PluginUnloaded(object sender, PluginInfrastructureEventArgs e) {
UpdateMessage("Unloaded " + e.Entity);
}
void manager_PluginLoaded(object sender, PluginInfrastructureEventArgs e) {
UpdateMessage("Loaded " + e.Entity);
}
void manager_Initialized(object sender, PluginInfrastructureEventArgs e) {
UpdateMessage("Initialized");
}
void manager_Initializing(object sender, PluginInfrastructureEventArgs e) {
UpdateMessage("Initializing");
}
void manager_ApplicationStarting(object sender, PluginInfrastructureEventArgs e) {
UpdateMessage("Starting " + e.Entity);
}
void manager_ApplicationStarted(object sender, PluginInfrastructureEventArgs e) {
UpdateMessage("Started " + e.Entity);
}
public void Show(string initialText) {
if (InvokeRequired) Invoke((Action)Show, initialText);
else {
Opacity = 1;
infoLabel.Text = initialText;
ResetFadeTimer();
Show();
}
}
public void Show(IWin32Window owner, string initialText) {
if (InvokeRequired) Invoke((Action)Show, initialText);
else {
Opacity = 1;
infoLabel.Text = initialText;
ResetFadeTimer();
Show(owner);
}
}
private void ResetFadeTimer() {
// wait initialInterval again for the first tick
fadeTimer.Stop();
fadeTimer.Interval = initialInterval;
fadeTimer.Start();
}
private void SetInfoText(string text) {
if (InvokeRequired) Invoke((Action)SetInfoText, text);
else {
infoLabel.Text = text;
}
}
private void UpdateMessage(string msg) {
if (InvokeRequired) {
Invoke((Action)UpdateMessage, msg);
} else {
ResetFadeTimer();
SetInfoText(msg);
Application.DoEvents(); // force immediate update of splash screen control
}
}
// each tick of the timer reduce opacity and restart timer
private void fadeTimer_Elapsed(object sender, EventArgs e) {
FadeOut();
}
// reduces opacity of the splashscreen one step and restarts the fade-timer
private void FadeOut() {
fadeTimer.Stop();
fadeTimer.Interval = FADE_INTERVAL;
if (this.Opacity > 0) {
Opacity -= 0.1;
fadeTimer.Start();
} else {
Opacity = 0;
fadeTimer.Stop();
Hide();
}
}
}
}