Add some documentation

This commit is contained in:
Oystein Kristoffer Tveit 2021-03-02 18:50:44 +01:00
parent 41362a45d4
commit 180627578b
8 changed files with 115 additions and 46 deletions

View File

@ -24,6 +24,7 @@ public class Main extends Application {
/** /**
* Boilerplate function to launch the application. * Boilerplate function to launch the application.
* @param args Additional arguments from commandline
*/ */
public static void main(String[] args) { public static void main(String[] args) {
launch(args); launch(args);

View File

@ -3,12 +3,12 @@ package app.controllers;
import com.google.common.eventbus.EventBus; import com.google.common.eventbus.EventBus;
/** /**
* Interface to make a controller that contains an EventBus * Interface describing a controller that contains an EventBus
*/ */
public interface Controller { public interface Controller {
/** /**
* Registers the main EventBus into the controller. * Registers the main EventBus into the controller.
* @param eventBus the main EventBus * @param eventBus The EventBus
*/ */
public void setEventBus(EventBus eventBus); public void setEventBus(EventBus eventBus);
} }

View File

@ -32,6 +32,9 @@ import app.service.LanguageOperations;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
/**
* A FXML controller that controls the editor component of the UI
*/
public class EditorController implements Initializable, Controller { public class EditorController implements Initializable, Controller {
@FXML @FXML
@ -73,8 +76,11 @@ public class EditorController implements Initializable, Controller {
} }
/** /**
* Uses Model.language to determine whether the current line/selection is * Uses the {@link app.model.ProgrammingLanguage ProgrammingLanguage} in
* commented or not, and toggles the comment. * {@link app.model.Model Model} to determine whether the current line/selection
* is commented or not, and toggles the comment.
*
* @see app.model.ProgrammingLanguage#commentLine(String) ProgrammingLanguage.commentLine(line)
*/ */
private void toggleComment() { private void toggleComment() {
if (editor.getSelectedText().equals("")) { if (editor.getSelectedText().equals("")) {
@ -101,6 +107,10 @@ public class EditorController implements Initializable, Controller {
} }
} }
/**
* Updates the wraptext setting of the code area
* @param isWrapText The new value for the setting
*/
private void setWrapText(boolean isWrapText) { private void setWrapText(boolean isWrapText) {
this.editor.setWrapText(isWrapText); this.editor.setWrapText(isWrapText);
} }
@ -120,34 +130,33 @@ public class EditorController implements Initializable, Controller {
} }
/** /**
* Refreshes the editor whenever the language is changed. * Updates the content of the editor to a specific filepath
* * @param filePath The path of the file
* @param event * @throws FileNotFoundException
*/ */
private void setEditorContent(String filePath) {
@Subscribe try (Scanner sc = new Scanner(new File(filePath))) {
private void handle(FileSelectedEvent event) {
try (Scanner sc = new Scanner(new File(event.getPath()))) {
editor.clear(); editor.clear();
while (sc.hasNextLine()) { while (sc.hasNextLine()) {
editor.appendText(sc.nextLine()); editor.appendText(sc.nextLine());
editor.appendText("\n"); editor.appendText("\n");
} }
} catch (FileNotFoundException ex) { } catch (FileNotFoundException ex) {
System.out.println(event.getPath()); // TODO: add better error handling and user feedback
System.err.println(filePath);
} }
} }
@Subscribe
private void handle(FileSelectedEvent event) {
this.setEditorContent(event.getPath());
}
@Subscribe @Subscribe
private void handle(LanguageChangedEvent event) { private void handle(LanguageChangedEvent event) {
this.refreshHighlighting(); this.refreshHighlighting();
} }
/**
* Toggles a language specific comment of the line/selection
*
* @param event
*/
@Subscribe @Subscribe
private void handle(ToggleCommentEvent event) { private void handle(ToggleCommentEvent event) {
this.toggleComment(); this.toggleComment();

View File

@ -22,6 +22,9 @@ import app.events.OpenProjectEvent;
import app.model.Model; import app.model.Model;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
/**
* A FXML controller that controls the filetree component of the UI
*/
public class FiletreeController implements Initializable, Controller { public class FiletreeController implements Initializable, Controller {
private EventBus eventBus; private EventBus eventBus;
@ -32,13 +35,12 @@ public class FiletreeController implements Initializable, Controller {
Image java = new Image(getClass().getResourceAsStream("/graphics/java.png")); Image java = new Image(getClass().getResourceAsStream("/graphics/java.png"));
Image placeholder = new Image(getClass().getResourceAsStream("/graphics/placeholder.png")); Image placeholder = new Image(getClass().getResourceAsStream("/graphics/placeholder.png"));
// Creating the variable.
@FXML @FXML
private TreeView<String> filetree; private TreeView<String> filetree;
@Override @Override
public void initialize(URL url, ResourceBundle resourceBundle) { public void initialize(URL url, ResourceBundle resourceBundle) {
// // TODO: Implement
} }
@Override @Override
@ -108,7 +110,7 @@ public class FiletreeController implements Initializable, Controller {
/** /**
* A help function to check if the extensions match .java or .md to insert the * A help function to check if the extensions match .java or .md to insert the
* spesific icons and sending it to another help funtion createExtension to * specific icons and sending it to another help funtion createExtension to
* create the new CheckboxTreeItem<String> that will add to the parent. * create the new CheckboxTreeItem<String> that will add to the parent.
*/ */
private void checkExtensions(File file, CheckBoxTreeItem<String> parent) { private void checkExtensions(File file, CheckBoxTreeItem<String> parent) {

View File

@ -32,6 +32,9 @@ import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser; import javafx.stage.FileChooser;
import javafx.stage.Stage; import javafx.stage.Stage;
/**
* A FXML controller that controls the filetree component of the UI
*/
public class MenubarController implements Initializable, Controller { public class MenubarController implements Initializable, Controller {
private EventBus eventBus; private EventBus eventBus;
@ -57,6 +60,9 @@ public class MenubarController implements Initializable, Controller {
/* FILE */ /* FILE */
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
/**
* Handles whenever the Open File button is pressed in the menubar
*/
@FXML @FXML
public void handleOpenFile() { public void handleOpenFile() {
FileChooser fc = new FileChooser(); FileChooser fc = new FileChooser();
@ -70,6 +76,9 @@ public class MenubarController implements Initializable, Controller {
this.eventBus.post(new FileSelectedEvent(correctFormat)); this.eventBus.post(new FileSelectedEvent(correctFormat));
} }
/**
* Handles whenever the Open Project button is pressed in the menubar
*/
@FXML @FXML
private void handleOpenProject() { private void handleOpenProject() {
DirectoryChooser dc = new DirectoryChooser(); DirectoryChooser dc = new DirectoryChooser();
@ -84,45 +93,33 @@ public class MenubarController implements Initializable, Controller {
} }
// @FXML
// public void handleSaveFile() {
// FileChooser fc = new FileChooser();
// fc.setTitle("Save File");
// Stage stage = (Stage) menubar.getScene().getWindow();
// FileChooser.ExtensionFilter extentionjava = new
// FileChooser.ExtensionFilter(".java");
// FileChooser.ExtensionFilter extentionmd = new
// FileChooser.ExtensionFilter(".md");
// fc.getExtensionFilters().addAll(extentionjava, extentionmd);
// fc.showOpenDialog(stage);
// }
/** /**
* Handles the event where the language was change from the menu. * Handles whenever the programming language is changed from the menubar.
*
* @param event
*/ */
@FXML @FXML
private void handleLanguageChange(ActionEvent event) { private void handleLanguageChange(ActionEvent event) {
this.eventBus.post(new LanguageChangedEvent(((RadioMenuItem) event.getSource()).getText())); this.eventBus.post(new LanguageChangedEvent(((RadioMenuItem) event.getSource()).getText()));
} }
/**
* Handles whenever the wraptext togglebutton is pressed in the menubar
*/
@FXML @FXML
private void handleToggleWraptext(ActionEvent event) { private void handleToggleWraptext(ActionEvent event) {
var isSelected = ((CheckMenuItem) event.getSource()).selectedProperty().get(); var isSelected = ((CheckMenuItem) event.getSource()).selectedProperty().get();
this.eventBus.post(new ToggleWrapTextEvent(isSelected)); this.eventBus.post(new ToggleWrapTextEvent(isSelected));
} }
/**
* Handles whenever the theme is changed from the menubar
*/
@FXML @FXML
private void handleThemeChange(ActionEvent event) { private void handleThemeChange(ActionEvent event) {
this.eventBus.post(new ThemeChangedEvent(((RadioMenuItem) event.getSource()).getText())); this.eventBus.post(new ThemeChangedEvent(((RadioMenuItem) event.getSource()).getText()));
} }
/** /**
* Handles the event where there was an exit request from the menu. * Handles whenever the exit button is pressed in the menubar
*
* @param event
*/ */
@FXML @FXML
private void handleExitApplication(ActionEvent event) { private void handleExitApplication(ActionEvent event) {
@ -133,31 +130,49 @@ public class MenubarController implements Initializable, Controller {
/* EDIT */ /* EDIT */
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
/**
* Handles whenever the undo button is pressed in the menubar
*/
@FXML @FXML
private void handleUndo(ActionEvent event) { private void handleUndo(ActionEvent event) {
this.eventBus.post(new UndoEvent()); this.eventBus.post(new UndoEvent());
} }
/**
* Handles whenever the redo button is pressed in the menubar
*/
@FXML @FXML
private void handleRedo(ActionEvent event) { private void handleRedo(ActionEvent event) {
this.eventBus.post(new RedoEvent()); this.eventBus.post(new RedoEvent());
} }
/**
* Handles whenever the copy button is pressed in the menubar
*/
@FXML @FXML
private void handleCopy(ActionEvent event) { private void handleCopy(ActionEvent event) {
this.eventBus.post(new CopyEvent()); this.eventBus.post(new CopyEvent());
} }
/**
* Handles whenever the cut button is pressed in the menubar
*/
@FXML @FXML
private void handleCut(ActionEvent event) { private void handleCut(ActionEvent event) {
this.eventBus.post(new CutEvent()); this.eventBus.post(new CutEvent());
} }
/**
* Handles whenever the paste button is pressed in the menubar
*/
@FXML @FXML
private void handlePaste(ActionEvent event) { private void handlePaste(ActionEvent event) {
this.eventBus.post(new PasteEvent()); this.eventBus.post(new PasteEvent());
} }
/**
* Handles whenever the Toggle Comment button is pressed in the menubar
*/
@FXML @FXML
private void handleToggleComment(ActionEvent event) { private void handleToggleComment(ActionEvent event) {
this.eventBus.post(new ToggleCommentEvent()); this.eventBus.post(new ToggleCommentEvent());
@ -167,6 +182,9 @@ public class MenubarController implements Initializable, Controller {
/* ABOUT */ /* ABOUT */
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
/**
* Handles whenever the About button is pressed in the menubar
*/
@FXML @FXML
private void handleAbout(ActionEvent event) { private void handleAbout(ActionEvent event) {
String aboutLink = "https://gitlab.stud.idi.ntnu.no/oysteikt/tdt4100-project-2021v/-/blob/master/README.md"; String aboutLink = "https://gitlab.stud.idi.ntnu.no/oysteikt/tdt4100-project-2021v/-/blob/master/README.md";
@ -179,8 +197,6 @@ public class MenubarController implements Initializable, Controller {
/** /**
* Updates menubuttons whenever the language is changed * Updates menubuttons whenever the language is changed
*
* @param event
*/ */
@Subscribe @Subscribe
private void handle(LanguageChangedEvent event) { private void handle(LanguageChangedEvent event) {

View File

@ -13,6 +13,9 @@ import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.scene.control.Label; import javafx.scene.control.Label;
/**
* A FXML controller that controls the modeline component of the UI
*/
public class ModelineController implements Initializable, Controller { public class ModelineController implements Initializable, Controller {
@FXML @FXML
@ -49,7 +52,6 @@ public class ModelineController implements Initializable, Controller {
/** /**
* Updates the column-row number display whenever the editor cursor * Updates the column-row number display whenever the editor cursor
* changes position. * changes position.
* @param event
*/ */
@Subscribe @Subscribe
private void handle(EditorChangedEvent event) { private void handle(EditorChangedEvent event) {
@ -58,7 +60,6 @@ public class ModelineController implements Initializable, Controller {
/** /**
* Updates the saveState label whenever the file either is saved or modified * Updates the saveState label whenever the file either is saved or modified
* @param event
*/ */
@Subscribe @Subscribe
private void handle(FileSaveStateChangedEvent event) { private void handle(FileSaveStateChangedEvent event) {
@ -70,7 +71,6 @@ public class ModelineController implements Initializable, Controller {
/** /**
* Updates the modeline to display a new language * Updates the modeline to display a new language
* whenever it is changed. * whenever it is changed.
* @param event
*/ */
@Subscribe @Subscribe
private void handle(LanguageChangedEvent event) { private void handle(LanguageChangedEvent event) {

View File

@ -4,6 +4,11 @@ import java.net.URL;
import java.util.Map; import java.util.Map;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/**
* An interface describing functions required for a class to
* provide language specific details and functionality to the
* editor
*/
public interface ProgrammingLanguage { public interface ProgrammingLanguage {
/** /**
* The name of the programming language * The name of the programming language
@ -26,12 +31,44 @@ public interface ProgrammingLanguage {
*/ */
public Pattern getPattern(); public Pattern getPattern();
/**
* Comment out a line
* @param line The text of the line to comment out
* @return The commented line
*/
public String commentLine(String line); public String commentLine(String line);
/**
* Uncomment a line
* @param line The text of the line to uncomment
* @return The uncommented line
*/
public String unCommentLine(String line); public String unCommentLine(String line);
/**
* Whether or not a line is commented
* @param line The text of the line
*/
public boolean isCommentedLine(String line); public boolean isCommentedLine(String line);
/**
* Comment out an area of text
* @param selection The text of the area to comment out
* @return The commented area
*/
public String commentSelection(String selection); public String commentSelection(String selection);
/**
* Uncomment a line
* @param selection The text of the line to uncomment
* @return The uncommented area
*/
public String unCommentSelection(String selection); public String unCommentSelection(String selection);
/**
* Whether or not an area of text is commented
* @param selection The content of the area
*/
public boolean isCommentedSelection(String selection); public boolean isCommentedSelection(String selection);
} }

View File

@ -9,6 +9,10 @@ import org.fxmisc.richtext.model.StyleSpansBuilder;
import app.model.ProgrammingLanguage; import app.model.ProgrammingLanguage;
/**
* Common static operations that can be executed on any class
* that implements {@link app.model.ProgrammingLanguage ProgrammingLanguage}
*/
public class LanguageOperations { public class LanguageOperations {
/** /**