1
0
Fork 0
mirror of https://gitlab.com/kauron/jstudy synced 2024-11-13 07:33:44 +01:00

Typos and warnings fix

This commit is contained in:
Carlos Galindo 2019-09-11 22:07:59 +02:00
parent 56b4f17a8c
commit 889295a0b2
Signed by: kauron
GPG key ID: 83E68706DEE119A3
9 changed files with 66 additions and 50 deletions

View file

@ -41,15 +41,18 @@ public class Controller implements Initializable {
private BorderPane root; private BorderPane root;
@FXML @FXML
private MenuItem menuCloseTab; private MenuItem menuCloseTab, menuSave;
private BooleanProperty table = new SimpleBooleanProperty(false); private final BooleanProperty tabIsTable = new SimpleBooleanProperty(false);
private Map<Tab, TableController> tabMap = new HashMap<>(); private final Map<Tab, TableController> tabMap = new HashMap<>();
@Override @Override
public void initialize(URL url, ResourceBundle resourceBundle) { public void initialize(URL url, ResourceBundle resourceBundle) {
tabPane.getSelectionModel().selectedItemProperty().addListener((ob, o, n) -> table.set(tabMap.get(n) != null)); tabPane.getSelectionModel().selectedItemProperty().addListener((ob, o, n) -> {
tabPane.getSelectionModel().selectedItemProperty().addListener((ob, o, n) -> menuCloseTab.setDisable(!n.isClosable())); tabIsTable.set(tabMap.get(n) != null);
menuCloseTab.setDisable(!n.isClosable());
menuSave.setDisable(!tabMap.containsKey(n) || tabMap.get(n).saved.get());
});
Platform.runLater(() -> Platform.runLater(() ->
root.getScene().getWindow().setOnCloseRequest(event -> { root.getScene().getWindow().setOnCloseRequest(event -> {
for (Tab tab : tabPane.getTabs()) { for (Tab tab : tabPane.getTabs()) {
@ -120,19 +123,23 @@ public class Controller implements Initializable {
} else if (result.isPresent() && result.get().equals(openBT)){ } else if (result.isPresent() && result.get().equals(openBT)){
for (File file : list) { for (File file : list) {
List<TestItem> aux = TestItem.loadFrom(file, TestItem.COLONS); List<TestItem> aux = TestItem.loadFrom(file, TestItem.COLONS);
if (aux != null) {
tabPane.getTabs().add(createTableTab(file.getName().substring(0, file.getName().lastIndexOf('.')), aux, file)); tabPane.getTabs().add(createTableTab(file.getName().substring(0, file.getName().lastIndexOf('.')), aux, file));
} }
} }
}
} else { } else {
File file = list.get(0); File file = list.get(0);
List<TestItem> aux = TestItem.loadFrom(file, TestItem.COLONS); List<TestItem> aux = TestItem.loadFrom(file, TestItem.COLONS);
if (aux != null) {
tabPane.getTabs().add(createTableTab(file.getName().substring(0, file.getName().lastIndexOf('.')), aux, file)); tabPane.getTabs().add(createTableTab(file.getName().substring(0, file.getName().lastIndexOf('.')), aux, file));
tabPane.getSelectionModel().selectLast(); tabPane.getSelectionModel().selectLast();
} }
} }
@FXML
private void onSaveAction(ActionEvent event) {
Tab tab = tabPane.getSelectionModel().getSelectedItem();
if (tabMap.containsKey(tab)) {
tabMap.get(tab).onSaveAction(event);
}
} }
@FXML @FXML
@ -151,11 +158,9 @@ public class Controller implements Initializable {
else else
separator = TestItem.COMMA; separator = TestItem.COMMA;
List<TestItem> aux = TestItem.loadFrom(file, separator); List<TestItem> aux = TestItem.loadFrom(file, separator);
if (aux != null) {
tabPane.getTabs().add(createTableTab(file.getName().substring(0, file.getName().lastIndexOf('.')), aux, null)); tabPane.getTabs().add(createTableTab(file.getName().substring(0, file.getName().lastIndexOf('.')), aux, null));
tabPane.getSelectionModel().selectLast(); tabPane.getSelectionModel().selectLast();
} }
}
private Tab createTableTab(String name, List<TestItem> list, File file) { private Tab createTableTab(String name, List<TestItem> list, File file) {
try { try {
@ -255,10 +260,8 @@ public class Controller implements Initializable {
List<File> files = event.getDragboard().getFiles(); List<File> files = event.getDragboard().getFiles();
for (File file : files) { for (File file : files) {
List<TestItem> aux = TestItem.loadFrom(file, TestItem.COLONS); List<TestItem> aux = TestItem.loadFrom(file, TestItem.COLONS);
if (aux != null) {
tabPane.getTabs().add(createTableTab(file.getName().substring(0, file.getName().lastIndexOf('.')), aux, file)); tabPane.getTabs().add(createTableTab(file.getName().substring(0, file.getName().lastIndexOf('.')), aux, file));
} }
}
event.consume(); event.consume();
} }

View file

@ -26,11 +26,11 @@ public class EditController implements Initializable {
public void initialize(URL url, ResourceBundle rb) { public void initialize(URL url, ResourceBundle rb) {
} }
protected void setList(ObservableList list, BooleanProperty saved) { void setList(ObservableList<TestItem> list, BooleanProperty saved) {
setList(list, -1, saved); setList(list, -1, saved);
} }
protected void setList(ObservableList<TestItem> list, int index, BooleanProperty saved) { void setList(ObservableList<TestItem> list, int index, BooleanProperty saved) {
this.list = list; // Save attributes correctly this.list = list; // Save attributes correctly
this.index = index; this.index = index;
this.saved = saved; this.saved = saved;

View file

@ -43,7 +43,7 @@ public class TableController implements Initializable {
private Controller parent; private Controller parent;
private File file; private File file;
StringProperty name; StringProperty name;
BooleanProperty saved = new SimpleBooleanProperty(); final BooleanProperty saved = new SimpleBooleanProperty();
@Override @Override
public void initialize(URL url, ResourceBundle resourceBundle) { public void initialize(URL url, ResourceBundle resourceBundle) {
@ -74,7 +74,7 @@ public class TableController implements Initializable {
@FXML @FXML
protected void onSaveAction(ActionEvent event) { protected void onSaveAction(ActionEvent event) {
if (file == null) { while (file == null) {
FileChooser chooser = new FileChooser(); FileChooser chooser = new FileChooser();
chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("JStudy file", "*.jsdb")); chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("JStudy file", "*.jsdb"));
if (AppPrefs.lastDir != null) chooser.setInitialDirectory(AppPrefs.lastDir); if (AppPrefs.lastDir != null) chooser.setInitialDirectory(AppPrefs.lastDir);
@ -82,11 +82,11 @@ public class TableController implements Initializable {
file = chooser.showSaveDialog(table.getScene().getWindow()); file = chooser.showSaveDialog(table.getScene().getWindow());
if (!file.getName().endsWith(".jsdb")) if (!file.getName().endsWith(".jsdb"))
file = new File(file.getPath() + ".jsdb"); file = new File(file.getPath() + ".jsdb");
if (file != null) if (file != null) {
AppPrefs.lastDir = file.getParentFile(); AppPrefs.lastDir = file.getParentFile();
name.set(file.getName().substring(0, file.getName().lastIndexOf('.'))); name.set(file.getName().substring(0, file.getName().lastIndexOf('.')));
} }
if (file == null) return; }
TestItem.saveTo(file, data); TestItem.saveTo(file, data);
saved.set(true); saved.set(true);
} }
@ -94,10 +94,10 @@ public class TableController implements Initializable {
@FXML @FXML
protected void onAddAction(ActionEvent event) { protected void onAddAction(ActionEvent event) {
try { try {
FXMLLoader cargador = new FXMLLoader(Main.class.getResource("view/edit.fxml")); FXMLLoader loader = new FXMLLoader(Main.class.getResource("view/edit.fxml"));
Parent pRoot = cargador.load(); Parent pRoot = loader.load();
((EditController) cargador.getController()).setList(data, saved); ((EditController) loader.getController()).setList(data, saved);
Stage stage = new Stage(); Stage stage = new Stage();
stage.setTitle("New entry"); stage.setTitle("New entry");
@ -115,10 +115,10 @@ public class TableController implements Initializable {
if (list.size() != 1) return; if (list.size() != 1) return;
int index = list.get(0); int index = list.get(0);
try { try {
FXMLLoader cargador = new FXMLLoader(Main.class.getResource("view/edit.fxml")); FXMLLoader loader = new FXMLLoader(Main.class.getResource("view/edit.fxml"));
Parent root = cargador.load(); Parent root = loader.load();
((EditController) cargador.getController()).setList(table.getItems(), index, saved); ((EditController) loader.getController()).setList(table.getItems(), index, saved);
Stage stage = new Stage(); Stage stage = new Stage();
stage.setTitle("Editing entry..."); stage.setTitle("Editing entry...");

View file

@ -29,11 +29,11 @@ public class TestController implements Initializable {
@FXML @FXML
private Button skipButton; private Button skipButton;
private SimpleBooleanProperty correctingError = new SimpleBooleanProperty(false); private final SimpleBooleanProperty correctingError = new SimpleBooleanProperty(false);
private List<TestItem> list; private List<TestItem> list;
private IntegerProperty errors = new SimpleIntegerProperty(0); private final IntegerProperty errors = new SimpleIntegerProperty(0);
private ObjectProperty<TestItem> item = new SimpleObjectProperty<>(); private final ObjectProperty<TestItem> item = new SimpleObjectProperty<>();
private IntegerProperty done = new SimpleIntegerProperty(0); private final IntegerProperty done = new SimpleIntegerProperty(0);
@Override @Override
public void initialize(URL url, ResourceBundle resourceBundle) { public void initialize(URL url, ResourceBundle resourceBundle) {
@ -63,7 +63,7 @@ public class TestController implements Initializable {
private void onNextAction(ActionEvent event) { private void onNextAction(ActionEvent event) {
prevAnswer.setText(answer.getText()); prevAnswer.setText(answer.getText());
boolean right = item.get().getAnswer().equals(answer.getText()); boolean right = item.get().checkAnswer(answer.getText());
correctAnswer.setVisible(!right); correctAnswer.setVisible(!right);
correctLabel.setVisible(!right); correctLabel.setVisible(!right);
@ -93,7 +93,7 @@ public class TestController implements Initializable {
private void chooseQuestion() { private void chooseQuestion() {
answer.setText(""); answer.setText("");
TestItem next = item.get(); TestItem next;
do do
next = list.get((int) (Math.random() * list.size())); next = list.get((int) (Math.random() * list.size()));
while (list.size() > 1 && item.get() == next); while (list.size() > 1 && item.get() == next);

View file

@ -4,7 +4,7 @@ import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty; import javafx.beans.property.StringProperty;
import java.io.*; import java.io.*;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.InputMismatchException; import java.util.InputMismatchException;
import java.util.List; import java.util.List;
@ -13,9 +13,10 @@ import java.util.Scanner;
public class TestItem { public class TestItem {
public static final String TAB = "\t", COLONS = "::", SEMICOLON = ";", COMMA = ","; public static final String TAB = "\t", COLONS = "::", SEMICOLON = ";", COMMA = ",";
private StringProperty question, answer; private final StringProperty question;
private final StringProperty answer;
public TestItem(SimpleStringProperty question, SimpleStringProperty answer) { private TestItem(SimpleStringProperty question, SimpleStringProperty answer) {
this.question = question; this.question = question;
this.answer = answer; this.answer = answer;
} }
@ -25,7 +26,7 @@ public class TestItem {
} }
public TestItem(String question, String answer) { public TestItem(String question, String answer) {
this(new SimpleStringProperty(new String(question)), new SimpleStringProperty(new String(answer))); this(new SimpleStringProperty(question), new SimpleStringProperty(answer));
} }
public String getQuestion() { public String getQuestion() {
@ -48,14 +49,14 @@ public class TestItem {
return !question.get().isEmpty() && !answer.get().isEmpty(); return !question.get().isEmpty() && !answer.get().isEmpty();
} }
public boolean checkAnswer(String answer, boolean sensible) { public boolean checkAnswer(String answer) {
return sensible ? getAnswer().equals(answer) : getAnswer().equalsIgnoreCase(answer); return getAnswer().equals(answer);
} }
public static void saveTo(File file, List<TestItem> data) { public static void saveTo(File file, List<TestItem> data) {
try { try {
OutputStreamWriter writer = new OutputStreamWriter( OutputStreamWriter writer = new OutputStreamWriter(
new FileOutputStream(file), Charset.forName("UTF-8").newEncoder()); new FileOutputStream(file), StandardCharsets.UTF_8.newEncoder());
for (TestItem item : data) { for (TestItem item : data) {
writer.write(item.getQuestion() + "::" + item.getAnswer() + "\n"); writer.write(item.getQuestion() + "::" + item.getAnswer() + "\n");
} }

View file

@ -3,7 +3,7 @@
<?import javafx.geometry.Insets?> <?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?> <?import javafx.scene.control.*?>
<?import javafx.scene.image.*?> <?import javafx.scene.image.*?>
<?import javafx.scene.input.KeyCodeCombination?> <?import javafx.scene.input.*?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<BorderPane fx:id="root" prefHeight="450.0" prefWidth="750.0" xmlns="http://javafx.com/javafx/8.0.162-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="es.kauron.jstudy.controller.Controller"> <BorderPane fx:id="root" prefHeight="450.0" prefWidth="750.0" xmlns="http://javafx.com/javafx/8.0.162-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="es.kauron.jstudy.controller.Controller">
<center> <center>
@ -102,7 +102,6 @@
</ImageView> </ImageView>
</graphic> </graphic>
</MenuItem> </MenuItem>
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem onAction="#onLoadAction" text="_Open"> <MenuItem onAction="#onLoadAction" text="_Open">
<accelerator> <accelerator>
<KeyCodeCombination alt="UP" code="O" control="DOWN" meta="UP" shift="UP" shortcut="UP" /> <KeyCodeCombination alt="UP" code="O" control="DOWN" meta="UP" shift="UP" shortcut="UP" />
@ -115,6 +114,19 @@
</ImageView> </ImageView>
</graphic> </graphic>
</MenuItem> </MenuItem>
<MenuItem fx:id="menuSave" onAction="#onSaveAction" text="_Save" disable="true">
<accelerator>
<KeyCodeCombination control="DOWN" code="S" alt="UP" meta="UP" shift="UP" shortcut="UP" />
</accelerator>
<graphic>
<ImageView fitHeight="25.0" fitWidth="25.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../img/Save.png" />
</image>
</ImageView>
</graphic>
</MenuItem>
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem onAction="#onImportAction" text="_Import"> <MenuItem onAction="#onImportAction" text="_Import">
<graphic> <graphic>
<ImageView fitHeight="25.0" fitWidth="25.0" pickOnBounds="true" preserveRatio="true"> <ImageView fitHeight="25.0" fitWidth="25.0" pickOnBounds="true" preserveRatio="true">

View file

@ -7,7 +7,7 @@
xmlns:fx="http://javafx.com/fxml/1" fx:controller="es.kauron.jstudy.controller.SettingsController"> xmlns:fx="http://javafx.com/fxml/1" fx:controller="es.kauron.jstudy.controller.SettingsController">
<children> <children>
<JFXCheckBox fx:id="repeatMistakes" text="_Repeat mistakes"/> <JFXCheckBox fx:id="repeatMistakes" text="_Repeat mistakes"/>
<JFXCheckBox fx:id="repeatImmediately" text="_Always repeat immediatly"/> <JFXCheckBox fx:id="repeatImmediately" text="_Always repeat immediately"/>
<JFXCheckBox fx:id="showFeedback" text="Show _feedback while testing"/> <JFXCheckBox fx:id="showFeedback" text="Show _feedback while testing"/>
</children> </children>
<padding> <padding>

View file

@ -62,7 +62,7 @@
</ImageView> </ImageView>
</graphic> </graphic>
<tooltip> <tooltip>
<Tooltip text="Make the answer the question and viceversa"/> <Tooltip text="Make the answer the question and vice versa"/>
</tooltip> </tooltip>
</Button> </Button>
<Button fx:id="duplicateButton" alignment="TOP_LEFT" layoutX="10.0" layoutY="76.0" onAction="#onDuplicateAction" <Button fx:id="duplicateButton" alignment="TOP_LEFT" layoutX="10.0" layoutY="76.0" onAction="#onDuplicateAction"

View file

@ -29,7 +29,7 @@ public class AppTest
} }
/** /**
* Rigourous Test :-) * Rigorous Test :-)
*/ */
public void testApp() public void testApp()
{ {