Search in sources :

Example 6 with Sentences

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());
    }
}
Also used : Sentences(eu.tn.model.Sentences) Rules(eu.tn.model.Rules)

Example 7 with Sentences

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());
            }
        });
    }
}
Also used : GridPane(javafx.scene.layout.GridPane) Insets(javafx.geometry.Insets) Label(javafx.scene.control.Label) IOException(java.io.IOException) Scene(javafx.scene.Scene) Rules(eu.tn.model.Rules) Button(javafx.scene.control.Button) Database(eu.tn.model.Database) TextField(javafx.scene.control.TextField) Sentences(eu.tn.model.Sentences) Stage(javafx.stage.Stage)

Example 8 with Sentences

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();
                }
            }
        });
    }
}
Also used : GridPane(javafx.scene.layout.GridPane) Insets(javafx.geometry.Insets) Label(javafx.scene.control.Label) IOException(java.io.IOException) Scene(javafx.scene.Scene) Rules(eu.tn.model.Rules) Button(javafx.scene.control.Button) Database(eu.tn.model.Database) TextField(javafx.scene.control.TextField) Stage(javafx.stage.Stage) Sentences(eu.tn.model.Sentences)

Aggregations

Rules (eu.tn.model.Rules)8 Sentences (eu.tn.model.Sentences)8 Database (eu.tn.model.Database)3 IOException (java.io.IOException)3 Scene (javafx.scene.Scene)3 Button (javafx.scene.control.Button)3 Label (javafx.scene.control.Label)3 TextField (javafx.scene.control.TextField)3 Stage (javafx.stage.Stage)3 FXML (javafx.fxml.FXML)2 Insets (javafx.geometry.Insets)2 GridPane (javafx.scene.layout.GridPane)2 Tests (eu.tn.model.Tests)1 Platform (javafx.application.Platform)1 FXMLLoader (javafx.fxml.FXMLLoader)1 BorderPane (javafx.scene.layout.BorderPane)1