1
0
Fork 0
mirror of https://gitlab.com/kauron/jstudy synced 2024-12-23 00:43:32 +01:00

Added settings tab

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

View file

@ -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"> <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" /> <output url="file://$PROJECT_DIR$/out" />
</component> </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> </project>

View file

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

View file

@ -42,6 +42,17 @@ public class Controller implements Initializable {
saveMenu.disableProperty().bind(table.not()); 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 @FXML
private void onNewAction(ActionEvent event) { private void onNewAction(ActionEvent event) {
TextInputDialog dialog = new TextInputDialog("Name"); 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)); list.add(new TestItem(question, answer));
System.err.println(question + " :: " + answer); System.err.println(question + " :: " + answer);
} }
in.close();
} catch (FileNotFoundException | InputMismatchException e) { } catch (FileNotFoundException | InputMismatchException e) {
e.printStackTrace(); e.printStackTrace();
} }

View file

@ -22,6 +22,7 @@
<Button mnemonicParsing="false" onAction="#onNewAction" prefWidth="100.0" text="New table" /> <Button mnemonicParsing="false" onAction="#onNewAction" prefWidth="100.0" text="New table" />
<Button mnemonicParsing="false" onAction="#onLoadAction" prefWidth="100.0" text="Load file" /> <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="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> </children>
</VBox> </VBox>
</content> </content>

View 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>