1
0
Fork 0
mirror of https://gitlab.com/kauron/jstudy synced 2024-11-13 07:33:44 +01:00

Added option to repeat question immediately until gotten right

This commit is contained in:
Carlos Galindo 2019-09-10 15:14:50 +02:00
parent 8d6b99bd59
commit 674ed9d7cf
Signed by: kauron
GPG key ID: 83E68706DEE119A3
5 changed files with 48 additions and 19 deletions

View file

@ -10,15 +10,16 @@ import java.util.ResourceBundle;
public class SettingsController implements Initializable {
@FXML
private JFXCheckBox repeatMistakes, showFeedback;
private JFXCheckBox repeatMistakes, showFeedback, repeatImmediately;
@Override
public void initialize(URL location, ResourceBundle resources) {
repeatMistakes.setSelected(AppConfig.repeatWrong);
repeatMistakes.selectedProperty().addListener((observable, old, value) -> AppConfig.repeatWrong = value);
showFeedback.setSelected(AppConfig.showFeedback);
showFeedback.selectedProperty().addListener((observable, old, value) -> AppConfig.showFeedback = value);
repeatImmediately.disableProperty().bind(repeatMistakes.selectedProperty().not());
repeatImmediately.selectedProperty().bindBidirectional(AppConfig.repeatImmediately);
repeatMistakes.selectedProperty().bindBidirectional(AppConfig.repeatWrong);
showFeedback.selectedProperty().bindBidirectional(AppConfig.showFeedback);
repeatMistakes.selectedProperty().addListener((obj, o, n) -> {
if (!n) repeatImmediately.setSelected(false);
});
}
}

View file

@ -2,10 +2,12 @@ package es.kauron.jstudy.controller;
import es.kauron.jstudy.model.AppConfig;
import es.kauron.jstudy.model.TestItem;
import javafx.beans.property.SimpleBooleanProperty;
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;
import javafx.scene.control.TextField;
@ -24,13 +26,17 @@ public class TestController implements Initializable {
private ProgressBar progress;
@FXML
private HBox feedback;
@FXML
private Button skipButton;
private SimpleBooleanProperty correctingError = new SimpleBooleanProperty(false);
private List<TestItem> list;
private int total, current = -1;
private int done = 0, errors = 0;
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
skipButton.disableProperty().bind(correctingError);
}
void setList(List<TestItem> list) {
@ -59,29 +65,42 @@ public class TestController implements Initializable {
}
// Remove the question from the pool if the question was correctly answered or there is no repetition
if (right || !AppConfig.repeatWrong) {
if ((right && !correctingError.get()) || !AppConfig.repeatWrong.get()) {
list.remove(current);
progress.setProgress(++done / (double) total);
progressLabel.setText(done + "/" + total);
if (list.size() == 0) {
onEndAction(event);
onEndAction(null);
return;
}
chooseQuestion();
} else if (!AppConfig.repeatImmediately.get()) {
chooseQuestion();
}
onSkipAction(event);
correctingError.set(!right && AppConfig.repeatImmediately.get());
setQuestion();
}
@FXML
private void onSkipAction(ActionEvent event) {
private void chooseQuestion() {
answer.setText("");
int previous = current;
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();
}
@FXML
private void onSkipAction(ActionEvent event) {
chooseQuestion();
setQuestion();
}
@FXML
private void onEndAction(ActionEvent event) {
answer.setText("");

View file

@ -1,17 +1,21 @@
package es.kauron.jstudy.model;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import java.io.File;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
public class AppConfig {
public static boolean repeatWrong, showFeedback;
public static BooleanProperty repeatWrong, showFeedback, repeatImmediately;
public static File lastDir;
public static void save() {
Preferences prefs = Preferences.userRoot();
prefs.putBoolean("repeatWrong", repeatWrong);
prefs.putBoolean("showFeedback", showFeedback);
prefs.putBoolean("repeatWrong", repeatWrong.get());
prefs.putBoolean("showFeedback", showFeedback.get());
prefs.putBoolean("repeatImmediately", repeatImmediately.get());
prefs.put("lastDir", lastDir == null ? "" : lastDir.getAbsolutePath());
try {
prefs.flush();
@ -22,8 +26,12 @@ public class AppConfig {
public static void load() {
Preferences prefs = Preferences.userRoot();
repeatWrong = prefs.getBoolean("repeatWrong", true);
showFeedback = prefs.getBoolean("showFeedback", true);
repeatWrong = new SimpleBooleanProperty(prefs.getBoolean("repeatWrong", true));
showFeedback = new SimpleBooleanProperty(prefs.getBoolean("showFeedback", true));
repeatImmediately = new SimpleBooleanProperty(prefs.getBoolean("repeatImmediately", false));
repeatWrong.addListener((obj, o, n) -> save());
showFeedback.addListener((obj, o, n) -> save());
repeatImmediately.addListener((obj, o, n) -> save());
String dirPath = prefs.get("lastDir", "");
if (!dirPath.isEmpty()) lastDir = new File(dirPath);
}

View file

@ -6,6 +6,7 @@
<VBox alignment="CENTER_LEFT" spacing="15.0" xmlns="http://javafx.com/javafx/8.0.76-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="es.kauron.jstudy.controller.SettingsController">
<children>
<JFXCheckBox fx:id="repeatMistakes" text="_Repeat mistakes" />
<JFXCheckBox fx:id="repeatImmediately" text="_Always repeat immediatly"/>
<JFXCheckBox fx:id="showFeedback" disable="true" layoutX="237.0" layoutY="201.0" text="Show _feedback while testing" />
</children>
<padding>

View file

@ -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" />
<Button cancelButton="true" focusTraversable="false" onAction="#onSkipAction" prefWidth="110.0" text="_Skip question" fx:id="skipButton"/>
<Button cancelButton="true" focusTraversable="false" layoutX="10.0" layoutY="48.0" onAction="#onEndAction" prefWidth="110.0" text="_End test" />
</children>
<BorderPane.margin>