123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- namespace OINA.Extender.Testharness
- {
- using System;
- using System.Globalization;
- using System.Windows.Forms;
- using OINA.Extender.Acquisition.Ed;
- using OINA.Extender.Data.Ed;
- /// <summary>
- /// Encapsulates an acquiring item
- /// </summary>
- public class AcquisitionItem
- {
- /// <summary>
- /// The parent ListBox
- /// </summary>
- private ListBox parentListBox;
- /// <summary>
- /// Gets the ed spectrum.
- /// </summary>
- /// <value>
- /// The ed spectrum.
- /// </value>
- public IEdSpectrum EdSpectrum { get; private set; }
- /// <summary>
- /// Gets the label.
- /// </summary>
- /// <value>
- /// The label.
- /// </value>
- public string Label
- {
- get
- {
- double progress = (this.CurrentProgress / this.AcquisitionTime) * 100.0;
- if (progress > 0.0)
- {
- return string.Format(CultureInfo.CurrentCulture, @"({0:0.00}%) {1}", progress, this.EdSpectrum.Label);
- }
- else
- {
- return this.EdSpectrum.Label;
- }
- }
- }
- /// <summary>
- /// Gets the aquisition mode.
- /// </summary>
- /// <value>
- /// The aquisition mode.
- /// </value>
- public EdAcquireMode AcquisitionMode { get; private set; }
- /// <summary>
- /// Gets the aquisition time.
- /// </summary>
- /// <value>
- /// The aquisition time.
- /// </value>
- public double AcquisitionTime { get; private set; }
- /// <summary>
- /// Gets the current progress.
- /// </summary>
- /// <value>
- /// The current progress.
- /// </value>
- public double CurrentProgress
- {
- get
- {
- if (this.AcquisitionMode == EdAcquireMode.LiveTime)
- {
- return this.EdSpectrum.LiveTimeSeconds * 1000.0;
- }
- else
- {
- return this.EdSpectrum.RealTimeSeconds * 1000.0;
- }
- }
- }
- /// <summary>
- /// Initializes a new instance of the <see cref="AcquisitionItem" /> class.
- /// </summary>
- /// <param name="edSpectrum">The ed spectrum.</param>
- /// <param name="mode">The mode.</param>
- /// <param name="acquisitionTime">The aquisition time.</param>
- /// <param name="parent">The parent.</param>
- public AcquisitionItem(IEdSpectrum edSpectrum, EdAcquireMode mode, double acquisitionTime, ListBox parent)
- {
- this.parentListBox = parent;
- this.EdSpectrum = edSpectrum;
- this.AcquisitionMode = mode;
- this.AcquisitionTime = acquisitionTime;
- this.EdSpectrum.DataChanged += this.OnEdSpectrumDataChanged;
- }
- /// <summary>
- /// Updates the ListBox item.
- /// </summary>
- /// <param name="listbox">The listbox.</param>
- /// <param name="item">The item.</param>
- private static void UpdateListBoxItem(ListBox listbox, object item)
- {
- int index = listbox.Items.IndexOf(item);
- if (index >= 0)
- {
- int currIndex = listbox.SelectedIndex;
- listbox.BeginUpdate();
- try
- {
- listbox.ClearSelected();
- listbox.Items[index] = item;
- listbox.SelectedIndex = currIndex;
- }
- finally
- {
- listbox.EndUpdate();
- }
- }
- }
- /// <summary>
- /// Called when [ed spectrum data changed].
- /// </summary>
- /// <param name="sender">The sender.</param>
- /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
- public void OnEdSpectrumDataChanged(object sender, EventArgs e)
- {
- if (this.parentListBox.InvokeRequired)
- {
- MethodInvoker updateItem = delegate { UpdateListBoxItem(this.parentListBox, this); };
- this.parentListBox.Invoke(updateItem);
- return;
- }
- }
- }
- }
|