From c12e98f9bec5068c563ffce61d9a1bf76ea5dfe6 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Mon, 26 Apr 2021 22:07:54 +0200 Subject: [PATCH] Add docs --- src/main/java/app/service/FileOperations.java | 32 ++++++++++++++++--- .../java/app/service/FiletreeOperations.java | 29 ++++++++++++++--- .../java/app/settings/SettingsProvider.java | 15 ++++++++- 3 files changed, 66 insertions(+), 10 deletions(-) diff --git a/src/main/java/app/service/FileOperations.java b/src/main/java/app/service/FileOperations.java index 64b6200..2e150f7 100644 --- a/src/main/java/app/service/FileOperations.java +++ b/src/main/java/app/service/FileOperations.java @@ -20,7 +20,7 @@ public class FileOperations { * * @param stage A JavaFX stage is required to show the dialog * @return The chosen file - * @throws FileNotFoundException + * @throws FileNotFoundException if the dialog was canceled */ public static File openFileWithDialog(Stage stage) throws FileNotFoundException { File chosenFile = DialogBoxes.showopenFileWithDialog(stage); @@ -33,11 +33,11 @@ public class FileOperations { } /** - * A function to get a file through a dialog + * A function to get directory through a dialog * * @param stage A JavaFX stage is required to show the dialog - * @return The chosen file - * @throws FileNotFoundException + * @return The chosen directory + * @throws FileNotFoundException if the dialog was canceled */ public static File openDirectoryWithDialog(Stage stage) throws FileNotFoundException { File dir = DialogBoxes.showOpenDirectoryWithDialog(stage); @@ -48,6 +48,14 @@ public class FileOperations { return dir; } + /** + * Saves a file a the specified filepath with the specified content. + * Shows an error message to the user if the file was not found at the specified location. + * + * @param filepath The path of the file to save the content into + * @param content The text content to be saved + * @return Whether the file was sucessfully saved + */ public static boolean saveFile(Path filepath, String content) { try (PrintWriter writer = new PrintWriter(filepath.toFile())) { writer.println(content); @@ -59,6 +67,14 @@ public class FileOperations { } } + /** + * Lets the user choose a file to save the specified content into + * + * @param stage A JavaFX stage is needed in order to show the file chooser + * @param content The content to be saved + * + * @return Whether the file was sucessfully saved + */ public static boolean saveFileWithDialog(Stage stage, String content) { File chosenLocation; @@ -78,6 +94,14 @@ public class FileOperations { return false; } + /** + * Tries to read the contents of a file in the specified filepath. + * If it fails, it shows the user a corresponding error message. + * + * @param filePath The path of the file to be read + * + * @return The text content of the file + */ public static String readFile(Path filePath) { if (filePath == null) diff --git a/src/main/java/app/service/FiletreeOperations.java b/src/main/java/app/service/FiletreeOperations.java index 5d64efe..325eb19 100644 --- a/src/main/java/app/service/FiletreeOperations.java +++ b/src/main/java/app/service/FiletreeOperations.java @@ -26,11 +26,11 @@ public class FiletreeOperations { // TODO: Error check for recursiveness, and files without icons /** - * The method to generate the fileTree recursively. If it is a directory a - * CheckBoxStringItem is created and the method is called again. It goes through - * all until every directory or file inside the orginal CheckBoxItem is made. If - * the item is a file it sends it to the help function checkExtension which is - * described below. + * Generate a filetree recursively, find icons for every file and append them to + * the root tree node. + * + * @param file The root directory to be at the top of the tree + * @param parent The root tree item to append children to */ public static void generateTree(File file, CheckBoxTreeItem parent) { @@ -73,6 +73,10 @@ public class FiletreeOperations { /** * A helping function to sort the files/directories in the fileTree so that it shows * in the correct order. + * + * @param dirList The list of directories to append all directories to + * @param fileList The list of files to append all the files to + * @param file The directory of which children to sort */ private static void sortFiles(List dirList, List fileList, File file) { for (File f : file.listFiles()) { @@ -85,6 +89,14 @@ public class FiletreeOperations { } + /** + * A function to get an icon for a file based on its mimetype. + * If no such icon is found, the function will return a default icon + * + * @param file The file to probe for a mimetype + * @return An image containing the icon + * @throws IOException if the default icon was not found. This should not happen + */ private static Image getIconForFile(File file) throws IOException { Image icon; @@ -113,6 +125,13 @@ public class FiletreeOperations { return icon; } + /** + * Determine the absolute path of a file within the filetree. + * @param item The treeitem that represents the file of which path is needed + * @return The absolute path of the file that the treeitem represents + * @throws FileNotFoundException if no path was found within the filetree such that the + * item could be connected with the root tree item. This should not happen + */ public static Path getPathOfTreeItem(TreeItem item) throws FileNotFoundException { Path projectPath = Model diff --git a/src/main/java/app/settings/SettingsProvider.java b/src/main/java/app/settings/SettingsProvider.java index 6ed5a87..fc267e4 100644 --- a/src/main/java/app/settings/SettingsProvider.java +++ b/src/main/java/app/settings/SettingsProvider.java @@ -15,6 +15,9 @@ import app.events.LanguageChangedEvent; import app.events.ThemeChangedEvent; import app.model.Model; +/** + * A provider for permanent storage of the settings of the application. + */ public class SettingsProvider implements SettingsProviderI { private EventBus eventBus; @@ -28,7 +31,7 @@ public class SettingsProvider implements SettingsProviderI { Arrays.asList("Java", "Markdown", "Monokai", "Solarized Light"); - // Only for testing purposes + /** Only for testing purposes */ protected void setSettingsPath(String settingsPath) { this.settingsPath = settingsPath; } @@ -86,11 +89,21 @@ public class SettingsProvider implements SettingsProviderI { } + /** + * Update the settings whenever the theme gets changed + * + * @param event + */ @Subscribe private void handle(ThemeChangedEvent event) { saveSettings(); } + /** + * Update the settings whenever the language gets changed + * + * @param event + */ @Subscribe private void handle(LanguageChangedEvent event) { saveSettings();