diff --git a/README.md b/README.md index 8715d4d915..00e4b38243 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,71 @@ -# Duke project template - -This is a project template for a greenfield Java project. It's named after the Java mascot _Duke_. Given below are instructions on how to use it. - -## Setting up in Intellij - -Prerequisites: JDK 11, update Intellij to the most recent version. - -1. Open Intellij (if you are not in the welcome screen, click `File` > `Close Project` to close the existing project first) -1. Open the project into Intellij as follows: - 1. Click `Open`. - 1. Select the project directory, and click `OK`. - 1. If there are any further prompts, accept the defaults. -1. Configure the project to use **JDK 11** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).
- In the same dialog, set the **Project language level** field to the `SDK default` option. -3. After that, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: - ``` - Hello from - ____ _ - | _ \ _ _| | _____ - | | | | | | | |/ / _ \ - | |_| | |_| | < __/ - |____/ \__,_|_|\_\___| - ``` +# Chad Personal Assistant User Guide + +## Features + +- Maintain a list of Tasks, Deadlines and Events. +- View your list at any time with a simple command `list`. +- Mark each item as Done or Not Done. +- Delete obsolete tasks. + +## Quick Start Guide +1. Download the latest Chad version from [here](https://github.com/fahim-tazz/ip/releases). +2. Open your Terminal/Command Prompt. +3. Type `cd Downloads` (or wherever the `chad.jar` file is stored). +4. Type in `java -jar chad.jar`. +5. Type in commands to use Chad. +6. Enjoy! + +--- + +## Usage + +### `list` - List all current tasks. + +Lists down all current tasks saved by Chad. +- T, D and E represent Todo, Deadline and Event tasks respectively. +- `[ ]` and `[X]` show whether a task is `Not Done` or `Done`, respectively. + + +### `todo [task name]` - Add a new Todo item. + +Adds a new Todo task to your list. + +### `deadline [task name] /by [due date YYYY-MM-DD]` - Add a new Deadline item. + +Adds a new Deadline task to your list. +- The name should be followed by a ` /by ` keyword. +- The due date should come after the ` by `, and be in the format `YYYY-MM-DD`. + +### `event [event name] /from [start time] /to [end time]` - Add a new Event item. + +Adds a new Event to your list. +- The name should be followed by a ` /from ` keyword. +- The start time should come after the ` /from ` keyword, followed by ` /to `. +- The end time should come after the ` /to ` keyoword. +- Start and End times do not have any format constraints. + +### `mark [task no.]` - Marks a task as done. + +Marks the task at that serial number as done. +- Task numbers start from 1, and follow the ordering shown by the `list` command. + +### `unmark [task no.]` - Marks a task as NOT done. + +Marks the task at that serial number as NOT done. +- Task numbers start from 1, and follow the ordering shown by the `list` command. + +### `delete [task no.]` - Removes a task from the list. + +Permanently deletes the task at that serial number from the list. +- Task numbers start from 1, and follow the ordering shown by the `list` command. +- Deleted tasks CANNOT be recovered. + +### `find [search phrase]` - Finds any task that matches with the search phrase. + +Searches for any task that contains the search phrase. +- Search is CASE-SENSITIVE. `laundry` will NOT match with a task named `Do Laundry`. + +### `bye` - Saves the current tasks and exits Chad. + +Saves the current task list on your computer, and exits Chad. Tasks will be retrieved the next time you open Chad. +- You can also exit by clicking the [X] button on the Chad window. Don't worry, Chad will save your tasks no matter what! diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..2e9f44da6a --- /dev/null +++ b/build.gradle @@ -0,0 +1,65 @@ +plugins { + id 'java' + id 'application' + id 'com.github.johnrengelman.shadow' version '5.1.0' + id 'checkstyle' +} + +repositories { + mavenCentral() +} + +checkstyle { + sourceSets = [] +} + +dependencies { + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.5.0' + testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.5.0' + + String javaFxVersion = '11' + + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'linux' + implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'linux' + implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'linux' + implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'linux' +} + +test { + useJUnitPlatform() + + testLogging { + events "passed", "skipped", "failed" + + showExceptions true + exceptionFormat "full" + showCauses true + showStackTraces true + showStandardStreams = false + } +} + +application { + mainClassName = "chad.frontend.Main" +} + +shadowJar { + archiveBaseName = "chad" + archiveClassifier = null +} + +run{ + standardInput = System.in +} + +checkstyle { + toolVersion = '10.2' +} diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml new file mode 100644 index 0000000000..62281d3553 --- /dev/null +++ b/config/checkstyle/checkstyle.xml @@ -0,0 +1,434 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/config/checkstyle/suppressions.xml b/config/checkstyle/suppressions.xml new file mode 100644 index 0000000000..135ea49ee0 --- /dev/null +++ b/config/checkstyle/suppressions.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index 8077118ebe..00e4b38243 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,71 @@ -# User Guide +# Chad Personal Assistant User Guide ## Features -### Feature-ABC +- Maintain a list of Tasks, Deadlines and Events. +- View your list at any time with a simple command `list`. +- Mark each item as Done or Not Done. +- Delete obsolete tasks. -Description of the feature. +## Quick Start Guide +1. Download the latest Chad version from [here](https://github.com/fahim-tazz/ip/releases). +2. Open your Terminal/Command Prompt. +3. Type `cd Downloads` (or wherever the `chad.jar` file is stored). +4. Type in `java -jar chad.jar`. +5. Type in commands to use Chad. +6. Enjoy! -### Feature-XYZ - -Description of the feature. +--- ## Usage -### `Keyword` - Describe action +### `list` - List all current tasks. + +Lists down all current tasks saved by Chad. +- T, D and E represent Todo, Deadline and Event tasks respectively. +- `[ ]` and `[X]` show whether a task is `Not Done` or `Done`, respectively. + + +### `todo [task name]` - Add a new Todo item. + +Adds a new Todo task to your list. + +### `deadline [task name] /by [due date YYYY-MM-DD]` - Add a new Deadline item. + +Adds a new Deadline task to your list. +- The name should be followed by a ` /by ` keyword. +- The due date should come after the ` by `, and be in the format `YYYY-MM-DD`. + +### `event [event name] /from [start time] /to [end time]` - Add a new Event item. + +Adds a new Event to your list. +- The name should be followed by a ` /from ` keyword. +- The start time should come after the ` /from ` keyword, followed by ` /to `. +- The end time should come after the ` /to ` keyoword. +- Start and End times do not have any format constraints. + +### `mark [task no.]` - Marks a task as done. + +Marks the task at that serial number as done. +- Task numbers start from 1, and follow the ordering shown by the `list` command. + +### `unmark [task no.]` - Marks a task as NOT done. + +Marks the task at that serial number as NOT done. +- Task numbers start from 1, and follow the ordering shown by the `list` command. -Describe the action and its outcome. +### `delete [task no.]` - Removes a task from the list. -Example of usage: +Permanently deletes the task at that serial number from the list. +- Task numbers start from 1, and follow the ordering shown by the `list` command. +- Deleted tasks CANNOT be recovered. -`keyword (optional arguments)` +### `find [search phrase]` - Finds any task that matches with the search phrase. -Expected outcome: +Searches for any task that contains the search phrase. +- Search is CASE-SENSITIVE. `laundry` will NOT match with a task named `Do Laundry`. -Description of the outcome. +### `bye` - Saves the current tasks and exits Chad. -``` -expected output -``` +Saves the current task list on your computer, and exits Chad. Tasks will be retrieved the next time you open Chad. +- You can also exit by clicking the [X] button on the Chad window. Don't worry, Chad will save your tasks no matter what! diff --git a/docs/Ui.png b/docs/Ui.png new file mode 100644 index 0000000000..ff17eeca4e Binary files /dev/null and b/docs/Ui.png differ diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000..f3d88b1c2f Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..b7c8c5dbf5 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000000..2fe81a7d95 --- /dev/null +++ b/gradlew @@ -0,0 +1,183 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000000..62bd9b9cce --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,103 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java deleted file mode 100644 index 5d313334cc..0000000000 --- a/src/main/java/Duke.java +++ /dev/null @@ -1,10 +0,0 @@ -public class Duke { - public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - } -} diff --git a/src/main/java/chad/backend/Chad.java b/src/main/java/chad/backend/Chad.java new file mode 100644 index 0000000000..dd262d129d --- /dev/null +++ b/src/main/java/chad/backend/Chad.java @@ -0,0 +1,32 @@ +package chad.backend; + +import java.io.IOException; + +/** + * Class encapsulating Chad. + */ +public class Chad { + private final TaskList tasklist; + private final Parser parser; + + /** + * Constructor for Chad. + */ + public Chad() { + try { + this.tasklist = new TaskList(); + } catch (IOException e) { + throw new RuntimeException(e); + } + this.parser = new Parser(this.tasklist); + } + + /** + * Get Duke's response for a given input. + * @param input Input taken from the user. + * @return Output from Chad. + */ + public String getResponse(String input) { + return parser.parse(input); + } +} diff --git a/src/main/java/chad/backend/Parser.java b/src/main/java/chad/backend/Parser.java new file mode 100644 index 0000000000..abb93f5a0f --- /dev/null +++ b/src/main/java/chad/backend/Parser.java @@ -0,0 +1,163 @@ +package chad.backend; + +import chad.commands.*; +import chad.tasks.Task; + +import java.time.format.DateTimeParseException; + +public class Parser { + private final TaskList tasklist; + + /** + * A flag to indicate that Chad is handling duplicates. + */ + private boolean isCheckingDuplicates = false; + + /** + * Stores the duplicate item that is being stored. + */ + private Task duplicateTask; + + public Parser(TaskList tasklist) { + this.tasklist = tasklist; + } + + public String parse(String instr) { + String[] tokens = instr.strip().toLowerCase().split(" ", 2); + String command = tokens[0]; + Command c; + + // Guard Clause for duplicate checking. + if (isCheckingDuplicates) { + switch (command) { + case "yes": + c = new ForceAddDuplicate(duplicateTask, tasklist); + this.isCheckingDuplicates = false; + return c.execute(); + + case "no": + this.isCheckingDuplicates = false; + return "OK, I'm not adding this duplicate task."; + + default: + this.isCheckingDuplicates = false; + } + } + + switch (command) { + case "welcome": + return "Hello, Boss. I am Chad, your personal assistant."; + case "list": + c = new List(tasklist); + break; + + case "bye": + c = new Bye(tasklist); + break; + + case "mark": + try { + int idx = Integer.parseInt(tokens[1]); + c = new Mark(idx, tasklist); + + // Executing here to catch IndexOutOfBoundsException. + c.execute(); + break; + } catch (NumberFormatException nfe) { + return "Boss, you gotta enter an index after \"mark\""; + } catch (IndexOutOfBoundsException ioobe) { + return "Boss, please enter a valid index."; + } + + case "unmark": + try { + int idx = Integer.parseInt(tokens[1]); + c = new Unmark(idx, tasklist); + + // Executing here to catch IndexOutOfBoundsException. + return c.execute(); + } catch (NumberFormatException nfe) { + return "Boss, you gotta enter an index after \"unmark\""; + } catch (IndexOutOfBoundsException ioobe) { + return "Boss, please enter a valid index."; + } + + case "todo": + assert tokens.length > 1; + try { + String description = tokens[1]; + c = new MakeTodo(description, tasklist, this); + break; + } catch (IndexOutOfBoundsException ioobe) { + return "Boss, please give me a name for this todo."; + } + + case "deadline": + assert tokens.length > 1; + + String[] tokensNameAndDeadline; + try { + tokensNameAndDeadline = tokens[1].split(" /by "); + assert tokensNameAndDeadline.length == 2; + String description = tokensNameAndDeadline[0]; + System.out.println("\n\n\nDeadline name is:" + description + "\n\n\n"); + String by = tokensNameAndDeadline[1]; + + c = new MakeDeadline(description, by, tasklist, this); + // Execute command here to catch dtpe. + return c.execute(); + } catch (IndexOutOfBoundsException ioobe) { + return "Boss, please give me a deadline in the format:" + + "\n\n\"deadline [name] /by [deadline yyyy-mm-dd]\""; + } catch (DateTimeParseException dtpe) { + return "Boss, you gotta enter the deadline date in the format: yyyy-mm-dd."; + } + + case "event": + try { + String[] tokensNameAndDates = tokens[1].split(" /from "); + String description = tokensNameAndDates[0]; + + String[] tokensStartdateAndEnddate = tokensNameAndDates[1].split(" /to "); + assert tokensStartdateAndEnddate.length == 2; + String from = tokensStartdateAndEnddate[0]; + String to = tokensStartdateAndEnddate[1]; + c = new MakeEvent(description, from, to, tasklist, this); + break; + } catch (IndexOutOfBoundsException ioobe) { + return "Boss, please give me an event in the format:" + + "\n\n\"event [name] /from [start] /to [end]\""; + } + + case "delete": + try { + int idx = Integer.parseInt(tokens[1]); + c = new Delete(idx, tasklist); + + // Executing here to catch IndexOutOfBoundsException. + return c.execute(); + } catch (IndexOutOfBoundsException ioobe) { + return "Please enter a valid index, Boss."; + } catch (NumberFormatException nfe) { + return "Please enter an index after \"delete\"."; + } + + case "find": + try { + String searchKey = tokens[1]; + c = new Find(searchKey, tasklist); + break; + } catch (IndexOutOfBoundsException ioobe) { + return "Please enter a search phrase after \"find\"."; + } + default: + return "Boss, I'm sorry, but I don't understand :-(\n"; + } + return c.execute(); + } + + public void handleDuplicates(Task t) { + this.isCheckingDuplicates = true; + this.duplicateTask = t; + } +} diff --git a/src/main/java/chad/backend/Storage.java b/src/main/java/chad/backend/Storage.java new file mode 100644 index 0000000000..c0c9a88328 --- /dev/null +++ b/src/main/java/chad/backend/Storage.java @@ -0,0 +1,92 @@ +package chad.backend; + +import java.io.File; +import java.io.FileWriter; + +import java.io.FileNotFoundException; +import java.io.IOException; + +import java.util.ArrayList; + +import java.util.Scanner; + +import chad.tasks.Deadline; +import chad.tasks.Event; +import chad.tasks.Task; +import chad.tasks.Todo; + +class Storage { + private final File prevTasks; + + public Storage(File prevTasks) { + this.prevTasks = prevTasks; + } + + public ArrayList extractTasks() throws IOException { + Scanner fileSc; + ArrayList tasks = new ArrayList<>(); + try { + fileSc = new Scanner(prevTasks); + while (fileSc.hasNextLine()) { + String[] savedData = fileSc.nextLine() + .split(" \\| "); + Task t = new Todo(""); + switch (savedData[0]) { + case "T": + t = new Todo(savedData[2]); + break; + case "D": + t = new Deadline(savedData[2], savedData[3]); + break; + case "E": + t = new Event(savedData[2], savedData[3], savedData[4]); + break; + default: + } + if (savedData[1].equals("0")) { + t.unmark(); + } else { + t.mark(); + } + tasks.add(t); + } + fileSc.close(); + } catch (FileNotFoundException fnfe) { + // Previous task file doesn't exist, + prevTasks.createNewFile(); + } + return tasks; + } + + public void saveTasks(ArrayList tasks) { + String encoding = ""; + for (int i = 0; i < tasks.size(); i++) { + Task t = tasks.get(i); + switch (t.getClass().getSimpleName()) { //encoding: "E | NAME | FROM | TO" + case "Todo": + encoding = encoding + ("T | " + (t.isDone() ? "1" : "0") + " | "); + encoding = encoding + t.getDescription(); + break; + case "Deadline": + encoding = encoding + ("D | " + (t.isDone() ? "1" : "0") + " | "); + encoding = encoding + t.getDescription() + " | " + ((Deadline) t).getDeadline(); + break; + case "Event": + encoding = encoding + ("E | " + (t.isDone() ? "1" : "0" + " | ")); + encoding = encoding + (t.getDescription() + " | " + ((Event) t).getStart() + " | " + + ((Event) t).getEnd()); + break; + default: + } + encoding = encoding + "\n"; + } + try { + FileWriter fw = new FileWriter(prevTasks); + fw.write(encoding); + fw.flush(); + fw.close(); + } catch (IOException e) { + + } + } +} diff --git a/src/main/java/chad/backend/TaskList.java b/src/main/java/chad/backend/TaskList.java new file mode 100644 index 0000000000..244634851f --- /dev/null +++ b/src/main/java/chad/backend/TaskList.java @@ -0,0 +1,96 @@ +package chad.backend; + +import chad.tasks.Task; + +import java.io.File; +import java.io.IOException; + +import java.util.ArrayList; + + +/** + * Class storing all the tasks stored in Duke. + */ +public class TaskList { + private final ArrayList tasks; + private final Storage saveManager; + + /** + * Constructor for a TaskList. + * @throws IOException + */ + public TaskList() throws IOException { + // load from file + File prevTasks = new File("tasks.txt"); + if (!prevTasks.exists()){ + prevTasks.createNewFile(); + } + this.saveManager = new Storage(prevTasks); + this.tasks = new ArrayList<>(saveManager.extractTasks()); + } + + /** + * Add a new task to the TaskList. + * @param t The Task to be added. + */ + public void add(Task t) { + tasks.add(t); + } + + /** + * Getter for TaskList Tasks. + * @param idx 0-Index of the task to get. + * @return The Task at that index. + */ + public Task get(int idx) { + return tasks.get(idx); + } + + /** + * Marks a Task as done. + * @param idx 0-Index of the Task to be marked. + * @return Task at index idx, marked as done. + */ + public Task mark(int idx) { + Task t = tasks.get(idx); + t.mark(); + return t; + } + + /** + * Marks a Task as not done. + * @param idx 0-Index of the Task to be unmarked. + * @return Task at index idx, marked as not done. + */ + public Task unmarkIdx(int idx) { + Task t = tasks.get(idx); + t.unmark(); + return t; + } + + /** + * Deletes the Task at a particular index. + * @param idx The 0-index of the Task to be deleted. + * @return The deleted Task object. + */ + public Task delete(int idx) { + Task t = tasks.get(idx); + tasks.remove(idx); + return t; + } + + /** + * Get the whole list of Tasks as an Array. + * @return An ArrayList of Tasks. + */ + public ArrayList getWholeList() { + return this.tasks; + } + + /** + * Saves the tasks to a .TXT file via the Storage object. + */ + public void closeAndSave() { + this.saveManager.saveTasks(this.tasks); + } +} diff --git a/src/main/java/chad/commands/Bye.java b/src/main/java/chad/commands/Bye.java new file mode 100644 index 0000000000..76128b387c --- /dev/null +++ b/src/main/java/chad/commands/Bye.java @@ -0,0 +1,24 @@ +package chad.commands; + +import chad.backend.TaskList; + +/** + * Command for exiting Duke. + */ +public class Bye extends Command { + private final TaskList tasklist; + + /** + * Constructor for a Bye command. + * @param tasklist The TaskList to save. + */ + public Bye(TaskList tasklist) { + this.tasklist = tasklist; + } + + @Override + public String execute() { + tasklist.closeAndSave(); + return "Cheers, Boss, I'll see you soon!\n"; + } +} diff --git a/src/main/java/chad/commands/Command.java b/src/main/java/chad/commands/Command.java new file mode 100644 index 0000000000..8754521a97 --- /dev/null +++ b/src/main/java/chad/commands/Command.java @@ -0,0 +1,12 @@ +package chad.commands; + +/** + * Abstract class representing a Command to be executed. + */ +public abstract class Command { + /** + * Executes the implemented Command. + * @return The string output result of execution. + */ + public abstract String execute(); +} diff --git a/src/main/java/chad/commands/Delete.java b/src/main/java/chad/commands/Delete.java new file mode 100644 index 0000000000..158694b993 --- /dev/null +++ b/src/main/java/chad/commands/Delete.java @@ -0,0 +1,31 @@ +package chad.commands; + +import chad.backend.TaskList; +import chad.tasks.Task; + +/** + * Command for Deletion. + */ +public class Delete extends Command { + + private final int idx; + private final TaskList tasklist; + + /** + * Constructor for Delete command. + * @param idx 1-index of Task to be deleted. + * @param tasklist The list to be deleted from. + */ + public Delete(int idx, TaskList tasklist) { + this.idx = idx; + this.tasklist = tasklist; + } + + @Override + public String execute() { + assert (idx <= tasklist.getWholeList().size()); + Task t = tasklist.delete(idx - 1); + String res = "Alright! I've deleted this task: " + t.toString() + "\n"; + return res; + } +} diff --git a/src/main/java/chad/commands/Find.java b/src/main/java/chad/commands/Find.java new file mode 100644 index 0000000000..65e32b3f0b --- /dev/null +++ b/src/main/java/chad/commands/Find.java @@ -0,0 +1,48 @@ +package chad.commands; + +import chad.backend.TaskList; +import chad.tasks.Task; +import javafx.util.Pair; + +import java.util.ArrayList; + +/** + * Command for finding a Task. + */ +public class Find extends Command { + + private final TaskList tasklist; + private final String searchKey; + + /** + * Constructor for a Find command. + * @param searchKey The keyword to search for. + * @param tasklist The list to search in. + */ + public Find(String searchKey, TaskList tasklist) { + this.tasklist = tasklist; + this.searchKey = searchKey; + } + + @Override + public String execute() { + ArrayList currentTasks = tasklist.getWholeList(); + ArrayList> searchResults = new ArrayList<>(); + for (int i = 0; i < currentTasks.size(); i++) { + Task curr = currentTasks.get(i); + if (curr.getDescription().contains(searchKey)) { + searchResults.add(new Pair<>(i + 1, curr)); + } + } + StringBuilder res = new StringBuilder(); + if (searchResults.size() != 0) { + res.append("I've found these matching tasks:\n"); + for (Pair p : searchResults) { + res.append(p.getKey() + ". " + p.getValue() + "\n"); + } + } else { + res.append("Too bad, Boss, I did not find any tasks matching your search keyword :-( ."); + } + return res.toString(); + } +} diff --git a/src/main/java/chad/commands/ForceAddDuplicate.java b/src/main/java/chad/commands/ForceAddDuplicate.java new file mode 100644 index 0000000000..0f5c3ed8ea --- /dev/null +++ b/src/main/java/chad/commands/ForceAddDuplicate.java @@ -0,0 +1,21 @@ +package chad.commands; + +import chad.backend.TaskList; +import chad.tasks.Task; + +public class ForceAddDuplicate extends Command { + private final Task task; + private final TaskList tasklist; + + public ForceAddDuplicate(Task task, TaskList tasklist) { + this.task = task; + this.tasklist = tasklist; + } + + + @Override + public String execute() { + tasklist.add(task); + return "Alright then, I'll add this duplicate task."; + } +} diff --git a/src/main/java/chad/commands/List.java b/src/main/java/chad/commands/List.java new file mode 100644 index 0000000000..411ecb8c21 --- /dev/null +++ b/src/main/java/chad/commands/List.java @@ -0,0 +1,36 @@ +package chad.commands; + +import chad.backend.TaskList; +import chad.tasks.Task; + +import java.util.ArrayList; + +/** + * Command to list down all current Tasks. + */ +public class List extends Command { + private final ArrayList tasks; + + /** + * Constructor for a List command. + * @param tasklist The list of tasks to enumerate. + */ + public List(TaskList tasklist) { + this.tasks = tasklist.getWholeList(); + } + + @Override + public String execute() { + // Guard Clause: + if (tasks.size() == 0) { + return "You don't have any pending tasks, Boss."; + } + + StringBuilder res = new StringBuilder(); + res.append("Here are the tasks in your list:\n"); + for (int i = 0; i < tasks.size(); i++) { + res.append(String.format("%d. %s\n", (i + 1), tasks.get(i).toString())); + } + return res.toString(); + } +} diff --git a/src/main/java/chad/commands/Make.java b/src/main/java/chad/commands/Make.java new file mode 100644 index 0000000000..f0f8dc3910 --- /dev/null +++ b/src/main/java/chad/commands/Make.java @@ -0,0 +1,40 @@ +package chad.commands; + +import chad.backend.Parser; +import chad.backend.TaskList; +import chad.tasks.Task; + +import java.util.ArrayList; + +abstract class Make extends Command { + protected String description; + protected TaskList tasklist; + protected Parser parser; + + Make(String description, TaskList tasklist, Parser parser) { + this.description = description; + this.tasklist = tasklist; + this.parser = parser; + } + + public Task findDuplicates() { + ArrayList list = tasklist.getWholeList(); + String lowerCaseDescription = this.description.toLowerCase(); + for (int i = 0; i < list.size(); i++) { + Task t = list.get(i); + String duplicateName = t.getDescription().toLowerCase(); + if (duplicateName.equals(lowerCaseDescription)) { + return t; + } + } + return null; + } + + public String duplicateFound(Task newTask, Task duplicate) { + parser.handleDuplicates(newTask); + return "Boss, I've found a an existing task with the same name:\n" + + duplicate + + "\nDo you still want to add this new task?\n" + + newTask; + } +} diff --git a/src/main/java/chad/commands/MakeDeadline.java b/src/main/java/chad/commands/MakeDeadline.java new file mode 100644 index 0000000000..42c7bedf95 --- /dev/null +++ b/src/main/java/chad/commands/MakeDeadline.java @@ -0,0 +1,38 @@ +package chad.commands; + +import chad.backend.Parser; +import chad.backend.TaskList; +import chad.tasks.Deadline; +import chad.tasks.Task; + +/** + * Command to create a Deadline. + */ +public class MakeDeadline extends Make { + private final String by; + private TaskList tasklist; + + /** + * Constructor for a MakeDeadline command. + * @param description The name of the Deadline. + * @param by Due date of the Deadline. + * @param tasklist The list to add the Deadline to. + */ + public MakeDeadline(String description, String by, TaskList tasklist, Parser parser) { + super(description, tasklist, parser); + this.by = by; + } + + @Override + public String execute() { + Task t = new Deadline(description, by); + // Guard Clause: + Task duplicate = findDuplicates(); + if (duplicate != null) { + return duplicateFound(t, duplicate); + } + System.out.println("created deadline " + t); + super.tasklist.add(t); + return "Added this new Deadline: \n" + t; + } +} diff --git a/src/main/java/chad/commands/MakeEvent.java b/src/main/java/chad/commands/MakeEvent.java new file mode 100644 index 0000000000..bac2ecd0f3 --- /dev/null +++ b/src/main/java/chad/commands/MakeEvent.java @@ -0,0 +1,39 @@ +package chad.commands; + +import chad.backend.Parser; +import chad.backend.TaskList; +import chad.tasks.Event; +import chad.tasks.Task; + +/** + * Command to create an Event. + */ +public class MakeEvent extends Make { + private final String from; + private final String to; + + /** + * Constructor for a command to make a new Event. + * @param description Name of the Event. + * @param from Start time of the Event. + * @param to End time of the Event. + * @param tasklist The list to add this Event to. + */ + public MakeEvent(String description, String from, String to, TaskList tasklist, Parser parser) { + super(description, tasklist, parser); + this.from = from; + this.to = to; + } + + @Override + public String execute() { + Task t = new Event(description, from, to); + // Guard clause: + Task duplicate = findDuplicates(); + if (duplicate != null) { + return duplicateFound(t, duplicate); + } + super.tasklist.add(t); + return "Added this new Event:\n" + t; + } +} diff --git a/src/main/java/chad/commands/MakeTodo.java b/src/main/java/chad/commands/MakeTodo.java new file mode 100644 index 0000000000..8af4c4bb39 --- /dev/null +++ b/src/main/java/chad/commands/MakeTodo.java @@ -0,0 +1,36 @@ +package chad.commands; + +import chad.backend.Parser; +import chad.backend.TaskList; +import chad.tasks.Task; +import chad.tasks.Todo; + +/** + * Command to create a Todo. + */ +public class MakeTodo extends Make { + + /** + * Constructor for a command to make a new Todo. + * @param description Name of the Todo. + * @param tasklist The list to add this Todo to. + */ + public MakeTodo(String description, TaskList tasklist, Parser parser) { + super(description, tasklist, parser); + } + + @Override + public String execute() { + Task t = new Todo(description); + // Guard Clause: + Task duplicate = findDuplicates(); + if (duplicate != null) { + return duplicateFound(t, duplicate); + } + + super.tasklist.add(t); + return "Added this new Todo: \n" + t; + } + + +} diff --git a/src/main/java/chad/commands/Mark.java b/src/main/java/chad/commands/Mark.java new file mode 100644 index 0000000000..d76d3c2c69 --- /dev/null +++ b/src/main/java/chad/commands/Mark.java @@ -0,0 +1,30 @@ +package chad.commands; + +import chad.backend.TaskList; +import chad.tasks.Task; + +/** + * Command to Mark a Task as done. + */ +public class Mark extends Command { + private final int idx; + private final TaskList tasklist; + + /** + * Constructor for a Mark command. + * @param idx The 1-index of the Task to mark. + * @param tasklist The list to mark the Task from. + */ + public Mark(int idx, TaskList tasklist) { + this.idx = idx; + this.tasklist = tasklist; + } + + @Override + public String execute() { + assert (idx <= tasklist.getWholeList().size()); + Task t = tasklist.get(idx - 1); + t.mark(); + return "Lesgo! I've marked this task as done:\n" + t + "\n"; + } +} diff --git a/src/main/java/chad/commands/Unmark.java b/src/main/java/chad/commands/Unmark.java new file mode 100644 index 0000000000..65755c880c --- /dev/null +++ b/src/main/java/chad/commands/Unmark.java @@ -0,0 +1,30 @@ +package chad.commands; + +import chad.backend.TaskList; +import chad.tasks.Task; + +/** + * Command to Mark a Task as not done. + */ +public class Unmark extends Command { + private final int idx; + private final TaskList tasklist; + + /** + * Constructor for an Unmark command. + * @param idx 1-index of the Task to be unmarked. + * @param tasklist The list to unmark the Task from. + */ + public Unmark(int idx, TaskList tasklist) { + this.idx = idx; + this.tasklist = tasklist; + } + + @Override + public String execute() { + assert (idx <= tasklist.getWholeList().size()); + Task t = tasklist.get(idx - 1); + t.unmark(); + return "Ok Boss, I've marked this task as not done:\n" + t + "\n"; + } +} diff --git a/src/main/java/chad/exceptions/DukeException.java b/src/main/java/chad/exceptions/DukeException.java new file mode 100644 index 0000000000..ebc67d31bd --- /dev/null +++ b/src/main/java/chad/exceptions/DukeException.java @@ -0,0 +1,14 @@ +package chad.exceptions; + +/** + * Parent class for all Duke-internal exceptions. + */ +public class DukeException extends Exception { + /** + * Constructor for a Duke exception. + * @param msg The exception message. + */ + public DukeException(String msg) { + super(msg); + } +} diff --git a/src/main/java/chad/frontend/DialogBox.java b/src/main/java/chad/frontend/DialogBox.java new file mode 100644 index 0000000000..a414a674f7 --- /dev/null +++ b/src/main/java/chad/frontend/DialogBox.java @@ -0,0 +1,61 @@ +package chad.frontend; + +import java.io.IOException; +import java.util.Collections; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.geometry.Pos; +import javafx.scene.Node; +import javafx.scene.control.Label; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.layout.HBox; + +/** + * An example of a custom control using FXML. + * This control represents a dialog box consisting of an ImageView to represent the speaker's face and a label + * containing text from the speaker. + */ +public class DialogBox extends HBox { + @FXML + private Label dialog; + @FXML + private ImageView displayPicture; + + private DialogBox(String text, Image img) { + try { + FXMLLoader fxmlLoader = new FXMLLoader(MainWindow.class.getResource("/view/DialogBox.fxml")); + fxmlLoader.setController(this); + fxmlLoader.setRoot(this); + fxmlLoader.load(); + } catch (IOException e) { + e.printStackTrace(); + } + + dialog.setText(text); + displayPicture.setImage(img); + } + + /** + * Flips the dialog box such that the ImageView is on the left and text on the right. + */ + private void flip() { + ObservableList tmp = FXCollections.observableArrayList(this.getChildren()); + Collections.reverse(tmp); + getChildren().setAll(tmp); + setAlignment(Pos.TOP_LEFT); + } + + public static DialogBox getUserDialog(String text, Image img) { + return new DialogBox(text, img); + } + + public static DialogBox getDukeDialog(String text, Image img) { + var db = new DialogBox(text, img); + db.flip(); + return db; + } +} diff --git a/src/main/java/chad/frontend/Main.java b/src/main/java/chad/frontend/Main.java new file mode 100644 index 0000000000..58c2bd08cd --- /dev/null +++ b/src/main/java/chad/frontend/Main.java @@ -0,0 +1,50 @@ +package chad.frontend; + +import java.io.IOException; + +import chad.backend.Chad; +import javafx.application.Application; +import javafx.application.Platform; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.scene.layout.AnchorPane; +import javafx.stage.Stage; + +/** + * A GUI for Duke using FXML. + */ +public class Main extends Application { + + private static Chad chad; + + public static void exit() { + Platform.exit(); + System.exit(0); + } + + @Override + public void start(Stage stage) { + try { + FXMLLoader fxmlLoader = new FXMLLoader(Main.class.getResource("/view/MainWindow.fxml")); + AnchorPane ap = fxmlLoader.load(); + Scene scene = new Scene(ap); + stage.setTitle("Chad - Your Personal Digital Assistant"); + stage.setScene(scene); + chad = new Chad(); + fxmlLoader.getController().setChad(chad); + stage.show(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void stop() throws Exception { + chad.getResponse("bye"); + super.stop(); + } + + public static void main(String[] args) { + Application.launch(Main.class, args); + } +} diff --git a/src/main/java/chad/frontend/MainWindow.java b/src/main/java/chad/frontend/MainWindow.java new file mode 100644 index 0000000000..d73063c303 --- /dev/null +++ b/src/main/java/chad/frontend/MainWindow.java @@ -0,0 +1,76 @@ +package chad.frontend; + +import chad.backend.Chad; +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.ScrollPane; +import javafx.scene.control.TextField; +import javafx.scene.image.Image; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.VBox; + +import java.util.Timer; +import java.util.TimerTask; + +/** + * Controller for MainWindow. Provides the layout for the other controls. + */ +public class MainWindow extends AnchorPane { + @FXML + private ScrollPane scrollPane; + @FXML + private VBox dialogContainer; + @FXML + private TextField userInput; + @FXML + private Button sendButton; + + private Chad chad; + + private final Image userImage = new Image(this.getClass().getResourceAsStream("/images/soyjak.png")); + private final Image jarvisImage + = new Image(this.getClass().getResourceAsStream("/images/chad.png")); + + @FXML + public void initialize() { + scrollPane.vvalueProperty().bind(dialogContainer.heightProperty()); + } + + public void setChad(Chad j) { + chad = j; + dialogContainer.getChildren().add(DialogBox.getDukeDialog(chad.getResponse("welcome"), jarvisImage + )); + } + + /** + * Creates two dialog boxes, one echoing user input and the other containing Duke's reply and then appends them to + * the dialog container. Clears the user input after processing. + */ + @FXML + private void handleUserInput() { + String input = userInput.getText(); + if (input.equals("")) { + return; + } + String response = chad.getResponse(input); + + dialogContainer.getChildren().addAll( + DialogBox.getUserDialog((input), userImage), + DialogBox.getDukeDialog((response), jarvisImage + ) + ); + userInput.clear(); + + if (input.strip().equals("bye")) { + Timer delay = new Timer(); + TimerTask exit = new TimerTask() { + @Override + public void run() { + Main.exit(); + } + }; + // Wait 2s before closing. + delay.schedule(exit, 1500); + } + } +} diff --git a/src/main/java/chad/tasks/Deadline.java b/src/main/java/chad/tasks/Deadline.java new file mode 100644 index 0000000000..0eb671ae0e --- /dev/null +++ b/src/main/java/chad/tasks/Deadline.java @@ -0,0 +1,40 @@ +package chad.tasks; + +import java.time.LocalDate; +import java.time.format.DateTimeParseException; + +/** + * Represents a Deadline task, encapsulating a deadline localDate. + */ +public class Deadline extends Task { + private final LocalDate by; + + /** + * Constructor for a Deadline task object. + * @param description The name of the deadline object. + * @param by The deadline date for this Deadline, in the format yyyy-mm-dd. + * @throws DateTimeParseException + */ + public Deadline(String description, String by) throws DateTimeParseException { + super(description); + this.by = LocalDate.parse(by); + } + + /** + * Getter method for a Deadline object. + * @return The deadline as a LocalDate object. + */ + public LocalDate getDeadline() { + return this.by; + } + + /** + * String representation of a Deadline task. + * @return String in the format [D] description (by: due date). + */ + @Override + public String toString() { + return "[D]" + super.toString() + " (by: " + by + ")"; + } +} + diff --git a/src/main/java/chad/tasks/Event.java b/src/main/java/chad/tasks/Event.java new file mode 100644 index 0000000000..7c0500a222 --- /dev/null +++ b/src/main/java/chad/tasks/Event.java @@ -0,0 +1,40 @@ +package chad.tasks; + +/** + * Represents an Event task, encapsulating a start and end times as Strings. + */ +public class Event extends Task { + + private final String start; + private final String end; + + /** + * Constructor for an Event task. + * @param description The name of the Event. + * @param start The start time as a String. + * @param end The end time as a String. + */ + public Event(String description, String start, String end) { + super(description); + this.start = start; + this.end = end; + } + + public String getStart() { + return start; + } + + public String getEnd() { + return end; + } + + /** + * String representation of an Event, in the format [E] description (from: start to end). + * @return String representation of Event object. + */ + @Override + public String toString() { + return "[E]" + super.toString() + " (from: " + start + " to: " + end + ")"; + } +} + diff --git a/src/main/java/chad/tasks/Task.java b/src/main/java/chad/tasks/Task.java new file mode 100644 index 0000000000..1a47c52524 --- /dev/null +++ b/src/main/java/chad/tasks/Task.java @@ -0,0 +1,62 @@ +package chad.tasks; + +/** + * An abstract task class that encapsulates the description of any type of Task. + */ +public abstract class Task { + private final String description; + private boolean isDone; + + /** + * Constructor for a Task object. Only to be used by subclasses. + * @param description The name of the Task. + */ + protected Task(String description) { + this.description = description; + this.isDone = false; + } + + private String getStatusIcon() { + return (isDone ? "X" : " "); + } + + /** + * Getter for description of a Task. + * @return Description as a String. + */ + public String getDescription() { + return description; + } + + /** + * Getter for the done status of a Task. + * @return True for done tasks, false for undone tasks. + */ + public boolean isDone() { + return isDone; + } + + /** + * Marks this Task as done. + */ + public void mark() { + this.isDone = true; + } + + /** + * (Un)Marks this task as done. + */ + public void unmark() { + this.isDone = false; + } + + /** + * String representation of any Task, in the format [doneIcon] description. + * @return String representation of this Task. + */ + @Override + public String toString() { + return "[" + this.getStatusIcon() + "] " + this.description; + } +} + diff --git a/src/main/java/chad/tasks/Todo.java b/src/main/java/chad/tasks/Todo.java new file mode 100644 index 0000000000..68b327cdef --- /dev/null +++ b/src/main/java/chad/tasks/Todo.java @@ -0,0 +1,25 @@ +package chad.tasks; + +/** + * Represents a Todo task, encapsulating only the description of the Todo. + */ +public class Todo extends Task { + + /** + * Constructor for a Todo task. + * @param description The name of the Todo. + */ + public Todo(String description) { + super(description); + } + + /** + * String representation of a Todo task, in the format [T] [doneIcon] description. + * @return A string representation of this Todo task. + */ + @Override + public String toString() { + return "[T]" + super.toString(); + } +} + diff --git a/src/main/resources/images/DaDuke.png b/src/main/resources/images/DaDuke.png new file mode 100644 index 0000000000..d893658717 Binary files /dev/null and b/src/main/resources/images/DaDuke.png differ diff --git a/src/main/resources/images/DaUser.png b/src/main/resources/images/DaUser.png new file mode 100644 index 0000000000..3c82f45461 Binary files /dev/null and b/src/main/resources/images/DaUser.png differ diff --git a/src/main/resources/images/chad.png b/src/main/resources/images/chad.png new file mode 100644 index 0000000000..707df41e7e Binary files /dev/null and b/src/main/resources/images/chad.png differ diff --git a/src/main/resources/images/soyjak.png b/src/main/resources/images/soyjak.png new file mode 100644 index 0000000000..a815eddedf Binary files /dev/null and b/src/main/resources/images/soyjak.png differ diff --git a/src/main/resources/view/DialogBox.fxml b/src/main/resources/view/DialogBox.fxml new file mode 100644 index 0000000000..59844f8590 --- /dev/null +++ b/src/main/resources/view/DialogBox.fxml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/view/MainWindow.fxml b/src/main/resources/view/MainWindow.fxml new file mode 100644 index 0000000000..0af68c93c0 --- /dev/null +++ b/src/main/resources/view/MainWindow.fxml @@ -0,0 +1,19 @@ + + + + + + + + + + + +