Search in sources :

Example 1 with Rules

use of eu.tn.model.Rules in project TNCY-English-Project by mrngg.

the class AnswerSheetController method updateSheet.

public void updateSheet() throws IOException {
    if (actualTest.successRules() != 0) {
        actualRules = actualTest.randomRules().getName();
        for (Rules r : actualTest.getRules()) {
            if (r.getName().equals(actualRules)) {
                r.setVisited(true);
                actualSentences = r.randomSentences().getName();
                for (Sentences s : r.getSentences()) {
                    if (s.getName().equals(actualSentences)) {
                        s.setVisited(true);
                    }
                }
                if (r.getError() >= 3) {
                    hint.setText(r.getHint());
                }
            }
        }
        sentences.setText(actualSentences);
        answer.setText("");
    } else {
        for (Rules r : actualTest.getRules()) {
            r.setSuccess(0);
            r.setVisited(false);
            r.setError(0);
            for (Sentences s : r.getSentences()) {
                s.setVisited(false);
            }
        }
        Stage primaryStage = new Stage();
        primaryStage.setTitle("Shakespeare");
        BorderPane root = new BorderPane();
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(getClass().getResource("../view/EndScreen.fxml"));
        loader.setControllerFactory((iC -> new EndScreenController(actualTest)));
        root.setCenter(loader.load());
        primaryStage.setOnCloseRequest(event -> {
            Platform.exit();
        });
        primaryStage.setTitle("Shakespeare");
        primaryStage.setScene(new Scene(root, 710, 532));
        primaryStage.show();
        Stage stage = (Stage) validateB.getScene().getWindow();
        stage.close();
    }
}
Also used : Button(javafx.scene.control.Button) Scene(javafx.scene.Scene) TextField(javafx.scene.control.TextField) Label(javafx.scene.control.Label) Rules(eu.tn.model.Rules) IOException(java.io.IOException) Tests(eu.tn.model.Tests) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) Stage(javafx.stage.Stage) FXMLLoader(javafx.fxml.FXMLLoader) Sentences(eu.tn.model.Sentences) BorderPane(javafx.scene.layout.BorderPane) BorderPane(javafx.scene.layout.BorderPane) Sentences(eu.tn.model.Sentences) Stage(javafx.stage.Stage) Scene(javafx.scene.Scene) Rules(eu.tn.model.Rules) FXMLLoader(javafx.fxml.FXMLLoader)

Example 2 with Rules

use of eu.tn.model.Rules in project TNCY-English-Project by mrngg.

the class DbRulesController method newRules.

public void newRules() {
    GridPane grid = new GridPane();
    grid.setAlignment(Pos.CENTER);
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(25, 25, 25, 25));
    Label name = new Label("Name :");
    TextField nameTF = new TextField();
    grid.add(nameTF, 1, 1);
    grid.add(name, 0, 1);
    Label hint = new Label("Hint :");
    TextField hintTF = new TextField();
    grid.add(hintTF, 1, 2);
    grid.add(hint, 0, 2);
    Button btn = new Button("Create");
    grid.add(btn, 0, 3);
    Scene secondScene = new Scene(grid, 300, 150);
    Stage newWindow = new Stage();
    newWindow.setTitle("Create a rule");
    newWindow.setScene(secondScene);
    newWindow.show();
    btn.setOnAction((event) -> {
        if (nameTF.getText() != null && hintTF.getText() != null) {
            new Rules(nameTF.getText(), hintTF.getText());
            ObservableList<String> items = FXCollections.observableArrayList();
            for (int i = 0; i < rules.size(); i++) {
                items.add(rules.get(i).getName());
            }
            availableRules.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)

Example 3 with Rules

use of eu.tn.model.Rules in project TNCY-English-Project by mrngg.

the class DbRulesController method editRules.

public void editRules() throws IOException {
    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 name = new Label("Name :");
        TextField nameTF = new TextField();
        nameTF.setText(availableRules.getSelectionModel().getSelectedItem().toString());
        grid.add(nameTF, 1, 1);
        grid.add(name, 0, 1);
        Label hint = new Label("Hint :");
        TextField hintTF = new TextField();
        String hintR = "";
        for (Rules r : rules) {
            if (r.getName().equals(availableRules.getSelectionModel().getSelectedItem().toString())) {
                hintR = r.getHint();
            }
        }
        hintTF.setText(hintR);
        grid.add(hintTF, 1, 2);
        grid.add(hint, 0, 2);
        Button btn = new Button("Edit");
        grid.add(btn, 0, 3);
        Scene secondScene = new Scene(grid, 300, 150);
        Stage newWindow = new Stage();
        newWindow.setTitle("Edit a rule");
        newWindow.setScene(secondScene);
        newWindow.show();
        btn.setOnAction((event) -> {
            if (nameTF.getText() != null && hintTF.getText() != null) {
                for (Rules r : rules) {
                    if (r.getName().equals(availableRules.getSelectionModel().getSelectedItem().toString())) {
                        r.setName(nameTF.getText());
                        r.setHint(hintTF.getText());
                    }
                }
                ObservableList<String> items = FXCollections.observableArrayList();
                for (int i = 0; i < rules.size(); i++) {
                    items.add(rules.get(i).getName());
                }
                availableRules.setItems(items);
                newWindow.close();
                rulesName.setText(nameTF.getText());
                rulesHint.setText(hintTF.getText());
                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)

Example 4 with Rules

use of eu.tn.model.Rules in project TNCY-English-Project by mrngg.

the class AnswerSheetController method validate.

public void validate() throws IOException {
    if (answer.getText() != null) {
        for (Rules r : actualTest.getRules()) {
            if (r.getName().equals(actualRules)) {
                for (Sentences s : r.getSentences()) {
                    if (s.getName().equals(actualSentences)) {
                        if (answer.getText().equals(s.getAnswer())) {
                            r.setSuccess(r.getSuccess() + 1);
                            r.setError(0);
                        } else {
                            r.setSuccess(0);
                            r.setError(r.getError() + 1);
                        }
                    }
                }
            }
        }
        updateSheet();
    }
}
Also used : Sentences(eu.tn.model.Sentences) Rules(eu.tn.model.Rules)

Example 5 with Rules

use of eu.tn.model.Rules in project TNCY-English-Project by mrngg.

the class AnswerSheetController method correctSentence.

public void correctSentence() throws IOException {
    for (Rules r : actualTest.getRules()) {
        if (r.getName().equals(actualRules)) {
            for (Sentences s : r.getSentences()) {
                if (s.getName().equals(actualSentences)) {
                    if (s.getAnswer().equals("")) {
                        r.setSuccess(r.getSuccess() + 1);
                        r.setError(0);
                    } else {
                        r.setSuccess(0);
                        r.setError(r.getError() + 1);
                    }
                }
            }
        }
    }
    updateSheet();
    for (Rules r : actualTest.getRules()) {
        System.out.println(r.getSuccess());
    }
}
Also used : Sentences(eu.tn.model.Sentences) Rules(eu.tn.model.Rules)

Aggregations

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