1
0
Fork 0
mirror of https://gitlab.com/kauron/jstudy synced 2024-12-22 08:23:33 +01:00

Test: enlarged feedback and improved internals

This commit is contained in:
Carlos Galindo 2019-09-11 19:09:11 +02:00
parent 59ffe397d3
commit b08e5aa1dc
Signed by: kauron
GPG key ID: 83E68706DEE119A3
3 changed files with 43 additions and 39 deletions

View file

@ -2,11 +2,11 @@ package es.kauron.jstudy.controller;
import es.kauron.jstudy.model.AppPrefs;
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.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
@ -31,8 +31,9 @@ public class TestController implements Initializable {
private SimpleBooleanProperty correctingError = new SimpleBooleanProperty(false);
private List<TestItem> list;
private int total, current = -1;
private int done = 0, errors = 0;
private IntegerProperty errors = new SimpleIntegerProperty(0);
private ObjectProperty<TestItem> item = new SimpleObjectProperty<>();
private IntegerProperty done = new SimpleIntegerProperty(0);
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
@ -42,24 +43,32 @@ public class TestController implements Initializable {
void setList(List<TestItem> list) {
this.list = list;
total = list.size();
int total = list.size();
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);
}
@FXML
private void onNextAction(ActionEvent event) {
prevQuestion.setText(list.get(current).getQuestion());
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);
correctLabel.setVisible(!right);
if (!right) {
errors++;
errors.set(errors.get() + 1);
prevAnswer.setStyle("-fx-text-fill: #C40000;");
} else {
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
if ((right && !correctingError.get()) || !AppPrefs.repeatWrong.get()) {
list.remove(current);
progress.setProgress(++done / (double) total);
progressLabel.setText(done + "/" + total);
list.remove(item.get());
done.set(done.get() + 1);
if (list.size() == 0) {
onEndAction(null);
return;
@ -79,27 +87,24 @@ public class TestController implements Initializable {
chooseQuestion();
}
correctingError.set(!right && AppPrefs.repeatImmediately.get());
setQuestion();
answer.setText("");
answer.requestFocus();
}
private void chooseQuestion() {
answer.setText("");
int previous = current;
TestItem next = item.get();
do
current = (int) (Math.random() * list.size());
while (list.size() > 1 && current == previous);
}
private void setQuestion() {
answer.setText("");
question.setText(list.get(current).getQuestion());
answer.requestFocus();
next = list.get((int) (Math.random() * list.size()));
while (list.size() > 1 && item.get() == next);
item.set(next);
}
@FXML
private void onSkipAction(ActionEvent event) {
chooseQuestion();
setQuestion();
answer.setText("");
answer.requestFocus();
}
@FXML
@ -107,10 +112,5 @@ public class TestController implements Initializable {
answer.setText("");
answer.setDisable(true);
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)));
}
}

View file

@ -1,3 +1,7 @@
.answer {
-fx-font-weight: bold;
}
.feedbackText {
-fx-font-size: 20;
}

View file

@ -4,7 +4,7 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?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>
<VBox minHeight="280.0" minWidth="360.0" spacing="10.0">
<children>
@ -21,10 +21,10 @@
<Separator />
<HBox fx:id="feedback" alignment="BOTTOM_CENTER" VBox.vgrow="ALWAYS">
<children>
<GridPane hgap="10.0" HBox.hgrow="NEVER">
<GridPane hgap="10.0" maxWidth="1.7976931348623157E308" HBox.hgrow="ALWAYS">
<columnConstraints>
<ColumnConstraints fillWidth="false" halignment="RIGHT" hgrow="NEVER" />
<ColumnConstraints fillWidth="false" hgrow="NEVER" maxWidth="1.7976931348623157E308" />
<ColumnConstraints fillWidth="false" hgrow="ALWAYS" maxWidth="1.7976931348623157E308" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
@ -32,12 +32,12 @@
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Previous question" />
<Label fx:id="prevQuestion" text="question" GridPane.columnIndex="1" />
<Label text="Previous answer" GridPane.rowIndex="1" />
<Label fx:id="prevAnswer" styleClass="answer" stylesheets="@../css/test.css" text="answer" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label fx:id="correctLabel" text="Correct answer" GridPane.rowIndex="2" />
<Label fx:id="correctAnswer" text="correct answer" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label text="Previous question" wrapText="true" />
<Label fx:id="prevQuestion" maxWidth="1.7976931348623157E308" styleClass="feedbackText" wrapText="true" GridPane.columnIndex="1" />
<Label text="Previous answer" wrapText="true" 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" wrapText="true" GridPane.rowIndex="2" />
<Label fx:id="correctAnswer" maxWidth="1.7976931348623157E308" styleClass="feedbackText" wrapText="true" GridPane.columnIndex="1" GridPane.rowIndex="2" />
</children>
</GridPane>
</children>
@ -64,7 +64,7 @@
<VBox alignment="TOP_RIGHT" spacing="10.0" BorderPane.alignment="CENTER">
<children>
<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" />
</children>
<BorderPane.margin>