mirror of
https://gitlab.com/kauron/jstudy
synced 2024-11-13 07:33:44 +01:00
Test: enlarged feedback and improved internals
This commit is contained in:
parent
59ffe397d3
commit
b08e5aa1dc
3 changed files with 43 additions and 39 deletions
|
@ -2,11 +2,11 @@ package es.kauron.jstudy.controller;
|
||||||
|
|
||||||
import es.kauron.jstudy.model.AppPrefs;
|
import es.kauron.jstudy.model.AppPrefs;
|
||||||
import es.kauron.jstudy.model.TestItem;
|
import es.kauron.jstudy.model.TestItem;
|
||||||
import javafx.beans.property.SimpleBooleanProperty;
|
import javafx.beans.binding.Bindings;
|
||||||
|
import javafx.beans.property.*;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
import javafx.geometry.Insets;
|
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.ProgressBar;
|
import javafx.scene.control.ProgressBar;
|
||||||
|
@ -31,8 +31,9 @@ public class TestController implements Initializable {
|
||||||
|
|
||||||
private SimpleBooleanProperty correctingError = new SimpleBooleanProperty(false);
|
private SimpleBooleanProperty correctingError = new SimpleBooleanProperty(false);
|
||||||
private List<TestItem> list;
|
private List<TestItem> list;
|
||||||
private int total, current = -1;
|
private IntegerProperty errors = new SimpleIntegerProperty(0);
|
||||||
private int done = 0, errors = 0;
|
private ObjectProperty<TestItem> item = new SimpleObjectProperty<>();
|
||||||
|
private IntegerProperty done = new SimpleIntegerProperty(0);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||||
|
@ -42,24 +43,32 @@ public class TestController implements Initializable {
|
||||||
|
|
||||||
void setList(List<TestItem> list) {
|
void setList(List<TestItem> list) {
|
||||||
this.list = list;
|
this.list = list;
|
||||||
total = list.size();
|
int total = list.size();
|
||||||
progress.setProgress(0);
|
progress.setProgress(0);
|
||||||
progressLabel.setText("0/" + total);
|
progressLabel.textProperty().bind(Bindings.format(
|
||||||
|
String.format("%%.2f%%%% %%d / %d %%d mistakes", total),
|
||||||
|
done.multiply(100.0).divide(total), done, errors));
|
||||||
|
progress.progressProperty().bind(done.divide((double) total));
|
||||||
|
item.addListener((obj, o, n) -> {
|
||||||
|
if (o != null) {
|
||||||
|
prevQuestion.setText(o.getQuestion());
|
||||||
|
correctAnswer.setText(o.getAnswer());
|
||||||
|
}
|
||||||
|
question.setText(n.getQuestion());
|
||||||
|
});
|
||||||
onSkipAction(null);
|
onSkipAction(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void onNextAction(ActionEvent event) {
|
private void onNextAction(ActionEvent event) {
|
||||||
prevQuestion.setText(list.get(current).getQuestion());
|
|
||||||
prevAnswer.setText(answer.getText());
|
prevAnswer.setText(answer.getText());
|
||||||
correctAnswer.setText(list.get(current).getAnswer());
|
|
||||||
|
|
||||||
boolean right = list.get(current).getAnswer().equals(answer.getText());
|
boolean right = item.get().getAnswer().equals(answer.getText());
|
||||||
correctAnswer.setVisible(!right);
|
correctAnswer.setVisible(!right);
|
||||||
correctLabel.setVisible(!right);
|
correctLabel.setVisible(!right);
|
||||||
|
|
||||||
if (!right) {
|
if (!right) {
|
||||||
errors++;
|
errors.set(errors.get() + 1);
|
||||||
prevAnswer.setStyle("-fx-text-fill: #C40000;");
|
prevAnswer.setStyle("-fx-text-fill: #C40000;");
|
||||||
} else {
|
} else {
|
||||||
prevAnswer.setStyle("-fx-text-fill: #00C400;");
|
prevAnswer.setStyle("-fx-text-fill: #00C400;");
|
||||||
|
@ -67,9 +76,8 @@ public class TestController implements Initializable {
|
||||||
|
|
||||||
// Remove the question from the pool if the question was correctly answered or there is no repetition
|
// Remove the question from the pool if the question was correctly answered or there is no repetition
|
||||||
if ((right && !correctingError.get()) || !AppPrefs.repeatWrong.get()) {
|
if ((right && !correctingError.get()) || !AppPrefs.repeatWrong.get()) {
|
||||||
list.remove(current);
|
list.remove(item.get());
|
||||||
progress.setProgress(++done / (double) total);
|
done.set(done.get() + 1);
|
||||||
progressLabel.setText(done + "/" + total);
|
|
||||||
if (list.size() == 0) {
|
if (list.size() == 0) {
|
||||||
onEndAction(null);
|
onEndAction(null);
|
||||||
return;
|
return;
|
||||||
|
@ -79,27 +87,24 @@ public class TestController implements Initializable {
|
||||||
chooseQuestion();
|
chooseQuestion();
|
||||||
}
|
}
|
||||||
correctingError.set(!right && AppPrefs.repeatImmediately.get());
|
correctingError.set(!right && AppPrefs.repeatImmediately.get());
|
||||||
setQuestion();
|
answer.setText("");
|
||||||
|
answer.requestFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void chooseQuestion() {
|
private void chooseQuestion() {
|
||||||
answer.setText("");
|
answer.setText("");
|
||||||
int previous = current;
|
TestItem next = item.get();
|
||||||
do
|
do
|
||||||
current = (int) (Math.random() * list.size());
|
next = list.get((int) (Math.random() * list.size()));
|
||||||
while (list.size() > 1 && current == previous);
|
while (list.size() > 1 && item.get() == next);
|
||||||
}
|
item.set(next);
|
||||||
|
|
||||||
private void setQuestion() {
|
|
||||||
answer.setText("");
|
|
||||||
question.setText(list.get(current).getQuestion());
|
|
||||||
answer.requestFocus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void onSkipAction(ActionEvent event) {
|
private void onSkipAction(ActionEvent event) {
|
||||||
chooseQuestion();
|
chooseQuestion();
|
||||||
setQuestion();
|
answer.setText("");
|
||||||
|
answer.requestFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
|
@ -107,10 +112,5 @@ public class TestController implements Initializable {
|
||||||
answer.setText("");
|
answer.setText("");
|
||||||
answer.setDisable(true);
|
answer.setDisable(true);
|
||||||
question.setText("That's it!");
|
question.setText("That's it!");
|
||||||
feedback.getChildren().clear();
|
|
||||||
feedback.setSpacing(5);
|
|
||||||
feedback.setPadding(new Insets(5, 5, 5, 5));
|
|
||||||
feedback.getChildren().add(new Label("Mistakes: " + errors));
|
|
||||||
feedback.getChildren().add(new Label(String.format("Mark: %.2f%%", (total - errors) / (double) total * 100)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
.answer {
|
.answer {
|
||||||
-fx-font-weight: bold;
|
-fx-font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.feedbackText {
|
||||||
|
-fx-font-size: 20;
|
||||||
|
}
|
|
@ -4,7 +4,7 @@
|
||||||
<?import javafx.scene.control.*?>
|
<?import javafx.scene.control.*?>
|
||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.layout.*?>
|
||||||
<?import javafx.scene.text.Font?>
|
<?import javafx.scene.text.Font?>
|
||||||
<BorderPane xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1" fx:controller="es.kauron.jstudy.controller.TestController">
|
<BorderPane xmlns="http://javafx.com/javafx/8.0.202-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="es.kauron.jstudy.controller.TestController" stylesheets="@../css/test.css">
|
||||||
<center>
|
<center>
|
||||||
<VBox minHeight="280.0" minWidth="360.0" spacing="10.0">
|
<VBox minHeight="280.0" minWidth="360.0" spacing="10.0">
|
||||||
<children>
|
<children>
|
||||||
|
@ -21,10 +21,10 @@
|
||||||
<Separator />
|
<Separator />
|
||||||
<HBox fx:id="feedback" alignment="BOTTOM_CENTER" VBox.vgrow="ALWAYS">
|
<HBox fx:id="feedback" alignment="BOTTOM_CENTER" VBox.vgrow="ALWAYS">
|
||||||
<children>
|
<children>
|
||||||
<GridPane hgap="10.0" HBox.hgrow="NEVER">
|
<GridPane hgap="10.0" maxWidth="1.7976931348623157E308" HBox.hgrow="ALWAYS">
|
||||||
<columnConstraints>
|
<columnConstraints>
|
||||||
<ColumnConstraints fillWidth="false" halignment="RIGHT" hgrow="NEVER" />
|
<ColumnConstraints fillWidth="false" halignment="RIGHT" hgrow="NEVER" />
|
||||||
<ColumnConstraints fillWidth="false" hgrow="NEVER" maxWidth="1.7976931348623157E308" />
|
<ColumnConstraints fillWidth="false" hgrow="ALWAYS" maxWidth="1.7976931348623157E308" />
|
||||||
</columnConstraints>
|
</columnConstraints>
|
||||||
<rowConstraints>
|
<rowConstraints>
|
||||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||||
|
@ -32,12 +32,12 @@
|
||||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||||
</rowConstraints>
|
</rowConstraints>
|
||||||
<children>
|
<children>
|
||||||
<Label text="Previous question" />
|
<Label text="Previous question" wrapText="true" />
|
||||||
<Label fx:id="prevQuestion" text="question" GridPane.columnIndex="1" />
|
<Label fx:id="prevQuestion" maxWidth="1.7976931348623157E308" styleClass="feedbackText" wrapText="true" GridPane.columnIndex="1" />
|
||||||
<Label text="Previous answer" GridPane.rowIndex="1" />
|
<Label text="Previous answer" wrapText="true" GridPane.rowIndex="1" />
|
||||||
<Label fx:id="prevAnswer" styleClass="answer" stylesheets="@../css/test.css" text="answer" GridPane.columnIndex="1" GridPane.rowIndex="1" />
|
<Label fx:id="prevAnswer" maxWidth="1.7976931348623157E308" styleClass="answer, feedbackText" wrapText="true" GridPane.columnIndex="1" GridPane.rowIndex="1" />
|
||||||
<Label fx:id="correctLabel" text="Correct answer" GridPane.rowIndex="2" />
|
<Label fx:id="correctLabel" text="Correct answer" wrapText="true" GridPane.rowIndex="2" />
|
||||||
<Label fx:id="correctAnswer" text="correct answer" GridPane.columnIndex="1" GridPane.rowIndex="2" />
|
<Label fx:id="correctAnswer" maxWidth="1.7976931348623157E308" styleClass="feedbackText" wrapText="true" GridPane.columnIndex="1" GridPane.rowIndex="2" />
|
||||||
</children>
|
</children>
|
||||||
</GridPane>
|
</GridPane>
|
||||||
</children>
|
</children>
|
||||||
|
@ -64,7 +64,7 @@
|
||||||
<VBox alignment="TOP_RIGHT" spacing="10.0" BorderPane.alignment="CENTER">
|
<VBox alignment="TOP_RIGHT" spacing="10.0" BorderPane.alignment="CENTER">
|
||||||
<children>
|
<children>
|
||||||
<Button defaultButton="true" focusTraversable="false" onAction="#onNextAction" prefWidth="110.0" text="_Next" />
|
<Button defaultButton="true" focusTraversable="false" onAction="#onNextAction" prefWidth="110.0" text="_Next" />
|
||||||
<Button cancelButton="true" focusTraversable="false" onAction="#onSkipAction" prefWidth="110.0" text="_Skip question" fx:id="skipButton"/>
|
<Button fx:id="skipButton" cancelButton="true" focusTraversable="false" onAction="#onSkipAction" prefWidth="110.0" text="_Skip question" />
|
||||||
<Button cancelButton="true" focusTraversable="false" layoutX="10.0" layoutY="48.0" onAction="#onEndAction" prefWidth="110.0" text="_End test" />
|
<Button cancelButton="true" focusTraversable="false" layoutX="10.0" layoutY="48.0" onAction="#onEndAction" prefWidth="110.0" text="_End test" />
|
||||||
</children>
|
</children>
|
||||||
<BorderPane.margin>
|
<BorderPane.margin>
|
||||||
|
|
Loading…
Reference in a new issue