Skip to content

Commit

Permalink
Improve GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
jolynloh committed Sep 14, 2022
1 parent 3889cca commit 83a29c4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/main/java/skyler/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public Parser(TaskList taskList) {
* @throws TaskNotRecognisedException If command is not recognised.
*/
public String parse(String command) throws EmptyDescriptionException, TaskNotRecognisedException {
if (checkIsCommandType(command, "list")) {
if (checkIsCommandType(command, "help")) {
return taskList.help();
} else if (checkIsCommandType(command, "list")) {
return taskList.list();
} else if (checkIsCommandType(command, "mark")) {
int itemID = getItemID(command);
Expand Down Expand Up @@ -58,12 +60,16 @@ public String parse(String command) throws EmptyDescriptionException, TaskNotRec
}

private boolean checkIsCommandType(String command, String type) throws EmptyDescriptionException {
if (!type.equals("list") && command.trim().equals(type)) {
if (isCommandTypeWithDescription(type) && command.trim().equals(type)) {
throw new EmptyDescriptionException();
}
return command.startsWith(type);
}

private boolean isCommandTypeWithDescription(String type) {
return !type.equals("list") && !type.equals("help");
}

private int getItemID(String command) {
return Integer.parseInt(command.substring(command.length() - 1));
}
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/skyler/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,28 @@ public TaskList(Storage storage) {
assert this.tasks != null : "ArrayList of tasks should be initialised";
}

// help() method below inspired by https://github.com/hsiaotingluv/ip
/**
* Prints permissible user commands and their corresponding formats (if any)
*
* @return User command list.
*/
public String help() {
StringBuilder response = new StringBuilder("Try entering one of the following commands...\n");
response.append("1. todo <task>\n");
response.append("2. deadline <item> /by <YYYY-MM-DD> <hhmm>\n");
response.append("3. event <occasion> /at <YYYY-MM-DD> <hhmm>\n");
response.append("4. reschedule <INDEX> <YYYY-MM-DD> <hhmm>\n");
response.append("5. mark <INDEX>\n");
response.append("6. unmark <INDEX>\n");
response.append("7. delete <INDEX>\n");
response.append("8. find <keyword>\n");
response.append("9. list\n");
response.append("10. help\n");
response.append("11. bye\n");
return response.toString();
}

/**
* Prints the current list of tasks
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/skyler/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Represents an interface for user interactions
*/
public class Ui {
protected static final String GREETING = "Hello! I'm Skyler\nHow can I help you?\n";
protected static final String GREETING = "Hello! I'm Skyler\nHow may I help you?";

public String showEmptyDescriptionError() {
return "Oh no! Cannot execute command without description.";
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/view/MainWindow.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="skyler.MainWindow">
<children>
<TextField fx:id="userInput" layoutY="558.0" onAction="#handleUserInput" prefHeight="41.0" prefWidth="324.0" AnchorPane.bottomAnchor="1.0" />
<TextField fx:id="userInput" layoutY="558.0" onAction="#handleUserInput" prefHeight="41.0" prefWidth="324.0" AnchorPane.bottomAnchor="1.0" promptText="Enter 'help' for a list of commands" />
<Button fx:id="sendButton" layoutX="324.0" layoutY="558.0" mnemonicParsing="false" onAction="#handleUserInput" prefHeight="41.0" prefWidth="76.0" text="Send" />
<ScrollPane fx:id="scrollPane" hbarPolicy="NEVER" hvalue="1.0" prefHeight="557.0" prefWidth="400.0" vvalue="1.0">
<content>
Expand Down

0 comments on commit 83a29c4

Please sign in to comment.