Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3038 was 2922, checked in by gkronber, 15 years ago

Worked on GUI for plugin management. #891 (Refactor GUI for plugin management)

File size: 5.6 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
39    internal SplashScreen() {
40      InitializeComponent();
41    }
42
43    internal SplashScreen(PluginManager manager, int initialInterval, string initialText)
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      infoLabel.Text = initialText;
56      titleLabel.Text = Application.ProductName;
57      versionLabel.Text = "Version " + Application.ProductVersion;
58      infoLabel.Text = "";
59
60      var attr = (AssemblyCopyrightAttribute)this.GetType().Assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false).Single();
61      copyrightLabel.Text = "Copyright " + attr.Copyright;
62
63      string user = HeuristicLab.PluginInfrastructure.Properties.Settings.Default.User;
64      string company = HeuristicLab.PluginInfrastructure.Properties.Settings.Default.Organization;
65
66      userNameLabel.Text = string.IsNullOrEmpty(user) ? "-" : user;
67      companyLabel.Text = string.IsNullOrEmpty(company) ? "-" : company;
68
69      fadeTimer = new Timer();
70      fadeTimer.Tick += fadeTimer_Elapsed;
71      fadeTimer.Interval = initialInterval;
72    }
73
74    void manager_PluginUnloaded(object sender, PluginInfrastructureEventArgs e) {
75      UpdateMessage("Unloaded " + e.Entity);
76    }
77
78    void manager_PluginLoaded(object sender, PluginInfrastructureEventArgs e) {
79      UpdateMessage("Loaded " + e.Entity);
80    }
81
82    void manager_Initialized(object sender, PluginInfrastructureEventArgs e) {
83      UpdateMessage("Initialized");
84    }
85
86    void manager_Initializing(object sender, PluginInfrastructureEventArgs e) {
87      UpdateMessage("Initializing");
88    }
89
90    void manager_ApplicationStarting(object sender, PluginInfrastructureEventArgs e) {
91      UpdateMessage("Starting " + e.Entity);
92    }
93
94    void manager_ApplicationStarted(object sender, PluginInfrastructureEventArgs e) {
95      UpdateMessage("Started " + e.Entity);
96    }
97
98    private void SetInfoText(string text) {
99      if (InvokeRequired) Invoke((Action<string>)SetInfoText, text);
100      else {
101        infoLabel.Text = text;
102      }
103    }
104
105    private void UpdateMessage(string msg) {
106      if (InvokeRequired) {
107        Invoke((Action<string>)UpdateMessage, msg);
108      } else {
109        ResetFadeTimer();
110        SetInfoText(msg);
111        Application.DoEvents(); // force immediate update of splash screen control
112      }
113    }
114
115    private void ResetFadeTimer() {
116      fadeTimer.Stop(); fadeTimer.Start();
117    }
118
119    private void fadeTimer_Elapsed(object sender, EventArgs e) {
120      FadeOutAndClose();
121    }
122
123    private void FadeOutAndClose() {
124      fadeTimer.Stop();
125      fadeTimer.Interval = FADE_INTERVAL;
126      if (this.Opacity > 0) {
127        Opacity -= 0.1;
128        fadeTimer.Start();
129      } else {
130        Opacity = 0;
131        fadeTimer.Stop();
132        fadeTimer.Dispose();
133        // remove event before calling close
134        manager.ApplicationStarted -= new EventHandler<PluginInfrastructureEventArgs>(manager_ApplicationStarted);
135        manager.ApplicationStarting -= new EventHandler<PluginInfrastructureEventArgs>(manager_ApplicationStarting);
136        manager.Initializing -= new EventHandler<PluginInfrastructureEventArgs>(manager_Initialized);
137        manager.Initialized -= new EventHandler<PluginInfrastructureEventArgs>(manager_Initializing);
138        manager.PluginLoaded -= new EventHandler<PluginInfrastructureEventArgs>(manager_PluginLoaded);
139        manager.PluginUnloaded -= new EventHandler<PluginInfrastructureEventArgs>(manager_PluginUnloaded);
140        Close();
141      }
142    }
143
144    private void closeButton_Click(object sender, EventArgs e) {
145      FadeOutAndClose();
146    }
147  }
148}
Note: See TracBrowser for help on using the repository browser.