private void BuildView() { this.SuspendLayout(); this.StimulusClass1 = this.StimulusClass2 = null; // tab control var tabs = new CustomTabControl() { Dock = DockStyle.Fill }; tabs.DisplayStyleProvider = new TabStyleVisualStudioProvider(tabs) { ShowTabCloser = true }; tabs.TabClosing += (sender, args) => ((CustomTab)args.TabPage).RaiseClosingSafe(args); // start tab var startTab = new CustomTab() { Text = "Classes" }; // columns var cols = GUIUtils.CreateTable(new double[] { .33, .33, .33 }, Direction.Horizontal); // image config var imageConfig = ConfigurationPanel.Create <ImageDisplaySettings>(); // image panel var imagePanel = new ImagePanel() { Dock = DockStyle.Fill, UseNativeSize = false }; bool cycle = true; var rand = new Random(); Func <StimulusClass, string> getImageForClass = stimulusClass => { var tab = this.stimulusClassTabs.First(t => t.StimulusClass == stimulusClass); if (tab.StimulusClass.Stimuli.Count == 0) { return(null); } if (!((ImageDisplaySettings)imageConfig.GetConfiguredObject()).CycleThroughImages) { return((tab.SelectedStimulus ?? tab.StimulusClass.Stimuli.First()).PathOrText); } return(tab.StimulusClass.Stimuli.ElementAt(rand.Next(tab.StimulusClass.Stimuli.Count)).PathOrText); }; Action setImage = () => { imagePanel.ImagePath = this.StimulusClass1 == null ? null : getImageForClass(this.StimulusClass1); imagePanel.SecondaryImagePath = this.StimulusClass2 == null ? null : getImageForClass(this.StimulusClass2); }; setImage(); var timer = new Timer() { Interval = 2500, Enabled = true }; timer.Tick += (sender, args) => { // just return if we're not cycling to avoid flicker if (!cycle && !timer.Enabled) { return; } // if the form is valid, set a new image var activeTextBox = this.FindForm().ActiveControl as TextBox; if (activeTextBox == null || activeTextBox.IsValid()) { setImage(); } }; Action <ImageDisplaySettings> configurePanel = settings => { imagePanel.Configure(settings); if (settings.CycleThroughImages != cycle) { cycle = settings.CycleThroughImages; setImage(); } this.ImageDisplaySettings = settings; }; configurePanel((ImageDisplaySettings)imageConfig.GetConfiguredObject()); imageConfig.PropertyChanged += args => configurePanel((ImageDisplaySettings)imageConfig.GetConfiguredObject()); // class list var classList = new CheckedListBox() { Dock = DockStyle.Fill, AllowDrop = true, CheckOnClick = true }; classList.AddContextMenu(); ItemCheckEventHandler refreshSelectedClasses = (sender, args) => { // get the list of checked indices, including the possibly not-yet-changed item List <int> checkedIndices = classList.CheckedIndices.Cast <int>().ToList(); if (args != null) { if (args.NewValue == CheckState.Checked) { checkedIndices.Add(args.Index); checkedIndices.Sort(); } else { checkedIndices.Remove(args.Index); } } this.StimulusClass1 = this.StimulusClass2 = null; if (checkedIndices.Count > 0) { this.StimulusClass1 = ((StimulusClassTab)classList.Items[checkedIndices[0]]).StimulusClass; if (checkedIndices.Count > 1) { this.StimulusClass2 = ((StimulusClassTab)classList.Items[checkedIndices[1]]).StimulusClass; } } setImage(); }; Action <string> addClass = path => { StimulusClass stimulusClass; if (!StimulusClass.TryLoad(path, out stimulusClass)) { GUIUtils.Alert("Failed to load stimulus class from " + path, MessageBoxIcon.Error); } else if (this.stimulusClassTabs .Count(tp => tp.StimulusClass.SourceFolder.Equals(path, StringComparison.OrdinalIgnoreCase) || tp.StimulusClass.SavePath.Equals(path, StringComparison.OrdinalIgnoreCase)) > 0) { GUIUtils.Alert("A class from " + path + " is already loaded!", MessageBoxIcon.Exclamation); } else { // get a unique marker unless this was the load of a saved class if (!File.Exists(stimulusClass.SavePath)) { stimulusClass.Settings.Marker = this.stimulusClassTabs.Count == 0 ? 1 : this.stimulusClassTabs.Max(s => s.StimulusClass.Settings.Marker) + 1; } var classTab = new StimulusClassTab(stimulusClass); classTab.TextChanged += (sender, args) => classList.Invalidate(); classTab.Closing += (sender, args) => { this.stimulusClassTabs.Remove(classTab); classList.Items.Remove(classTab); refreshSelectedClasses(classList, null); }; this.stimulusClassTabs.Add(classTab); tabs.TabPages.Add(classTab); classList.Items.Add(classTab, true); refreshSelectedClasses(classList, null); } }; classList.ItemCheck += refreshSelectedClasses; classList.DragEnter += (sender, args) => { if (args.Data.GetDataPresent(DataFormats.FileDrop, false) && ((string[])args.Data.GetData(DataFormats.FileDrop)).Where(StimulusClass.IsValidLoadPath).Count() > 0) { args.Effect = DragDropEffects.All; } }; classList.DragDrop += (sender, args) => { // check that the form is in a valid state var activeTextBox = this.FindForm().ActiveControl as TextBox; if (activeTextBox != null && !activeTextBox.IsValid()) { GUIUtils.Alert("All entered data must be valid in order for drag and drop to be enabled", MessageBoxIcon.Error); return; } string[] data = (string[])args.Data.GetData(DataFormats.FileDrop); foreach (string path in data.Where(StimulusClass.IsValidLoadPath)) { addClass(path); } }; // button table var buttonTable = GUIUtils.CreateButtonTable(Direction.Horizontal, DockStyle.Bottom, GUIUtils.CreateFlatButton("New", b => { if (this.folderDialog.ShowDialog() == DialogResult.OK) { addClass(this.folderDialog.SelectedPath); } }, startTab.ToolTip, "Create a new stimulus class from a folder of images"), GUIUtils.CreateFlatButton("Load", b => { if (this.fileDialog.ShowDialog() == DialogResult.OK) { addClass(this.fileDialog.FileName); } }, startTab.ToolTip, "Load a previously saved stimulus class settings file")); startTab.Closing += (sender, args) => { args.Cancel = true; if (GUIUtils.IsUserSure("Reset stimulus classes?")) { this.stimulusClassTabs.Clear(); this.Controls.Remove(tabs); tabs.Dispose(); timer.Enabled = false; timer.Dispose(); this.BuildView(); this.OnSizeChanged(EventArgs.Empty); } }; // add all controls // left column var panel = new Panel() { Dock = DockStyle.Fill }; panel.Controls.Add(classList); panel.Controls.Add(buttonTable); cols.Controls.Add(panel, 0, 0); // middle column cols.Controls.Add(imageConfig, 1, 0); // right column cols.Controls.Add(imagePanel, 2, 0); startTab.Controls.Add(cols); tabs.Controls.Add(startTab); this.Controls.Add(tabs); this.ResumeLayout(false); }
/// <summary> /// Builds the application view for the Adaptive Application /// </summary> public void BuildAdaptiveView() { this.SuspendLayout(); this.Text = GUIUtils.Strings.APP_NAME; this.Size = new System.Drawing.Size(1500, 750); //Settings panels var config = ConfigurationPanel.Create <AdaptiveSettings>(); //var artifactConfig = ConfigurationPanel.Create<ArtifactDetectionSettings>(); var stimulipanel = new AdaptiveSelectorPanel() { Dock = DockStyle.Fill }; // classifier settings var classifierPanel = new ClassificationSchemePanel() { Dock = DockStyle.Fill }; //Headset Connected? EmotivStatusCheckerPanel statusChecker = new EmotivStatusCheckerPanel() { Dock = DockStyle.Fill }; // start button var startButton = GUIUtils.CreateFlatButton("Start Experiment", b => { var settings = (AdaptiveSettings)config.GetConfiguredObject(); //settings.ArtifactDetectionSettings = (ArtifactDetectionSettings)artifactConfig.GetConfiguredObject(); settings.ArtifactDetectionSettings = (ArtifactDetectionSettings)classifierPanel.ArtifactDetectionSettings; var test = this.ReadAdaptStimuli(stimulipanel.TestFile); var ans = this.ReadAdaptStimuli(stimulipanel.AnsFile); var presentation = this.ReadCompetitionStimuli(stimulipanel.PresentationFile); var class1 = this.ReadCompetitionStimuli(stimulipanel.Class1File); var class2 = this.ReadCompetitionStimuli(stimulipanel.Class2File); //Make study-test pairs for practice phase RandomizedQueue <MCAEmotiv.GUI.Adaptive.StudyTestPair> stp = new RandomizedQueue <MCAEmotiv.GUI.Adaptive.StudyTestPair>(); for (int i = 0; i < test.Count; i++) { stp.Add(new MCAEmotiv.GUI.Adaptive.StudyTestPair(test[i], ans[i], i)); } //To Do: Add a dialog box so that the user knows whether the headset is connected IEEGDataSource dataSource; if (statusChecker.HeadsetConnected) { dataSource = EmotivDataSource.Instance; } else { dataSource = new MockEEGDataSource(); } var classifiers = classifierPanel.SelectedClassifiers; this.Animate(new AdaptiveProvider(stp, presentation, class1, class2, settings, dataSource, classifiers.Where(c => c.Settings.FeatureCount > 0).ToIArray())); }); //Dialog boxes for saving and loading experiment settings var saveDialog = new SaveFileDialog() { Title = "Save experiment settings", Filter = "Experiment settings files|*.adaptsettings", InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) }; var openDialog = new OpenFileDialog() { Title = "Select the saved experiment settings (.adaptsettings) file", Filter = "Experiment settings files|*.adaptsettings", InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), Multiselect = false }; // button table for saving and loading experiment settings var buttonTable = GUIUtils.CreateButtonTable(Direction.Horizontal, DockStyle.Fill, GUIUtils.CreateFlatButton("Save", b => { var settings = (AdaptiveSettings)config.GetConfiguredObject(); settings.TestFile = stimulipanel.TestFile; settings.AnsFile = stimulipanel.AnsFile; settings.PresentationFile = stimulipanel.PresentationFile; settings.Class1File = stimulipanel.Class1File; settings.Class2File = stimulipanel.Class2File; //settings.ArtifactDetectionSettings = (ArtifactDetectionSettings)artifactConfig.GetConfiguredObject(); settings.ArtifactDetectionSettings = (ArtifactDetectionSettings)classifierPanel.ArtifactDetectionSettings; //ISSUE HERE //settings.ClassificationSettings = (ClassificationScheme) classifierPanel saveDialog.FileName = string.IsNullOrWhiteSpace(settings.ExperimentName) ? "my experiment" : settings.ExperimentName; if (saveDialog.ShowDialog() != DialogResult.OK) { return; } bool saved = settings.TrySerializeToFile(saveDialog.FileName); GUIUtils.Alert((saved ? "Saved" : "Failed to save") + " experiment info to " + saveDialog.FileName, (saved ? MessageBoxIcon.Information : MessageBoxIcon.Error)); string directory = Path.GetDirectoryName(saveDialog.FileName); if (Directory.Exists(directory)) { saveDialog.InitialDirectory = directory; } }, null, "Save experiment configuration information"), GUIUtils.CreateFlatButton("Load", b => { if (openDialog.ShowDialog() != DialogResult.OK) { return; } AdaptiveSettings settings; if (Utils.TryDeserializeFile(openDialog.FileName, out settings)) { config.SetConfiguredObject(settings); stimulipanel.TestFile = settings.TestFile; stimulipanel.AnsFile = settings.AnsFile; stimulipanel.PresentationFile = settings.PresentationFile; stimulipanel.Class1File = settings.Class1File; stimulipanel.Class2File = settings.Class2File; //NEED TO DO EACH CLASSIFIERPANEL PROPERTY ONE BY ONE :( //artifactConfig.SetConfiguredObject(settings.ArtifactDetectionSettings); //classifierPanel.SetConfiguredObject(settings.ArtifactDetectionSettings); } else { GUIUtils.Alert("Failed to load experiment info from " + openDialog.FileName, MessageBoxIcon.Error); } }, null, "Load a previously saved experiment settings file")); //Put together the GUI var rows = GUIUtils.CreateTable(new[] { .5, .35, .15 }, Direction.Vertical); var col1 = GUIUtils.CreateTable(new[] { .5, .5 }, Direction.Horizontal); var col2 = GUIUtils.CreateTable(new[] { .5, .5 }, Direction.Horizontal); var col3 = GUIUtils.CreateTable(new[] { .5, .5 }, Direction.Horizontal); //col2.Controls.Add(artifactConfig, 1, 0); col1.Controls.Add(startButton, 1, 0); col1.Controls.Add(statusChecker, 0, 0); col2.Controls.Add(config, 0, 0); col2.Controls.Add(classifierPanel, 1, 0); col3.Controls.Add(stimulipanel, 1, 0); col3.Controls.Add(buttonTable, 0, 0); rows.Controls.Add(col3, 0, 1); rows.Controls.Add(col1, 0, 2); rows.Controls.Add(col2, 0, 0); this.Controls.Add(rows); this.ResumeLayout(false); }
/// <summary> /// Builds the application view for the competition experiment /// </summary> public void BuildCompetitionExperimenterView() { this.SuspendLayout(); this.Text = GUIUtils.Strings.APP_NAME; this.Size = new System.Drawing.Size(1500, 750); //Settings panel var config = ConfigurationPanel.Create <CompetitionExperimentSettings>(); var artifactConfig = ConfigurationPanel.Create <ArtifactDetectionSettings>(); var stimulipanel = new CompetitionClassSelectorPanel() { Dock = DockStyle.Fill }; //Headset Connected? EmotivStatusCheckerPanel statusChecker = new EmotivStatusCheckerPanel() { Dock = DockStyle.Fill }; // start button var startButton = GUIUtils.CreateFlatButton("Start Experiment", b => { var settings = (CompetitionExperimentSettings)config.GetConfiguredObject(); settings.ArtifactDetectionSettings = (ArtifactDetectionSettings)artifactConfig.GetConfiguredObject(); var presentation = this.ReadCompetitionStimuli(stimulipanel.PresentationFile); var class1 = this.ReadCompetitionStimuli(stimulipanel.Class1File); var class2 = this.ReadCompetitionStimuli(stimulipanel.Class2File); if (presentation == null) { return; } //To Do: Add a dialog box so that the user knows whether the headset is connected IEEGDataSource dataSource; if (statusChecker.HeadsetConnected) { dataSource = EmotivDataSource.Instance; } else { dataSource = new MockEEGDataSource(); } this.Animate(new CompetitionExperimentProvider(presentation, class1, class2, settings, dataSource)); }); //Dialog boxes for saving and loading experiment settings var saveDialog = new SaveFileDialog() { Title = "Save experiment settings", Filter = "Experiment settings files|*.compexpsettings", InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) }; var openDialog = new OpenFileDialog() { Title = "Select the saved experiment settings (.compexpsettings) file", Filter = "Experiment settings files|*.compexpsettings", InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), Multiselect = false }; // button table for saving and loading experiment settings var buttonTable = GUIUtils.CreateButtonTable(Direction.Horizontal, DockStyle.Fill, GUIUtils.CreateFlatButton("Save", b => { var settings = (CompetitionExperimentSettings)config.GetConfiguredObject(); settings.PresentationFile = stimulipanel.PresentationFile; settings.Class1File = stimulipanel.Class1File; settings.Class2File = stimulipanel.Class2File; settings.ArtifactDetectionSettings = (ArtifactDetectionSettings)artifactConfig.GetConfiguredObject(); saveDialog.FileName = string.IsNullOrWhiteSpace(settings.ExperimentName) ? "my experiment" : settings.ExperimentName; if (saveDialog.ShowDialog() != DialogResult.OK) { return; } bool saved = settings.TrySerializeToFile(saveDialog.FileName); GUIUtils.Alert((saved ? "Saved" : "Failed to save") + " experiment info to " + saveDialog.FileName, (saved ? MessageBoxIcon.Information : MessageBoxIcon.Error)); string directory = Path.GetDirectoryName(saveDialog.FileName); if (Directory.Exists(directory)) { saveDialog.InitialDirectory = directory; } }, null, "Save experiment configuration information"), GUIUtils.CreateFlatButton("Load", b => { if (openDialog.ShowDialog() != DialogResult.OK) { return; } CompetitionExperimentSettings settings; if (Utils.TryDeserializeFile(openDialog.FileName, out settings)) { config.SetConfiguredObject(settings); stimulipanel.PresentationFile = settings.PresentationFile; stimulipanel.Class1File = settings.Class1File; stimulipanel.Class2File = settings.Class2File; artifactConfig.SetConfiguredObject(settings.ArtifactDetectionSettings); } else { GUIUtils.Alert("Failed to load experiment info from " + openDialog.FileName, MessageBoxIcon.Error); } }, null, "Load a previously saved experiment settings file")); //Put together the GUI var rows = GUIUtils.CreateTable(new[] { .5, .2, .3 }, Direction.Vertical); var col1 = GUIUtils.CreateTable(new[] { .5, .5 }, Direction.Horizontal); var col2 = GUIUtils.CreateTable(new[] { .5, .5 }, Direction.Horizontal); var col3 = GUIUtils.CreateTable(new[] { .5, .5 }, Direction.Horizontal); col2.Controls.Add(artifactConfig, 1, 0); col1.Controls.Add(startButton, 1, 0); col1.Controls.Add(statusChecker, 0, 0); col2.Controls.Add(config, 0, 0); col3.Controls.Add(stimulipanel, 1, 0); col3.Controls.Add(buttonTable, 0, 0); rows.Controls.Add(col3, 0, 1); rows.Controls.Add(col1, 0, 2); rows.Controls.Add(col2, 0, 0); this.Controls.Add(rows); this.ResumeLayout(false); }
/// <summary> /// Builds the application view for the User Control Vocabulary Application /// </summary> public void BuildUserCtrlView() { this.SuspendLayout(); this.Text = GUIUtils.Strings.APP_NAME; this.Size = new System.Drawing.Size(1500, 750); //Settings panel var config = ConfigurationPanel.Create <UserCtrlSettings>(); var stimulipanel = new UserCtrlSelectorPanel() { Dock = DockStyle.Fill }; // start button var startButton = GUIUtils.CreateFlatButton("Start Experiment", b => { var settings = (UserCtrlSettings)config.GetConfiguredObject(); var presentation = this.ReadUserStimuli(stimulipanel.PresentationFile); var test = this.ReadUserStimuli(stimulipanel.TestFile); var ans = this.ReadUserStimuli(stimulipanel.AnsFile); var comp = this.ReadCompetitionStimuli(stimulipanel.CompFile); var class1 = this.ReadCompetitionStimuli(stimulipanel.Class1File); var class2 = this.ReadCompetitionStimuli(stimulipanel.Class2File); //Make study-test pairs for the practice phase RandomizedQueue <MCAEmotiv.GUI.UserControlVocab.StudyTestPair> stp = new RandomizedQueue <MCAEmotiv.GUI.UserControlVocab.StudyTestPair>(); for (int i = 0; i < test.Count; i++) { stp.Add(new MCAEmotiv.GUI.UserControlVocab.StudyTestPair(test[i], ans[i], i)); } if (presentation == null) { return; } this.Animate(new UserCtrlProvider(presentation, comp, class1, class2, stp, settings)); }); //Dialog boxes for saving and loading experiment settings var saveDialog = new SaveFileDialog() { Title = "Save experiment settings", Filter = "Experiment settings files|*.usersettings", InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) }; var openDialog = new OpenFileDialog() { Title = "Select the saved experiment settings (.usersettings) file", Filter = "Experiment settings files|*.usersettings", InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), Multiselect = false }; // button table for saving and loading experiment settings var buttonTable = GUIUtils.CreateButtonTable(Direction.Horizontal, DockStyle.Fill, GUIUtils.CreateFlatButton("Save", b => { var settings = (UserCtrlSettings)config.GetConfiguredObject(); settings.PresentationFile = stimulipanel.PresentationFile; settings.TestFile = stimulipanel.TestFile; settings.AnsFile = stimulipanel.AnsFile; settings.CompFile = stimulipanel.CompFile; settings.Class1File = stimulipanel.Class1File; settings.Class2File = stimulipanel.Class2File; saveDialog.FileName = string.IsNullOrWhiteSpace(settings.ExperimentName) ? "my experiment" : settings.ExperimentName; if (saveDialog.ShowDialog() != DialogResult.OK) { return; } bool saved = settings.TrySerializeToFile(saveDialog.FileName); GUIUtils.Alert((saved ? "Saved" : "Failed to save") + " experiment info to " + saveDialog.FileName, (saved ? MessageBoxIcon.Information : MessageBoxIcon.Error)); string directory = Path.GetDirectoryName(saveDialog.FileName); if (Directory.Exists(directory)) { saveDialog.InitialDirectory = directory; } }, null, "Save experiment configuration information"), GUIUtils.CreateFlatButton("Load", b => { if (openDialog.ShowDialog() != DialogResult.OK) { return; } UserCtrlSettings settings; if (Utils.TryDeserializeFile(openDialog.FileName, out settings)) { config.SetConfiguredObject(settings); stimulipanel.PresentationFile = settings.PresentationFile; stimulipanel.TestFile = settings.TestFile; stimulipanel.AnsFile = settings.AnsFile; stimulipanel.CompFile = settings.CompFile; stimulipanel.Class1File = settings.Class1File; stimulipanel.Class2File = settings.Class2File; } else { GUIUtils.Alert("Failed to load experiment info from " + openDialog.FileName, MessageBoxIcon.Error); } }, null, "Load a previously saved experiment settings file")); //Put together the GUI var rows = GUIUtils.CreateTable(new[] { .5, .35, .15 }, Direction.Vertical); var col3 = GUIUtils.CreateTable(new[] { .5, .5 }, Direction.Horizontal); col3.Controls.Add(stimulipanel, 1, 0); col3.Controls.Add(buttonTable, 0, 0); rows.Controls.Add(col3, 0, 1); rows.Controls.Add(startButton, 0, 2); rows.Controls.Add(config, 0, 0); this.Controls.Add(rows); this.ResumeLayout(false); }
/// <summary> /// Builds the application view for the False Adaptive Application /// </summary> public void BuildFAdaptView() { this.SuspendLayout(); this.Text = GUIUtils.Strings.APP_NAME; this.Size = new System.Drawing.Size(1500, 750); //Settings panels var config = ConfigurationPanel.Create <FalseAdaptSettings>(); var artifactConfig = ConfigurationPanel.Create <ArtifactDetectionSettings>(); var stimulipanel = new FalseAdaptSelectorPanel() { Dock = DockStyle.Fill }; //Headset Connected? EmotivStatusCheckerPanel statusChecker = new EmotivStatusCheckerPanel() { Dock = DockStyle.Fill }; // start button var startButton = GUIUtils.CreateFlatButton("Start Experiment", b => { var settings = (FalseAdaptSettings)config.GetConfiguredObject(); settings.ArtifactDetectionSettings = (ArtifactDetectionSettings)artifactConfig.GetConfiguredObject(); var presentation = this.ReadFAStimuli(stimulipanel.PresentationFile); var comp = this.ReadCompetitionStimuli(stimulipanel.CompFile); var class1 = this.ReadCompetitionStimuli(stimulipanel.Class1File); var class2 = this.ReadCompetitionStimuli(stimulipanel.Class2File); var study = this.ReadUserStimuli(stimulipanel.StudyFile); //Make study-test pairs for practice phase RandomizedQueue <StudyTestTuple> stt = new RandomizedQueue <StudyTestTuple>(); for (int i = 0; i < presentation.Count; i++) { if (presentation[i] == "5") { stt.Add(new StudyTestTuple(presentation[i + 1], presentation[i + 1], true)); } if (presentation[i] == "7") { stt.Add(new StudyTestTuple(presentation[i + 1], presentation[i + 2], false)); } } this.Animate(new FalseAdaptProvider(stt, comp, class1, class2, study, settings)); }); //Dialog boxes for saving and loading experiment settings var saveDialog = new SaveFileDialog() { Title = "Save experiment settings", Filter = "Experiment settings files|*.fasettings", InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) }; var openDialog = new OpenFileDialog() { Title = "Select the saved experiment settings (.fasettings) file", Filter = "Experiment settings files|*.fasettings", InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), Multiselect = false }; // button table for saving and loading experiment settings var buttonTable = GUIUtils.CreateButtonTable(Direction.Horizontal, DockStyle.Fill, GUIUtils.CreateFlatButton("Save", b => { var settings = (FalseAdaptSettings)config.GetConfiguredObject(); settings.PresentationFile = stimulipanel.PresentationFile; settings.StudyFile = stimulipanel.StudyFile; settings.CompFile = stimulipanel.CompFile; settings.Class1File = stimulipanel.Class1File; settings.Class2File = stimulipanel.Class2File; settings.ArtifactDetectionSettings = (ArtifactDetectionSettings)artifactConfig.GetConfiguredObject(); saveDialog.FileName = string.IsNullOrWhiteSpace(settings.ExperimentName) ? "my experiment" : settings.ExperimentName; if (saveDialog.ShowDialog() != DialogResult.OK) { return; } bool saved = settings.TrySerializeToFile(saveDialog.FileName); GUIUtils.Alert((saved ? "Saved" : "Failed to save") + " experiment info to " + saveDialog.FileName, (saved ? MessageBoxIcon.Information : MessageBoxIcon.Error)); string directory = Path.GetDirectoryName(saveDialog.FileName); if (Directory.Exists(directory)) { saveDialog.InitialDirectory = directory; } }, null, "Save experiment configuration information"), GUIUtils.CreateFlatButton("Load", b => { if (openDialog.ShowDialog() != DialogResult.OK) { return; } FalseAdaptSettings settings; if (Utils.TryDeserializeFile(openDialog.FileName, out settings)) { config.SetConfiguredObject(settings); stimulipanel.PresentationFile = settings.PresentationFile; stimulipanel.StudyFile = settings.StudyFile; stimulipanel.CompFile = settings.CompFile; stimulipanel.Class1File = settings.Class1File; stimulipanel.Class2File = settings.Class2File; artifactConfig.SetConfiguredObject(settings.ArtifactDetectionSettings); } else { GUIUtils.Alert("Failed to load experiment info from " + openDialog.FileName, MessageBoxIcon.Error); } }, null, "Load a previously saved experiment settings file")); //Put together the GUI var rows = GUIUtils.CreateTable(new[] { .5, .3, .2 }, Direction.Vertical); var col1 = GUIUtils.CreateTable(new[] { .5, .5 }, Direction.Horizontal); var col2 = GUIUtils.CreateTable(new[] { .5, .5 }, Direction.Horizontal); var col3 = GUIUtils.CreateTable(new[] { .5, .5 }, Direction.Horizontal); col2.Controls.Add(artifactConfig, 1, 0); col1.Controls.Add(startButton, 1, 0); col1.Controls.Add(statusChecker, 0, 0); col2.Controls.Add(config, 0, 0); col3.Controls.Add(stimulipanel, 1, 0); col3.Controls.Add(buttonTable, 0, 0); rows.Controls.Add(col3, 0, 1); rows.Controls.Add(col1, 0, 2); rows.Controls.Add(col2, 0, 0); this.Controls.Add(rows); this.ResumeLayout(false); }
private void BuildView() { // config panel var config = ConfigurationPanel.Create <ExperimentSettings>(); // output folder var outputLabel = "Data Output Folder".ToLabel(DockStyle.Bottom); var outputLink = new LinkLabel() { Text = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), Dock = DockStyle.Bottom }; outputLink.Click += (sender, args) => { if (this.folderDialog.ShowDialog() != DialogResult.OK) { return; } outputLink.Text = this.folderDialog.SelectedPath; }; this.getExperimentSettings = () => { var settings = (ExperimentSettings)config.GetConfiguredObject(); settings.OutputFolder = outputLink.Text; return(settings); }; // button table var buttonTable = GUIUtils.CreateButtonTable(Direction.Horizontal, DockStyle.Bottom, GUIUtils.CreateFlatButton("Save", b => { var settings = this.ExperimentSettings; this.saveDialog.FileName = string.IsNullOrWhiteSpace(settings.ExperimentName) ? "my experiment" : settings.ExperimentName; if (this.saveDialog.ShowDialog() != DialogResult.OK) { return; } bool saved = settings.TrySerializeToFile(this.saveDialog.FileName); GUIUtils.Alert((saved ? "Saved" : "Failed to save") + " experiment info to " + this.saveDialog.FileName, (saved ? MessageBoxIcon.Information : MessageBoxIcon.Error)); string directory = Path.GetDirectoryName(this.saveDialog.FileName); if (Directory.Exists(directory)) { this.saveDialog.InitialDirectory = directory; } }, this.toolTip, "Save experiment configuration information"), GUIUtils.CreateFlatButton("Load", b => { if (this.openDialog.ShowDialog() != DialogResult.OK) { return; } ExperimentSettings settings; foreach (var path in this.openDialog.FileNames) { if (Utils.TryDeserializeFile(this.openDialog.FileName, out settings)) { config.SetConfiguredObject(settings); } else { GUIUtils.Alert("Failed to load experiment info from " + path, MessageBoxIcon.Error); } } }, this.toolTip, "Load a previously saved experiment settings file")); // add all controls this.Controls.Add(config); this.Controls.Add(outputLabel); this.Controls.Add(outputLink); this.Controls.Add(buttonTable); }