added som comments

master
Oystein 2021-04-07 06:42:48 +02:00
parent 4a63aa6edf
commit be748d9138
3 changed files with 38 additions and 7 deletions

View File

@ -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());

View File

@ -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());

View File

@ -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 {