Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3291


Ignore:
Timestamp:
04/09/10 02:57:16 (14 years ago)
Author:
swagner
Message:

Loaded samples asynchronously in start page (#964).

Location:
trunk/sources/HeuristicLab.Optimizer/3.3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimizer/3.3/MenuItems/StartPageMenuItem.cs

    r3163 r3291  
    6666        view = new StartPage();
    6767        view.Show();
     68      } else if (view.IsShown) {
     69        view.Hide();
    6870      } else {
    69         view.Close();
     71        view.Show();
    7072      }
    7173    }
  • trunk/sources/HeuristicLab.Optimizer/3.3/StartPage.Designer.cs

    r3202 r3291  
    5050      this.titleLabel = new System.Windows.Forms.Label();
    5151      this.samplesGroupBox = new System.Windows.Forms.GroupBox();
     52      this.loadingPanel = new System.Windows.Forms.Panel();
     53      this.loadingProgressBar = new System.Windows.Forms.ProgressBar();
     54      this.loadingLabel = new System.Windows.Forms.Label();
    5255      this.samplesListView = new System.Windows.Forms.ListView();
    5356      this.nameColumnHeader = new System.Windows.Forms.ColumnHeader();
     
    5558      this.imageList = new System.Windows.Forms.ImageList(this.components);
    5659      this.samplesGroupBox.SuspendLayout();
     60      this.loadingPanel.SuspendLayout();
    5761      this.SuspendLayout();
    5862      //
     
    6266      this.showStartPageCheckBox.AutoSize = true;
    6367      this.showStartPageCheckBox.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
    64       this.showStartPageCheckBox.Location = new System.Drawing.Point(3, 491);
     68      this.showStartPageCheckBox.Location = new System.Drawing.Point(3, 542);
    6569      this.showStartPageCheckBox.Name = "showStartPageCheckBox";
    6670      this.showStartPageCheckBox.Size = new System.Drawing.Size(158, 17);
     
    8185      this.firstStepsRichTextBox.Name = "firstStepsRichTextBox";
    8286      this.firstStepsRichTextBox.ReadOnly = true;
    83       this.firstStepsRichTextBox.Size = new System.Drawing.Size(815, 268);
     87      this.firstStepsRichTextBox.Size = new System.Drawing.Size(760, 319);
    8488      this.firstStepsRichTextBox.TabIndex = 1;
    8589      this.firstStepsRichTextBox.Text = "First Steps";
     
    9397      this.titleLabel.Location = new System.Drawing.Point(3, 0);
    9498      this.titleLabel.Name = "titleLabel";
    95       this.titleLabel.Size = new System.Drawing.Size(815, 30);
     99      this.titleLabel.Size = new System.Drawing.Size(760, 30);
    96100      this.titleLabel.TabIndex = 0;
    97101      this.titleLabel.Text = "Title";
     
    102106      this.samplesGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
    103107                  | System.Windows.Forms.AnchorStyles.Right)));
     108      this.samplesGroupBox.Controls.Add(this.loadingPanel);
    104109      this.samplesGroupBox.Controls.Add(this.samplesListView);
    105       this.samplesGroupBox.Location = new System.Drawing.Point(3, 307);
     110      this.samplesGroupBox.Location = new System.Drawing.Point(3, 358);
    106111      this.samplesGroupBox.Name = "samplesGroupBox";
    107       this.samplesGroupBox.Size = new System.Drawing.Size(815, 178);
     112      this.samplesGroupBox.Size = new System.Drawing.Size(760, 178);
    108113      this.samplesGroupBox.TabIndex = 2;
    109114      this.samplesGroupBox.TabStop = false;
    110115      this.samplesGroupBox.Text = "Samples";
     116      //
     117      // loadingPanel
     118      //
     119      this.loadingPanel.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
     120      this.loadingPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
     121      this.loadingPanel.Controls.Add(this.loadingProgressBar);
     122      this.loadingPanel.Controls.Add(this.loadingLabel);
     123      this.loadingPanel.Enabled = false;
     124      this.loadingPanel.Location = new System.Drawing.Point(205, 74);
     125      this.loadingPanel.Name = "loadingPanel";
     126      this.loadingPanel.Size = new System.Drawing.Size(350, 62);
     127      this.loadingPanel.TabIndex = 1;
     128      //
     129      // loadingProgressBar
     130      //
     131      this.loadingProgressBar.Anchor = System.Windows.Forms.AnchorStyles.None;
     132      this.loadingProgressBar.Location = new System.Drawing.Point(101, 19);
     133      this.loadingProgressBar.Name = "loadingProgressBar";
     134      this.loadingProgressBar.Size = new System.Drawing.Size(229, 23);
     135      this.loadingProgressBar.Step = 1;
     136      this.loadingProgressBar.TabIndex = 1;
     137      //
     138      // loadingLabel
     139      //
     140      this.loadingLabel.Anchor = System.Windows.Forms.AnchorStyles.None;
     141      this.loadingLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
     142      this.loadingLabel.Location = new System.Drawing.Point(12, 19);
     143      this.loadingLabel.Name = "loadingLabel";
     144      this.loadingLabel.Size = new System.Drawing.Size(83, 23);
     145      this.loadingLabel.TabIndex = 0;
     146      this.loadingLabel.Text = "Loading ...";
    111147      //
    112148      // samplesListView
     
    121157      this.samplesListView.Name = "samplesListView";
    122158      this.samplesListView.ShowItemToolTips = true;
    123       this.samplesListView.Size = new System.Drawing.Size(809, 159);
     159      this.samplesListView.Size = new System.Drawing.Size(754, 159);
    124160      this.samplesListView.SmallImageList = this.imageList;
    125161      this.samplesListView.Sorting = System.Windows.Forms.SortOrder.Ascending;
     
    154190      this.Controls.Add(this.showStartPageCheckBox);
    155191      this.Name = "StartPage";
    156       this.Size = new System.Drawing.Size(821, 511);
     192      this.Size = new System.Drawing.Size(766, 562);
    157193      this.samplesGroupBox.ResumeLayout(false);
     194      this.loadingPanel.ResumeLayout(false);
    158195      this.ResumeLayout(false);
    159196      this.PerformLayout();
     
    171208    private System.Windows.Forms.ImageList imageList;
    172209    private System.Windows.Forms.ColumnHeader descriptionColumnHeader;
     210    private System.Windows.Forms.Panel loadingPanel;
     211    private System.Windows.Forms.ProgressBar loadingProgressBar;
     212    private System.Windows.Forms.Label loadingLabel;
    173213  }
    174214}
  • trunk/sources/HeuristicLab.Optimizer/3.3/StartPage.cs

    r3202 r3291  
    2929using HeuristicLab.MainForm;
    3030using HeuristicLab.Persistence.Default.Xml;
     31using System.Threading;
    3132
    3233namespace HeuristicLab.Optimizer {
     
    5455      catch (Exception) { }
    5556
    56       samples = new List<INamedItem>();
     57      samplesListView.Enabled = false;
     58      showStartPageCheckBox.Checked = Properties.Settings.Default.ShowStartPage;
     59      Cursor = Cursors.AppStarting;
     60
     61      ThreadPool.QueueUserWorkItem(new WaitCallback(LoadSamples));
     62    }
     63
     64    protected override void OnClosing(FormClosingEventArgs e) {
     65      base.OnClosing(e);
     66      if (e.CloseReason == CloseReason.UserClosing) {
     67        e.Cancel = true;
     68        this.Hide();
     69      }
     70    }
     71
     72    private void LoadSamples(object state) {
     73      Assembly assembly = Assembly.GetExecutingAssembly();
     74      var samples = assembly.GetManifestResourceNames().Where(x => x.EndsWith(".hl"));
    5775      string path = Path.GetTempFileName();
    58       foreach (string name in assembly.GetManifestResourceNames()) {
    59         if (name.EndsWith(".hl")) {
    60           try {
    61             using (Stream stream = assembly.GetManifestResourceStream(name)) {
    62               WriteStreamToTempFile(stream, path);
    63               IItem item = XmlParser.Deserialize<IItem>(path);
    64               if (item is INamedItem) samples.Add((INamedItem)item);
    65             }
     76      int progress = loadingProgressBar.Maximum / samples.Count();
     77
     78      foreach (string name in samples) {
     79        try {
     80          using (Stream stream = assembly.GetManifestResourceStream(name)) {
     81            WriteStreamToTempFile(stream, path);
     82            IItem item = XmlParser.Deserialize<IItem>(path);
     83            OnSampleLoaded(item as INamedItem, progress);
    6684          }
    67           catch (Exception) { }
     85        }
     86        catch (Exception) { }
     87      }
     88      OnAllSamplesLoaded();
     89    }
     90    private void OnSampleLoaded(INamedItem sample, int progress) {
     91      if (sample != null) {
     92        if (InvokeRequired)
     93          Invoke(new Action<INamedItem, int>(OnSampleLoaded), sample, progress);
     94        else {
     95          ListViewItem item = new ListViewItem(new string[] { sample.Name, sample.Description });
     96          item.ToolTipText = sample.ItemName + " (" + sample.ItemDescription + ")";
     97          samplesListView.SmallImageList.Images.Add(sample.ItemImage);
     98          item.ImageIndex = samplesListView.SmallImageList.Images.Count - 1;
     99          item.Tag = sample;
     100          samplesListView.Items.Add(item);
     101          loadingProgressBar.Value += progress;
    68102        }
    69103      }
    70       foreach (INamedItem sample in samples) {
    71         ListViewItem item = new ListViewItem(new string[] { sample.Name, sample.Description });
    72         item.ToolTipText = sample.ItemName + " (" + sample.ItemDescription + ")";
    73         samplesListView.SmallImageList.Images.Add(sample.ItemImage);
    74         item.ImageIndex = samplesListView.SmallImageList.Images.Count - 1;
    75         item.Tag = sample;
    76         samplesListView.Items.Add(item);
     104    }
     105    private void OnAllSamplesLoaded() {
     106      if (InvokeRequired)
     107        Invoke(new Action(OnAllSamplesLoaded));
     108      else {
     109        samplesListView.Enabled = samplesListView.Items.Count > 0;
     110        if (samplesListView.Items.Count > 0) {
     111          for (int i = 0; i < samplesListView.Columns.Count; i++)
     112            samplesListView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
     113        }
     114        loadingPanel.Visible = false;
     115        Cursor = Cursors.Default;
    77116      }
    78       samplesListView.Enabled = samplesListView.Items.Count > 0;
    79       if (samplesListView.Items.Count > 0) {
    80         for (int i = 0; i < samplesListView.Columns.Count; i++)
    81           samplesListView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
    82       }
    83 
    84       showStartPageCheckBox.Checked = Properties.Settings.Default.ShowStartPage;
    85117    }
    86118
Note: See TracChangeset for help on using the changeset viewer.