namespace OINA.Extender.Testharness { using System; using System.Globalization; using System.Windows.Forms; using OINA.Extender.Acquisition.Ed; using OINA.Extender.Data.Ed; /// /// Encapsulates an acquiring item /// public class AcquisitionItem { /// /// The parent ListBox /// private ListBox parentListBox; /// /// Gets the ed spectrum. /// /// /// The ed spectrum. /// public IEdSpectrum EdSpectrum { get; private set; } /// /// Gets the label. /// /// /// The label. /// 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; } } } /// /// Gets the aquisition mode. /// /// /// The aquisition mode. /// public EdAcquireMode AcquisitionMode { get; private set; } /// /// Gets the aquisition time. /// /// /// The aquisition time. /// public double AcquisitionTime { get; private set; } /// /// Gets the current progress. /// /// /// The current progress. /// public double CurrentProgress { get { if (this.AcquisitionMode == EdAcquireMode.LiveTime) { return this.EdSpectrum.LiveTimeSeconds * 1000.0; } else { return this.EdSpectrum.RealTimeSeconds * 1000.0; } } } /// /// Initializes a new instance of the class. /// /// The ed spectrum. /// The mode. /// The aquisition time. /// The parent. 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; } /// /// Updates the ListBox item. /// /// The listbox. /// The item. 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(); } } } /// /// Called when [ed spectrum data changed]. /// /// The sender. /// The instance containing the event data. public void OnEdSpectrumDataChanged(object sender, EventArgs e) { if (this.parentListBox.InvokeRequired) { MethodInvoker updateItem = delegate { UpdateListBoxItem(this.parentListBox, this); }; this.parentListBox.Invoke(updateItem); return; } } } }