* @param source The XML Parser it will read detail data from
*/
public SyncTest(ExtendedElement source, Dimension preferredSize) throws TestException {
super(source, preferredSize);
ExtendedElement main = source.child("timesyncTest");
pageHeaderText = main.textChild("header");
ExtendedElement pause = main.child("pause");
if (pause != null) {
int delay = pause.intAttribute("delay");
m_pauseMessage = pause.text();
if (pause.attribute("unit").equals("pages"))
m_pausePages = delay;
else m_pauseMinutes = delay;
}
backable = main.booleanAttribute("backable");
cycling = main.booleanAttribute("looping");
Vector<String> resultClassVector = new Vector<String>();
resultClassVector.add("Stimuli");
resultClassVector.add("time");
ExtendedElement mouseRecorder = main.child("questions").child("mouseRecorder");
if (mouseRecorder != null) {
myMouseRecorder = new MouseRecorder(mouseRecorder);
resultClassVector.add(mouseRecorder.attribute("name") + "X");
resultClassVector.add(mouseRecorder.attribute("name") + "Y");
} else myMouseRecorder = null;
boolean useStopButton = false;
boolean usePauseButton = false;
ExtendedElement controlsSource = main.child("playControls");
if (controlsSource != null) {
useStopButton = controlsSource.booleanAttribute("stop");
usePauseButton = controlsSource.booleanAttribute("pause");
}
int controls = ControlButtons.CONTROL_PLAY | (useStopButton ? ControlButtons.CONTROL_STOP : 0) | (usePauseButton ? ControlButtons.CONTROL_PAUSE : 0);
int repetitions = main.intAttribute("repetitions");
myFolderParser = new FolderParser(new Dimension(myPage.getPreferredSize().width, (int) (myPage.getPreferredSize().height * 0.6)), 1, repetitions, controls);
if (!myFolderParser.setSource(myStimuliFolder))
throw new TestException(myStimuliFolder.getAbsolutePath() + " Cannot be used as the source folder.");
myFolderParser.setInnerStimuli(0);
visitedPages = new boolean[myFolderParser.getInnerStimuliCount()];
Arrays.fill(visitedPages, false);
m_visitedPageCount = 0;
myRecorderThread = new RecorderThread(this);
ExtendedElement[] udpReceivers = main.child("questions").children("udpReceiver");
if (udpReceivers.length != 0) {
Vector<Integer> handledPorts = new Vector<Integer>();
Vector<Vector<String>> names = new Vector<Vector<String>>();
for (ExtendedElement udp : udpReceivers) {
int port = udp.intAttribute("port");
int portIndex = handledPorts.indexOf(port);
if (portIndex == -1) {
handledPorts.add(port);
names.add(new Vector<String>());
names.get(0).add(udp.attribute("name"));
} else {
names.get(portIndex).add(udp.attribute("name"));
}
}
for (int i = 0; i < handledPorts.size(); ++i) {
UdpReceiver udp = new UdpReceiver(names.get(i).toArray(new String[0]), handledPorts.get(i));
myRecorderThread.add(udp);
udp.start();
resultClassVector.addAll(names.get(i));
}
}
ExtendedElement nameSender = main.child("nameSender");
if (nameSender != null) {
String dest = nameSender.attribute("destination");
int destPort = nameSender.intAttribute("port");
myNameSender = new NameSender(this, dest, destPort);
}
myResultClasses = resultClassVector.toArray(new String[0]);