diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/org/ilintar/study/MainScreenController.java b/src/org/ilintar/study/MainScreenController.java
index 3a473fd..70854a5 100644
--- a/src/org/ilintar/study/MainScreenController.java
+++ b/src/org/ilintar/study/MainScreenController.java
@@ -1,5 +1,13 @@
package org.ilintar.study;
+import javafx.event.ActionEvent;
+import javafx.fxml.FXML;
+import javafx.scene.control.Button;
+import javafx.scene.layout.AnchorPane;
+import org.ilintar.study.question.*;
+import org.ilintar.study.question.event.QuestionAnsweredEvent;
+import org.ilintar.study.question.event.QuestionAnsweredEventListener;
+
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@@ -9,14 +17,7 @@
import java.util.List;
import java.util.Map;
-import org.ilintar.study.question.QuestionFactory;
-import org.ilintar.study.question.RadioQuestionFactory;
-
-import javafx.fxml.FXML;
-import javafx.scene.Node;
-import javafx.scene.layout.AnchorPane;
-
-public class MainScreenController {
+public class MainScreenController implements QuestionAnsweredEventListener {
protected static Map factoryMap;
@@ -25,18 +26,42 @@ public class MainScreenController {
factoryMap.put("radio", new RadioQuestionFactory());
}
- @FXML AnchorPane mainStudy;
+ //Storage of already answered & gathered questions from current study;
+ //questions are stored as their IDs to save memory; answers are stored as Answer objects.
+ private Map collectedAnswers = new HashMap<>();
+ @FXML AnchorPane mainStudy;
+
+ //Just a self-explanatory dummy variable for startStudy():
+ int questionCounter = 0;
+ //AND NOW FOR STH COMPLETELY DIFFERENT:
@FXML public void startStudy() {
+ //Clear the pane:
mainStudy.getChildren().clear();
- Node questionComponent = readQuestionFromFile(0, getClass().getResourceAsStream("StudyDetails.sqf"));
- mainStudy.getChildren().add(questionComponent);
+ //Create a new Question object basing on the input file:
+ RadioQuestion createdQuestion = (RadioQuestion) readQuestionFromFile(questionCounter,
+ getClass().getResourceAsStream("StudyDetails.sqf"));
+ //Add the question's graphical component to the pane:
+ mainStudy.getChildren().add(createdQuestion.getRenderedQuestion());
+ //Create new button for question ending:
+ Button questionAnsweredButton = new Button("Zakończ pytanie");
+ //Add the button to the pane:
+ mainStudy.getChildren().add(questionAnsweredButton);
+ //Set button's reaction:
+ questionAnsweredButton.setOnAction((event) -> {
+ mainStudy.getChildren().remove(createdQuestion);
+ questionCounter++;
+ RadioQuestion tempQuestion = (RadioQuestion) readQuestionFromFile(questionCounter,
+ getClass().getResourceAsStream("StudyDetails.sqf"));
+ mainStudy.getChildren().add(tempQuestion.getRenderedQuestion());
+ });
}
- private Node readQuestionFromFile(int i, InputStream resourceAsStream) {
+ //The .sqf parser:
+ private Question readQuestionFromFile(int questionCounter, InputStream resourceAsStream) {
BufferedReader br = new BufferedReader(new InputStreamReader(resourceAsStream));
String currentLine;
- int which = 0;
+ int counter = 0;
List questionLines = new ArrayList<>();
boolean readingQuestions = false;
String questionType = null;
@@ -46,7 +71,7 @@ private Node readQuestionFromFile(int i, InputStream resourceAsStream) {
if (readingQuestions) {
throw new IllegalArgumentException("Invalid file format: StartQuestion without EndQuestion");
}
- if (which == i) {
+ if (counter == questionCounter) {
readingQuestions = true;
String[] split = currentLine.split(" ");
if (split.length > 1) {
@@ -59,7 +84,7 @@ private Node readQuestionFromFile(int i, InputStream resourceAsStream) {
throw new IllegalArgumentException("Invalid file format: StartQuestion type=");
}
} else {
- which++;
+ counter++;
}
} else {
if (readingQuestions) {
@@ -80,5 +105,11 @@ private Node readQuestionFromFile(int i, InputStream resourceAsStream) {
}
return null;
}
+
+ //Method from the QuestionAnsweredListener interface.
+ //Puts the current question & its answer into the collectedAnswers HashMap and reads the next question.
+ public void handleQuestionAnsweredEvent(QuestionAnsweredEvent e) {
+ this.collectedAnswers.put(e.getQuestion().getId(), e.getAnswer());
+ }
}
diff --git a/src/org/ilintar/study/StudyDetails.sqf b/src/org/ilintar/study/StudyDetails.sqf
index b3f0c76..f7aee64 100644
--- a/src/org/ilintar/study/StudyDetails.sqf
+++ b/src/org/ilintar/study/StudyDetails.sqf
@@ -4,6 +4,17 @@ First answer
A
Second answer
B
+Third answer
+C
+Fourth answer
+D
+EndQuestion
+StartQuestion type=radio
+This is FUCKUP
+First answer
+A
+Second answer
+B
Third answer modified
C
Fourth answer
diff --git a/src/org/ilintar/study/question/QuestionFactory.java b/src/org/ilintar/study/question/QuestionFactory.java
index 954d7a0..0743b52 100644
--- a/src/org/ilintar/study/question/QuestionFactory.java
+++ b/src/org/ilintar/study/question/QuestionFactory.java
@@ -6,6 +6,6 @@
public interface QuestionFactory {
- public Node createQuestion(List lines);
+ public Question createQuestion(List lines);
}
diff --git a/src/org/ilintar/study/question/RadioQuestion.java b/src/org/ilintar/study/question/RadioQuestion.java
new file mode 100644
index 0000000..9f4c33b
--- /dev/null
+++ b/src/org/ilintar/study/question/RadioQuestion.java
@@ -0,0 +1,73 @@
+package org.ilintar.study.question;
+
+import javafx.event.Event;
+import javafx.scene.Node;
+import javafx.scene.layout.VBox;
+import org.ilintar.study.question.event.QuestionAnsweredEvent;
+import org.ilintar.study.question.event.QuestionAnsweredEventListener;
+
+import java.util.ArrayList;
+
+/**
+ * Created by RJ on 2016-12-01.
+ */
+//Class for standard radio questions.
+public class RadioQuestion implements Question {
+ //Visible part of the question (javafx Node);
+ private VBox empiricalPart;
+ //QuestionID, specified at the constructor method:
+ private String questionID;
+ //Question's answer, initialised here & added later on:
+ private Answer answer;
+ //List of active listeners:
+ private ArrayList listeners;
+
+ //Constructor method:
+ public RadioQuestion() {
+ this.listeners = new ArrayList<>();
+ }
+
+ //Adds new listener to the list:
+ @Override
+ public void addQuestionAnsweredListener(QuestionAnsweredEventListener listener) {
+ listeners.add(listener);
+ }
+
+ //Removes the listener from the list:
+ @Override
+ public void removeQuestionAnsweredListener(QuestionAnsweredEventListener listener) {
+ listeners.remove(listener);
+ }
+
+ //Create new event carrying the question itself & its answer; then return the event:
+ public QuestionAnsweredEvent emitEvent() {
+ return new QuestionAnsweredEvent(this, this.answer);
+ }
+
+ //Returns the question wrapped in a Node object (for further use by the controller);
+ @Override
+ public Node getRenderedQuestion(){
+ return this.getEmpiricalPart();
+ }
+
+ //Getter for the question's ID:
+ @Override
+ public String getId() {
+ return questionID;
+ }
+
+ //Setter for the question's answer;
+ public void setAnswer(Answer answer) {
+ this.answer = answer;
+ }
+
+ //Getter fot the graphical component:
+ public VBox getEmpiricalPart() {
+ return this.empiricalPart;
+ }
+
+ //Setter for the graphical component:
+ public void setEmpiricalPart(VBox empiricalPart) {
+ this.empiricalPart = empiricalPart;
+ }
+}
diff --git a/src/org/ilintar/study/question/RadioQuestionFactory.java b/src/org/ilintar/study/question/RadioQuestionFactory.java
index 749b67c..7c52af8 100644
--- a/src/org/ilintar/study/question/RadioQuestionFactory.java
+++ b/src/org/ilintar/study/question/RadioQuestionFactory.java
@@ -2,16 +2,16 @@
import java.util.List;
-import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.VBox;
public class RadioQuestionFactory implements QuestionFactory {
-
+//Creates Question objects basing on parsed .sqf;
+//At the first step, creates visual component of the question (a VBox object).
@Override
- public Node createQuestion(List lines) {
+ public Question createQuestion(List lines) {
VBox questions = new VBox();
String question = lines.get(0);
questions.getChildren().add(new Label(question));
@@ -25,7 +25,12 @@ public Node createQuestion(List lines) {
questions.getChildren().add(button);
}
questions.onContextMenuRequestedProperty();
- return questions;
+ //Create new RadioQuestion object:
+ RadioQuestion createdQuestion = new RadioQuestion();
+ //Add the created VBox to the question (later available by getEmpiricalComponent()):
+ createdQuestion.setEmpiricalPart(questions);
+ //Return the whole question as a RadioQuestion object:
+ return createdQuestion;
}
}
diff --git a/src/org/ilintar/study/question/event/QuestionAnsweredEvent.java b/src/org/ilintar/study/question/event/QuestionAnsweredEvent.java
index 6813104..3df9e20 100644
--- a/src/org/ilintar/study/question/event/QuestionAnsweredEvent.java
+++ b/src/org/ilintar/study/question/event/QuestionAnsweredEvent.java
@@ -1,5 +1,8 @@
package org.ilintar.study.question.event;
+import javafx.beans.NamedArg;
+import javafx.event.Event;
+import javafx.event.EventType;
import org.ilintar.study.question.Answer;
import org.ilintar.study.question.Question;
diff --git a/src/org/ilintar/study/question/event/QuestionAnsweredEventListener.java b/src/org/ilintar/study/question/event/QuestionAnsweredEventListener.java
index 8fdec03..859561d 100644
--- a/src/org/ilintar/study/question/event/QuestionAnsweredEventListener.java
+++ b/src/org/ilintar/study/question/event/QuestionAnsweredEventListener.java
@@ -1,5 +1,5 @@
package org.ilintar.study.question.event;
-public class QuestionAnsweredEventListener {
-
+public interface QuestionAnsweredEventListener {
+ void handleQuestionAnsweredEvent(QuestionAnsweredEvent e);
}