Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3721 was 3697, checked in by mkommend, 14 years ago

fixed SplashScreen (ticket #989)

File size: 5.9 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;
31
32namespace HeuristicLab.PluginInfrastructure.Starter {
33  internal partial class SplashScreen : Form {
34    private const int FADE_INTERVAL = 50;
35    private Timer fadeTimer;
36    private int initialInterval;
37    private PluginManager manager;
38    private bool fadeOutForced;
39    internal SplashScreen() {
40      InitializeComponent();
41    }
42
43    internal SplashScreen(PluginManager manager, int initialInterval)
44      : this() {
45      this.initialInterval = initialInterval;
46      this.manager = manager;
47
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);
54
55      titleLabel.Text = Application.ProductName;
56      versionLabel.Text = "Version " + Application.ProductVersion;
57      infoLabel.Text = "";
58
59      var attr = (AssemblyCopyrightAttribute)this.GetType().Assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false).Single();
60      copyrightLabel.Text = "Copyright " + attr.Copyright;
61
62      string user = HeuristicLab.PluginInfrastructure.Properties.Settings.Default.User;
63      string company = HeuristicLab.PluginInfrastructure.Properties.Settings.Default.Organization;
64
65      userNameLabel.Text = string.IsNullOrEmpty(user) ? "-" : user;
66      companyLabel.Text = string.IsNullOrEmpty(company) ? "-" : company;
67
68      fadeTimer = new Timer();
69      fadeTimer.Tick += fadeTimer_Elapsed;
70      fadeTimer.Interval = initialInterval;
71    }
72
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
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    public void Show(IWin32Window owner, string initialText) {
109      if (InvokeRequired) Invoke((Action<string>)Show, initialText);
110      else {
111        Opacity = 1;
112        infoLabel.Text = initialText;
113        fadeOutForced = false;
114        ResetFadeTimer();
115        Show(owner);
116      }
117    }
118
119    private void ResetFadeTimer() {
120      // wait initialInterval again for the first tick
121      fadeTimer.Stop();
122      fadeTimer.Interval = initialInterval;
123      fadeTimer.Start();
124    }
125
126
127    private void SetInfoText(string text) {
128      if (InvokeRequired) Invoke((Action<string>)SetInfoText, text);
129      else {
130        infoLabel.Text = text;
131      }
132    }
133
134    private void UpdateMessage(string msg) {
135      if (InvokeRequired) {
136        Invoke((Action<string>)UpdateMessage, msg);
137      } else {
138        // when the user forced a fade-out (by closing the splashscreen)
139        // don't reset the fadeTimer
140        if (!fadeOutForced) {
141          ResetFadeTimer();
142        }
143        SetInfoText(msg);
144        Application.DoEvents(); // force immediate update of splash screen control
145      }
146    }
147
148    // each tick of the timer reduce opacity and restart timer
149    private void fadeTimer_Elapsed(object sender, EventArgs e) {
150      FadeOut();
151    }
152
153    // reduces opacity of the splashscreen one step and restarts the fade-timer
154    private void FadeOut() {
155      fadeTimer.Stop();
156      fadeTimer.Interval = FADE_INTERVAL;
157      if (this.Opacity > 0) {
158        Opacity -= 0.1;
159        fadeTimer.Start();
160      } else {
161        Opacity = 0;
162        fadeTimer.Stop();
163        Hide();
164      }
165    }
166
167    // force fade out
168    private void closeButton_Click(object sender, EventArgs e) {
169      fadeOutForced = true;
170      FadeOut();
171    }
172  }
173}
Note: See TracBrowser for help on using the repository browser.