Skip to content

Commit c003884

Browse files
authored
Merge pull request #12 from Zaiah0505/branch-touchup
Branch touchup
2 parents 67887a0 + bd81374 commit c003884

22 files changed

Lines changed: 531 additions & 35 deletions

src/main/java/Sweh.java

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,29 @@
1010
import javafx.scene.layout.AnchorPane;
1111
import javafx.scene.layout.Region;
1212
import javafx.scene.layout.VBox;
13+
import javafx.scene.text.Font;
14+
import javafx.scene.text.FontPosture;
15+
import javafx.scene.text.FontWeight;
1316
import javafx.stage.Stage;
1417
import nodes.DialogBox;
1518
import util.Storage;
1619

20+
import java.io.IOException;
21+
1722
/**
1823
* JavaFX Application used to wrap a Duke instance and provide GUI interaction
1924
* for Duke.
2025
*/
2126
public class Sweh extends Application {
22-
private final Image userImage = new Image(this.getClass().getResourceAsStream("/images/DaUser.png"));
23-
private final Image dukeImage = new Image(this.getClass().getResourceAsStream("/images/DaDuke.png"));
27+
private final Image userImage = new Image(this.getClass()
28+
.getResourceAsStream("/images/DaUser.jpg"));
29+
private final Image dukeImage = new Image(this.getClass()
30+
.getResourceAsStream("/images/DaSweh.jpg"));
31+
private final Label greetingText = new Label("Hello, I am SWEH. "
32+
+ "Your Simple Word-Executed Helper!\n"
33+
+ "What shall we do today?");
34+
private final Label storageErrorText = new Label("A save file was found, "
35+
+ "but the contents could not be read... I will start from scratch instead.");
2436
private Duke duke;
2537
private ScrollPane scrollPane;
2638
private VBox dialogContainer;
@@ -51,7 +63,7 @@ public void start(Stage stage) {
5163
stage.show();
5264

5365
//Step 2. Formatting the window to look as expected
54-
stage.setTitle("Duke");
66+
stage.setTitle("Sweh");
5567
stage.setResizable(false);
5668
stage.setMinHeight(600.0);
5769
stage.setMinWidth(400.0);
@@ -69,6 +81,9 @@ public void start(Stage stage) {
6981
dialogContainer.setPrefHeight(Region.USE_COMPUTED_SIZE);
7082

7183
userInput.setPrefWidth(325.0);
84+
userInput.setFont(Font.font("Consolas", FontWeight.BOLD,
85+
FontPosture.REGULAR, 12));
86+
userInput.setStyle("-fx-text-inner-color: saddlebrown");
7287

7388
sendButton.setPrefWidth(55.0);
7489

@@ -88,7 +103,20 @@ public void start(Stage stage) {
88103
//Scroll down to the end every time dialogContainer's height changes.
89104
dialogContainer.heightProperty().addListener((observable) -> scrollPane.setVvalue(1.0));
90105

91-
// more code to be added here later
106+
//Show greeting text
107+
dialogContainer.getChildren().addAll(
108+
DialogBox.getDukeDialog(greetingText, new ImageView(dukeImage))
109+
);
110+
111+
//Print error text if storage could not load a save file.
112+
try {
113+
storage.readTaskManager();
114+
} catch (IOException e) {
115+
dialogContainer.getChildren().addAll(
116+
DialogBox.getDukeDialog(storageErrorText, new ImageView(dukeImage))
117+
);
118+
}
119+
92120
}
93121

94122
/**

src/main/java/command/Command.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,28 @@
33
import task.TaskManager;
44
import util.DukeException;
55

6+
/**
7+
* Command class representing a future action that can be executed on the supplied
8+
* TaskManager object.
9+
*/
610
public abstract class Command {
11+
/**
12+
* Performs an action on the supplied taskManager and returns a String response
13+
* based on the action that was performed.
14+
*
15+
* @param taskManager TaskManager object to perform the action on.
16+
* @return String response of the action that was performed.
17+
* @throws DukeException Whenever the supplied action cannot be performed on
18+
* the given
19+
*/
720
public abstract String execute(TaskManager taskManager) throws DukeException;
821

22+
/**
23+
* Indicates if the Command object should signal to the application that the
24+
* user wants to terminate it.
25+
*
26+
* @return True, if the Command should tell the application to end.
27+
*/
928
public boolean isQuitCommand() {
1029
return false;
1130
}

src/main/java/command/DeadlineCommand.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,52 @@
33
import task.Deadline;
44
import task.TaskManager;
55
import util.DukeException;
6+
import util.Parser;
67

78
import java.time.LocalDate;
89
import java.time.format.DateTimeFormatter;
910
import java.time.format.DateTimeParseException;
1011
import java.util.HashMap;
1112
import java.util.List;
1213

14+
/**
15+
* Command to add a Deadline Task to a TaskManager.
16+
*/
1317
public class DeadlineCommand extends Command {
1418
public static final String COMMAND_STRING = Deadline.COMMAND_STRING;
1519
public static final CommandType COMMAND_TYPE = CommandType.DEADLINE;
1620

1721
private final String description;
1822
private final LocalDate date;
1923

24+
/**
25+
* Creates a DeadlineCommand that would add a Deadline with the supplied
26+
* description and date to a TaskManager when executed.
27+
*
28+
* @param description Description of the Deadline to be added.
29+
* @param date Date of the Deadline to be added.
30+
*/
2031
private DeadlineCommand(String description, LocalDate date) {
2132
this.description = description;
2233
this.date = date;
2334
}
2435

36+
/**
37+
* Constructs a DeadlineCommand from a commandMap.
38+
*
39+
* @param commandMap CommandMap representing the instruction.
40+
* @return DeadlineCommand object based on the commandMap.
41+
* @throws DukeException When the user inputs an illegal instruction for the
42+
* Deadline command.
43+
*/
2544
public static DeadlineCommand fromCommandMap(HashMap<String, List<String>> commandMap)
2645
throws DukeException {
2746
String description;
2847
LocalDate date;
2948

49+
assert Parser.extractCommandString(commandMap).equals(COMMAND_STRING)
50+
: COMMAND_STRING + "CommandFlag does not match";
51+
3052
// Validate description
3153
List<String> descriptionStrings = commandMap.get(COMMAND_STRING);
3254
if (descriptionStrings.isEmpty()) {
@@ -40,14 +62,20 @@ public static DeadlineCommand fromCommandMap(HashMap<String, List<String>> comma
4062
String dateString = dateStrings.get(0);
4163
date = LocalDate.parse(dateString, DateTimeFormatter.ISO_LOCAL_DATE);
4264
} catch (NullPointerException e) {
43-
throw new DukeException("Please provide an end date");
44-
} catch (DateTimeParseException e) {
65+
throw new DukeException("Please provide an end date using the \"/by\" flag");
66+
} catch (IndexOutOfBoundsException | DateTimeParseException e) {
4567
throw new DukeException("Please input date in the form YYYY-MM-DD");
4668
}
4769

4870
return new DeadlineCommand(description, date);
4971
}
5072

73+
/**
74+
* Adds the specified Deadline Task to the supplied TaskManager.
75+
*
76+
* @param taskManager TaskManager object to add the Deadline Task to.
77+
* @return String response of the action that was performed.
78+
*/
5179
@Override
5280
public String execute(TaskManager taskManager) {
5381
return taskManager.addTask(new Deadline(description, date));

src/main/java/command/DeleteCommand.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,43 @@
22

33
import task.TaskManager;
44
import util.DukeException;
5+
import util.Parser;
56

67
import java.util.HashMap;
78
import java.util.List;
89

10+
/**
11+
* Command to remove the specified Task from a TaskManger.
12+
*/
913
public class DeleteCommand extends Command {
1014
public static final String COMMAND_STRING = "delete";
1115
public static final CommandType COMMAND_TYPE = CommandType.DELETE;
1216
private final int position;
1317

18+
/**
19+
* Creates a DeleteCommand that would delete the task at the specified
20+
* position in the TaskManager when executed.
21+
*
22+
* @param position The position / index of the task to be deleted.
23+
*/
1424
public DeleteCommand(int position) {
1525
this.position = position;
1626
}
1727

28+
/**
29+
* Constructs a DeleteCommand from a commandMap.
30+
*
31+
* @param commandMap CommandMap representing the instruction.
32+
* @return DeleteCommand object based on the commandMap.
33+
* @throws DukeException When the user inputs an argument that cannot be parsed
34+
* into a valid Integer position.
35+
*/
1836
public static DeleteCommand fromCommandMap(HashMap<String, List<String>> commandMap)
1937
throws DukeException {
38+
39+
assert Parser.extractCommandString(commandMap).equals(COMMAND_STRING)
40+
: COMMAND_STRING + "CommandFlag does not match";
41+
2042
try {
2143
List<String> descriptions = commandMap.get(COMMAND_STRING);
2244
String indexString = descriptions.get(0);
@@ -29,6 +51,14 @@ public static DeleteCommand fromCommandMap(HashMap<String, List<String>> command
2951
}
3052
}
3153

54+
/**
55+
* Deletes the pre-specified task in the supplied TaskManager.
56+
*
57+
* @param taskManager TaskManager object to delete a Task from.
58+
* @return String response of the deletion.
59+
* @throws DukeException If the specified position does not exist within the
60+
* supplied TaskManager.
61+
*/
3262
@Override
3363
public String execute(TaskManager taskManager) throws DukeException {
3464
return taskManager.deleteTask(position);

src/main/java/command/EventCommand.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,52 @@
33
import task.Event;
44
import task.TaskManager;
55
import util.DukeException;
6+
import util.Parser;
67

78
import java.time.LocalDate;
89
import java.time.format.DateTimeFormatter;
910
import java.time.format.DateTimeParseException;
1011
import java.util.HashMap;
1112
import java.util.List;
1213

14+
/**
15+
* Command to add an Event Task to a TaskManager.
16+
*/
1317
public class EventCommand extends Command {
1418
public static final String COMMAND_STRING = "event";
1519
public static final CommandType COMMAND_TYPE = CommandType.EVENT;
1620

1721
private final String description;
1822
private final LocalDate date;
1923

24+
/**
25+
* Creates an EventCommand that would add a Event with the supplied
26+
* description and date to a TaskManager when executed.
27+
*
28+
* @param description Description of the Event to be added.
29+
* @param date Date of the Event to be added.
30+
*/
2031
private EventCommand(String description, LocalDate date) {
2132
this.description = description;
2233
this.date = date;
2334
}
2435

36+
/**
37+
* Constructs an EventCommand from a commandMap.
38+
*
39+
* @param commandMap CommandMap representing the instruction.
40+
* @return EventCommand object based on the commandMap.
41+
* @throws DukeException When the user inputs an illegal instruction for the
42+
* Event command.
43+
*/
2544
public static EventCommand fromCommandMap(HashMap<String, List<String>> commandMap)
2645
throws DukeException {
2746
String description;
2847
LocalDate date;
2948

49+
assert Parser.extractCommandString(commandMap).equals(COMMAND_STRING)
50+
: COMMAND_STRING + "CommandFlag does not match";
51+
3052
// Validate description
3153
List<String> descriptionStrings = commandMap.get(COMMAND_STRING);
3254
if (descriptionStrings.isEmpty()) {
@@ -40,14 +62,20 @@ public static EventCommand fromCommandMap(HashMap<String, List<String>> commandM
4062
String dateString = dateStrings.get(0);
4163
date = LocalDate.parse(dateString, DateTimeFormatter.ISO_LOCAL_DATE);
4264
} catch (NullPointerException e) {
43-
throw new DukeException("Please provide a date");
44-
} catch (DateTimeParseException e) {
65+
throw new DukeException("Please provide a date using the \"/at\" flag");
66+
} catch (IndexOutOfBoundsException | DateTimeParseException e) {
4567
throw new DukeException("Please input date in the form YYYY-MM-DD");
4668
}
4769

4870
return new EventCommand(description, date);
4971
}
5072

73+
/**
74+
* Adds the specified Event Task to the supplied TaskManger.
75+
*
76+
* @param taskManager TaskManager object to add the Event Task to.
77+
* @return String response of the action that was performed.
78+
*/
5179
@Override
5280
public String execute(TaskManager taskManager) {
5381
return taskManager.addTask(new Event(description, date));

src/main/java/command/FindCommand.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,44 @@
44
import task.TaskManager;
55
import util.DukeException;
66
import util.Formatter;
7+
import util.Parser;
78

89
import java.util.HashMap;
910
import java.util.List;
1011
import java.util.function.Predicate;
1112
import java.util.stream.Collectors;
1213

14+
/**
15+
* Command to search for keywords in the description of Tasks in a supplied
16+
* TaskManager and return a list of the matching Tasks.
17+
*/
1318
public class FindCommand extends Command {
1419
public static final String COMMAND_STRING = "find";
1520
public static final CommandType COMMAND_TYPE = CommandType.FIND;
1621
private final List<String> keywords;
1722

23+
/**
24+
* Creates a FindCommand that would return a String that lists all the Tasks
25+
* whose descriptions match all the keywords.
26+
*
27+
* @param keywords List of keywords that must appear in the matching Tasks.
28+
*/
1829
private FindCommand(List<String> keywords) {
1930
this.keywords = keywords;
2031
}
2132

33+
/**
34+
* Constructs a FindCommand from a commandMap.
35+
*
36+
* @param commandMap CommandMap representing the instruction.
37+
* @return FindCommand object based on the commandMap.
38+
* @throws DukeException When the user does not specify any search keywords.
39+
*/
2240
public static FindCommand fromCommandMap(HashMap<String, List<String>> commandMap)
2341
throws DukeException {
42+
assert Parser.extractCommandString(commandMap).equals(COMMAND_STRING)
43+
: COMMAND_STRING + "CommandFlag does not match";
44+
2445
List<String> keywords = commandMap.get(COMMAND_STRING);
2546

2647
if (keywords.isEmpty()) {
@@ -30,6 +51,13 @@ public static FindCommand fromCommandMap(HashMap<String, List<String>> commandMa
3051
return new FindCommand(keywords);
3152
}
3253

54+
/**
55+
* Searches the supplied TaskManager for all Tasks whose descriptions contain
56+
* all of the keywords.
57+
*
58+
* @param taskManager TaskManager object to search in.
59+
* @return String that lists all the matching tasks.
60+
*/
3361
@Override
3462
public String execute(TaskManager taskManager) {
3563
StringBuilder output = new StringBuilder();
@@ -50,10 +78,19 @@ public String execute(TaskManager taskManager) {
5078
.filter(taskPredicate)
5179
.map(Task::toString)
5280
.collect(Collectors.toList());
53-
String listOfTasks = Formatter.formatList(filteredTaskStrings);
5481

82+
// If no tasks match the predicate, inform the user.
83+
if (filteredTaskStrings.isEmpty()) {
84+
String quotedKeywords = keywords.stream()
85+
.map(s -> "\"" + s + "\"")
86+
.collect(Collectors.joining(" + "));
87+
return "No tasks match the keywords: \n" + quotedKeywords;
88+
}
89+
90+
String listOfTasks = Formatter.formatList(filteredTaskStrings);
5591
output.append("Here are the tasks that match your search: ").append("\n");
5692
output.append(listOfTasks);
93+
5794
return output.toString();
5895
}
5996
}

0 commit comments

Comments
 (0)