Skip to content

Commit

Permalink
Fixed styling and added more javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
WinstonLeonard committed Sep 20, 2023
1 parent d0e7202 commit 72e7ee1
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 56 deletions.
9 changes: 9 additions & 0 deletions src/main/java/duke/CircleClip.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@
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;
private final int centerY;
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;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/duke/DialogBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

/**
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/EmptyDescriptionException.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}

}
51 changes: 33 additions & 18 deletions src/main/java/duke/EventTypeHandler.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}
3 changes: 3 additions & 0 deletions src/main/java/duke/InvalidInputException.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package duke;

/**
* Exception for invalid input
*/
public class InvalidInputException extends DukeException {
public InvalidInputException() {

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/duke/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/duke/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
67 changes: 41 additions & 26 deletions src/main/java/duke/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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";
}

}
3 changes: 1 addition & 2 deletions src/main/java/duke/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 19 additions & 1 deletion src/main/java/duke/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

/**
* Creates the GUI
*/
public class Window {

@FXML
Expand All @@ -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;

Expand Down Expand Up @@ -81,13 +84,19 @@ private static void handleUserInput() {
userInput.clear();
}

/**
* Initializes the GUI
*/
public static void initializeWindow() {
dialogContainer.setSpacing(20.0);
scrollPane.setContent(dialogContainer);
stage.setScene(scene);
stage.show();
}

/**
* Formats the GUI
*/
public static void formatWindow() {
stage.setTitle("Duke");
stage.setResizable(false);
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 72e7ee1

Please sign in to comment.