[2] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[2790] | 3 | * Copyright (C) 2002-2010 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Data;
|
---|
| 25 | using System.Drawing;
|
---|
| 26 | using System.Windows.Forms;
|
---|
| 27 | using System.Reflection;
|
---|
[2505] | 28 | using System.Linq;
|
---|
[2] | 29 | using HeuristicLab.PluginInfrastructure;
|
---|
[2481] | 30 | using HeuristicLab.PluginInfrastructure.Manager;
|
---|
[2] | 31 |
|
---|
[2527] | 32 | namespace HeuristicLab.PluginInfrastructure.Starter {
|
---|
[2504] | 33 | internal partial class SplashScreen : Form {
|
---|
[595] | 34 | private const int FADE_INTERVAL = 50;
|
---|
[2505] | 35 | private Timer fadeTimer;
|
---|
[596] | 36 | private int initialInterval;
|
---|
[2481] | 37 | private PluginManager manager;
|
---|
[3113] | 38 | private bool fadeOutForced;
|
---|
[2504] | 39 | internal SplashScreen() {
|
---|
[2] | 40 | InitializeComponent();
|
---|
[2481] | 41 | }
|
---|
[2] | 42 |
|
---|
[3113] | 43 | internal SplashScreen(PluginManager manager, int initialInterval)
|
---|
[2481] | 44 | : this() {
|
---|
| 45 | this.initialInterval = initialInterval;
|
---|
| 46 | this.manager = manager;
|
---|
[2505] | 47 |
|
---|
[2922] | 48 | manager.ApplicationStarted += new EventHandler<PluginInfrastructureEventArgs>(manager_ApplicationStarted);
|
---|
| 49 | manager.ApplicationStarting += new EventHandler<PluginInfrastructureEventArgs>(manager_ApplicationStarting);
|
---|
| 50 | manager.Initializing += new EventHandler<PluginInfrastructureEventArgs>(manager_Initializing);
|
---|
| 51 | manager.Initialized += new EventHandler<PluginInfrastructureEventArgs>(manager_Initialized);
|
---|
| 52 | manager.PluginLoaded += new EventHandler<PluginInfrastructureEventArgs>(manager_PluginLoaded);
|
---|
| 53 | manager.PluginUnloaded += new EventHandler<PluginInfrastructureEventArgs>(manager_PluginUnloaded);
|
---|
[2] | 54 |
|
---|
| 55 | titleLabel.Text = Application.ProductName;
|
---|
| 56 | versionLabel.Text = "Version " + Application.ProductVersion;
|
---|
| 57 | infoLabel.Text = "";
|
---|
| 58 |
|
---|
[2505] | 59 | var attr = (AssemblyCopyrightAttribute)this.GetType().Assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false).Single();
|
---|
| 60 | copyrightLabel.Text = "Copyright " + attr.Copyright;
|
---|
[2] | 61 |
|
---|
[2505] | 62 | string user = HeuristicLab.PluginInfrastructure.Properties.Settings.Default.User;
|
---|
| 63 | string company = HeuristicLab.PluginInfrastructure.Properties.Settings.Default.Organization;
|
---|
[2] | 64 |
|
---|
[2505] | 65 | userNameLabel.Text = string.IsNullOrEmpty(user) ? "-" : user;
|
---|
| 66 | companyLabel.Text = string.IsNullOrEmpty(company) ? "-" : company;
|
---|
[2] | 67 |
|
---|
[2505] | 68 | fadeTimer = new Timer();
|
---|
| 69 | fadeTimer.Tick += fadeTimer_Elapsed;
|
---|
| 70 | fadeTimer.Interval = initialInterval;
|
---|
[2] | 71 | }
|
---|
| 72 |
|
---|
[2922] | 73 | void manager_PluginUnloaded(object sender, PluginInfrastructureEventArgs e) {
|
---|
| 74 | UpdateMessage("Unloaded " + e.Entity);
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | void manager_PluginLoaded(object sender, PluginInfrastructureEventArgs e) {
|
---|
| 78 | UpdateMessage("Loaded " + e.Entity);
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | void manager_Initialized(object sender, PluginInfrastructureEventArgs e) {
|
---|
| 82 | UpdateMessage("Initialized");
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | void manager_Initializing(object sender, PluginInfrastructureEventArgs e) {
|
---|
| 86 | UpdateMessage("Initializing");
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | void manager_ApplicationStarting(object sender, PluginInfrastructureEventArgs e) {
|
---|
| 90 | UpdateMessage("Starting " + e.Entity);
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | void manager_ApplicationStarted(object sender, PluginInfrastructureEventArgs e) {
|
---|
| 94 | UpdateMessage("Started " + e.Entity);
|
---|
| 95 | }
|
---|
| 96 |
|
---|
[3113] | 97 | public void Show(string initialText) {
|
---|
| 98 | if (InvokeRequired) Invoke((Action<string>)Show, initialText);
|
---|
| 99 | else {
|
---|
| 100 | Opacity = 1;
|
---|
| 101 | infoLabel.Text = initialText;
|
---|
| 102 | fadeOutForced = false;
|
---|
| 103 | ResetFadeTimer();
|
---|
| 104 | Show();
|
---|
| 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 |
|
---|
[2] | 116 | private void SetInfoText(string text) {
|
---|
[2505] | 117 | if (InvokeRequired) Invoke((Action<string>)SetInfoText, text);
|
---|
| 118 | else {
|
---|
| 119 | infoLabel.Text = text;
|
---|
| 120 | }
|
---|
[2] | 121 | }
|
---|
| 122 |
|
---|
[2922] | 123 | private void UpdateMessage(string msg) {
|
---|
[2481] | 124 | if (InvokeRequired) {
|
---|
[2922] | 125 | Invoke((Action<string>)UpdateMessage, msg);
|
---|
[596] | 126 | } else {
|
---|
[3113] | 127 | // when the user forced a fade-out (by closing the splashscreen)
|
---|
| 128 | // don't reset the fadeTimer
|
---|
| 129 | if (!fadeOutForced) {
|
---|
| 130 | ResetFadeTimer();
|
---|
| 131 | }
|
---|
[2922] | 132 | SetInfoText(msg);
|
---|
[2505] | 133 | Application.DoEvents(); // force immediate update of splash screen control
|
---|
[2] | 134 | }
|
---|
| 135 | }
|
---|
| 136 |
|
---|
[3113] | 137 | // each tick of the timer reduce opacity and restart timer
|
---|
[2505] | 138 | private void fadeTimer_Elapsed(object sender, EventArgs e) {
|
---|
[3113] | 139 | FadeOut();
|
---|
[2] | 140 | }
|
---|
[2439] | 141 |
|
---|
[3113] | 142 | // reduces opacity of the splashscreen one step and restarts the fade-timer
|
---|
| 143 | private void FadeOut() {
|
---|
[2505] | 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();
|
---|
[3113] | 152 | Hide();
|
---|
[2439] | 153 | }
|
---|
| 154 | }
|
---|
[2505] | 155 |
|
---|
[3113] | 156 | // force fade out
|
---|
[2505] | 157 | private void closeButton_Click(object sender, EventArgs e) {
|
---|
[3113] | 158 | fadeOutForced = true;
|
---|
| 159 | FadeOut();
|
---|
[2505] | 160 | }
|
---|
[2] | 161 | }
|
---|
| 162 | }
|
---|