From e8111c0714d29a4acc393daad6bf6498d586b879 Mon Sep 17 00:00:00 2001 From: Carlos Galindo Date: Sun, 12 Jun 2016 13:37:45 +0200 Subject: [PATCH] Show feedback setting --- .../jstudy/controller/SettingsController.java | 10 ++++------ .../kauron/jstudy/controller/TestController.java | 6 +++++- .../java/es/kauron/jstudy/model/AppConfig.java | 15 +++++++++------ .../resources/es/kauron/jstudy/view/settings.fxml | 13 +++++++++++-- .../resources/es/kauron/jstudy/view/test.fxml | 2 +- 5 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/main/java/es/kauron/jstudy/controller/SettingsController.java b/src/main/java/es/kauron/jstudy/controller/SettingsController.java index 7164b05..fa53ac5 100644 --- a/src/main/java/es/kauron/jstudy/controller/SettingsController.java +++ b/src/main/java/es/kauron/jstudy/controller/SettingsController.java @@ -10,16 +10,14 @@ import java.util.ResourceBundle; public class SettingsController implements Initializable { @FXML - private JFXCheckBox repeatMistakes; + private JFXCheckBox repeatMistakes, showFeedback; @Override public void initialize(URL location, ResourceBundle resources) { - System.err.println(AppConfig.printValues()); repeatMistakes.setSelected(AppConfig.repeatWrong); - repeatMistakes.selectedProperty().addListener((change, o, n) -> { - AppConfig.repeatWrong = n; - System.err.println(AppConfig.printValues()); - }); + repeatMistakes.selectedProperty().addListener((observable, old, value) -> AppConfig.repeatWrong = value); + showFeedback.setSelected(AppConfig.showFeedback); + showFeedback.selectedProperty().addListener((observable, old, value) -> AppConfig.showFeedback = value); } diff --git a/src/main/java/es/kauron/jstudy/controller/TestController.java b/src/main/java/es/kauron/jstudy/controller/TestController.java index b97f55e..e2cb533 100644 --- a/src/main/java/es/kauron/jstudy/controller/TestController.java +++ b/src/main/java/es/kauron/jstudy/controller/TestController.java @@ -8,6 +8,7 @@ import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.Label; import javafx.scene.control.ProgressBar; +import javafx.scene.layout.HBox; import java.net.URL; import java.util.List; @@ -20,13 +21,15 @@ public class TestController implements Initializable { private JFXTextField answer; @FXML private ProgressBar progress; + @FXML + private HBox feedback; private List list; private int total, current; @Override public void initialize(URL url, ResourceBundle resourceBundle) { - + feedback.setVisible(AppConfig.showFeedback); } void setList(List list) { @@ -64,6 +67,7 @@ public class TestController implements Initializable { @FXML private void onSkipAction(ActionEvent event) { + feedback.setVisible(AppConfig.showFeedback); answer.setText(""); current = (int) (Math.random() * list.size()); question.setText(list.get(current).getQuestion()); diff --git a/src/main/java/es/kauron/jstudy/model/AppConfig.java b/src/main/java/es/kauron/jstudy/model/AppConfig.java index a6a759e..89a6bd2 100644 --- a/src/main/java/es/kauron/jstudy/model/AppConfig.java +++ b/src/main/java/es/kauron/jstudy/model/AppConfig.java @@ -7,12 +7,13 @@ import java.util.Scanner; public class AppConfig { private static final String FILE = "./config.ini"; - public static boolean repeatWrong; + public static boolean repeatWrong, showFeedback; public static void save() { try { PrintWriter pw = new PrintWriter(new File(FILE)); - pw.print("repeatWrong=" + repeatWrong); + pw.println("repeatWrong=" + repeatWrong); + pw.println("showFeedback=" + showFeedback); pw.flush(); pw.close(); } catch (FileNotFoundException e) { @@ -25,9 +26,11 @@ public class AppConfig { Scanner in = new Scanner(new File(FILE)); while (in.hasNextLine()) { String line = in.nextLine(); - if (line.matches("repeatWrong=.*")) { - repeatWrong = Boolean.parseBoolean(line.substring(line.indexOf('=') + 1)); - } + String value = line.substring(line.indexOf('=') + 1); + if (line.matches("repeatWrong=.*")) + repeatWrong = Boolean.parseBoolean(value); + else if (line.matches("showFeedback=.*")) + showFeedback = Boolean.parseBoolean(value); } } catch (FileNotFoundException e) { e.printStackTrace(); @@ -35,6 +38,6 @@ public class AppConfig { } public static String printValues() { - return "repeatWrong=" + repeatWrong; + return String.format("repeatWrong=%b\nshowFeedback=%b", repeatWrong, showFeedback); } } diff --git a/src/main/resources/es/kauron/jstudy/view/settings.fxml b/src/main/resources/es/kauron/jstudy/view/settings.fxml index eb01a07..4a1ac7b 100644 --- a/src/main/resources/es/kauron/jstudy/view/settings.fxml +++ b/src/main/resources/es/kauron/jstudy/view/settings.fxml @@ -1,11 +1,20 @@ + - + - + + + + + + + + + diff --git a/src/main/resources/es/kauron/jstudy/view/test.fxml b/src/main/resources/es/kauron/jstudy/view/test.fxml index efa2fd6..2e98988 100644 --- a/src/main/resources/es/kauron/jstudy/view/test.fxml +++ b/src/main/resources/es/kauron/jstudy/view/test.fxml @@ -36,7 +36,7 @@