Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2505


Ignore:
Timestamp:
11/19/09 14:48:36 (14 years ago)
Author:
gkronber
Message:

Re-introduced fading out of splash screen. Replaced timer with a Windows.Forms.Timer which doesn't cause so much concurrency related headache (because it uses the EventQueue). #799

Location:
branches/PluginInfrastructure Refactoring/HeuristicLab.PluginInfrastructure/Starter
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/PluginInfrastructure Refactoring/HeuristicLab.PluginInfrastructure/Starter/MainForm.cs

    r2504 r2505  
    4747      pluginManager = new PluginManager(pluginPath);
    4848      SplashScreen splashScreen = new SplashScreen(pluginManager, 1000, "Loading HeuristicLab...");
    49       splashScreen.Owner = this;
    5049      splashScreen.Show();
    51 
    52       Application.DoEvents();
    53       this.Enabled = false;
    5450
    5551      pluginManager.DiscoverAndCheckPlugins();
     
    9894          ApplicationDescription app = (ApplicationDescription)applicationsListView.SelectedItems[0].Tag;
    9995          SplashScreen splashScreen = new SplashScreen(pluginManager, 2000, "Loading " + app.Name);
    100           splashScreen.Owner = this;
    10196          splashScreen.Show();
    10297          Thread t = new Thread(delegate() {
     
    143138    private void ShowErrorMessageBox(Exception ex) {
    144139      MessageBoxOptions options = RightToLeft == RightToLeft.Yes ? MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading : MessageBoxOptions.DefaultDesktopOnly;
    145       MessageBox.Show(this,
     140      MessageBox.Show(null,
    146141         BuildErrorMessage(ex),
    147142         "Error - " + ex.GetType().Name,
  • branches/PluginInfrastructure Refactoring/HeuristicLab.PluginInfrastructure/Starter/SplashScreen.cs

    r2504 r2505  
    2626using System.Windows.Forms;
    2727using System.Reflection;
     28using System.Linq;
    2829using HeuristicLab.PluginInfrastructure;
    2930using HeuristicLab.PluginInfrastructure.Manager;
     
    3233  internal partial class SplashScreen : Form {
    3334    private const int FADE_INTERVAL = 50;
    34     private System.Timers.Timer fadeTimer;
     35    private Timer fadeTimer;
     36    // private System.Timers.Timer fadeTimer;
    3537    private int initialInterval;
    36     private object bigLock = new object();
    37     private bool closing;
     38    //    private object bigLock = new object();
    3839    private PluginManager manager;
    3940
     
    4546      : this() {
    4647      this.initialInterval = initialInterval;
     48      this.manager = manager;
     49
     50      manager.Action += managerActionEventHandler;
     51
    4752      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 
    5453      titleLabel.Text = Application.ProductName;
    5554      versionLabel.Text = "Version " + Application.ProductVersion;
    5655      infoLabel.Text = "";
    5756
    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;
    6459
    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;
    6762
    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;
    7365
    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;
    7875      }
    7976    }
    8077
    81     private void SetInfoText(string text) {
    82       this.Invoke((MethodInvoker)delegate() { infoLabel.Text = text; });
    83     }
    84 
    8578    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();
    10779      if (InvokeRequired) {
    108         Invoke((MethodInvoker)UpdateOpacity);
     80        Invoke((EventHandler<PluginInfrastructureEventArgs>)managerActionEventHandler, sender, e);
    10981      } 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
    11186      }
    11287    }
    11388
    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();
    128109      }
    129110    }
    130111
    131112    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();
    145114    }
    146115  }
Note: See TracChangeset for help on using the changeset viewer.