Add several pieces of documentation

This commit is contained in:
Oystein Kristoffer Tveit 2021-03-02 02:05:50 +01:00
parent 09118ee3b2
commit 41362a45d4
24 changed files with 196 additions and 36 deletions

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>tdt4100-v2021</groupId>
<artifactId>project</artifactId>
<artifactId>banana-editor</artifactId>
<version>1.0.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -99,9 +99,6 @@
<argLine>@{argLine} --enable-preview</argLine>
<forkCount>1</forkCount>
<reuseForks>true</reuseForks>
<!-- <includes>
<include>**/test/**/*Test.java</include>
</includes> -->
</configuration>
</plugin>

View File

@ -37,11 +37,19 @@ public class Main extends Application {
window.getIcons().add(new Image(getClass().getResourceAsStream(ICON_PATH)));
}
/**
* Loads all FXML documents of the main UI and initializes all correlated subcontrollers
* @throws IOException
*/
private void loadFXML() throws IOException {
// TODO: Error handle this function.
this.fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/Main.fxml"));
this.fxmlRoot = fxmlLoader.load();
}
/**
* Generates a scene for the window, and adds it to {@link Model}
*/
private void createScene() {
this.scene = new Scene(fxmlRoot);
Model.setScene(scene);

View File

@ -46,31 +46,47 @@ public class MainController implements Initializable {
}
/**
* Get the global eventbus.
* Get the global eventbus
*
* @return The eventbus
* @return The EventBus object
*/
public EventBus getEventBus() {
return this.eventBus;
}
/**
* Get the global Host Services API
*
* @return The JavaFX HostServices object
* @see #setHostServices(HostServices)
*/
public HostServices getHostServices() {
return hostServices;
}
/**
* Set a reference to the global Host Services API
* @param hostServices The JavaFX HostServices object
* @see #getHostServices()
*/
public void setHostServices(HostServices hostServices) {
this.hostServices = hostServices;
}
/**
* Replace a CSS file in a specific location in the application CSS array
* @param position The position of the CSS file to replace
* @param cssPath The path in resources to the new CSS file
*/
private void setCSSAt(int position, String cssPath) {
//TODO: Error check that position in range 0 to 1
String nextStyleSheet = getClass().getResource(cssPath).toExternalForm();
Model.getScene().getStylesheets().set(position, nextStyleSheet);
}
/**
* Change the CSS according to which language is being used.
*
* Change the CSS according to which language is being used
* @param event
*/
@Subscribe
@ -78,19 +94,26 @@ public class MainController implements Initializable {
this.setCSSAt(1, "/styling/languages/" + event.getLanguage().toLowerCase() + ".css");
}
/**
* Change the CSS according to which theme the user chooses
* @param event
*/
@Subscribe
private void handle(ThemeChangedEvent event) {
this.setCSSAt(0, "/styling/themes/" + event.getTheme().toLowerCase().replace(" ", "-") + ".css");
}
/**
* Open a link in the browser.
* @param event
*/
@Subscribe
private void handle(OpenLinkInBrowserEvent event) {
this.getHostServices().showDocument(event.getLink());
}
/**
* Handle an exit request for the whole program.
*
* Handle an exit request for the whole program
* @param event
*/
@Subscribe

View File

@ -53,7 +53,7 @@ public class ModelineController implements Initializable, Controller {
*/
@Subscribe
private void handle(EditorChangedEvent event) {
this.setColumnRow(event.getColumn(), event.getLineNumber());
this.setColumnRow(event.getColumn(), event.getLine());
}
/**

View File

@ -1,5 +1,8 @@
package app.events;
/**
* Event signalizing that something is being copied to the clipboard in an arbitrary place in the UI
*/
public class CopyEvent extends Event {
}

View File

@ -1,5 +1,8 @@
package app.events;
/**
* Event signalizing that something is being cut to the clipboard in an arbitrary place in the UI
*/
public class CutEvent extends Event {
}

View File

@ -1,19 +1,33 @@
package app.events;
/**
* Event signalizing that the content or the cursor state in the editor has been modified
*/
public class EditorChangedEvent extends Event {
private int lineNumber;
private int line;
private int column;
public EditorChangedEvent(int lineNumber, int column) {
this.lineNumber = lineNumber;
/**
* Event signalizing that the content or the cursor state in the editor has been modified
* @param line The line number of the cursor
* @param column The column number of the cursor
*/
public EditorChangedEvent(int line, int column) {
this.line = line;
this.column = column;
}
public int getLineNumber() {
return this.lineNumber;
/**
* @return The line number of the cursor
*/
public int getLine() {
return this.line;
}
/**
* @return The column number of the cursor
*/
public int getColumn() {
return column;
}

View File

@ -1,3 +1,6 @@
package app.events;
class Event {}
/**
* Base class for any type of event of the eventbus
*/
abstract class Event {}

View File

@ -1,5 +1,8 @@
package app.events;
/**
* Event signalizing a shutdown request for the whole applicaton
*/
public class ExitApplicationEvent extends Event {
}

View File

@ -2,15 +2,25 @@ package app.events;
import app.model.Model;
/**
* Event signalizing that the current file either has been modified or saved
*/
public class FileSaveStateChangedEvent extends Event {
private boolean isSaved;
/**
* Event signalizing that the current file either has been modified or saved
* @param isSaved Whether or not the file has been modified or saved
*/
public FileSaveStateChangedEvent(boolean isSaved) {
this.isSaved = isSaved;
Model.setFileIsSaved(isSaved);
}
/**
* @return Whether or not the file has been modified or saved
*/
public boolean getIsSaved() {
return this.isSaved;
}

View File

@ -1,15 +1,29 @@
package app.events;
public class FileSelectedEvent {
/**
* Event signalizing that a file was selected in the filetree.
*
* Not to be confused with {@link OpenFileEvent}
*/
public class FileSelectedEvent extends Event {
private String path;
private String path;
public FileSelectedEvent(String path) {
this.path = path;
}
/**
* Event signalizing that a file was selected in the filetree.
*
* Not to be confused with {@link OpenFileEvent}
* @param path The path of the selected file
*/
public FileSelectedEvent(String path) {
this.path = path;
}
public String getPath() {
return this.path;
}
/**
* @return The path of the selected file
*/
public String getPath() {
return this.path;
}
}

View File

@ -1,13 +1,19 @@
package app.events;
import app.model.languages.Java;
import app.model.languages.Markdown;
import app.model.languages.*;
import app.model.Model;
/**
* Event signalizing that the programming language of the editor has changed
*/
public class LanguageChangedEvent extends Event {
private String language;
/**
* Event signalizing that the programming language of the editor has changed
* @param language The name of the language, capitalized
*/
public LanguageChangedEvent(String language) {
this.language = language;
@ -26,6 +32,9 @@ public class LanguageChangedEvent extends Event {
}
}
/**
* @return The name of the language
*/
public String getLanguage() {
return language;
}

View File

@ -1,13 +1,25 @@
package app.events;
/**
* Event signalizing that a file outside the current project is supposed to be opened in the editor.
*
* Not to be confused with {@link FileSelectedEvent}
*/
public class OpenFileEvent extends Event {
private String path;
/**
* Event signalizing that a file outside the current project is supposed to be opened in the editor.
* @param path The path of the file to be opened
*/
public OpenFileEvent(String path) {
this.path = path;
}
/**
* @return The path of the file to be opened
*/
public String getPath() {
return this.path;
}

View File

@ -1,13 +1,23 @@
package app.events;
/**
* Event signalizing that the application is going to open a link in an external browser
*/
public class OpenLinkInBrowserEvent extends Event {
private String link;
/**
* Event signalizing that the application is going to open a link in an external browser
* @param link The link to open
*/
public OpenLinkInBrowserEvent(String link) {
this.link = link;
}
/**
* @return The link to open
*/
public String getLink() {
return link;
}

View File

@ -1,13 +1,23 @@
package app.events;
/**
* Event signalizing that a folder is supposed to be opened in the filetree.
*/
public class OpenProjectEvent extends Event {
private String path;
/**
* Event signalizing that a folder is supposed to be opened in the filetree.
* @param path The path of the folder to be opened
*/
public OpenProjectEvent(String path) {
this.path = path;
}
/**
* @return The path of the folder to be opened
*/
public String getPath() {
return this.path;
}

View File

@ -1,5 +1,8 @@
package app.events;
/**
* Event signalizing that something is being pasted from the clipboard in an arbitrary place in the UI
*/
public class PasteEvent extends Event {
}

View File

@ -1,5 +1,8 @@
package app.events;
/**
* Event signalizing that an action is being undone in an arbitrary place in the UI
*/
public class RedoEvent extends Event {
}

View File

@ -1,13 +1,23 @@
package app.events;
public class ThemeChangedEvent {
/**
* Event signalizing that the theme of the applicaton has been changed
*/
public class ThemeChangedEvent extends Event {
private String theme;
/**
* Event signalizing that the theme of the applicaton has been changed
* @param theme The name of the theme
*/
public ThemeChangedEvent(String theme) {
this.theme = theme;
}
/**
* @return The name of the theme
*/
public String getTheme() {
return theme;
}

View File

@ -1,5 +1,8 @@
package app.events;
/**
* Event signalizing that the editor is going to toggle a language specific comment of a line or selecton
*/
public class ToggleCommentEvent extends Event {
}

View File

@ -1,13 +1,23 @@
package app.events;
/**
* Event signalizing that the editor wrap text function was toggled on or off
*/
public class ToggleWrapTextEvent extends Event {
private boolean isWrapped;
/**
* Event signalizing that the editor wraptext function was toggled on or off
* @param isWrapped Whether or not wraptext was turned on or off
*/
public ToggleWrapTextEvent(boolean isWrapped) {
this.isWrapped = isWrapped;
}
/**
* @return Whether or not wraptext was turned on or off
*/
public boolean getIsWrapped() {
return this.isWrapped;
}

View File

@ -1,5 +1,8 @@
package app.events;
/**
* Event signalizing that an action is being undone in an arbitrary place in the UI
*/
public class UndoEvent extends Event {
}

View File

@ -8,7 +8,7 @@ import javafx.scene.Scene;
* Data model of the application.
*
* Contains a static reference to state that has to be accessed by multiple
* pieces in the application, including the primary scene.
* pieces in the application, including the state like primary scene.
*/
public class Model {
private static boolean fileIsSaved;

View File

@ -11,14 +11,28 @@ import app.model.ProgrammingLanguage;
public class LanguageOperations {
private static String getMatch(Matcher m, Collection<String> kws) {
return kws
/**
* Use a matcher to find the styleclass of the next match
* from several available styleclasses.
* @param m The matcher
* @param styleClasses Collection of styleclasses
* @return The styleclass of the next match
*/
private static String getMatch(Matcher m, Collection<String> styleClasses) {
return styleClasses
.stream()
.filter(keyword -> m.group(keyword) != null)
.findFirst()
.orElse(""); // This is not possible, but is needed to convert Optional<String> to String
}
/**
* Calculate syntax highlighting data for a code area
* @param text The text to highlight
* @param language The language object to use for highlighting
* @return The syntax highlighting data
* @see app.controllers.EditorController#setHighlighting(StyleSpans) EditorController.setHighlighting()
*/
public static StyleSpans<Collection<String>>
syntaxHighlight(String text, ProgrammingLanguage language) {
Matcher matcher = language.getPattern().matcher(text);

View File

@ -1,5 +0,0 @@
package service;
public class FileOperations {
}