From be748d9138fb6849a37aab6d06b964cdd904ce9e Mon Sep 17 00:00:00 2001 From: Oystein Date: Wed, 7 Apr 2021 06:42:48 +0200 Subject: [PATCH] added som comments --- .../app/controllers/EditorController.java | 22 +++++++++++++++---- .../app/controllers/FiletreeController.java | 19 ++++++++++++++++ .../app/controllers/MenubarController.java | 4 +--- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/main/java/app/controllers/EditorController.java b/src/main/java/app/controllers/EditorController.java index 17dbdc1..4e958a1 100644 --- a/src/main/java/app/controllers/EditorController.java +++ b/src/main/java/app/controllers/EditorController.java @@ -4,8 +4,6 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Paths; import java.util.Collection; import java.util.ResourceBundle; import java.util.Scanner; @@ -138,7 +136,8 @@ public class EditorController implements Initializable, Controller { } /** - * Updates the content of the editor to a specific filepath + * Updates the content of the editor to a specific filepath. Otherwise it will + * open an error dialog to give the user feedback about what has happened. * * @param filePath The path of the file * @throws FileNotFoundException @@ -169,6 +168,11 @@ public class EditorController implements Initializable, Controller { } } + /** + * Saving/Writing to the file based on the spesific filepath. Otherwise it will + * open an error dialog to give the user feedback about what has happened. + */ + private void saveCodeArea(String filePath) { try (PrintWriter writer = new PrintWriter(new File(filePath))) { if (filePath.endsWith(".java") || filePath.endsWith(".md")) { @@ -179,18 +183,28 @@ public class EditorController implements Initializable, Controller { } catch (FileNotFoundException ex) { Alert error = new Alert(AlertType.ERROR); - error.setContentText("Could not save file!\nMust be a java or md file. Try again."); + error.setContentText("Could not save file!\nMust be a java or md file or not null. Try again."); error.showAndWait(); System.err.println(filePath); } } + /* ------------------------------------------------------------------------ */ + /* SUBSCRIPTIONS */ + /* ------------------------------------------------------------------------ */ + + /** + * Updates Code Area (read from file) whenever the FileSelected is changed + */ @Subscribe private void handle(FileSelectedEvent event) { this.setEditorContent(event.getPath()); } + /** + * Save file (write to file) whenever the save in the menubare is selected + */ @Subscribe private void handle(SaveFile event) { this.saveCodeArea(event.getPath()); diff --git a/src/main/java/app/controllers/FiletreeController.java b/src/main/java/app/controllers/FiletreeController.java index 6c67de8..0c8ace5 100644 --- a/src/main/java/app/controllers/FiletreeController.java +++ b/src/main/java/app/controllers/FiletreeController.java @@ -52,6 +52,10 @@ public class FiletreeController implements Initializable, Controller { this.eventBus.register(this); } + /* ------------------------------------------------------------------------ */ + /* FILETREE */ + /* ------------------------------------------------------------------------ */ + /** * The displaying of the fileTree. The inputChosen(the path) is aquired from the * eventBus (OpeFileProjectEvent). The root is created as a CheckBoxItems and @@ -133,6 +137,13 @@ public class FiletreeController implements Initializable, Controller { parent.getChildren().add(element); } + /* ------------------------------------------------------------------------ */ + /* MouseClick */ + /* ------------------------------------------------------------------------ */ + + /** + * Handles whenever a filetree item is clicked twice. + */ @FXML private void handleMouseClick(MouseEvent event) { if (event.getClickCount() == 2) { @@ -154,6 +165,14 @@ public class FiletreeController implements Initializable, Controller { } } + /* ------------------------------------------------------------------------ */ + /* SUBSCRIPTIONS */ + /* ------------------------------------------------------------------------ */ + + /** + * Updates the filetree whenever a new ProjectPath is selected. + */ + @Subscribe private void handle(OpenProjectEvent event) { this.showTree(event.getPath()); diff --git a/src/main/java/app/controllers/MenubarController.java b/src/main/java/app/controllers/MenubarController.java index 4d755ad..7bdf358 100644 --- a/src/main/java/app/controllers/MenubarController.java +++ b/src/main/java/app/controllers/MenubarController.java @@ -1,8 +1,6 @@ package app.controllers; import java.io.File; -import java.io.FileNotFoundException; -import java.io.PrintWriter; import java.net.URL; import java.nio.file.Path; import java.nio.file.Paths; @@ -38,7 +36,7 @@ import javafx.stage.FileChooser; import javafx.stage.Stage; /** - * A FXML controller that controls the filetree component of the UI + * A FXML controller that controls the menubar component of the UI */ public class MenubarController implements Initializable, Controller {