mirror of
https://gitlab.com/kauron/jstudy
synced 2025-09-30 21:01:10 +02:00
Added settings tab
This commit is contained in:
parent
c3c57afd79
commit
56575f6a1e
8 changed files with 95 additions and 16 deletions
|
@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
40
src/main/java/es/kauron/jstudy/model/AppConfig.java
Normal file
40
src/main/java/es/kauron/jstudy/model/AppConfig.java
Normal 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;
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue