mirror of
https://gitlab.com/kauron/jstudy
synced 2024-11-13 07:33:44 +01:00
Added settings tab
This commit is contained in:
parent
c3c57afd79
commit
56575f6a1e
8 changed files with 95 additions and 16 deletions
|
@ -23,20 +23,4 @@
|
|||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
<component name="masterDetails">
|
||||
<states>
|
||||
<state key="ProjectJDKs.UI">
|
||||
<settings>
|
||||
<last-edited>1.8</last-edited>
|
||||
<splitter-proportions>
|
||||
<option name="proportions">
|
||||
<list>
|
||||
<option value="0.2" />
|
||||
</list>
|
||||
</option>
|
||||
</splitter-proportions>
|
||||
</settings>
|
||||
</state>
|
||||
</states>
|
||||
</component>
|
||||
</project>
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
<Button mnemonicParsing="false" onAction="#onNewAction" prefWidth="100.0" text="New table" />
|
||||
<Button mnemonicParsing="false" onAction="#onLoadAction" prefWidth="100.0" text="Load file" />
|
||||
<Button layoutX="260.0" layoutY="187.0" mnemonicParsing="false" onAction="#onImportAction" prefWidth="100.0" text="Import data" />
|
||||
<Button layoutX="260.0" layoutY="208.0" mnemonicParsing="false" onAction="#onSettingsAction" prefWidth="100.0" text="Settings" />
|
||||
</children>
|
||||
</VBox>
|
||||
</content>
|
||||
|
|
11
src/main/resources/es/kauron/jstudy/view/settings.fxml
Normal file
11
src/main/resources/es/kauron/jstudy/view/settings.fxml
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import com.jfoenix.controls.JFXCheckBox?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
|
||||
|
||||
<VBox alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.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" />
|
||||
</children>
|
||||
</VBox>
|
Loading…
Reference in a new issue