From 72e7ee180faa73b07d4b6bdfd0ac60d07532481d Mon Sep 17 00:00:00 2001 From: Winston Date: Thu, 21 Sep 2023 01:21:24 +0800 Subject: [PATCH] Fixed styling and added more javadoc --- src/main/java/duke/CircleClip.java | 9 +++ src/main/java/duke/DialogBox.java | 6 +- src/main/java/duke/Duke.java | 3 - .../java/duke/EmptyDescriptionException.java | 2 +- src/main/java/duke/EventTypeHandler.java | 51 +++++++++----- src/main/java/duke/InvalidInputException.java | 3 + src/main/java/duke/Parser.java | 6 ++ src/main/java/duke/Task.java | 4 +- src/main/java/duke/TaskList.java | 67 ++++++++++++------- src/main/java/duke/Ui.java | 3 +- src/main/java/duke/Window.java | 20 +++++- 11 files changed, 118 insertions(+), 56 deletions(-) diff --git a/src/main/java/duke/CircleClip.java b/src/main/java/duke/CircleClip.java index 44e0497a40..077b6334e2 100644 --- a/src/main/java/duke/CircleClip.java +++ b/src/main/java/duke/CircleClip.java @@ -3,6 +3,9 @@ import javafx.scene.image.ImageView; import javafx.scene.shape.Circle; +/** + * Creates a Circle Clip for the avatars in the chatbot + */ public class CircleClip { private final int centerX; @@ -10,6 +13,12 @@ public class CircleClip { private final int radius; private final Circle circle; + /** + * constructor for Circle clip + * @param centerX x-coordinates of center + * @param centerY y-coordinates of center + * @param radius radius of the clip + */ public CircleClip(int centerX, int centerY, int radius) { this.centerX = centerX; this.centerY = centerY; diff --git a/src/main/java/duke/DialogBox.java b/src/main/java/duke/DialogBox.java index 317969592d..49d010571a 100644 --- a/src/main/java/duke/DialogBox.java +++ b/src/main/java/duke/DialogBox.java @@ -24,9 +24,9 @@ public class DialogBox extends HBox { private ImageView displayPicture; /** - * DialogBox - * @param l Label - * @param iv ImageView + * DialogBox inside the GUI + * @param l Label given to the GUI + * @param iv ImageView given to the GUI * @param isUserDialog Whether this dialogbox is userdialog or duke dialog * @param content content to be displayed */ diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 927476872c..41342b1197 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -30,7 +30,6 @@ public Duke() { } public static void main(String[] args) throws EmptyDescriptionException, InvalidCommandException, NotANumberException { - //Duke duke = new Duke("../ip/src/main/data/duke.txt"); } /** @@ -41,8 +40,6 @@ public static void main(String[] args) throws EmptyDescriptionException, Invalid @Override public void start(Stage stage) { - //Window window = new Window(stage, storage, ui); - Window.setParameters(stage, storage, ui); Window.initializeWindow(); diff --git a/src/main/java/duke/EmptyDescriptionException.java b/src/main/java/duke/EmptyDescriptionException.java index 0544b0c2a1..5a1c337d70 100644 --- a/src/main/java/duke/EmptyDescriptionException.java +++ b/src/main/java/duke/EmptyDescriptionException.java @@ -6,7 +6,7 @@ public class EmptyDescriptionException extends DukeException { private static String line = "\t____________________________________________________________\n"; public EmptyDescriptionException(String task) { - //System.out.println( line + "\t☹ OOPS!!! The description of a " + task + " cannot be empty." + "\n" + line); + } } diff --git a/src/main/java/duke/EventTypeHandler.java b/src/main/java/duke/EventTypeHandler.java index 6f8ce887e9..c012cdc87f 100644 --- a/src/main/java/duke/EventTypeHandler.java +++ b/src/main/java/duke/EventTypeHandler.java @@ -1,35 +1,50 @@ package duke; +/** + * Class to determine EventTypeHandler + */ public class EventTypeHandler { private TaskList tasks; private String extractedSubstring; private String isDone; + + /** + * Constructor for eventHandler + * @param tasks TaskList + * @param extractedSubstring Substring to determine which type of event + * @param isDone whether the event is marked as done or not + */ public EventTypeHandler(TaskList tasks, String extractedSubstring, String isDone) { this.tasks = tasks; this.extractedSubstring = extractedSubstring; this.isDone = isDone; } + /** + * To handle the different type of tasks (T,D,E) + * @param eventType + * @throws EmptyDescriptionException + */ public void handleEventType(String eventType) throws EmptyDescriptionException { switch (eventType) { - case "T": { - tasks.toDoHandler(extractedSubstring, isDone.equals("X"), true); - break; - } - case "D": { - //System.out.println(extractedSubstring); - String description = Parser.convertDeadlineFormat(extractedSubstring); - tasks.deadlineHandler(description, isDone.equals("X"), true); - break; - } - case "E": { - String description = Parser.convertEventFormat(extractedSubstring); - tasks.eventHandler(description, isDone.equals("X"), true); - break; - } - default: { - break; - } + case "T": { + tasks.toDoHandler(extractedSubstring, isDone.equals("X"), true); + break; + } + case "D": { + //System.out.println(extractedSubstring); + String description = Parser.convertDeadlineFormat(extractedSubstring); + tasks.deadlineHandler(description, isDone.equals("X"), true); + break; + } + case "E": { + String description = Parser.convertEventFormat(extractedSubstring); + tasks.eventHandler(description, isDone.equals("X"), true); + break; + } + default: { + break; + } } } } diff --git a/src/main/java/duke/InvalidInputException.java b/src/main/java/duke/InvalidInputException.java index 06cee68105..aa93675144 100644 --- a/src/main/java/duke/InvalidInputException.java +++ b/src/main/java/duke/InvalidInputException.java @@ -1,5 +1,8 @@ package duke; +/** + * Exception for invalid input + */ public class InvalidInputException extends DukeException { public InvalidInputException() { diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java index bb5df340ab..4a92f85749 100644 --- a/src/main/java/duke/Parser.java +++ b/src/main/java/duke/Parser.java @@ -83,6 +83,12 @@ public static LocalDateTime retrieveDeadlineTime(String input) { return LocalDateTime.parse(dateTimeStr, formatter); } + /** + * Extracts out the time for an Event. + * @param input String representation of the Event + * @return array of times (from time and to time) + * @throws InvalidInputException + */ public static LocalDateTime[] retrieveEventTime(String input) throws InvalidInputException { String[] parts = input.split("/from | /to "); if (parts.length != 3) { diff --git a/src/main/java/duke/Task.java b/src/main/java/duke/Task.java index b77f37d038..fec062d199 100644 --- a/src/main/java/duke/Task.java +++ b/src/main/java/duke/Task.java @@ -34,14 +34,14 @@ public String getDescription() { } /** - * Method to mark a task as done + * Method to mark a task as done inside the taskList */ public void markTask() { this.isDone = true; } /** - * Method to mark a task as not done + * Method to mark a task as not done inside the taskList */ public void unmarkTask() { this.isDone = false; diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java index 27adc93058..0848d2e935 100644 --- a/src/main/java/duke/TaskList.java +++ b/src/main/java/duke/TaskList.java @@ -236,6 +236,15 @@ public String findTask(String taskName) { System.out.println(line); return message; } + + /** + * Method to update the time of a task + * @param description String representation of the task + * @param number Number of the task inside the TaskList + * @return Confirmation that the task has been updated + * @throws NotANumberException + * @throws InvalidInputException + */ public String updateTime(String description, char number) throws NotANumberException, InvalidInputException { if (!Character.isDigit(number)) { throw new NotANumberException(); @@ -246,33 +255,39 @@ public String updateTime(String description, char number) throws NotANumberExcep } } + /** + * Prints out all the commands + * @return all commands + */ public String help() { - return "Here is a list of my commands:\n " + - "1. todo taskDescription. This adds a todo task to your list of tasks.\n" + - "\tExample Usage:\n" + - "\ttodo Homework\n\n" + - "2. deadline taskDescription /by dd-mm-yy HH:MM. This adds a deadline task your list of tasks.\n" + - "\tExample Usage:\n" + - "\tdeadline CS2103T assignment /by 21-09-2023 23:59\n\n" + - "3. event taskDescription /from dd-mm-yy HH:MM /to dd-mm-yy HH:MM. This adds an event to your list of tasks.\n" + - "\tExample Usage: \n" + - "\tevent CS2103T Team Meeting /from 21-09-2023 21:00 /to 21-09-2023 22:00\n\n" + - "4. list. This command displays the list of tasks you have.\n\n" + - "5. mark taskNumber. This command marks the corresponding task in the list as done\n" + - "\tExample Usage: \n" + - "\t mark 1\n\n" + - "6. unmark taskNumber. This command unmarks the corresponding task in the list\n" + - "\tExample Usage:\n" + - "\tunmark 1\n\n" + - "7. delete taskNumber. This command deletes the corresponding task from the list\n" + - "\tExample Usage:\n" + - "\tdelete 1\n\n" + - "8. find taskDescription. This command returns a list of task that matches the taskName given\n" + - "\tExample Usage:\n" + - "\tfind CS2103T\n\n" + - "9.update taskNumber /by dd-mm-yy HH:MM. This command updates the time of an event or deadline task.\n" + - "\tExample Usage: \n" + - "\tupdate 2 /by 30-09-2023 23:59"; + return "Here is a list of my commands:\n " + + "1. todo taskDescription. This adds a todo task to your list of tasks.\n" + + "\tExample Usage:\n" + + "\ttodo Homework\n\n" + + "2. deadline taskDescription /by dd-mm-yy HH:MM. This adds a deadline task your list of tasks.\n" + + "\tExample Usage:\n" + + "\tdeadline CS2103T assignment /by 21-09-2023 23:59\n\n" + + "3. event taskDescription /from dd-mm-yy HH:MM /to dd-mm-yy HH:MM. This adds an event to your list " + + "of tasks.\n" + + "\tExample Usage: \n" + + "\tevent CS2103T Team Meeting /from 21-09-2023 21:00 /to 21-09-2023 22:00\n\n" + + "4. list. This command displays the list of tasks you have.\n\n" + + "5. mark taskNumber. This command marks the corresponding task in the list as done\n" + + "\tExample Usage: \n" + + "\t mark 1\n\n" + + "6. unmark taskNumber. This command unmarks the corresponding task in the list\n" + + "\tExample Usage:\n" + + "\tunmark 1\n\n" + + "7. delete taskNumber. This command deletes the corresponding task from the list\n" + + "\tExample Usage:\n" + + "\tdelete 1\n\n" + + "8. find taskDescription. This command returns a list of task that matches the taskName given\n" + + "\tExample Usage:\n" + + "\tfind CS2103T\n\n" + + "9.update taskNumber /by dd-mm-yy HH:MM. This command updates the time of an event " + + "or deadline task.\n" + + "\tExample Usage: \n" + + "\tupdate 2 /by 30-09-2023 23:59"; } } diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java index b044eb3272..496fed2cd5 100644 --- a/src/main/java/duke/Ui.java +++ b/src/main/java/duke/Ui.java @@ -55,8 +55,7 @@ public String startUi(String echo) { return tasks.updateTime(description, number); } else if (words[0].equalsIgnoreCase("help")) { return tasks.help(); - } - else { + } else { throw new InvalidCommandException(); } } catch (EmptyDescriptionException | InvalidCommandException e) { diff --git a/src/main/java/duke/Window.java b/src/main/java/duke/Window.java index 3e994cb8ae..3b322f575f 100644 --- a/src/main/java/duke/Window.java +++ b/src/main/java/duke/Window.java @@ -14,6 +14,9 @@ import javafx.scene.layout.VBox; import javafx.stage.Stage; +/** + * Creates the GUI + */ public class Window { @FXML @@ -28,7 +31,7 @@ public class Window { private static final AnchorPane mainLayout = new AnchorPane(); private static final Scene scene = new Scene(mainLayout); private static final Image user = new Image(Window.class.getResourceAsStream("/images/DaUser.png")); - private static final Image duke = new Image(Window.class.getResourceAsStream("/images/DaDuke.png")); + private static final Image duke = new Image(Window.class.getResourceAsStream("/images/DaDuke.png")); private static Storage storage = null; private static Ui ui = null; @@ -81,6 +84,9 @@ private static void handleUserInput() { userInput.clear(); } + /** + * Initializes the GUI + */ public static void initializeWindow() { dialogContainer.setSpacing(20.0); scrollPane.setContent(dialogContainer); @@ -88,6 +94,9 @@ public static void initializeWindow() { stage.show(); } + /** + * Formats the GUI + */ public static void formatWindow() { stage.setTitle("Duke"); stage.setResizable(false); @@ -114,6 +123,9 @@ public static void formatWindow() { dialogContainer.heightProperty().addListener((observable) -> scrollPane.setVvalue(1.0)); } + /** + * Adds user input to the GUI + */ public static void addUserInput() { sendButton.setOnMouseClicked((event) -> { handleUserInput(); @@ -124,6 +136,9 @@ public static void addUserInput() { }); } + /** + * Prints out a welcome message + */ public static void welcomeMessage() { CircleClip clip = new CircleClip(40, 40, 40); ImageView dukeImageView = new ImageView(duke); @@ -133,6 +148,9 @@ public static void welcomeMessage() { dialogContainer.getChildren().add(DialogBox.getDukeDialog(welcomeMessage, dukeImageView, welMessage)); } + /** + * Sends error message + */ public static void sendErrorMessage() { CircleClip clip = new CircleClip(40, 40, 40); ImageView dukeImageView = new ImageView(duke);