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, 15 years ago

fixed SplashScreen (ticket #989)

File size: 5.9 KB
RevLine 
[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
22using System;
23using System.Collections.Generic;
24using System.Data;
25using System.Drawing;
26using System.Windows.Forms;
27using System.Reflection;
[2505]28using System.Linq;
[2]29using HeuristicLab.PluginInfrastructure;
[2481]30using HeuristicLab.PluginInfrastructure.Manager;
[2]31
[2527]32namespace 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
[3697]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
[3113]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
[2]127    private void SetInfoText(string text) {
[2505]128      if (InvokeRequired) Invoke((Action<string>)SetInfoText, text);
129      else {
130        infoLabel.Text = text;
131      }
[2]132    }
133
[2922]134    private void UpdateMessage(string msg) {
[2481]135      if (InvokeRequired) {
[2922]136        Invoke((Action<string>)UpdateMessage, msg);
[596]137      } else {
[3113]138        // when the user forced a fade-out (by closing the splashscreen)
139        // don't reset the fadeTimer
140        if (!fadeOutForced) {
141          ResetFadeTimer();
142        }
[2922]143        SetInfoText(msg);
[2505]144        Application.DoEvents(); // force immediate update of splash screen control
[2]145      }
146    }
147
[3113]148    // each tick of the timer reduce opacity and restart timer
[2505]149    private void fadeTimer_Elapsed(object sender, EventArgs e) {
[3113]150      FadeOut();
[2]151    }
[2439]152
[3113]153    // reduces opacity of the splashscreen one step and restarts the fade-timer
154    private void FadeOut() {
[2505]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();
[3113]163        Hide();
[2439]164      }
165    }
[2505]166
[3113]167    // force fade out
[2505]168    private void closeButton_Click(object sender, EventArgs e) {
[3113]169      fadeOutForced = true;
170      FadeOut();
[2505]171    }
[2]172  }
173}
Note: See TracBrowser for help on using the repository browser.