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

Added settings tab

This commit is contained in:
Carlos Galindo 2016-06-12 12:58:35 +02:00
commit 56575f6a1e
Signed by: kauron
GPG key ID: 83E68706DEE119A3
8 changed files with 95 additions and 16 deletions

View file

@ -1,5 +1,6 @@
package es.kauron.jstudy;
import es.kauron.jstudy.model.AppConfig;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
@ -10,10 +11,14 @@ public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
AppConfig.load();
Parent root = FXMLLoader.load(Main.class.getResource("view/main.fxml"));
primaryStage.setTitle("JStudy");
primaryStage.setScene(new Scene(root));
primaryStage.show();
primaryStage.setOnCloseRequest(event -> {
AppConfig.save();
});
}

View file

@ -42,6 +42,17 @@ public class Controller implements Initializable {
saveMenu.disableProperty().bind(table.not());
}
@FXML
private void onSettingsAction(ActionEvent event) {
try {
Parent root = FXMLLoader.load(Main.class.getResource("view/settings.fxml"));
tabPane.getTabs().add(new Tab("Settings", root));
tabPane.getSelectionModel().selectLast();
} catch (IOException e) {
e.printStackTrace();
}
}
@FXML
private void onNewAction(ActionEvent event) {
TextInputDialog dialog = new TextInputDialog("Name");

View file

@ -0,0 +1,26 @@
package es.kauron.jstudy.controller;
import com.jfoenix.controls.JFXCheckBox;
import es.kauron.jstudy.model.AppConfig;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import java.net.URL;
import java.util.ResourceBundle;
public class SettingsController implements Initializable {
@FXML
private JFXCheckBox repeatMistakes;
@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());
});
}
}

View file

@ -0,0 +1,40 @@
package es.kauron.jstudy.model;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
public class AppConfig {
private static final String FILE = "./config.ini";
public static boolean repeatWrong;
public static void save() {
try {
PrintWriter pw = new PrintWriter(new File(FILE));
pw.print("repeatWrong=" + repeatWrong);
pw.flush();
pw.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public static void load() {
try {
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));
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public static String printValues() {
return "repeatWrong=" + repeatWrong;
}
}

View file

@ -76,6 +76,7 @@ public class TestItem {
list.add(new TestItem(question, answer));
System.err.println(question + " :: " + answer);
}
in.close();
} catch (FileNotFoundException | InputMismatchException e) {
e.printStackTrace();
}