1
0
Fork 0
mirror of https://gitlab.com/kauron/jstudy synced 2025-09-30 21:01:10 +02:00

Test: enlarged feedback and improved internals

This commit is contained in:
Carlos Galindo 2019-09-11 19:09:11 +02:00
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)));
}
}