Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.1/sources/HeuristicLab/SplashScreen.cs @ 11315

Last change on this file since 11315 was 599, checked in by gkronber, 16 years ago

fixed #138 (Starting multiple applications concurrently causes some of the splashscreens to stay visible) in 3.1 branch

File size: 4.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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 HeuristicLab.PluginInfrastructure;
29
30namespace HeuristicLab {
31  public partial class SplashScreen : Form {
32    private const int FADE_INTERVAL = 50;
33    private System.Timers.Timer fadeTimer;
34    private int initialInterval;
35    private object bigLock = new object();
36    private bool closing = false;
37
38    public SplashScreen() {
39      InitializeComponent();
40
41      Assembly assembly = this.GetType().Assembly;
42      object[] attributes = assembly.GetCustomAttributes(false);
43      string user, company;
44
45      titleLabel.Text = Application.ProductName;
46      versionLabel.Text = "Version " + Application.ProductVersion;
47      infoLabel.Text = "";
48
49      foreach(object obj in attributes) {
50        if(obj is AssemblyCopyrightAttribute) {
51          copyrightLabel.Text = "Copyright " + ((AssemblyCopyrightAttribute)obj).Copyright;
52        }
53      }
54
55      try {
56        user = HeuristicLab.Properties.Settings.Default.User;
57        company = HeuristicLab.Properties.Settings.Default.Organization;
58
59        if((user == null) || (user.Equals(""))) {
60          userNameLabel.Text = "-";
61        } else {
62          userNameLabel.Text = user;
63        }
64
65        if((company == null) || (company.Equals(""))) {
66          companyLabel.Text = "-";
67        } else {
68          companyLabel.Text = company;
69        }
70      } catch(Exception) {
71        userNameLabel.Text = "-";
72        companyLabel.Text = "-";
73      }
74    }
75
76    public SplashScreen(int initialInterval, string initialText)
77      : this() {
78      this.initialInterval = initialInterval;
79      infoLabel.Text = initialText;
80    }
81
82    private void SetInfoText(string text) {
83      this.Invoke((MethodInvoker)delegate() { infoLabel.Text = text; });
84    }
85
86    public void Manager_Action(object sender, PluginManagerActionEventArgs e) {
87      string info;
88      if(e.Action == PluginManagerAction.Initializing) info = "Initializing ...";
89      else if(e.Action == PluginManagerAction.InitializingPlugin) info = "Initializing Plugin " + e.Id + " ...";
90      else if(e.Action == PluginManagerAction.InitializedPlugin) info = "Initializing Plugin " + e.Id + " ... Initialized";
91      else if(e.Action == PluginManagerAction.Initialized) {
92        info = "Initialization Completed";
93        fadeTimer = new System.Timers.Timer();
94        fadeTimer.SynchronizingObject = this;
95        fadeTimer.Elapsed += new System.Timers.ElapsedEventHandler(fadeTimer_Elapsed);
96        fadeTimer.Interval = initialInterval;
97        fadeTimer.AutoReset = true;
98        fadeTimer.Start();
99      } else {
100        if(e.Id != null) info = e.Action.ToString() + "   (" + e.Id + ")";
101        else info = e.Action.ToString();
102      }
103      SetInfoText(info);
104      Application.DoEvents();
105    }
106
107    private void fadeTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) {
108      fadeTimer.Stop();
109      if(InvokeRequired) {
110        Invoke((MethodInvoker)UpdateOpacity);
111      } else {
112        UpdateOpacity();
113      }
114    }
115
116    private void UpdateOpacity() {
117      lock(bigLock) {
118        if(closing) return;
119        if(Opacity > 0.9) {
120          Opacity = 0.9;
121          fadeTimer.Interval = FADE_INTERVAL;
122          fadeTimer.Start();
123        } else if(this.Opacity > 0) {
124          Opacity -= 0.1;
125          fadeTimer.Start();
126        } else {
127          Opacity = 0;
128          Close();
129        }
130      }
131    }
132
133    private void SplashScreen_FormClosing(object sender, FormClosingEventArgs e) {
134      PluginManager.Manager.Action -= new PluginManagerActionEventHandler(this.Manager_Action);
135    }
136
137    private void closeButton_Click(object sender, EventArgs e) {
138      lock(bigLock) {
139        closing = true;
140        if(fadeTimer != null) fadeTimer.Stop();
141        Close();
142      }
143    }
144  }
145}
Note: See TracBrowser for help on using the repository browser.