Skip to content

Commit c5fefd3

Browse files
committed
Added Spacial Reconition Forms
1 parent 8f38796 commit c5fefd3

9 files changed

+6963
-0
lines changed

StroopTest/Views/SpacialRecognitionPages/FormSRConfig.Designer.cs

Lines changed: 852 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 358 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,358 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Drawing;
5+
using System.Data;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using System.Windows.Forms;
10+
using TestPlatform.Models.Tests.SpacialRecognition;
11+
using System.Resources;
12+
using System.Globalization;
13+
using TestPlatform.Controllers;
14+
using TestPlatform.Models;
15+
16+
namespace TestPlatform.Views.SpecialRecognitionPages
17+
{
18+
public partial class FormSRConfig : UserControl
19+
{
20+
private String instructionBoxText;
21+
private ResourceManager LocRM = new ResourceManager("TestPlatform.Resources.Localizations.LocalizedResources", typeof(FormMain).Assembly);
22+
private CultureInfo currentCulture = CultureInfo.CurrentUICulture;
23+
private String editPrgName = "false";
24+
private String prgName = "false";
25+
public String PrgName
26+
{
27+
set
28+
{
29+
this.prgName = value;
30+
}
31+
}
32+
public FormSRConfig(string prgName)
33+
{
34+
this.prgName = prgName;
35+
instructionBoxText = LocRM.GetString("instructionBox", currentCulture);
36+
InitializeComponent();
37+
38+
if (prgName != "false")
39+
{
40+
editPrgName = prgName;
41+
editProgram();
42+
}
43+
}
44+
45+
private void editProgram()
46+
{
47+
SpacialRecognitionProgram editProgram = new SpacialRecognitionProgram(editPrgName);
48+
prgNameTextBox.Text = editProgram.ProgramName;
49+
numExpo.Value = editProgram.NumExpositions;
50+
isRandomExposition.Checked = editProgram.ExpositionRandom;
51+
if (editProgram.getWordListFile() != null) openWordListButton.Text = editProgram.getWordListFile().ListName;
52+
if (editProgram.getColorListFile() != null) openColorListButton.Text = editProgram.getColorListFile().ListName;
53+
if (editProgram.getImageListFile() != null) openImgListButton.Text = editProgram.getImageListFile().ListName;
54+
stimulusExpoTime.Value = editProgram.ExpositionTime;
55+
attemptInterval.Value = editProgram.IntervalTime;
56+
randomAttemptTime.Checked = editProgram.IntervalTimeRandom;
57+
chooseExpoType.SelectedIndex = editProgram.StimuluType;
58+
stimuluSize.Value = (decimal)editProgram.StimuluSize;
59+
fontSizeUpDown.Value = editProgram.FontSize;
60+
stimuluQuantity.Value = editProgram.StimuluCount;
61+
if(editProgram.StimuluSingleColor != "false")
62+
{
63+
wordSingleColor.Text = editProgram.StimuluSingleColor;
64+
WordColorPanel.BackColor = ColorTranslator.FromHtml(editProgram.StimuluSingleColor);
65+
}
66+
stimulusInterval.Value = editProgram.StimuluDelay;
67+
randomStimulusTime.Checked = editProgram.StimuluDelayRandom;
68+
expositonAudioResponse.Checked = editProgram.PlayExpositionSound;
69+
omissionAudioResponse.Checked = editProgram.PlayOmissionSound;
70+
clickAudioResponse.Checked = editProgram.PlayClickSound;
71+
if (editProgram.InstructionText != null)
72+
{
73+
instructionsBox.ForeColor = Color.Black;
74+
instructionsBox.Text = editProgram.InstructionText[0];
75+
for (int i = 1; i < editProgram.InstructionText.Count; i++)
76+
{
77+
instructionsBox.AppendText(Environment.NewLine + editProgram.InstructionText[i]);
78+
}
79+
}
80+
else
81+
{
82+
instructionsBox.Text = "";
83+
}
84+
}
85+
86+
public bool save()
87+
{
88+
saveButton_Click(this, null);
89+
foreach (Control c in this.errorProvider1.ContainerControl.Controls)
90+
{
91+
if (errorProvider1.GetError(c) != "")
92+
{
93+
return false;
94+
}
95+
}
96+
return true;
97+
}
98+
99+
100+
private void chooseExpoType_SelectedIndexChanged(object sender, EventArgs e)
101+
{
102+
if((sender as ComboBox).SelectedIndex == 0) /* Image */
103+
{
104+
openColorListButton.Enabled = false;
105+
openColorListButton.Text = LocRM.GetString("open", currentCulture);
106+
openImgListButton.Enabled = true;
107+
openWordListButton.Enabled = false;
108+
openWordListButton.Text = LocRM.GetString("open", currentCulture);
109+
stimuluSize.Enabled = true;
110+
fontSizeUpDown.Enabled = false;
111+
wordSingleColorButton.Enabled = false;
112+
wordSingleColor.Enabled = false;
113+
wordSingleColorLabel.Enabled = false;
114+
}
115+
else if ((sender as ComboBox).SelectedIndex == 1)
116+
{ /* Word */
117+
openColorListButton.Enabled = false;
118+
openColorListButton.Text = LocRM.GetString("open", currentCulture);
119+
openImgListButton.Enabled = false;
120+
openImgListButton.Text = LocRM.GetString("open", currentCulture);
121+
openWordListButton.Enabled = true;
122+
stimuluSize.Enabled = false;
123+
fontSizeUpDown.Enabled = true;
124+
wordSingleColorButton.Enabled = true;
125+
wordSingleColor.Enabled = true;
126+
wordSingleColorLabel.Enabled = true;
127+
}
128+
else
129+
{ /* Word and color */
130+
openColorListButton.Enabled = true;
131+
openImgListButton.Enabled = false;
132+
openImgListButton.Text = LocRM.GetString("open", currentCulture);
133+
openWordListButton.Enabled = true;
134+
stimuluSize.Enabled = false;
135+
fontSizeUpDown.Enabled = true;
136+
wordSingleColorButton.Enabled = false;
137+
wordSingleColor.Enabled = false;
138+
wordSingleColorLabel.Enabled = false;
139+
}
140+
}
141+
142+
private void cancelButton_Click(object sender, EventArgs e)
143+
{
144+
this.Parent.Controls.Remove(this);
145+
}
146+
147+
void showWarningMessage(Button button)
148+
{
149+
StrList ListFile = null;
150+
if (button.Text != LocRM.GetString("open", currentCulture) && button.Text != LocRM.GetString("createNewList", currentCulture))
151+
{
152+
if (button.Name == "openImgListButton")
153+
{
154+
ListFile = new StrList(button.Text, 0);
155+
}
156+
else if (button.Name == "openWordListButton")
157+
{
158+
ListFile = new StrList(button.Text, 2);
159+
}
160+
if (ListFile != null && ListFile.ListContent.Count < this.numExpo.Value * this.stimuluQuantity.Value)
161+
{
162+
errorProvider2.SetError(button, LocRM.GetString("smallImageList", currentCulture));
163+
saveButton.Enabled = true;
164+
}
165+
else
166+
{
167+
errorProvider2.SetError(button, "");
168+
saveButton.Enabled = true;
169+
}
170+
}
171+
else
172+
{
173+
errorProvider2.SetError(button, "");
174+
saveButton.Enabled = true;
175+
}
176+
}
177+
178+
SpacialRecognitionProgram configureNewProgram()
179+
{
180+
return new SpacialRecognitionProgram(
181+
this.prgNameTextBox.Text, (int)this.numExpo.Value, this.isRandomExposition.Checked,
182+
openWordListButton.Text, openColorListButton.Text, openImgListButton.Text,
183+
(int)this.stimulusExpoTime.Value, (int)this.attemptInterval.Value, this.randomAttemptTime.Checked,
184+
this.chooseExpoType.SelectedIndex, (float)this.stimuluSize.Value, (int)this.fontSizeUpDown.Value,
185+
(int)this.stimuluQuantity.Value, this.wordSingleColor.Text, (int)this.stimulusInterval.Value,
186+
this.randomStimulusTime.Checked, this.expositonAudioResponse.Checked,
187+
this.omissionAudioResponse.Checked, this.clickAudioResponse.Checked);
188+
}
189+
190+
private void saveButton_Click(object sender, EventArgs e)
191+
{
192+
if (saveButton.Enabled)
193+
{
194+
if (this.ValidateChildren(ValidationConstraints.Enabled))
195+
{
196+
bool hasToSave = true;
197+
if (this.ValidateChildren(ValidationConstraints.Enabled))
198+
{
199+
SpacialRecognitionProgram newProgram = configureNewProgram();
200+
201+
if (SpacialRecognitionProgram.ProgramExists(prgNameTextBox.Text))
202+
{
203+
DialogResult dialogResult = MessageBox.Show(LocRM.GetString("programExists", currentCulture), "", MessageBoxButtons.OKCancel);
204+
if (dialogResult == DialogResult.Cancel)
205+
{
206+
hasToSave = false;
207+
MessageBox.Show(LocRM.GetString("programNotSave", currentCulture));
208+
}
209+
}
210+
if (hasToSave && newProgram.saveProgramFile(instructionsBox.Text))
211+
{
212+
MessageBox.Show(LocRM.GetString("programSave", currentCulture));
213+
}
214+
this.Parent.Controls.Remove(this);
215+
}
216+
}
217+
else
218+
{
219+
MessageBox.Show(LocRM.GetString("fieldNotRight", currentCulture));
220+
}
221+
}
222+
else
223+
{
224+
/*do nothing*/
225+
}
226+
}
227+
228+
private void chooseExpoType_Validated(object sender, EventArgs e)
229+
{
230+
this.errorProvider1.SetError(chooseExpoType, "");
231+
}
232+
233+
private void chooseExpoType_Validating(object sender, CancelEventArgs e)
234+
{
235+
string errorMsg;
236+
if (!validExpositionType(out errorMsg))
237+
{
238+
e.Cancel = true;
239+
this.errorProvider1.SetError(chooseExpoType, errorMsg);
240+
}
241+
}
242+
243+
private void wordSingleColorButton_Click(object sender, EventArgs e)
244+
{
245+
string colorCode = ListController.PickColor(this);
246+
WordColorPanel.BackColor = ColorTranslator.FromHtml(colorCode);
247+
wordSingleColor.Text = colorCode;
248+
}
249+
250+
private bool validExpositionType(out string errorMessage)
251+
{
252+
if (this.chooseExpoType.SelectedIndex >= 0 && this.chooseExpoType.SelectedIndex < 3)
253+
{
254+
errorMessage = "";
255+
return true;
256+
}
257+
else
258+
{
259+
errorMessage = LocRM.GetString("expoTypeError", currentCulture);
260+
return false;
261+
}
262+
}
263+
264+
private void openListButton_Validated(object sender, EventArgs e)
265+
{
266+
errorProvider1.SetError((Control)sender, "");
267+
}
268+
269+
private bool ValidList(string buttonText, out string errorMessage)
270+
{
271+
if (buttonText.Length != 0 && buttonText != LocRM.GetString("open", currentCulture))
272+
{
273+
errorMessage = "";
274+
return true;
275+
}
276+
else
277+
{
278+
errorMessage = LocRM.GetString("listError", currentCulture);
279+
return false;
280+
}
281+
}
282+
283+
private void openListButton_Validating(object sender, CancelEventArgs e)
284+
{
285+
if ((sender as Control).Enabled)
286+
{
287+
string errorMsg;
288+
if (ValidList((sender as Control).Text, out errorMsg))
289+
{
290+
//do nothing
291+
}
292+
else
293+
{
294+
e.Cancel = true;
295+
this.errorProvider1.SetError((sender as Control), errorMsg);
296+
}
297+
}
298+
}
299+
300+
private void openWordListButton_Click(object sender, EventArgs e)
301+
{
302+
openWordListButton.Text = ListController.OpenListFile("_words", openWordListButton.Text, "lst");
303+
}
304+
305+
private void openColorsList_Click(object sender, EventArgs e)
306+
{
307+
openColorListButton.Text = ListController.OpenListFile("_color", openColorListButton.Text, "lst");
308+
}
309+
310+
private void openImagesList_Click(object sender, EventArgs e)
311+
{
312+
openImgListButton.Text = ListController.OpenListFile("_image", openImgListButton.Text, "dir");
313+
}
314+
315+
private void prgNameTextBox_Validating(object sender, CancelEventArgs e)
316+
{
317+
string errorMsg;
318+
if (!ValidProgramName(prgNameTextBox.Text, out errorMsg))
319+
{
320+
e.Cancel = true;
321+
this.errorProvider1.SetError(prgNameTextBox, errorMsg);
322+
}
323+
}
324+
325+
private bool ValidProgramName(string pgrName, out string errorMessage)
326+
{
327+
if (pgrName.Length == 0)
328+
{
329+
errorMessage = LocRM.GetString("programNotFilled", currentCulture);
330+
return false;
331+
}
332+
if (!Validations.isAlphanumeric(pgrName))
333+
{
334+
errorMessage = LocRM.GetString("programNotAlphanumeric", currentCulture);
335+
return false;
336+
}
337+
338+
errorMessage = "";
339+
return true;
340+
}
341+
342+
private void prgNameTextBox_Validated(object sender, EventArgs e)
343+
{
344+
this.errorProvider1.SetError(prgNameTextBox, "");
345+
}
346+
347+
private void openListButton_TextChanged(object sender, EventArgs e)
348+
{
349+
showWarningMessage(sender as Button);
350+
}
351+
352+
private void numExpo_ValueChanged(object sender, EventArgs e)
353+
{
354+
showWarningMessage(openWordListButton);
355+
showWarningMessage(openImgListButton);
356+
}
357+
}
358+
}

0 commit comments

Comments
 (0)