Search in sources :

Example 1 with Database

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

the class Main method start.

@Override
public void start(Stage primaryStage) throws Exception {
    File db = new File("src/eu/tn/data/tests.txt");
    File db2 = new File("src/eu/tn/data/rules.txt");
    if (db.exists()) {
        new Database().loadTests();
    }
    if (db2.exists()) {
        new Database().loadRules();
    }
    BorderPane root = new BorderPane();
    FXMLLoader loader = new FXMLLoader();
    loader.setLocation(getClass().getResource("view/FirstScreen.fxml"));
    loader.setControllerFactory((iC -> new FirstScreenController()));
    root.setCenter(loader.load());
    primaryStage.setOnCloseRequest(event -> {
        Platform.exit();
    });
    primaryStage.setTitle("Shakespeare");
    primaryStage.setScene(new Scene(root, 800, 500));
    primaryStage.show();
}
Also used : Application(javafx.application.Application) Platform(javafx.application.Platform) Scene(javafx.scene.Scene) Stage(javafx.stage.Stage) FXMLLoader(javafx.fxml.FXMLLoader) FirstScreenController(eu.tn.controller.FirstScreenController) BorderPane(javafx.scene.layout.BorderPane) Database(eu.tn.model.Database) File(java.io.File) BorderPane(javafx.scene.layout.BorderPane) FirstScreenController(eu.tn.controller.FirstScreenController) Database(eu.tn.model.Database) Scene(javafx.scene.Scene) File(java.io.File) FXMLLoader(javafx.fxml.FXMLLoader)

Example 2 with Database

use of eu.tn.model.Database 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 Database

use of eu.tn.model.Database 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 Database

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

the class DbTestsController method removeTest.

@FXML
public void removeTest() throws IOException {
    int j = 0;
    if (testsListView.getSelectionModel().getSelectedItem() != null) {
        for (Tests t : tests) {
            if (t.getName().equals(testsListView.getSelectionModel().getSelectedItem().toString())) {
                j = tests.indexOf(t);
            }
        }
        tests.remove(j);
        ObservableList<String> items = FXCollections.observableArrayList();
        for (int i = 0; i < tests.size(); i++) {
            items.add(tests.get(i).getName());
        }
        testsListView.setItems(items);
        ObservableList<String> itemS = FXCollections.observableArrayList();
        testRuleListView.setItems(itemS);
        new Database().save();
    }
}
Also used : Database(eu.tn.model.Database) Tests(eu.tn.model.Tests) FXML(javafx.fxml.FXML)

Example 5 with Database

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

the class DbTestsController method newTest.

@FXML
public void newTest() {
    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);
    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 test");
    newWindow.setScene(secondScene);
    newWindow.show();
    btn.setOnAction((event) -> {
        if (nameTF.getText() != null) {
            new Tests(nameTF.getText());
            ObservableList<String> items = FXCollections.observableArrayList();
            for (int i = 0; i < tests.size(); i++) {
                items.add(tests.get(i).getName());
            }
            testsListView.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) Tests(eu.tn.model.Tests) Button(javafx.scene.control.Button) Database(eu.tn.model.Database) TextField(javafx.scene.control.TextField) Stage(javafx.stage.Stage) FXML(javafx.fxml.FXML)

Aggregations

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