mirror of
https://gitlab.com/kauron/jstudy
synced 2024-12-22 08:23:33 +01:00
Added option to repeat question immediately until gotten right
This commit is contained in:
parent
8d6b99bd59
commit
674ed9d7cf
5 changed files with 48 additions and 19 deletions
|
@ -10,15 +10,16 @@ import java.util.ResourceBundle;
|
||||||
|
|
||||||
public class SettingsController implements Initializable {
|
public class SettingsController implements Initializable {
|
||||||
@FXML
|
@FXML
|
||||||
private JFXCheckBox repeatMistakes, showFeedback;
|
private JFXCheckBox repeatMistakes, showFeedback, repeatImmediately;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
repeatMistakes.setSelected(AppConfig.repeatWrong);
|
repeatImmediately.disableProperty().bind(repeatMistakes.selectedProperty().not());
|
||||||
repeatMistakes.selectedProperty().addListener((observable, old, value) -> AppConfig.repeatWrong = value);
|
repeatImmediately.selectedProperty().bindBidirectional(AppConfig.repeatImmediately);
|
||||||
showFeedback.setSelected(AppConfig.showFeedback);
|
repeatMistakes.selectedProperty().bindBidirectional(AppConfig.repeatWrong);
|
||||||
showFeedback.selectedProperty().addListener((observable, old, value) -> AppConfig.showFeedback = value);
|
showFeedback.selectedProperty().bindBidirectional(AppConfig.showFeedback);
|
||||||
|
repeatMistakes.selectedProperty().addListener((obj, o, n) -> {
|
||||||
|
if (!n) repeatImmediately.setSelected(false);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,12 @@ package es.kauron.jstudy.controller;
|
||||||
|
|
||||||
import es.kauron.jstudy.model.AppConfig;
|
import es.kauron.jstudy.model.AppConfig;
|
||||||
import es.kauron.jstudy.model.TestItem;
|
import es.kauron.jstudy.model.TestItem;
|
||||||
|
import javafx.beans.property.SimpleBooleanProperty;
|
||||||
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.geometry.Insets;
|
||||||
|
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;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
|
@ -24,13 +26,17 @@ public class TestController implements Initializable {
|
||||||
private ProgressBar progress;
|
private ProgressBar progress;
|
||||||
@FXML
|
@FXML
|
||||||
private HBox feedback;
|
private HBox feedback;
|
||||||
|
@FXML
|
||||||
|
private Button skipButton;
|
||||||
|
|
||||||
|
private SimpleBooleanProperty correctingError = new SimpleBooleanProperty(false);
|
||||||
private List<TestItem> list;
|
private List<TestItem> list;
|
||||||
private int total, current = -1;
|
private int total, current = -1;
|
||||||
private int done = 0, errors = 0;
|
private int done = 0, errors = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||||
|
skipButton.disableProperty().bind(correctingError);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setList(List<TestItem> list) {
|
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
|
// 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);
|
list.remove(current);
|
||||||
progress.setProgress(++done/(double)total);
|
progress.setProgress(++done / (double) total);
|
||||||
progressLabel.setText(done + "/" + total);
|
progressLabel.setText(done + "/" + total);
|
||||||
if (list.size() == 0) {
|
if (list.size() == 0) {
|
||||||
onEndAction(event);
|
onEndAction(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
chooseQuestion();
|
||||||
|
} else if (!AppConfig.repeatImmediately.get()) {
|
||||||
|
chooseQuestion();
|
||||||
}
|
}
|
||||||
onSkipAction(event);
|
correctingError.set(!right && AppConfig.repeatImmediately.get());
|
||||||
|
setQuestion();
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
private void chooseQuestion() {
|
||||||
private void onSkipAction(ActionEvent event) {
|
|
||||||
answer.setText("");
|
answer.setText("");
|
||||||
int previous = current;
|
int previous = current;
|
||||||
do
|
do
|
||||||
current = (int) (Math.random() * list.size());
|
current = (int) (Math.random() * list.size());
|
||||||
while (list.size() > 1 && current == previous);
|
while (list.size() > 1 && current == previous);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setQuestion() {
|
||||||
|
answer.setText("");
|
||||||
question.setText(list.get(current).getQuestion());
|
question.setText(list.get(current).getQuestion());
|
||||||
answer.requestFocus();
|
answer.requestFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void onSkipAction(ActionEvent event) {
|
||||||
|
chooseQuestion();
|
||||||
|
setQuestion();
|
||||||
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void onEndAction(ActionEvent event) {
|
private void onEndAction(ActionEvent event) {
|
||||||
answer.setText("");
|
answer.setText("");
|
||||||
|
|
|
@ -1,17 +1,21 @@
|
||||||
package es.kauron.jstudy.model;
|
package es.kauron.jstudy.model;
|
||||||
|
|
||||||
|
import javafx.beans.property.BooleanProperty;
|
||||||
|
import javafx.beans.property.SimpleBooleanProperty;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.prefs.BackingStoreException;
|
import java.util.prefs.BackingStoreException;
|
||||||
import java.util.prefs.Preferences;
|
import java.util.prefs.Preferences;
|
||||||
|
|
||||||
public class AppConfig {
|
public class AppConfig {
|
||||||
public static boolean repeatWrong, showFeedback;
|
public static BooleanProperty repeatWrong, showFeedback, repeatImmediately;
|
||||||
public static File lastDir;
|
public static File lastDir;
|
||||||
|
|
||||||
public static void save() {
|
public static void save() {
|
||||||
Preferences prefs = Preferences.userRoot();
|
Preferences prefs = Preferences.userRoot();
|
||||||
prefs.putBoolean("repeatWrong", repeatWrong);
|
prefs.putBoolean("repeatWrong", repeatWrong.get());
|
||||||
prefs.putBoolean("showFeedback", showFeedback);
|
prefs.putBoolean("showFeedback", showFeedback.get());
|
||||||
|
prefs.putBoolean("repeatImmediately", repeatImmediately.get());
|
||||||
prefs.put("lastDir", lastDir == null ? "" : lastDir.getAbsolutePath());
|
prefs.put("lastDir", lastDir == null ? "" : lastDir.getAbsolutePath());
|
||||||
try {
|
try {
|
||||||
prefs.flush();
|
prefs.flush();
|
||||||
|
@ -22,8 +26,12 @@ public class AppConfig {
|
||||||
|
|
||||||
public static void load() {
|
public static void load() {
|
||||||
Preferences prefs = Preferences.userRoot();
|
Preferences prefs = Preferences.userRoot();
|
||||||
repeatWrong = prefs.getBoolean("repeatWrong", true);
|
repeatWrong = new SimpleBooleanProperty(prefs.getBoolean("repeatWrong", true));
|
||||||
showFeedback = prefs.getBoolean("showFeedback", 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", "");
|
String dirPath = prefs.get("lastDir", "");
|
||||||
if (!dirPath.isEmpty()) lastDir = new File(dirPath);
|
if (!dirPath.isEmpty()) lastDir = new File(dirPath);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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">
|
<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>
|
<children>
|
||||||
<JFXCheckBox fx:id="repeatMistakes" text="_Repeat mistakes" />
|
<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" />
|
<JFXCheckBox fx:id="showFeedback" disable="true" layoutX="237.0" layoutY="201.0" text="Show _feedback while testing" />
|
||||||
</children>
|
</children>
|
||||||
<padding>
|
<padding>
|
||||||
|
|
|
@ -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" />
|
<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" />
|
<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