Add some documentation
This commit is contained in:
parent
41362a45d4
commit
180627578b
@ -24,6 +24,7 @@ public class Main extends Application {
|
||||
|
||||
/**
|
||||
* Boilerplate function to launch the application.
|
||||
* @param args Additional arguments from commandline
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
|
@ -3,12 +3,12 @@ package app.controllers;
|
||||
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 {
|
||||
/**
|
||||
* Registers the main EventBus into the controller.
|
||||
* @param eventBus the main EventBus
|
||||
* @param eventBus The EventBus
|
||||
*/
|
||||
public void setEventBus(EventBus eventBus);
|
||||
}
|
||||
|
@ -32,6 +32,9 @@ import app.service.LanguageOperations;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
|
||||
/**
|
||||
* A FXML controller that controls the editor component of the UI
|
||||
*/
|
||||
public class EditorController implements Initializable, Controller {
|
||||
|
||||
@FXML
|
||||
@ -73,8 +76,11 @@ public class EditorController implements Initializable, Controller {
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses Model.language to determine whether the current line/selection is
|
||||
* commented or not, and toggles the comment.
|
||||
* Uses the {@link app.model.ProgrammingLanguage ProgrammingLanguage} in
|
||||
* {@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() {
|
||||
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) {
|
||||
this.editor.setWrapText(isWrapText);
|
||||
}
|
||||
@ -120,34 +130,33 @@ public class EditorController implements Initializable, Controller {
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes the editor whenever the language is changed.
|
||||
*
|
||||
* @param event
|
||||
* Updates the content of the editor to a specific filepath
|
||||
* @param filePath The path of the file
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
|
||||
@Subscribe
|
||||
private void handle(FileSelectedEvent event) {
|
||||
try (Scanner sc = new Scanner(new File(event.getPath()))) {
|
||||
private void setEditorContent(String filePath) {
|
||||
try (Scanner sc = new Scanner(new File(filePath))) {
|
||||
editor.clear();
|
||||
while (sc.hasNextLine()) {
|
||||
editor.appendText(sc.nextLine());
|
||||
editor.appendText("\n");
|
||||
}
|
||||
} 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
|
||||
private void handle(LanguageChangedEvent event) {
|
||||
this.refreshHighlighting();
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles a language specific comment of the line/selection
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
@Subscribe
|
||||
private void handle(ToggleCommentEvent event) {
|
||||
this.toggleComment();
|
||||
|
@ -22,6 +22,9 @@ import app.events.OpenProjectEvent;
|
||||
import app.model.Model;
|
||||
import javafx.fxml.Initializable;
|
||||
|
||||
/**
|
||||
* A FXML controller that controls the filetree component of the UI
|
||||
*/
|
||||
public class FiletreeController implements Initializable, Controller {
|
||||
|
||||
private EventBus eventBus;
|
||||
@ -32,13 +35,12 @@ public class FiletreeController implements Initializable, Controller {
|
||||
Image java = new Image(getClass().getResourceAsStream("/graphics/java.png"));
|
||||
Image placeholder = new Image(getClass().getResourceAsStream("/graphics/placeholder.png"));
|
||||
|
||||
// Creating the variable.
|
||||
@FXML
|
||||
private TreeView<String> filetree;
|
||||
|
||||
@Override
|
||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||
//
|
||||
// TODO: Implement
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -107,8 +109,8 @@ public class FiletreeController implements Initializable, Controller {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* A help function to check if the extensions match .java or .md to insert the
|
||||
* specific icons and sending it to another help funtion createExtension to
|
||||
* create the new CheckboxTreeItem<String> that will add to the parent.
|
||||
*/
|
||||
private void checkExtensions(File file, CheckBoxTreeItem<String> parent) {
|
||||
|
@ -32,6 +32,9 @@ import javafx.stage.DirectoryChooser;
|
||||
import javafx.stage.FileChooser;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
* A FXML controller that controls the filetree component of the UI
|
||||
*/
|
||||
public class MenubarController implements Initializable, Controller {
|
||||
|
||||
private EventBus eventBus;
|
||||
@ -57,6 +60,9 @@ public class MenubarController implements Initializable, Controller {
|
||||
/* FILE */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
/**
|
||||
* Handles whenever the Open File button is pressed in the menubar
|
||||
*/
|
||||
@FXML
|
||||
public void handleOpenFile() {
|
||||
FileChooser fc = new FileChooser();
|
||||
@ -70,6 +76,9 @@ public class MenubarController implements Initializable, Controller {
|
||||
this.eventBus.post(new FileSelectedEvent(correctFormat));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles whenever the Open Project button is pressed in the menubar
|
||||
*/
|
||||
@FXML
|
||||
private void handleOpenProject() {
|
||||
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.
|
||||
*
|
||||
* @param event
|
||||
* Handles whenever the programming language is changed from the menubar.
|
||||
*/
|
||||
@FXML
|
||||
private void handleLanguageChange(ActionEvent event) {
|
||||
this.eventBus.post(new LanguageChangedEvent(((RadioMenuItem) event.getSource()).getText()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles whenever the wraptext togglebutton is pressed in the menubar
|
||||
*/
|
||||
@FXML
|
||||
private void handleToggleWraptext(ActionEvent event) {
|
||||
var isSelected = ((CheckMenuItem) event.getSource()).selectedProperty().get();
|
||||
this.eventBus.post(new ToggleWrapTextEvent(isSelected));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles whenever the theme is changed from the menubar
|
||||
*/
|
||||
@FXML
|
||||
private void handleThemeChange(ActionEvent event) {
|
||||
this.eventBus.post(new ThemeChangedEvent(((RadioMenuItem) event.getSource()).getText()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the event where there was an exit request from the menu.
|
||||
*
|
||||
* @param event
|
||||
* Handles whenever the exit button is pressed in the menubar
|
||||
*/
|
||||
@FXML
|
||||
private void handleExitApplication(ActionEvent event) {
|
||||
@ -133,31 +130,49 @@ public class MenubarController implements Initializable, Controller {
|
||||
/* EDIT */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
/**
|
||||
* Handles whenever the undo button is pressed in the menubar
|
||||
*/
|
||||
@FXML
|
||||
private void handleUndo(ActionEvent event) {
|
||||
this.eventBus.post(new UndoEvent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles whenever the redo button is pressed in the menubar
|
||||
*/
|
||||
@FXML
|
||||
private void handleRedo(ActionEvent event) {
|
||||
this.eventBus.post(new RedoEvent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles whenever the copy button is pressed in the menubar
|
||||
*/
|
||||
@FXML
|
||||
private void handleCopy(ActionEvent event) {
|
||||
this.eventBus.post(new CopyEvent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles whenever the cut button is pressed in the menubar
|
||||
*/
|
||||
@FXML
|
||||
private void handleCut(ActionEvent event) {
|
||||
this.eventBus.post(new CutEvent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles whenever the paste button is pressed in the menubar
|
||||
*/
|
||||
@FXML
|
||||
private void handlePaste(ActionEvent event) {
|
||||
this.eventBus.post(new PasteEvent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles whenever the Toggle Comment button is pressed in the menubar
|
||||
*/
|
||||
@FXML
|
||||
private void handleToggleComment(ActionEvent event) {
|
||||
this.eventBus.post(new ToggleCommentEvent());
|
||||
@ -167,6 +182,9 @@ public class MenubarController implements Initializable, Controller {
|
||||
/* ABOUT */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
/**
|
||||
* Handles whenever the About button is pressed in the menubar
|
||||
*/
|
||||
@FXML
|
||||
private void handleAbout(ActionEvent event) {
|
||||
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
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
@Subscribe
|
||||
private void handle(LanguageChangedEvent event) {
|
||||
|
@ -13,6 +13,9 @@ import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.Label;
|
||||
|
||||
/**
|
||||
* A FXML controller that controls the modeline component of the UI
|
||||
*/
|
||||
public class ModelineController implements Initializable, Controller {
|
||||
|
||||
@FXML
|
||||
@ -49,7 +52,6 @@ public class ModelineController implements Initializable, Controller {
|
||||
/**
|
||||
* Updates the column-row number display whenever the editor cursor
|
||||
* changes position.
|
||||
* @param event
|
||||
*/
|
||||
@Subscribe
|
||||
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
|
||||
* @param event
|
||||
*/
|
||||
@Subscribe
|
||||
private void handle(FileSaveStateChangedEvent event) {
|
||||
@ -70,7 +71,6 @@ public class ModelineController implements Initializable, Controller {
|
||||
/**
|
||||
* Updates the modeline to display a new language
|
||||
* whenever it is changed.
|
||||
* @param event
|
||||
*/
|
||||
@Subscribe
|
||||
private void handle(LanguageChangedEvent event) {
|
||||
|
@ -4,6 +4,11 @@ import java.net.URL;
|
||||
import java.util.Map;
|
||||
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 {
|
||||
/**
|
||||
* The name of the programming language
|
||||
@ -26,12 +31,44 @@ public interface ProgrammingLanguage {
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* Uncomment a line
|
||||
* @param line The text of the line to uncomment
|
||||
* @return The uncommented 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);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Uncomment a line
|
||||
* @param selection The text of the line to uncomment
|
||||
* @return The uncommented area
|
||||
*/
|
||||
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);
|
||||
|
||||
}
|
||||
|
@ -9,6 +9,10 @@ import org.fxmisc.richtext.model.StyleSpansBuilder;
|
||||
|
||||
import app.model.ProgrammingLanguage;
|
||||
|
||||
/**
|
||||
* Common static operations that can be executed on any class
|
||||
* that implements {@link app.model.ProgrammingLanguage ProgrammingLanguage}
|
||||
*/
|
||||
public class LanguageOperations {
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user