use of eu.tn.model.Sentences in project TNCY-English-Project by mrngg.
the class DbRulesController method sentenceChoosen.
public void sentenceChoosen() {
if (availableRules.getSelectionModel().getSelectedItem() != null && rulesSentences.getSelectionModel().getSelectedItem() != null) {
int j = 0;
int i = 0;
for (Rules r : rules) {
if (r.getName().equals(availableRules.getSelectionModel().getSelectedItem().toString())) {
j = rules.indexOf(r);
for (Sentences s : r.getSentences()) {
if (s.getName().equals(rulesSentences.getSelectionModel().getSelectedItem().toString())) {
i = r.getSentences().indexOf(s);
}
}
}
}
sentencesName.setText(rules.get(j).getSentences().get(i).getName());
sentencesAnswer.setText(rules.get(j).getSentences().get(i).getAnswer());
}
}
use of eu.tn.model.Sentences in project TNCY-English-Project by mrngg.
the class DbRulesController method editSentences.
public void editSentences() {
if (rulesSentences.getSelectionModel().getSelectedItem() != null) {
GridPane grid = new GridPane();
grid.setAlignment(Pos.CENTER);
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(25, 25, 25, 25));
Label sentence = new Label("Sentence :");
TextField sentenceTF = new TextField();
sentenceTF.setText(rulesSentences.getSelectionModel().getSelectedItem().toString());
grid.add(sentenceTF, 1, 1);
grid.add(sentence, 0, 1);
Label answer = new Label("Answer :");
TextField answerTF = new TextField();
String answerS = "";
for (Rules r : rules) {
if (r.getName().equals(availableRules.getSelectionModel().getSelectedItem().toString())) {
for (Sentences s : r.getSentences()) {
if (s.getName().equals(rulesSentences.getSelectionModel().getSelectedItem().toString())) {
answerS = s.getAnswer();
}
}
}
}
answerTF.setText(answerS);
grid.add(answerTF, 1, 2);
grid.add(answer, 0, 2);
Button btn = new Button("Edit");
grid.add(btn, 0, 3);
Scene secondScene = new Scene(grid, 300, 300);
Stage newWindow = new Stage();
newWindow.setTitle("Edit a sentence");
newWindow.setScene(secondScene);
newWindow.show();
btn.setOnAction((event) -> {
int j = 0;
if (sentenceTF.getText() != null) {
for (Rules r : rules) {
if (r.getName().equals(availableRules.getSelectionModel().getSelectedItem().toString())) {
j = rules.indexOf(r);
for (Sentences s : r.getSentences()) {
if (s.getName().equals(rulesSentences.getSelectionModel().getSelectedItem().toString())) {
s.setName(sentenceTF.getText());
if (answerTF.getText() == null) {
s.setAnswer("");
} else {
s.setAnswer(answerTF.getText());
}
}
}
}
}
ObservableList<String> items = FXCollections.observableArrayList();
for (int i = 0; i < rules.get(j).getSentences().size(); i++) {
items.add(rules.get(j).getSentences().get(i).getName());
}
rulesSentences.setItems(items);
newWindow.close();
try {
new Database().save();
} catch (IOException e) {
e.printStackTrace();
}
sentencesName.setText(sentenceTF.getText());
sentencesAnswer.setText(answerTF.getText());
}
});
}
}
use of eu.tn.model.Sentences in project TNCY-English-Project by mrngg.
the class DbRulesController method newSentences.
public void newSentences() {
if (availableRules.getSelectionModel().getSelectedItem() != null) {
GridPane grid = new GridPane();
grid.setAlignment(Pos.CENTER);
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(25, 25, 25, 25));
Label sentence = new Label("Sentence :");
TextField sentenceTF = new TextField();
grid.add(sentenceTF, 1, 1);
grid.add(sentence, 0, 1);
Label answer = new Label("Answer :");
TextField answerTF = new TextField();
grid.add(answerTF, 1, 2);
grid.add(answer, 0, 2);
Button btn = new Button("Create");
grid.add(btn, 0, 3);
Scene secondScene = new Scene(grid, 300, 300);
Stage newWindow = new Stage();
newWindow.setTitle("New sentence");
newWindow.setScene(secondScene);
newWindow.show();
btn.setOnAction((event) -> {
if (sentenceTF.getText() != null && sentenceTF.getText() != null) {
Sentences s;
if (answerTF == null) {
s = new Sentences(sentenceTF.getText(), "");
} else {
s = new Sentences(sentenceTF.getText(), answerTF.getText());
}
int j = 0;
for (Rules r : rules) {
if (r.getName().equals(availableRules.getSelectionModel().getSelectedItem().toString())) {
r.addSentences(s);
j = rules.indexOf(r);
}
}
ObservableList<String> items = FXCollections.observableArrayList();
for (int i = 0; i < rules.get(j).getSentences().size(); i++) {
items.add(rules.get(j).getSentences().get(i).getName());
}
rulesSentences.setItems(items);
newWindow.close();
try {
new Database().save();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
}
Aggregations