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 |
|
---|
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;
|
---|
28 | using HeuristicLab.PluginInfrastructure;
|
---|
29 |
|
---|
30 | namespace HeuristicLab {
|
---|
31 | public partial class SplashScreen : Form {
|
---|
32 | private const int FADE_INTERVAL = 50;
|
---|
33 | private System.Timers.Timer waitTimer;
|
---|
34 | private System.Timers.Timer fadeTimer;
|
---|
35 | private object bigLock = new object();
|
---|
36 |
|
---|
37 | private int displayTime = 1000;
|
---|
38 | public int DisplayTime {
|
---|
39 | get { return (displayTime); }
|
---|
40 | set {
|
---|
41 | if(value > 0) {
|
---|
42 | displayTime = value;
|
---|
43 | }
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | public SplashScreen() {
|
---|
48 | InitializeComponent();
|
---|
49 |
|
---|
50 | Assembly assembly = this.GetType().Assembly;
|
---|
51 | object[] attributes = assembly.GetCustomAttributes(false);
|
---|
52 | string user, company;
|
---|
53 |
|
---|
54 | titleLabel.Text = Application.ProductName;
|
---|
55 | versionLabel.Text = "Version " + Application.ProductVersion;
|
---|
56 | infoLabel.Text = "";
|
---|
57 |
|
---|
58 | foreach(object obj in attributes) {
|
---|
59 | if(obj is AssemblyCopyrightAttribute) {
|
---|
60 | copyrightLabel.Text = "Copyright " + ((AssemblyCopyrightAttribute)obj).Copyright;
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 | try {
|
---|
65 | user = HeuristicLab.Properties.Settings.Default.User;
|
---|
66 | company = HeuristicLab.Properties.Settings.Default.Organization;
|
---|
67 |
|
---|
68 | if((user == null) || (user.Equals(""))) {
|
---|
69 | userNameLabel.Text = "-";
|
---|
70 | } else {
|
---|
71 | userNameLabel.Text = user;
|
---|
72 | }
|
---|
73 |
|
---|
74 | if((company == null) || (company.Equals(""))) {
|
---|
75 | companyLabel.Text = "-";
|
---|
76 | } else {
|
---|
77 | companyLabel.Text = company;
|
---|
78 | }
|
---|
79 | } catch(Exception) {
|
---|
80 | userNameLabel.Text = "-";
|
---|
81 | companyLabel.Text = "-";
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | public SplashScreen(int displayTime, string initialText)
|
---|
86 | : this() {
|
---|
87 | DisplayTime = displayTime;
|
---|
88 | infoLabel.Text = initialText;
|
---|
89 | }
|
---|
90 |
|
---|
91 | private void SetInfoText(string text) {
|
---|
92 | this.Invoke((MethodInvoker)delegate() { infoLabel.Text = text; });
|
---|
93 | }
|
---|
94 |
|
---|
95 | public void Manager_Action(object sender, PluginManagerActionEventArgs e) {
|
---|
96 | lock(bigLock) {
|
---|
97 | if(!this.Disposing && !this.IsDisposed) {
|
---|
98 | if(waitTimer == null) {
|
---|
99 | waitTimer = new System.Timers.Timer();
|
---|
100 | waitTimer.SynchronizingObject = this;
|
---|
101 | waitTimer.Elapsed += new System.Timers.ElapsedEventHandler(waitTimer_Elapsed);
|
---|
102 | }
|
---|
103 | waitTimer.Stop();
|
---|
104 | waitTimer.Interval = DisplayTime;
|
---|
105 | waitTimer.AutoReset = true;
|
---|
106 | string info;
|
---|
107 | if(e.Action == PluginManagerAction.Initializing) info = "Initializing ...";
|
---|
108 | else if(e.Action == PluginManagerAction.InitializingPlugin) info = "Initializing Plugin " + e.Id + " ...";
|
---|
109 | else if(e.Action == PluginManagerAction.InitializedPlugin) info = "Initializing Plugin " + e.Id + " ... Initialized";
|
---|
110 | else if(e.Action == PluginManagerAction.Initialized) info = "Initialization Completed";
|
---|
111 | else {
|
---|
112 | if(e.Id != null) info = e.Action.ToString() + " (" + e.Id + ")";
|
---|
113 | else info = e.Action.ToString();
|
---|
114 | }
|
---|
115 | SetInfoText(info);
|
---|
116 | Application.DoEvents();
|
---|
117 | waitTimer.Start();
|
---|
118 | }
|
---|
119 | }
|
---|
120 | }
|
---|
121 |
|
---|
122 | private void waitTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) {
|
---|
123 | lock(bigLock) {
|
---|
124 | if(!this.Disposing && !this.IsDisposed) {
|
---|
125 | if(fadeTimer == null) {
|
---|
126 | fadeTimer = new System.Timers.Timer();
|
---|
127 | fadeTimer.SynchronizingObject = this;
|
---|
128 | fadeTimer.Elapsed += new System.Timers.ElapsedEventHandler(fadeTimer_Elapsed);
|
---|
129 | fadeTimer.Interval = FADE_INTERVAL;
|
---|
130 | fadeTimer.AutoReset = true;
|
---|
131 | fadeTimer.Start();
|
---|
132 | }
|
---|
133 | }
|
---|
134 | }
|
---|
135 | }
|
---|
136 |
|
---|
137 | private void fadeTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) {
|
---|
138 | lock(bigLock) {
|
---|
139 | if(!this.Disposing && !this.IsDisposed) {
|
---|
140 | fadeTimer.Stop();
|
---|
141 | if(InvokeRequired) {
|
---|
142 | Invoke((MethodInvoker)UpdateOpacity);
|
---|
143 | } else {
|
---|
144 | UpdateOpacity();
|
---|
145 | }
|
---|
146 | }
|
---|
147 | }
|
---|
148 | }
|
---|
149 |
|
---|
150 | private void UpdateOpacity() {
|
---|
151 | if(Opacity > 0.9) {
|
---|
152 | Opacity = 0.9;
|
---|
153 | fadeTimer.Start();
|
---|
154 | } else if(this.Opacity > 0) {
|
---|
155 | Opacity -= 0.1;
|
---|
156 | fadeTimer.Start();
|
---|
157 | } else {
|
---|
158 | Opacity = 0;
|
---|
159 | Close();
|
---|
160 | }
|
---|
161 | }
|
---|
162 |
|
---|
163 | private void SplashScreen_FormClosing(object sender, FormClosingEventArgs e) {
|
---|
164 | PluginManager.Manager.Action -= new PluginManagerActionEventHandler(this.Manager_Action);
|
---|
165 | }
|
---|
166 |
|
---|
167 | private void closeButton_Click(object sender, EventArgs e) {
|
---|
168 | lock(bigLock) {
|
---|
169 | if(fadeTimer != null) fadeTimer.Stop();
|
---|
170 | if(waitTimer != null) waitTimer.Stop();
|
---|
171 | Close();
|
---|
172 | }
|
---|
173 | }
|
---|
174 | }
|
---|
175 | }
|
---|