From 067ba971e9fad07213a757c94e886fa3e7e16c1b Mon Sep 17 00:00:00 2001 From: mariusz Date: Sat, 31 Dec 2016 01:24:14 +0100 Subject: [PATCH 1/4] ver1 --- .idea/misc.xml | 22 +++ .idea/modules.xml | 8 + .idea/uiDesigner.xml | 124 +++++++++++++ org/ilintar/study/Main.java | 27 +++ org/ilintar/study/MainScreenController.java | 173 ++++++++++++++++++ org/ilintar/study/StudyDetails.sqf | 45 +++++ org/ilintar/study/StudyMainScreen.fxml | 39 ++++ org/ilintar/study/application.css | 1 + org/ilintar/study/question/Answer.java | 5 + org/ilintar/study/question/AnswerHolder.java | 10 + org/ilintar/study/question/Question.java | 13 ++ .../study/question/QuestionFactory.java | 9 + org/ilintar/study/question/RadioQuestion.java | 56 ++++++ .../study/question/RadioQuestionFactory.java | 36 ++++ .../RadioWithTimeQuestionFactory.java | 13 ++ .../study/question/SimpleAnswerHolder.java | 21 +++ org/ilintar/study/question/WriteQuestion.java | 61 ++++++ .../study/question/WriteQuestionFactory.java | 36 ++++ .../WriteWithTimeQuestionFactory.java | 13 ++ .../question/event/QuestionAnsweredEvent.java | 34 ++++ .../event/QuestionAnsweredEventListener.java | 14 ++ .../event/QuestionAnsweredEventNotifier.java | 13 ++ .../event/RadioQuestionAnswerListener.java | 39 ++++ .../event/WriteQuestionAnswerListener.java | 42 +++++ ppa-badanie-master.iml | 11 ++ 25 files changed, 865 insertions(+) create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 org/ilintar/study/Main.java create mode 100644 org/ilintar/study/MainScreenController.java create mode 100644 org/ilintar/study/StudyDetails.sqf create mode 100644 org/ilintar/study/StudyMainScreen.fxml create mode 100644 org/ilintar/study/application.css create mode 100644 org/ilintar/study/question/Answer.java create mode 100644 org/ilintar/study/question/AnswerHolder.java create mode 100644 org/ilintar/study/question/Question.java create mode 100644 org/ilintar/study/question/QuestionFactory.java create mode 100644 org/ilintar/study/question/RadioQuestion.java create mode 100644 org/ilintar/study/question/RadioQuestionFactory.java create mode 100644 org/ilintar/study/question/RadioWithTimeQuestionFactory.java create mode 100644 org/ilintar/study/question/SimpleAnswerHolder.java create mode 100644 org/ilintar/study/question/WriteQuestion.java create mode 100644 org/ilintar/study/question/WriteQuestionFactory.java create mode 100644 org/ilintar/study/question/WriteWithTimeQuestionFactory.java create mode 100644 org/ilintar/study/question/event/QuestionAnsweredEvent.java create mode 100644 org/ilintar/study/question/event/QuestionAnsweredEventListener.java create mode 100644 org/ilintar/study/question/event/QuestionAnsweredEventNotifier.java create mode 100644 org/ilintar/study/question/event/RadioQuestionAnswerListener.java create mode 100644 org/ilintar/study/question/event/WriteQuestionAnswerListener.java create mode 100644 ppa-badanie-master.iml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..2e47c90 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,22 @@ + + + + + + + + + + 1.8 + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..5eb0ba7 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/org/ilintar/study/Main.java b/org/ilintar/study/Main.java new file mode 100644 index 0000000..840fd3a --- /dev/null +++ b/org/ilintar/study/Main.java @@ -0,0 +1,27 @@ +package org.ilintar.study; + +import javafx.application.Application; +import javafx.stage.Stage; +import javafx.scene.Scene; +import javafx.scene.layout.BorderPane; +import javafx.fxml.FXMLLoader; + + +public class Main extends Application { + @Override + public void start(Stage primaryStage) { + try { + BorderPane root = (BorderPane)FXMLLoader.load(getClass().getResource("StudyMainScreen.fxml")); + Scene scene = new Scene(root,400,400); + scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm()); + primaryStage.setScene(scene); + primaryStage.show(); + } catch(Exception e) { + e.printStackTrace(); + } + } + + public static void main(String[] args) { + launch(args); + } +} diff --git a/org/ilintar/study/MainScreenController.java b/org/ilintar/study/MainScreenController.java new file mode 100644 index 0000000..3ec52f8 --- /dev/null +++ b/org/ilintar/study/MainScreenController.java @@ -0,0 +1,173 @@ +package org.ilintar.study; + +import javafx.application.Platform; +import javafx.event.EventHandler; +import javafx.fxml.FXML; +import javafx.scene.Node; +import javafx.scene.control.Button; +import javafx.scene.effect.Effect; +import javafx.scene.layout.AnchorPane; +import javafx.scene.text.Text; +import org.ilintar.study.question.*; +import org.ilintar.study.question.event.RadioQuestionAnswerListener; +import org.ilintar.study.question.event.WriteQuestionAnswerListener; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class MainScreenController { + + protected static Map factoryMap; + + private AnswerHolder answerHolder = new SimpleAnswerHolder(); + private BufferedReader openedFile; + private Node currentQuestionComponent; + + private int resultsHandlerCount = 0; + + static { + factoryMap = new HashMap<>(); + factoryMap.put("radio", new RadioQuestionFactory()); + factoryMap.put("radiowithtime", new RadioWithTimeQuestionFactory()); + factoryMap.put("write", new WriteQuestionFactory()); + factoryMap.put("writewithtime", new WriteWithTimeQuestionFactory()); + // / słowo klucz wskazujace której konkretnie fabryki chcemy użyć + } + + @FXML + AnchorPane mainStudy; + + @FXML + public void startStudy() throws IOException { + mainStudy.getChildren().clear(); + openedFile = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("StudyDetails.sqf"))); + currentQuestionComponent = readNextQuestionFromFile(); + mainStudy.getChildren().add(currentQuestionComponent); + } + + private Node readNextQuestionFromFile() throws IOException { + String questionStartLine = getQuestionStartLine(); + if (questionStartLine != null) { + String questionType = getQuestionType(questionStartLine); + List questionLines = readQuestionLines(); + return createQuestion(questionLines, questionType); + } + else { + //finalScreen(); + return null; + } + } + + private String getQuestionStartLine() throws IOException { + String currentLine; + currentLine = openedFile.readLine(); + if (currentLine == null) + return null; + if (!currentLine.startsWith("StartQuestion")) + throw new IllegalArgumentException("Question does not start properly"); + return currentLine; + } + + private String getQuestionType(String startLine) { + String questionType = null; + String[] split = startLine.split(" "); + if (split.length > 1) { + String[] split2 = split[1].split("="); + if (split2.length > 1) { + questionType = split2[1]; + } + } + if (factoryMap.containsKey(questionType)) + return questionType; + else + throw new IllegalArgumentException("InvalidQuestionType"); + } + + private List readQuestionLines() throws IOException { + List questionLines = new ArrayList<>(); + String currentLine; + while ((currentLine = openedFile.readLine()) != null) { + if (currentLine.startsWith("EndQuestion")) + return questionLines; + else + questionLines.add(currentLine.trim()); + } + throw new IllegalArgumentException("No end question mark"); + } + + private Node createQuestion(List questionLines, String questionType) { + Question q = factoryMap.get(questionType).createQuestion(questionLines); + if(questionType.equals("radio")) { + q.addQuestionAnsweredListener(new RadioQuestionAnswerListener(answerHolder, this)); + } + else if (questionType.equals("write")) { + q.addQuestionAnsweredListener(new WriteQuestionAnswerListener(answerHolder, this)); + } + return q.getRenderedQuestion(); + } + + public void getNewQuestion() throws IOException { + mainStudy.getChildren().remove(currentQuestionComponent); + currentQuestionComponent = readNextQuestionFromFile(); + if (currentQuestionComponent == null) { + finalScreen(); + return; + } + mainStudy.getChildren().add(currentQuestionComponent); + } + + private void finalScreen(){ + mainStudy.getChildren().add(new Text(50 , 50, "Thank you for participating in this study.\n")); + Button exitButton = new Button("Exit"); + Button resultsButton = new Button("See results"); + //int resultsHandlerCount = 0; + + exitButton.relocate(mainStudy.getWidth()/2, mainStudy.getHeight()/2); + resultsButton.relocate(mainStudy.getWidth()/4, mainStudy.getHeight()/2); + + //quitButton.setOnAction(e -> System.out.println()); + exitButton.setOnAction(new EventHandler() { //zamienne z lambdą + @Override + public void handle(javafx.event.ActionEvent event) { + Platform.exit(); + } + }); + resultsButton.setOnAction(new EventHandler() { + @Override + public void handle(javafx.event.ActionEvent event) { + if (resultsHandlerCount < 3) { + resultsScreen(); + resultsHandlerCount++; + } + else if (resultsHandlerCount >= 3) { + resultsButton.setText("Them results, in console they are"); //this is supposed to be funny + exitButton.setVisible(false); + } + } + }); + + try { + mainStudy.getChildren().add(exitButton); + mainStudy.getChildren().add(resultsButton); + } catch(Exception e) { + e.printStackTrace(); + } + + } + private void resultsScreen(){ //TODO: wyniki w oknie a nie konsoli + for (Object o: answerHolder.getAnswers()) { //ufff, getAnswers() zwraca odpowiedzi jako ArrayList + System.out.println(o); + } + } + +} + + + diff --git a/org/ilintar/study/StudyDetails.sqf b/org/ilintar/study/StudyDetails.sqf new file mode 100644 index 0000000..18cb2d9 --- /dev/null +++ b/org/ilintar/study/StudyDetails.sqf @@ -0,0 +1,45 @@ +StartQuestion type=write +Second question +EndQuestion +StartQuestion type=write +Second question +EndQuestion +StartQuestion type=write +Second question +EndQuestion +StartQuestion type=radio +This is the question +First answer +A +Second answer +B +Third answer modified +C +Fourth answer +D +EndQuestion +StartQuestion type=write +Second question +EndQuestion +StartQuestion type=radio +Third question +Answer1 +A +Answer2 +B +Answer3 +C +Answer4 +D +EndQuestion +StartQuestion type=radio +Third question +Answer1 +A +Answer2 +B +Answer3 +C +Answer4 +D +EndQuestion \ No newline at end of file diff --git a/org/ilintar/study/StudyMainScreen.fxml b/org/ilintar/study/StudyMainScreen.fxml new file mode 100644 index 0000000..0fab964 --- /dev/null +++ b/org/ilintar/study/StudyMainScreen.fxml @@ -0,0 +1,39 @@ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + +
+
diff --git a/org/ilintar/study/application.css b/org/ilintar/study/application.css new file mode 100644 index 0000000..83d6f33 --- /dev/null +++ b/org/ilintar/study/application.css @@ -0,0 +1 @@ +/* JavaFX CSS - Leave this comment until you have at least create one rule which uses -fx-Property */ \ No newline at end of file diff --git a/org/ilintar/study/question/Answer.java b/org/ilintar/study/question/Answer.java new file mode 100644 index 0000000..e19ea7f --- /dev/null +++ b/org/ilintar/study/question/Answer.java @@ -0,0 +1,5 @@ +package org.ilintar.study.question; + +public interface Answer { + +} diff --git a/org/ilintar/study/question/AnswerHolder.java b/org/ilintar/study/question/AnswerHolder.java new file mode 100644 index 0000000..ba0f52a --- /dev/null +++ b/org/ilintar/study/question/AnswerHolder.java @@ -0,0 +1,10 @@ +package org.ilintar.study.question; + +import java.util.Collection; +import java.util.Objects; + + +public interface AnswerHolder { + void putAnswer(Object answer); + Collection getAnswers(); +} diff --git a/org/ilintar/study/question/Question.java b/org/ilintar/study/question/Question.java new file mode 100644 index 0000000..0d86c96 --- /dev/null +++ b/org/ilintar/study/question/Question.java @@ -0,0 +1,13 @@ +package org.ilintar.study.question; + +import javafx.scene.Node; +import org.ilintar.study.question.event.QuestionAnsweredEventNotifier; + +public interface Question extends QuestionAnsweredEventNotifier { + + public Node getRenderedQuestion(); + public String getId(); + + + +} diff --git a/org/ilintar/study/question/QuestionFactory.java b/org/ilintar/study/question/QuestionFactory.java new file mode 100644 index 0000000..5ac0902 --- /dev/null +++ b/org/ilintar/study/question/QuestionFactory.java @@ -0,0 +1,9 @@ +package org.ilintar.study.question; + +import java.util.List; + +public interface QuestionFactory { + + Question createQuestion(List lines); + +} diff --git a/org/ilintar/study/question/RadioQuestion.java b/org/ilintar/study/question/RadioQuestion.java new file mode 100644 index 0000000..d3889e7 --- /dev/null +++ b/org/ilintar/study/question/RadioQuestion.java @@ -0,0 +1,56 @@ +package org.ilintar.study.question; + +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.scene.Node; +import javafx.scene.control.Button; +import javafx.scene.control.Toggle; +import javafx.scene.control.ToggleGroup; +import javafx.scene.layout.VBox; +import org.ilintar.study.question.event.QuestionAnsweredEventListener; + +public class RadioQuestion implements Question { + + private VBox vBox; + private ToggleGroup group; + private Button nextButton; + + public RadioQuestion(VBox vBox, ToggleGroup group, Button nextButton) { + this.vBox = vBox; + this.group = group; + this.nextButton = nextButton; + passToggleResult(group, nextButton); + } + + private void passToggleResult(final ToggleGroup group, final Button nextButton) { + + group.selectedToggleProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, Toggle oldValue, Toggle newValue) { + //System.out.println(group.getSelectedToggle()); + nextButton.setUserData(group.getSelectedToggle().getUserData().toString()); + } + }); + } + + @Override + public Node getRenderedQuestion() { + vBox.getChildren().add(nextButton); + return vBox; + } + + @Override + public String getId() { + return vBox.getId(); + } + + @Override + public void addQuestionAnsweredListener(QuestionAnsweredEventListener listener) { + nextButton.setOnAction(listener::handleEvent); + } + + @Override + public void removeQuestionAnsweredListener(QuestionAnsweredEventListener listener) { + + } +} diff --git a/org/ilintar/study/question/RadioQuestionFactory.java b/org/ilintar/study/question/RadioQuestionFactory.java new file mode 100644 index 0000000..5dbb066 --- /dev/null +++ b/org/ilintar/study/question/RadioQuestionFactory.java @@ -0,0 +1,36 @@ +package org.ilintar.study.question; + +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.RadioButton; +import javafx.scene.control.ToggleGroup; +import javafx.scene.layout.VBox; + +import java.util.List; + +public class RadioQuestionFactory implements QuestionFactory { + + @Override + public Question createQuestion(List lines) { + VBox question = new VBox(); //VBox lays out its children in a single vertical column + String questionText = lines.get(0); + question.getChildren().add(new Label(questionText)); + ToggleGroup group = new ToggleGroup(); //grupa przycisków wewnątrz tylko jeden może być zaznaczony + for (int i = 1; i < lines.size(); i+=2) { + String answer = lines.get(i); + String answerCode = lines.get(i+1); + RadioButton button = new RadioButton(answer); + button.setUserData(answerCode); + button.setToggleGroup(group); + question.getChildren().add(button); + } + question.onContextMenuRequestedProperty(); + Button nextButton = createNextButton(); + return new RadioQuestion(question, group, nextButton); + } + + private Button createNextButton() { + Button nextButton = new Button("Next"); + return nextButton; + } +} diff --git a/org/ilintar/study/question/RadioWithTimeQuestionFactory.java b/org/ilintar/study/question/RadioWithTimeQuestionFactory.java new file mode 100644 index 0000000..6f907fe --- /dev/null +++ b/org/ilintar/study/question/RadioWithTimeQuestionFactory.java @@ -0,0 +1,13 @@ +package org.ilintar.study.question; + +import java.util.List; + +/** + * Created by mariusz on 2016-12-29. + */ +public class RadioWithTimeQuestionFactory implements QuestionFactory{ + @Override + public Question createQuestion(List lines) { + return null; + } +} diff --git a/org/ilintar/study/question/SimpleAnswerHolder.java b/org/ilintar/study/question/SimpleAnswerHolder.java new file mode 100644 index 0000000..95a6c64 --- /dev/null +++ b/org/ilintar/study/question/SimpleAnswerHolder.java @@ -0,0 +1,21 @@ +package org.ilintar.study.question; + + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Objects; + +public class SimpleAnswerHolder implements AnswerHolder{ + + private List list = new ArrayList(); + @Override + public void putAnswer(Object answer) { + list.add(answer); + } + + @Override + public Collection getAnswers() { + return list; + } +} diff --git a/org/ilintar/study/question/WriteQuestion.java b/org/ilintar/study/question/WriteQuestion.java new file mode 100644 index 0000000..f250e2a --- /dev/null +++ b/org/ilintar/study/question/WriteQuestion.java @@ -0,0 +1,61 @@ +package org.ilintar.study.question; + +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.scene.Node; +import javafx.scene.control.Button; +import javafx.scene.control.TextArea; +import javafx.scene.control.Toggle; +import javafx.scene.control.ToggleGroup; +import javafx.scene.layout.VBox; +import org.ilintar.study.question.event.QuestionAnsweredEventListener; + +/** + * Created by mariusz on 2016-12-29. + */ +public class WriteQuestion implements Question { + + private VBox vBox; + private TextArea textArea; + private Button nextButton; + + public WriteQuestion(VBox vBox, TextArea textArea, Button nextButton) { + this.vBox = vBox; + this.textArea = textArea; + this.nextButton = nextButton; + passWriteResult(textArea, nextButton); + } + + private void passWriteResult(final TextArea textArea, final Button nextButton) { + + textArea.textProperty().addListener(new ChangeListener() { //kiedykolwiek wartosc textProperty() się zmienia wywołaj listener + @Override + public void changed(ObservableValue observable, String oldValue, String newValue) { //to samo mozna zrobic lambdą, przesylajac argumenty do metody changed + String text = textArea.getText(); //z anonimowej klasy ChangeListener + //System.out.println(text); + nextButton.setUserData(text); //ustawiamy property UserData, ktorą przechwyci handler w listenerze + } + }); + } + + @Override + public Node getRenderedQuestion() { + vBox.getChildren().add(nextButton); + return vBox; + } + + @Override + public String getId() { + return vBox.getId(); + } + + @Override + public void addQuestionAnsweredListener(QuestionAnsweredEventListener listener) { + nextButton.setOnAction(listener::handleEvent); + } + + @Override + public void removeQuestionAnsweredListener(QuestionAnsweredEventListener listener) { + + } +} diff --git a/org/ilintar/study/question/WriteQuestionFactory.java b/org/ilintar/study/question/WriteQuestionFactory.java new file mode 100644 index 0000000..f941ff4 --- /dev/null +++ b/org/ilintar/study/question/WriteQuestionFactory.java @@ -0,0 +1,36 @@ +package org.ilintar.study.question; + +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.TextArea; +import javafx.scene.layout.VBox; +import org.ilintar.study.question.Question; +import org.ilintar.study.question.QuestionFactory; + +import java.util.List; + +/** + * Created by mariusz on 2016-12-29. + */ +public class WriteQuestionFactory implements QuestionFactory { + + @Override + public Question createQuestion(List lines) { + VBox question = new VBox(); + String questionText = lines.get(0); + + TextArea textArea = new TextArea(); + textArea.setMaxHeight(10); // inaczej nachodzilo na nextbuttona + + question.getChildren().add(new Label(questionText)); + question.getChildren().add(textArea); + + Button nextButton = createNextButton(); + return new WriteQuestion(question, textArea, nextButton); + } + + private Button createNextButton() { + Button nextButton = new Button("Next"); + return nextButton; + } +} diff --git a/org/ilintar/study/question/WriteWithTimeQuestionFactory.java b/org/ilintar/study/question/WriteWithTimeQuestionFactory.java new file mode 100644 index 0000000..1fa70b9 --- /dev/null +++ b/org/ilintar/study/question/WriteWithTimeQuestionFactory.java @@ -0,0 +1,13 @@ +package org.ilintar.study.question; + +import java.util.List; + +/** + * Created by mariusz on 2016-12-29. + */ +public class WriteWithTimeQuestionFactory implements QuestionFactory { + @Override + public Question createQuestion(List lines) { + return null; + } +} diff --git a/org/ilintar/study/question/event/QuestionAnsweredEvent.java b/org/ilintar/study/question/event/QuestionAnsweredEvent.java new file mode 100644 index 0000000..6813104 --- /dev/null +++ b/org/ilintar/study/question/event/QuestionAnsweredEvent.java @@ -0,0 +1,34 @@ +package org.ilintar.study.question.event; + +import org.ilintar.study.question.Answer; +import org.ilintar.study.question.Question; + +public class QuestionAnsweredEvent { + + protected Question question; + protected Answer answer; + + public QuestionAnsweredEvent(Question question, Answer answer) { + this.question = question; + this.answer = answer; + } + + public Question getQuestion() { + return question; + } + + public void setQuestion(Question question) { + this.question = question; + } + + public Answer getAnswer() { + return answer; + } + + public void setAnswer(Answer answer) { + this.answer = answer; + } + + + +} diff --git a/org/ilintar/study/question/event/QuestionAnsweredEventListener.java b/org/ilintar/study/question/event/QuestionAnsweredEventListener.java new file mode 100644 index 0000000..0535830 --- /dev/null +++ b/org/ilintar/study/question/event/QuestionAnsweredEventListener.java @@ -0,0 +1,14 @@ +package org.ilintar.study.question.event; + +import javafx.event.ActionEvent; +import javafx.fxml.FXML; + + +public interface QuestionAnsweredEventListener { + //zazwyczaj ma jedna metode - handleEvent + //interfejs funkcyjny (zawiera tylko jedna metode) + + @FXML + void handleEvent(ActionEvent event); + +} diff --git a/org/ilintar/study/question/event/QuestionAnsweredEventNotifier.java b/org/ilintar/study/question/event/QuestionAnsweredEventNotifier.java new file mode 100644 index 0000000..e82c8b2 --- /dev/null +++ b/org/ilintar/study/question/event/QuestionAnsweredEventNotifier.java @@ -0,0 +1,13 @@ +package org.ilintar.study.question.event; + +public interface QuestionAnsweredEventNotifier { + //produkuje zdarzenia, jest źródłem zdarzeń + //wysyła zdarzenie do jednego lub więcej listenerów + //obiekt ktory jest notifierem musi rejestrowac w sobie listenerow + // fire...event --> wez listenerow i wywolaj w nim handleEvent + + + void addQuestionAnsweredListener(QuestionAnsweredEventListener listener); + void removeQuestionAnsweredListener(QuestionAnsweredEventListener listener); + +} diff --git a/org/ilintar/study/question/event/RadioQuestionAnswerListener.java b/org/ilintar/study/question/event/RadioQuestionAnswerListener.java new file mode 100644 index 0000000..7a62464 --- /dev/null +++ b/org/ilintar/study/question/event/RadioQuestionAnswerListener.java @@ -0,0 +1,39 @@ +package org.ilintar.study.question.event; + + +import javafx.event.ActionEvent; +import javafx.scene.control.Button; +import org.ilintar.study.MainScreenController; +import org.ilintar.study.question.AnswerHolder; + +import java.io.IOException; + +public class RadioQuestionAnswerListener implements QuestionAnsweredEventListener { + + private final AnswerHolder answerHolder; + MainScreenController mainScreenController; + + + public RadioQuestionAnswerListener(AnswerHolder answerHolder, MainScreenController mainScreenController) { + this.answerHolder = answerHolder; + this.mainScreenController = mainScreenController; + } + + @Override + public void handleEvent(ActionEvent event) { + String answerCode = (String) ((Button) event.getSource()).getUserData(); + if (answerCode != null) { + answerHolder.putAnswer(answerCode); + //System.out.println("answerCode w handleEvent Radio = " + answerCode); + try { + mainScreenController.getNewQuestion(); + } catch (IOException e) { + e.printStackTrace(); + } + } + else { + System.out.println("DupaRadio!"); + + } + } +} diff --git a/org/ilintar/study/question/event/WriteQuestionAnswerListener.java b/org/ilintar/study/question/event/WriteQuestionAnswerListener.java new file mode 100644 index 0000000..67a3306 --- /dev/null +++ b/org/ilintar/study/question/event/WriteQuestionAnswerListener.java @@ -0,0 +1,42 @@ +package org.ilintar.study.question.event; + +import javafx.event.ActionEvent; +import javafx.scene.control.Button; +import org.ilintar.study.MainScreenController; +import org.ilintar.study.question.AnswerHolder; + +import java.io.IOException; + +/** + * Created by mariusz on 2016-12-29. + */ +public class WriteQuestionAnswerListener implements QuestionAnsweredEventListener { + + private final AnswerHolder answerHolder; + MainScreenController mainScreenController; + + + public WriteQuestionAnswerListener(AnswerHolder answerHolder, MainScreenController mainScreenController) { + this.answerHolder = answerHolder; + this.mainScreenController = mainScreenController; + } + + @Override + public void handleEvent(ActionEvent event) { + String answerCode = (String) ((Button) event.getSource()).getUserData(); + if (answerCode != null) { + answerHolder.putAnswer(answerCode); + //System.out.println("answerCode w handleEvent Write = " + answerCode); + try { + mainScreenController.getNewQuestion(); + } catch (IOException e) { + e.printStackTrace(); + } + } + else { + System.out.println("DupaWrite!"); + + } + } +} + diff --git a/ppa-badanie-master.iml b/ppa-badanie-master.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/ppa-badanie-master.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file From e3eb8926d372eb2ef1ea74bb8342c05dc243ad12 Mon Sep 17 00:00:00 2001 From: mariusz Date: Sat, 31 Dec 2016 13:41:07 +0100 Subject: [PATCH 2/4] ver1 --- org/ilintar/study/MainScreenController.java | 20 ++++++++++++++++---- org/ilintar/study/StudyDetails.sqf | 10 +++++----- org/ilintar/study/StudyMainScreen.fxml | 3 ++- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/org/ilintar/study/MainScreenController.java b/org/ilintar/study/MainScreenController.java index 3ec52f8..0033858 100644 --- a/org/ilintar/study/MainScreenController.java +++ b/org/ilintar/study/MainScreenController.java @@ -1,19 +1,18 @@ package org.ilintar.study; +import com.sun.org.apache.xerces.internal.xs.StringList; import javafx.application.Platform; +import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.fxml.FXML; import javafx.scene.Node; import javafx.scene.control.Button; -import javafx.scene.effect.Effect; import javafx.scene.layout.AnchorPane; import javafx.scene.text.Text; import org.ilintar.study.question.*; import org.ilintar.study.question.event.RadioQuestionAnswerListener; import org.ilintar.study.question.event.WriteQuestionAnswerListener; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -110,6 +109,7 @@ private Node createQuestion(List questionLines, String questionType) { else if (questionType.equals("write")) { q.addQuestionAnsweredListener(new WriteQuestionAnswerListener(answerHolder, this)); } + //TODO: dodac nastepne typy pytan, wygenerowalem juz klasy return q.getRenderedQuestion(); } @@ -132,7 +132,7 @@ private void finalScreen(){ exitButton.relocate(mainStudy.getWidth()/2, mainStudy.getHeight()/2); resultsButton.relocate(mainStudy.getWidth()/4, mainStudy.getHeight()/2); - //quitButton.setOnAction(e -> System.out.println()); + //exitButton.setOnAction(e -> System.out.println()); exitButton.setOnAction(new EventHandler() { //zamienne z lambdą @Override public void handle(javafx.event.ActionEvent event) { @@ -162,11 +162,23 @@ else if (resultsHandlerCount >= 3) { } private void resultsScreen(){ //TODO: wyniki w oknie a nie konsoli + System.out.println("\nResults"); for (Object o: answerHolder.getAnswers()) { //ufff, getAnswers() zwraca odpowiedzi jako ArrayList System.out.println(o); } } + public void generateStudy(ActionEvent actionEvent) { //TODO: interfejs do generowania .sqf dla naszego programu + + mainStudy.getChildren().clear(); + mainStudy.getChildren().add(new Text(50,50,"It will be done")); + + + + } + //TODO: moznaby tez zrobic przycisk "Go back" ktory bylby odziedziczone przez niektóre okna (ale to trzeba zrobic w mainie + //TODO: uzywajac stage.setScene()? + } diff --git a/org/ilintar/study/StudyDetails.sqf b/org/ilintar/study/StudyDetails.sqf index 18cb2d9..490ee57 100644 --- a/org/ilintar/study/StudyDetails.sqf +++ b/org/ilintar/study/StudyDetails.sqf @@ -1,11 +1,11 @@ StartQuestion type=write -Second question +First question EndQuestion StartQuestion type=write Second question EndQuestion StartQuestion type=write -Second question +Third question EndQuestion StartQuestion type=radio This is the question @@ -19,10 +19,10 @@ Fourth answer D EndQuestion StartQuestion type=write -Second question +Next question EndQuestion StartQuestion type=radio -Third question +Another question Answer1 A Answer2 @@ -33,7 +33,7 @@ Answer4 D EndQuestion StartQuestion type=radio -Third question +Last question Answer1 A Answer2 diff --git a/org/ilintar/study/StudyMainScreen.fxml b/org/ilintar/study/StudyMainScreen.fxml index 0fab964..2542db6 100644 --- a/org/ilintar/study/StudyMainScreen.fxml +++ b/org/ilintar/study/StudyMainScreen.fxml @@ -28,7 +28,8 @@