mirror of
https://gitlab.com/kauron/jstudy
synced 2024-12-22 08:23:33 +01:00
Added timer for test
This commit is contained in:
parent
7d835018e3
commit
93b7dce200
1 changed files with 23 additions and 2 deletions
|
@ -2,6 +2,7 @@ package es.kauron.jstudy.controller;
|
|||
|
||||
import es.kauron.jstudy.model.AppPrefs;
|
||||
import es.kauron.jstudy.model.TestItem;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.beans.property.*;
|
||||
import javafx.event.ActionEvent;
|
||||
|
@ -16,6 +17,8 @@ import javafx.scene.layout.HBox;
|
|||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class TestController implements Initializable {
|
||||
@FXML
|
||||
|
@ -34,19 +37,30 @@ public class TestController implements Initializable {
|
|||
private final IntegerProperty errors = new SimpleIntegerProperty(0);
|
||||
private final ObjectProperty<TestItem> item = new SimpleObjectProperty<>();
|
||||
private final IntegerProperty done = new SimpleIntegerProperty(0);
|
||||
// Time accounting
|
||||
private final IntegerProperty seconds = new SimpleIntegerProperty(0);
|
||||
private final IntegerProperty minutes = new SimpleIntegerProperty(0);
|
||||
private final Timer timer = new Timer();
|
||||
|
||||
@Override
|
||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||
skipButton.disableProperty().bind(correctingError);
|
||||
feedback.visibleProperty().bind(AppPrefs.showFeedback);
|
||||
seconds.addListener((obj, o, n) -> {
|
||||
if (n.intValue() == 60) {
|
||||
minutes.set(minutes.get() + 1);
|
||||
seconds.set(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void setList(List<TestItem> list) {
|
||||
this.list = list;
|
||||
int total = list.size();
|
||||
progressLabel.textProperty().bind(Bindings.format(
|
||||
String.format("%%.2f%%%% %%d / %d %%d mistakes", total),
|
||||
done.multiply(100.0).divide(total), done, errors));
|
||||
String.format("%%.2f%%%% %%d / %d %%d mistakes %%02d:%%02d", total),
|
||||
done.multiply(100.0).divide(total), done,
|
||||
errors, minutes, seconds));
|
||||
progress.progressProperty().bind(done.divide((double) total));
|
||||
item.addListener((obj, o, n) -> {
|
||||
if (o != null) {
|
||||
|
@ -55,6 +69,12 @@ public class TestController implements Initializable {
|
|||
}
|
||||
question.setText(n.getQuestion());
|
||||
});
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
Platform.runLater(() -> seconds.set(seconds.get() + 1));
|
||||
}
|
||||
}, 0, 1000);
|
||||
onSkipAction(null);
|
||||
}
|
||||
|
||||
|
@ -116,5 +136,6 @@ public class TestController implements Initializable {
|
|||
answer.setText("");
|
||||
answer.setDisable(true);
|
||||
question.setText("That's it!");
|
||||
timer.cancel();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue