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

View File

@ -26,11 +26,11 @@ public class EditController implements Initializable {
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);
}
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.index = index;
this.saved = saved;

View File

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

View File

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

View File

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

View File

@ -3,7 +3,7 @@
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.input.KeyCodeCombination?>
<?import javafx.scene.input.*?>
<?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">
<center>
@ -102,7 +102,6 @@
</ImageView>
</graphic>
</MenuItem>
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem onAction="#onLoadAction" text="_Open">
<accelerator>
<KeyCodeCombination alt="UP" code="O" control="DOWN" meta="UP" shift="UP" shortcut="UP" />
@ -115,6 +114,19 @@
</ImageView>
</graphic>
</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">
<graphic>
<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">
<children>
<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"/>
</children>
<padding>

View File

@ -62,7 +62,7 @@
</ImageView>
</graphic>
<tooltip>
<Tooltip text="Make the answer the question and viceversa"/>
<Tooltip text="Make the answer the question and vice versa"/>
</tooltip>
</Button>
<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()
{