- Timestamp:
- 11/19/09 14:48:36 (15 years ago)
- Location:
- branches/PluginInfrastructure Refactoring/HeuristicLab.PluginInfrastructure/Starter
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PluginInfrastructure Refactoring/HeuristicLab.PluginInfrastructure/Starter/MainForm.cs
r2504 r2505 47 47 pluginManager = new PluginManager(pluginPath); 48 48 SplashScreen splashScreen = new SplashScreen(pluginManager, 1000, "Loading HeuristicLab..."); 49 splashScreen.Owner = this;50 49 splashScreen.Show(); 51 52 Application.DoEvents();53 this.Enabled = false;54 50 55 51 pluginManager.DiscoverAndCheckPlugins(); … … 98 94 ApplicationDescription app = (ApplicationDescription)applicationsListView.SelectedItems[0].Tag; 99 95 SplashScreen splashScreen = new SplashScreen(pluginManager, 2000, "Loading " + app.Name); 100 splashScreen.Owner = this;101 96 splashScreen.Show(); 102 97 Thread t = new Thread(delegate() { … … 143 138 private void ShowErrorMessageBox(Exception ex) { 144 139 MessageBoxOptions options = RightToLeft == RightToLeft.Yes ? MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading : MessageBoxOptions.DefaultDesktopOnly; 145 MessageBox.Show( this,140 MessageBox.Show(null, 146 141 BuildErrorMessage(ex), 147 142 "Error - " + ex.GetType().Name, -
branches/PluginInfrastructure Refactoring/HeuristicLab.PluginInfrastructure/Starter/SplashScreen.cs
r2504 r2505 26 26 using System.Windows.Forms; 27 27 using System.Reflection; 28 using System.Linq; 28 29 using HeuristicLab.PluginInfrastructure; 29 30 using HeuristicLab.PluginInfrastructure.Manager; … … 32 33 internal partial class SplashScreen : Form { 33 34 private const int FADE_INTERVAL = 50; 34 private System.Timers.Timer fadeTimer; 35 private Timer fadeTimer; 36 // private System.Timers.Timer fadeTimer; 35 37 private int initialInterval; 36 private object bigLock = new object(); 37 private bool closing; 38 // private object bigLock = new object(); 38 39 private PluginManager manager; 39 40 … … 45 46 : this() { 46 47 this.initialInterval = initialInterval; 48 this.manager = manager; 49 50 manager.Action += managerActionEventHandler; 51 47 52 infoLabel.Text = initialText; 48 this.manager = manager;49 manager.Action += managerActionEventHandler;50 Assembly assembly = this.GetType().Assembly;51 object[] attributes = assembly.GetCustomAttributes(false);52 string user, company;53 54 53 titleLabel.Text = Application.ProductName; 55 54 versionLabel.Text = "Version " + Application.ProductVersion; 56 55 infoLabel.Text = ""; 57 56 58 foreach (object obj in attributes) { 59 var attr = obj as AssemblyCopyrightAttribute; 60 if (attr != null) { 61 copyrightLabel.Text = "Copyright " + attr.Copyright; 62 } 63 } 57 var attr = (AssemblyCopyrightAttribute)this.GetType().Assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false).Single(); 58 copyrightLabel.Text = "Copyright " + attr.Copyright; 64 59 65 user = HeuristicLab.PluginInfrastructure.Properties.Settings.Default.User;66 company = HeuristicLab.PluginInfrastructure.Properties.Settings.Default.Organization;60 string user = HeuristicLab.PluginInfrastructure.Properties.Settings.Default.User; 61 string company = HeuristicLab.PluginInfrastructure.Properties.Settings.Default.Organization; 67 62 68 if (string.IsNullOrEmpty(user)) { 69 userNameLabel.Text = "-"; 70 } else { 71 userNameLabel.Text = user; 72 } 63 userNameLabel.Text = string.IsNullOrEmpty(user) ? "-" : user; 64 companyLabel.Text = string.IsNullOrEmpty(company) ? "-" : company; 73 65 74 if (string.IsNullOrEmpty(company)) { 75 companyLabel.Text = "-"; 76 } else { 77 companyLabel.Text = company; 66 fadeTimer = new Timer(); 67 fadeTimer.Tick += fadeTimer_Elapsed; 68 fadeTimer.Interval = initialInterval; 69 } 70 71 private void SetInfoText(string text) { 72 if (InvokeRequired) Invoke((Action<string>)SetInfoText, text); 73 else { 74 infoLabel.Text = text; 78 75 } 79 76 } 80 77 81 private void SetInfoText(string text) {82 this.Invoke((MethodInvoker)delegate() { infoLabel.Text = text; });83 }84 85 78 private void managerActionEventHandler(object sender, PluginInfrastructureEventArgs e) { 86 string info = e.Action + ": " + e.Entity;87 //if (e.Action == PluginManagerAction.Initializing) info = "Initializing ...";88 //else if (e.Action == PluginManagerAction.PluginLoaded) info = "Loaded plugin " + e.Id + " ...";89 //else if (e.Action == PluginManagerAction.Initialized) {90 // info = "Initialization Completed";91 // fadeTimer = new System.Timers.Timer();92 // fadeTimer.SynchronizingObject = this;93 // fadeTimer.Elapsed += new System.Timers.ElapsedEventHandler(fadeTimer_Elapsed);94 // fadeTimer.Interval = initialInterval;95 // fadeTimer.AutoReset = true;96 // fadeTimer.Start();97 //} else {98 // if (e.Id != null) info = e.Action.ToString() + " (" + e.Id + ")";99 // else info = e.Action.ToString();100 //}101 SetInfoText(info);102 Application.DoEvents();103 }104 105 private void fadeTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) {106 fadeTimer.Stop();107 79 if (InvokeRequired) { 108 Invoke(( MethodInvoker)UpdateOpacity);80 Invoke((EventHandler<PluginInfrastructureEventArgs>)managerActionEventHandler, sender, e); 109 81 } else { 110 UpdateOpacity(); 82 ResetFadeTimer(); 83 string info = e.Action + ": " + e.Entity; 84 SetInfoText(info); 85 Application.DoEvents(); // force immediate update of splash screen control 111 86 } 112 87 } 113 88 114 private void UpdateOpacity() { 115 lock (bigLock) { 116 if (closing) return; 117 if (Opacity > 0.9) { 118 Opacity = 0.9; 119 fadeTimer.Interval = FADE_INTERVAL; 120 fadeTimer.Start(); 121 } else if (this.Opacity > 0) { 122 Opacity -= 0.1; 123 fadeTimer.Start(); 124 } else { 125 Opacity = 0; 126 CloseSplashScreen(); 127 } 89 private void ResetFadeTimer() { 90 fadeTimer.Stop(); fadeTimer.Start(); 91 } 92 93 private void fadeTimer_Elapsed(object sender, EventArgs e) { 94 FadeOutAndClose(); 95 } 96 97 private void FadeOutAndClose() { 98 fadeTimer.Stop(); 99 fadeTimer.Interval = FADE_INTERVAL; 100 if (this.Opacity > 0) { 101 Opacity -= 0.1; 102 fadeTimer.Start(); 103 } else { 104 Opacity = 0; 105 fadeTimer.Stop(); 106 fadeTimer.Dispose(); 107 manager.Action -= managerActionEventHandler; // remove event before calling close 108 Close(); 128 109 } 129 110 } 130 111 131 112 private void closeButton_Click(object sender, EventArgs e) { 132 CloseSplashScreen(); 133 } 134 135 private void CloseSplashScreen() { 136 lock (bigLock) { 137 if (!closing) { // just close once 138 closing = true; 139 if (fadeTimer != null) fadeTimer.Stop(); 140 manager.Action -= managerActionEventHandler; // remove event before calling close 141 Application.DoEvents(); // work up all existing events 142 Close(); // close 143 } 144 } 113 FadeOutAndClose(); 145 114 } 146 115 }
Note: See TracChangeset
for help on using the changeset viewer.