From 6d4c3a6b297f49d3d3e66b607460a27f984e5aa9 Mon Sep 17 00:00:00 2001 From: peppapighs Date: Wed, 31 Aug 2022 13:12:25 +0800 Subject: [PATCH] Add JavaDoc for GUI classes --- data/tasks.txt | 2 +- src/main/java/duke/Main.java | 10 ++++++++ src/main/java/duke/command/AddCommand.java | 8 +++--- src/main/java/duke/command/Command.java | 4 +-- src/main/java/duke/command/DeleteCommand.java | 4 +-- src/main/java/duke/command/ExitCommand.java | 4 +-- src/main/java/duke/command/FindCommand.java | 4 +-- src/main/java/duke/command/ListCommand.java | 4 +-- src/main/java/duke/command/MarkCommand.java | 4 +-- src/main/java/duke/command/UnmarkCommand.java | 4 +-- src/main/java/duke/controller/DialogBox.java | 25 +++++++++++++++++++ src/main/java/duke/controller/MainWindow.java | 18 +++++++++++++ src/main/java/duke/task/Deadline.java | 9 +++---- src/main/java/duke/task/Event.java | 9 +++---- src/main/java/duke/task/Task.java | 2 +- src/main/java/duke/task/TaskList.java | 2 +- src/main/java/duke/task/Todo.java | 2 +- src/main/java/duke/ui/Ui.java | 5 ++-- 18 files changed, 86 insertions(+), 34 deletions(-) diff --git a/data/tasks.txt b/data/tasks.txt index 9c23cbe7f3..e523029e0c 100644 --- a/data/tasks.txt +++ b/data/tasks.txt @@ -1 +1 @@ -T | 0 | peppapig +T | 0 | do your mom diff --git a/src/main/java/duke/Main.java b/src/main/java/duke/Main.java index a1088e4e2d..c73a28280a 100644 --- a/src/main/java/duke/Main.java +++ b/src/main/java/duke/Main.java @@ -9,11 +9,21 @@ import java.io.IOException; +/** + * GUI application entry point + * + * @author Pontakorn Prasertsuk + */ public class Main extends Application { private static final String FILE_PATH = "data/tasks.txt"; private final Duke duke = new Duke(FILE_PATH); + /** + * Starts the GUI application + * + * @param stage JavaFX stage + */ @Override public void start(Stage stage) { try { diff --git a/src/main/java/duke/command/AddCommand.java b/src/main/java/duke/command/AddCommand.java index 29465a4fab..3084121616 100644 --- a/src/main/java/duke/command/AddCommand.java +++ b/src/main/java/duke/command/AddCommand.java @@ -28,8 +28,8 @@ public AddCommand(Task task) { * Executes the AddCommand. * * @param taskList the task list to be added to - * @param ui the user interface to be used - * @param storage the storage to be used + * @param ui the user interface to be used + * @param storage the storage to be used * @return output to be shown * @throws DukeException if an error occurs */ @@ -40,8 +40,8 @@ public String execute(TaskList taskList, Ui ui, Storage storage) throws DukeExce ui.showOutput("Total tasks: " + taskList.getTaskList().size()); storage.save(taskList.getTaskList()); - return "Task has been added!: " + task.toString() + "\n" + "Total tasks: " + taskList.getTaskList() - .size(); + return "Task has been added!: " + task.toString() + "\n" + "Total tasks: " + + taskList.getTaskList().size(); } /** diff --git a/src/main/java/duke/command/Command.java b/src/main/java/duke/command/Command.java index e45811d097..f53805bde6 100644 --- a/src/main/java/duke/command/Command.java +++ b/src/main/java/duke/command/Command.java @@ -16,8 +16,8 @@ public abstract class Command { * Executes the Command * * @param taskList the task list to be mutated - * @param ui the user interface to be used - * @param storage the storage to be used + * @param ui the user interface to be used + * @param storage the storage to be used * @return output to be shown * @throws DukeException if an error occurs */ diff --git a/src/main/java/duke/command/DeleteCommand.java b/src/main/java/duke/command/DeleteCommand.java index 29972244c7..86b122da03 100644 --- a/src/main/java/duke/command/DeleteCommand.java +++ b/src/main/java/duke/command/DeleteCommand.java @@ -27,8 +27,8 @@ public DeleteCommand(int index) { * Executes the DeleteCommand * * @param taskList the task list to be mutated - * @param ui the user interface to be used - * @param storage the storage to be used + * @param ui the user interface to be used + * @param storage the storage to be used * @return output to be shown * @throws DukeException if an error occurs */ diff --git a/src/main/java/duke/command/ExitCommand.java b/src/main/java/duke/command/ExitCommand.java index a8a5234ab0..4f604fd964 100644 --- a/src/main/java/duke/command/ExitCommand.java +++ b/src/main/java/duke/command/ExitCommand.java @@ -16,8 +16,8 @@ public class ExitCommand extends Command { * Executes the ExitCommand * * @param taskList not being used - * @param ui the user interface to be used - * @param storage not being used + * @param ui the user interface to be used + * @param storage not being used * @return output to be shown * @throws DukeException if an error occurs */ diff --git a/src/main/java/duke/command/FindCommand.java b/src/main/java/duke/command/FindCommand.java index cd86ebceb8..063ec4e954 100644 --- a/src/main/java/duke/command/FindCommand.java +++ b/src/main/java/duke/command/FindCommand.java @@ -27,8 +27,8 @@ public FindCommand(String keyword) { * Executes the FindCommand * * @param taskList the task list to be searched - * @param ui the user interface to be used - * @param storage not being used + * @param ui the user interface to be used + * @param storage not being used * @return output to be shown * @throws DukeException if an error occurs */ diff --git a/src/main/java/duke/command/ListCommand.java b/src/main/java/duke/command/ListCommand.java index 6aea209273..6d48952212 100644 --- a/src/main/java/duke/command/ListCommand.java +++ b/src/main/java/duke/command/ListCommand.java @@ -16,8 +16,8 @@ public class ListCommand extends Command { * Executes the ListCommand * * @param taskList the task list to be shown - * @param ui the user interface to be used - * @param storage not being used + * @param ui the user interface to be used + * @param storage not being used * @return output to be shown * @throws DukeException if an error occurs */ diff --git a/src/main/java/duke/command/MarkCommand.java b/src/main/java/duke/command/MarkCommand.java index 2fd799f945..0acb73ef63 100644 --- a/src/main/java/duke/command/MarkCommand.java +++ b/src/main/java/duke/command/MarkCommand.java @@ -27,8 +27,8 @@ public MarkCommand(int index) { * Executes the MarkCommand * * @param taskList the task list to be mutated - * @param ui the user interface to be used - * @param storage the storage to be used + * @param ui the user interface to be used + * @param storage the storage to be used * @return output to be shown * @throws DukeException if an error occurs */ diff --git a/src/main/java/duke/command/UnmarkCommand.java b/src/main/java/duke/command/UnmarkCommand.java index 978d54b09f..31065a21ba 100644 --- a/src/main/java/duke/command/UnmarkCommand.java +++ b/src/main/java/duke/command/UnmarkCommand.java @@ -27,8 +27,8 @@ public UnmarkCommand(int index) { * Executes the UnmarkCommand * * @param taskList the task list to be mutated - * @param ui the user interface to be used - * @param storage the storage to be used + * @param ui the user interface to be used + * @param storage the storage to be used * @return output to be shown * @throws DukeException if an error occurs */ diff --git a/src/main/java/duke/controller/DialogBox.java b/src/main/java/duke/controller/DialogBox.java index 7f71d0c007..00f24d30ea 100644 --- a/src/main/java/duke/controller/DialogBox.java +++ b/src/main/java/duke/controller/DialogBox.java @@ -14,12 +14,23 @@ import java.io.IOException; import java.util.Collections; +/** + * Controller for the dialog box + * + * @author Pontakorn Prasertsuk + */ public class DialogBox extends HBox { @FXML private Label dialog; @FXML private ImageView displayPicture; + /** + * Constructs a new DialogBox instance + * + * @param text the text to be displayed + * @param img the image of the dialog's owner + */ private DialogBox(String text, Image img) { try { FXMLLoader fxmlLoader = @@ -45,10 +56,24 @@ private void flip() { setAlignment(Pos.TOP_LEFT); } + /** + * Creates a new DialogBox instance for user + * + * @param text the text to be displayed + * @param img the image of the user + * @return the new DialogBox instance + */ public static DialogBox getUserDialog(String text, Image img) { return new DialogBox(text, img); } + /** + * Creates a new DialogBox instance for bot + * + * @param text the text to be displayed + * @param img the image of the bot + * @return the new DialogBox instance + */ public static DialogBox getDukeDialog(String text, Image img) { var db = new DialogBox(text, img); db.flip(); diff --git a/src/main/java/duke/controller/MainWindow.java b/src/main/java/duke/controller/MainWindow.java index dc96e3f7de..b2b0c741b1 100644 --- a/src/main/java/duke/controller/MainWindow.java +++ b/src/main/java/duke/controller/MainWindow.java @@ -7,6 +7,11 @@ import javafx.scene.layout.AnchorPane; import javafx.scene.layout.VBox; +/** + * Controller for the main window + * + * @author Pontakorn Prasertsuk + */ public class MainWindow extends AnchorPane { @FXML private ScrollPane scrollPane; @@ -21,11 +26,24 @@ public class MainWindow extends AnchorPane { private Image userImage = new Image(this.getClass().getResourceAsStream("/images/user.png")); private Image dukeImage = new Image(this.getClass().getResourceAsStream("/images/robot.png")); + /** + * Initializes the main window on rendered by the JavaFX application + */ @FXML public void initialize() { scrollPane.vvalueProperty().bind(dialogContainer.heightProperty()); + dialogContainer.getChildren() + .add(DialogBox.getDukeDialog("Hello from\n" + "______ _ \n" + + "| ___ \\ | | \n" + "| |_/ / ___ | |__ \n" + + "| ___ \\/ _ \\| '_ \\ \n" + "| |_/ / (_) | |_) |\n" + + "\\____/ \\___/|_.__/ \n" + "What can I do for you?", dukeImage)); } + /** + * Sets the Duke instance for the application + * + * @param duke the Duke instance + */ public void setDuke(Duke duke) { this.duke = duke; } diff --git a/src/main/java/duke/task/Deadline.java b/src/main/java/duke/task/Deadline.java index 32281105ba..86c08bf1a5 100644 --- a/src/main/java/duke/task/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -17,9 +17,9 @@ public class Deadline extends Task { /** * Constructs a new Deadline instance * - * @param title the name of the task + * @param title the name of the task * @param status whether the task is completed or not - * @param date the deadline of the task + * @param date the deadline of the task */ public Deadline(String title, boolean status, String date) throws DateTimeParseException { super(title, status); @@ -33,9 +33,8 @@ public Deadline(String title, boolean status, String date) throws DateTimeParseE */ @Override public String encode() { - return (SYMBOL + " | " + (this.status ? - "1" : - "0") + " | " + this.title + " | " + this.date); + return (SYMBOL + " | " + (this.status ? "1" : "0") + " | " + this.title + " | " + + this.date); } @Override diff --git a/src/main/java/duke/task/Event.java b/src/main/java/duke/task/Event.java index 2133fc2f25..2fb0d6d9dc 100644 --- a/src/main/java/duke/task/Event.java +++ b/src/main/java/duke/task/Event.java @@ -17,9 +17,9 @@ public class Event extends Task { /** * Constructs a new Event instance * - * @param title the name of the task + * @param title the name of the task * @param status whether the task is completed or not - * @param date the date where the event occurs + * @param date the date where the event occurs */ public Event(String title, boolean status, String date) throws DateTimeParseException { super(title, status); @@ -33,9 +33,8 @@ public Event(String title, boolean status, String date) throws DateTimeParseExce */ @Override public String encode() { - return (SYMBOL + " | " + (this.status ? - "1" : - "0") + " | " + this.title + " | " + this.date); + return (SYMBOL + " | " + (this.status ? "1" : "0") + " | " + this.title + " | " + + this.date); } @Override diff --git a/src/main/java/duke/task/Task.java b/src/main/java/duke/task/Task.java index a653f0eaf5..aff1a97ece 100644 --- a/src/main/java/duke/task/Task.java +++ b/src/main/java/duke/task/Task.java @@ -17,7 +17,7 @@ public abstract class Task { /** * Constructs a new Task instance * - * @param title the name of the task + * @param title the name of the task * @param status whether the task is completed or not */ Task(String title, boolean status) { diff --git a/src/main/java/duke/task/TaskList.java b/src/main/java/duke/task/TaskList.java index d83d80bb3b..0582a118b8 100644 --- a/src/main/java/duke/task/TaskList.java +++ b/src/main/java/duke/task/TaskList.java @@ -69,7 +69,7 @@ public TaskList delete(int index) throws DukeException { /** * Marks a task with status * - * @param index the index of the task to be marked + * @param index the index of the task to be marked * @param status the status of the task to be marked * @return the task list after marking the task * @throws DukeException if an error occurs diff --git a/src/main/java/duke/task/Todo.java b/src/main/java/duke/task/Todo.java index 6ade070201..d9466d99ef 100644 --- a/src/main/java/duke/task/Todo.java +++ b/src/main/java/duke/task/Todo.java @@ -12,7 +12,7 @@ public class Todo extends Task { /** * Constructs a new Todo instance * - * @param title the name of the task + * @param title the name of the task * @param status whether the task is completed or not */ public Todo(String title, boolean status) { diff --git a/src/main/java/duke/ui/Ui.java b/src/main/java/duke/ui/Ui.java index 25d0af628e..61559141f1 100644 --- a/src/main/java/duke/ui/Ui.java +++ b/src/main/java/duke/ui/Ui.java @@ -7,8 +7,9 @@ */ public class Ui { - private static final String LOGO = - "______ _ \n" + "| ___ \\ | | \n" + "| |_/ / ___ | |__ \n" + "| ___ \\/ _ \\| '_ \\ \n" + "| |_/ / (_) | |_) |\n" + "\\____/ \\___/|_.__/ \n"; + private static final String LOGO = "______ _ \n" + "| ___ \\ | | \n" + + "| |_/ / ___ | |__ \n" + "| ___ \\/ _ \\| '_ \\ \n" + "| |_/ / (_) | |_) |\n" + + "\\____/ \\___/|_.__/ \n"; /** * Shows the logo of the application