diff --git a/.gitignore b/.gitignore index f69985ef1f..a1c9245d1c 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ bin/ /text-ui-test/ACTUAL.txt text-ui-test/EXPECTED-UNIX.TXT +.vscode/ +data/tasks.txt diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..4a715b6cb6 --- /dev/null +++ b/build.gradle @@ -0,0 +1,59 @@ +plugins { + id 'java' + id 'application' + id 'com.github.johnrengelman.shadow' version '5.1.0' + +} + + + +repositories { + mavenCentral() +} + +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 = "chacha.Launcher" +} + +shadowJar { + archiveBaseName = "chacha" + archiveClassifier = null +} + +run{ + standardInput = System.in +} diff --git a/config/checkstyle/checkstyle_checks.xml b/config/checkstyle/checkstyle_checks.xml new file mode 100644 index 0000000000..3e919ba382 --- /dev/null +++ b/config/checkstyle/checkstyle_checks.xml @@ -0,0 +1,915 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/checkstyle/suppressions.xml b/config/checkstyle/suppressions.xml new file mode 100644 index 0000000000..1e1ff016d2 --- /dev/null +++ b/config/checkstyle/suppressions.xml @@ -0,0 +1,175 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/README.md b/docs/README.md index 8077118ebe..cb330c9339 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,28 +2,202 @@ ## Features -### Feature-ABC +### List Tasks -Description of the feature. +- List all current todos/deadlines/events. -### Feature-XYZ +### Add Tasks -Description of the feature. +- Add todo/deadline/event as a task to list of tasks. + +### Deleting Tasks + +- Delete specified task from list of tasks. + +### Mark Tasks + +- Mark specified task as completed. +- Mark specified task as not completed. + +### Find Tasks + +- Find tasks containing specific keyword(s). + +### Sort Tasks + +- Sort tasks in chronological order. ## Usage -### `Keyword` - Describe action +### `todo` - Adds todo + +Adds a todo task to task list. + +Example of usage: + +`todo (description) + +Expected outcome: + +Adds todo to task list. + +``` +Alrighty! I've added this todo: +[T][ ] Eat dinner +``` + +### `deadline` - Adds deadline + +Adds a deadline task to task list. + +Example of usage: + +`deadline (description) /by (yyyy-MM-dd HH:mm)` + +Expected outcome: + +Adds todo to task list. + +``` +Alrighty! I've added this deadline: +[D][ ] CS2101 CA1 Submission (by: Sep 17 2022 23:59) +``` + +### `event` - Adds event + +Adds a event task to task list. + +Example of usage: + +`event (description) /at (yyyy-MM-dd HH:mm)` + +Expected outcome: + +Adds event to task list. + +``` +Alrighty! I've added this event: +[E][ ] CS2103T Tutorial (at: Sep 15 2022 10:00) +``` + +### `delete` - Deletes specified task + +Deletes specified task from task list. + +Example of usage: + +`delete (index of task)` + +Expected outcome: + +Deletes task at specified index from task list. + +``` +Alrighty! I've deleted this task: +[T][ ] Eat dinner +``` + +### `mark` - Marks task as completed + +Marks a specified task as completed. + +Example of usage: + +`mark (index of task)` + +Expected outcome: + +Sets the task at specified index as completed. + +``` +Alrighty! I've marked this task as completed: +[T][X] Watch lecture recording +``` + +### `unmark` - Marks task as not completed + +Unmarks a specified task as not completed. + +Example of usage: + +`unmark (index of task)` + +Expected outcome: + +Sets the task at specified index as not completed. + +``` +Alrighty! I've marked this task as not completed: +[T][ ] Watch lecture recording +``` + +### `list` - Displays all tasks + +Displays all tasks currently in task list. + +Example of usage: + +`list` + +Expected outcome: + +Outputs a list of all tasks in task list. + +``` +1. [D][ ] CS2101 CA1 Submission (by: Sep 17 2022 23:59) +2. [E][X] CS2103T Tutorial (at: Sep 15 2022 10:00) +3. [T][ ] Watch lecture recording +``` + +### `sort` - Sorts tasks in chronological order + +Sort all tasks in task list from earliest to latest. + +Example of usage: + +`sort` + +Expected outcome: + +Outputs a list of all tasks sorted chronologically. + +``` +1. [E][X] CS2103T Tutorial (at: Sep 15 2022 10:00) +2. [D][ ] CS2101 CA1 Submission (by: Sep 17 2022 23:59 +3. [T][ ] Watch lecture recording +``` + +### `find` - Finds tasks containing keyword(s) + +Find tasks from task list containing keyword(s) provided. + +Example of usage: + +`find (keyword), ... (optional keyword)` + +Expected outcome: + +Outputs a list of tasks containing keyword(s) provided. + +``` +Here are the tasks you are looking for: +1. [D][ ] CS2101 CA1 Submission (by: Sep 17 2022 23:59) +2. [E][X] CS2103T Tutorial (at: Sep 15 2022 10:00) +``` + +### `exit` - Exits the app -Describe the action and its outcome. +Saves and exits the app. -Example of usage: +Example of usage: -`keyword (optional arguments)` +`exit` Expected outcome: -Description of the outcome. +Chacha outputs exit message and user can close the app. ``` -expected output +I've saved all your tasks! You may close the app now, +Bye! ``` diff --git a/docs/Ui.png b/docs/Ui.png new file mode 100644 index 0000000000..bd034e3610 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/chacha/Chacha.java b/src/main/java/chacha/Chacha.java new file mode 100644 index 0000000000..f1dad42d74 --- /dev/null +++ b/src/main/java/chacha/Chacha.java @@ -0,0 +1,100 @@ +package chacha; + +import chacha.commands.Command; +import java.io.IOException; + + +/** + * Chatbot for task tracking. + * + * @author Singh Abdullah Alexander + */ +public class Chacha { + + private Storage storage; + private TaskList taskList; + private Ui ui; + boolean isExit; + + /** + * Constructs Chacha. + * + * @param filePath File path to save data to and load data from. + */ + public Chacha(String filePath) { + isExit = false; + ui = new Ui(); + storage = new Storage("data/tasks.txt"); + try { + taskList = new TaskList(storage.load()); + } catch (IOException e) { + ui.printError("making new file"); + taskList = new TaskList(); + } + } + + /** + * Initialises Chacha. + * + * @param args Command line arguments. + */ + public static void main(String[] args) { + new Chacha("data/tasks.txt").run(); + } + + /** + * Runs an instantiated Chacha. + */ + public void run() { + while (!isExit) { + try { + System.out.println("parsing"); + String fullCommand = ui.readInput(); + Command command = Parser.parse(fullCommand); + command.execute(taskList, ui, storage); + isExit = command.isExit(); + } catch (ChachaException e) { + ui.printError(e.getMessage()); + } + } + try { + storage.saveToFile(taskList); + } catch (IOException e) { + System.out.println("Unable to save file"); + } + } + + /** + * Returns reponse. + * + * @param input User input. + * @return Response as a string. + */ + public String getResponse(String input) { + try { + Command command = Parser.parse(input); + saveAll(command); + command.execute(taskList, ui, storage); + + } catch (ChachaException e) { + ui.printError(e.getMessage()); + } + return ui.buildResponse(); + } + + public String getInitMessage() { + ui.printWelcome(); + return ui.buildResponse(); + } + + public void saveAll(Command command) { + if (command.isExit()) { + try { + storage.saveToFile(taskList); + command.execute(taskList, ui, storage); + } catch (IOException e) { + System.out.println("Unable to save file"); + } + } + } +} diff --git a/src/main/java/chacha/ChachaException.java b/src/main/java/chacha/ChachaException.java new file mode 100644 index 0000000000..2b52740bd4 --- /dev/null +++ b/src/main/java/chacha/ChachaException.java @@ -0,0 +1,15 @@ +package chacha; + +/** + * Handles all Chacha exceptions. + */ +public class ChachaException extends Exception { + /** + * Constructs ChachaException with custom message. + * + * @param message Custom error message to be printed. + */ + public ChachaException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/src/main/java/chacha/CommandEnums.java b/src/main/java/chacha/CommandEnums.java new file mode 100644 index 0000000000..2988baf873 --- /dev/null +++ b/src/main/java/chacha/CommandEnums.java @@ -0,0 +1,17 @@ +package chacha; + +public enum CommandEnums { + + TODO, + DEADLINE, + EVENT, + ADD, + DELETE, + MARK, + UNMARK, + LIST, + SORT, + FIND, + ERROR, + EXIT; +} diff --git a/src/main/java/chacha/DateComparator.java b/src/main/java/chacha/DateComparator.java new file mode 100644 index 0000000000..20e190d25f --- /dev/null +++ b/src/main/java/chacha/DateComparator.java @@ -0,0 +1,16 @@ +package chacha; + +import chacha.tasks.Task; + +import java.util.Comparator; + + public class DateComparator implements Comparator { + + @Override + public int compare(Task task1, Task task2) { + System.out.println("sorting command"); + return task1.getDate().compareTo(task2.getDate()); + } + + } + diff --git a/src/main/java/chacha/DialogBox.java b/src/main/java/chacha/DialogBox.java new file mode 100644 index 0000000000..13dcce6042 --- /dev/null +++ b/src/main/java/chacha/DialogBox.java @@ -0,0 +1,61 @@ +package chacha; + +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 getChachaDialog(String text, Image img) { + var db = new DialogBox(text, img); + db.flip(); + return db; + } +} \ No newline at end of file diff --git a/src/main/java/chacha/Launcher.java b/src/main/java/chacha/Launcher.java new file mode 100644 index 0000000000..d1557f2a93 --- /dev/null +++ b/src/main/java/chacha/Launcher.java @@ -0,0 +1,18 @@ +package chacha; + +import javafx.application.Application; + +/** + * Launcher class to launch app. + */ +public class Launcher { + + /** + * Launches main class. + * + * @param args Arguments. + */ + public static void main(String[] args) { + Application.launch(Main.class, args); + } +} diff --git a/src/main/java/chacha/Main.java b/src/main/java/chacha/Main.java new file mode 100644 index 0000000000..1e62641453 --- /dev/null +++ b/src/main/java/chacha/Main.java @@ -0,0 +1,28 @@ +package chacha; + +import java.io.IOException; +import javafx.application.Application; +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 { + + @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.setScene(scene); + fxmlLoader.getController().setChacha(new Chacha("data/tasks.txt")); + stage.show(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/src/main/java/chacha/MainWindow.java b/src/main/java/chacha/MainWindow.java new file mode 100644 index 0000000000..006c48c8de --- /dev/null +++ b/src/main/java/chacha/MainWindow.java @@ -0,0 +1,55 @@ +package chacha; + +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; +/** + * 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 Chacha chacha; + + private Image userImage = new Image(this.getClass().getResourceAsStream("/images/DaUser.png")); + private Image chachaImage = new Image(this.getClass().getResourceAsStream("/images/DaChacha.png")); + + @FXML + public void initialize() { + scrollPane.vvalueProperty().bind(dialogContainer.heightProperty()); + } + + public void setChacha(Chacha chachaBot) { + chacha = chachaBot; + String response = chacha.getInitMessage(); + dialogContainer.getChildren().add( + DialogBox.getChachaDialog(response, chachaImage)); + } + + /** + * 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(); + String response = chacha.getResponse(input); + assert response != null : "Response cannot be null"; + dialogContainer.getChildren().addAll( + DialogBox.getUserDialog(input, userImage), + DialogBox.getChachaDialog(response, chachaImage) + ); + userInput.clear(); + } +} \ No newline at end of file diff --git a/src/main/java/chacha/Parser.java b/src/main/java/chacha/Parser.java new file mode 100644 index 0000000000..3e303e8df6 --- /dev/null +++ b/src/main/java/chacha/Parser.java @@ -0,0 +1,175 @@ +package chacha; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + +import chacha.commands.*; +import chacha.tasks.Deadline; +import chacha.tasks.Event; +import chacha.tasks.Todo; + +/** + * Parser to parse user input into Chacha commands. + */ +public class Parser { + + /** + * Parses user input into command. + * + * @param userInput User input from user interaction with Chacha. + * @return Chacha command. + * @throws ChachaException If user input cannot be parsed. + */ + public static Command parse(String userInput) throws ChachaException { + assert userInput.length() > 0 : "userInput length should be more than 0"; + String[] inputArray = userInput.split(" "); + String commandStr = inputArray[0]; + CommandEnums command = CommandEnums.ERROR; + try { + command = CommandEnums.valueOf(commandStr.toUpperCase()); + } catch (Exception e) { + command = CommandEnums.ERROR; + } + switch (command) { + case TODO: + return todoCommand(userInput); + case DEADLINE: + return deadlineCommand(userInput); + case EVENT: + return eventCommand(userInput); + case LIST: + return listCommand(inputArray); + case MARK: + return markCommand(inputArray, userInput); + case UNMARK: + return unmarkCommand(inputArray, userInput); + case DELETE: + return deleteCommand(inputArray, userInput); + case EXIT: + return exitCommand(inputArray); + case FIND: + return findCommand(inputArray, userInput); + case SORT: + return sortCommand(inputArray); + default: + throw new ChachaException("Invalid input. Please try again!"); + + + } + + } + + private static Command todoCommand(String userInput) throws ChachaException { + try { + String description = userInput.substring(userInput.indexOf("todo ") + 5); + description.trim(); + Todo todo = new Todo(description); + return new AddCommand(todo); + } catch(Exception e) { + throw new ChachaException("The description of a todo cannot be empty.\n" + "Please try again with a description."); + } + } + + private static Command deadlineCommand(String userInput) throws ChachaException { + try { + String description = userInput.substring(0, userInput.indexOf("/") - 1); + description = description.substring(userInput.indexOf("deadline ") + 9); + description.trim(); + String date = userInput.substring(userInput.indexOf("/by ") + 4); + date.trim(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + LocalDateTime dateTime = LocalDateTime.parse(date, formatter); + Deadline deadline = new Deadline(description, dateTime); + return new AddCommand(deadline); + } catch(DateTimeParseException e) { + throw new ChachaException("The date should be in this format: yyyy-MM-dd HH:mm"); + } catch(Exception e) { + throw new ChachaException("The description of a deadline cannot be empty.\n" + "Please try again with a description."); + } + } + + private static Command eventCommand(String userInput) throws ChachaException { + try { + String description = userInput.substring(0, userInput.indexOf("/") - 1); + description = description.substring(userInput.indexOf("event ") + 6); + System.out.println(description + "here"); + description.trim(); + String date = userInput.substring(userInput.indexOf("/at ") + 4); + date.trim(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + LocalDateTime dateTime = LocalDateTime.parse(date, formatter); + Event event = new Event(description, dateTime); + return new AddCommand(event); + } catch(DateTimeParseException e) { + throw new ChachaException("The date should be in this format: yyyy-MM-dd HH:mm"); + } catch(Exception e) { + throw new ChachaException("The description of an event cannot be empty.\n" + "Please try again with a description."); + } + } + + private static Command listCommand(String[] inputArray) throws ChachaException { + if (inputArray.length == 1) { + return new ListCommand(); + } else { + throw new ChachaException("Sorry, I don't recognise this command."); + } + } + + private static Command markCommand(String[] inputArray, String userInput) throws ChachaException { + if (inputArray.length == 2) { + String[] split = userInput.split("\\s+"); + int taskIndex = Integer.valueOf(split[1]) - 1; + return new MarkCommand(taskIndex); + } else { + throw new ChachaException("Please enter valid task number to mark."); + } + } + + private static Command unmarkCommand(String[] inputArray, String userInput) throws ChachaException { + if (inputArray.length == 2) { + String[] split = userInput.split("\\s+"); + int taskIndex = Integer.valueOf(split[1]) - 1; + return new UnmarkCommand(taskIndex); + } else { + throw new ChachaException("Please enter valid task number to unmark."); + } + } + + private static Command deleteCommand(String[] inputArray, String userInput) throws ChachaException { + if (inputArray.length == 2) { + String[] split = userInput.split("\\s+"); + int taskIndex = Integer.valueOf(split[1]) - 1; + return new DeleteCommand(taskIndex); + } else { + throw new ChachaException("Please enter valid task number to delete."); + } + } + + private static Command exitCommand(String[] inputArray) throws ChachaException { + if (inputArray.length == 1) { + return new ExitCommand(); + } else { + throw new ChachaException("Sorry, I don't recognise this command."); + } + } + + private static Command findCommand(String[] inputArray, String userInput) throws ChachaException { + if (inputArray.length >= 2) { + String keywordsStr = userInput.substring(5); + String[] keywords = keywordsStr.split(", "); + return new FindCommand(keywords); + } else { + throw new ChachaException("Please enter valid search keyword."); + } + } + + private static Command sortCommand(String[] inputArray) throws ChachaException { + if (inputArray.length == 1) { + return new SortCommand(); + } else { + throw new ChachaException("Sorry, I don't recognise this command."); + } + } + +} diff --git a/src/main/java/chacha/Storage.java b/src/main/java/chacha/Storage.java new file mode 100644 index 0000000000..9b1d1796fe --- /dev/null +++ b/src/main/java/chacha/Storage.java @@ -0,0 +1,121 @@ +package chacha; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.io.BufferedReader; +import chacha.tasks.Deadline; +import chacha.tasks.Event; +import chacha.tasks.Task; +import chacha.tasks.Todo; + +/** + * Storage class to handle saving and loading data. + */ +public class Storage { + private Path path; + + public Storage(String path) { + this.path = Paths.get(path); + } + + + /** + * Saves task list of tasks to a file. + * + * @param tasks Tasks to save. + * @throws IOException If the file does not exist. + */ + public void saveToFile(TaskList tasks) throws IOException { + BufferedWriter writer = Files.newBufferedWriter(path); + for (int i = 0; i < tasks.getSize(); i++) { + Task task = tasks.get(i); + writer.write(taskToText(task)); + writer.newLine(); + } + writer.close(); + } + + /** + * Loads tasks from file into task list of tasks. + * Creates new file if path does not exist. + * + * @return List of tasks. + * @throws IOException If error when reading file. + */ + public ArrayList load() throws IOException { + Path parent = path.getParent(); + if (!Files.isDirectory(parent)) { + Files.createDirectories(parent); + } + if (!Files.isRegularFile(path)) { + Files.createFile(path); + } + + ArrayList tasks = new ArrayList<>(); + BufferedReader reader = Files.newBufferedReader(path); + String line = reader.readLine(); + while (line != null) { + tasks.add(textToTask(line)); + line = reader.readLine(); + } + reader.close(); + return tasks; + } + + private String taskToText(Task task) { + DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME; + String date; + if (task.getDate() != LocalDateTime.MAX) { + date = task.getDate().format(formatter); + date = date.replace("T", " "); + date = date.substring(0, 16); + } else { + date = "no date"; + } + return task.getType() + " , " + task.getStatusIcon() + " , " + task.getDescription() + " , " + date; + } + + + /** + * Converts text to a task. + * + * @param text + * @return Task + */ + private Task textToTask(String text) { + String[] textArray = text.split(" , "); + String type = textArray[0]; + String isDone = textArray[1]; + String description = textArray[2]; + String date = textArray[3]; + LocalDateTime dateTime = null; + if (!date.contains("no date")) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + dateTime = LocalDateTime.parse(date, formatter); + } + Task task = new Task(); + switch (type) { + case "T": + task = new Todo(description); + break; + case "D": + task = new Deadline(description, dateTime); + break; + case "E": + task = new Event(description, dateTime); + break; + default: + break; + } + if (isDone.contains("X")) { + task.markAsDone(); + } + return task; + } +} \ No newline at end of file diff --git a/src/main/java/chacha/TaskList.java b/src/main/java/chacha/TaskList.java new file mode 100644 index 0000000000..3c0886888e --- /dev/null +++ b/src/main/java/chacha/TaskList.java @@ -0,0 +1,104 @@ +package chacha; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import chacha.tasks.Task; + +/** + * Task list containing tasks. + */ +public class TaskList { + + private List tasks; + + /** + * Constructs new task list. + */ + public TaskList() { + this.tasks = new ArrayList<>(); + } + + /** + * Constructos task list with tasks. + * + * @param inputTasks List of tasks to input into task list. + */ + public TaskList(ArrayList inputTasks) { + this.tasks = new ArrayList<>(); + for(Task task : inputTasks) { + tasks.add(task); + } + } + + /** + * Gets the length of task list. + * + * @return Length of task list. + */ + public int getSize() { + return tasks.size(); + } + + /** + * Gets the task at a certain index. + * + * @param taskIndex Index of task in task list to get. + * @return Task at given index. + */ + public Task get(int taskIndex) { + return tasks.get(taskIndex); + } + + /** + * Adds a task to task list. + * + * @param task To be added to task list. + */ + public void add(Task task) { + tasks.add(task); + } + + /** + * Removes task at a certain index. + * + * @param taskIndex Task at a given index. + */ + public void remove(int taskIndex) { + tasks.remove(taskIndex); + } + + /** + * Finds all tasks with keyword in description. + * + * @param keywords Input varargs keywords to search for. + * @return New task list with tasks containing keyword. + */ + public TaskList find(String ... keywords) { + TaskList newTasks = new TaskList(); + for (Task task : tasks) { + for (String keyword : keywords) { + if (task.getDescription().contains(keyword)) { + newTasks.add(task); + break; + } + } + + } + return newTasks; + } + + /** + * Sorts all tasks in chronological order. + * + * @return New task list with sorted tasks. + */ + public List sort() { + List newTasks = new ArrayList<>(); + for (Task task : tasks) { + newTasks.add(task); + } + Collections.sort(newTasks, new DateComparator()); + return newTasks; + } +} diff --git a/src/main/java/chacha/Ui.java b/src/main/java/chacha/Ui.java new file mode 100644 index 0000000000..ad369e584d --- /dev/null +++ b/src/main/java/chacha/Ui.java @@ -0,0 +1,129 @@ +package chacha; + +import java.util.Scanner; +import chacha.tasks.Task; + +/** + * Handles all user interaction. + */ +public class Ui { + private String response = ""; + + /** + * Takes in user typed input as a string. + * + * @return User input as string. + */ + public String readInput() { + Scanner input = new Scanner(System.in); + String s = input.nextLine(); + if (s == "exit") { + input.close(); + } + return s; + } + + /** + * Prints Chacha welcome message. + * + * @return Welcome message as a string. + */ + public void printWelcome() { + response = "Welcome! I'm Chacha.\n" + "How may I help you today?"; + } + + /** + * Prints each task in given task list. + * + * @param taskList Task list to print tasks from. + */ + public void printList(TaskList taskList) { + String res = ""; + for (int i = 0; i < taskList.getSize();i++) { + Task t = taskList.get(i); + res = res + (i + 1) + + ". " + + t.toString() + "\n"; + } + response = res; + } + + /** + * Prints tasks that has been added to task list. + * + * @param task Task to add into given task list. + * @param taskList Task list to add given task to. + */ + public void printAdd(Task task, TaskList taskList) { + response = "Gotcha! I've added:\n" + task.toString() + + "\nYou now have " + taskList.getSize() + " tasks in the list."; + } + + /** + * Prints tasks that has been deleted from task list. + * + * @param task Task to be deleted from task list. + * @param size Number of remaining tasks in task list. + */ + public void printDelete(Task task, int size) { + response = "Gotcha! I've removed:\n" + task.toString() + + "\nNow you have " + size + " tasks in the list."; + } + + /** + * Prints tasks that has been marked as done. + * + * @param task Task to be marked. + */ + public void printMark(Task task) { + response = "Great job! I've marked this as done:\n" + task.toString(); + } + + + /** + * Prints task that has been unmarked as done. + * + * @param task Task to be unmarked. + */ + public void printUnmark(Task task) { + response = "Alrighty! I've marked this task as to be completed:\n" + task.toString(); + } + + /** + * Prints tasks from task list containing certain keyword. + * + * @param taskList TaskList with tasks containing certain keyword. + */ + public void printFind(TaskList taskList) { + if (taskList.getSize() == 0) { + response = "Can't seem to find such a task."; + } else { + String res = ""; + for (int i = 0; i < taskList.getSize();i++) { + Task t = taskList.get(i); + res = res + (i + 1) + + ". " + + t.toString() + "\n"; + } + response = "Here are the tasks you're looking for:\n" + res; + } + } + + /** + * Prints custom error message. + * + * @param message Custom error message to be printed. + */ + public void printError(String message) { + response = "Chacha Error: " + message; + } + + public void printExit() { + response = "I've saved all your tasks! You may close the app now, Bye!"; + } + + public String buildResponse() { + return response; + } + +} diff --git a/src/main/java/chacha/commands/AddCommand.java b/src/main/java/chacha/commands/AddCommand.java new file mode 100644 index 0000000000..ca6f367601 --- /dev/null +++ b/src/main/java/chacha/commands/AddCommand.java @@ -0,0 +1,45 @@ +package chacha.commands; + +import chacha.Storage; +import chacha.TaskList; +import chacha.Ui; +import chacha.tasks.Task; + +/** + * Command to add task. + */ +public class AddCommand extends Command { + private Task task; + + /** + * Constructs AddCommand with input task to add. + * + * @param task Task to be added. + */ + public AddCommand(Task task) { + this.task = task; + } + + /** + * Adds task to task list and saves to storage. + * + * @param taskList Task list to add task to. + * @param ui Ui to handle printing message. + * @param storage Storage. + */ + @Override + public void execute(TaskList taskList, Ui ui, Storage storage) { + assert task != null : "task should not be null"; + taskList.add(task); + ui.printAdd(task, taskList); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isExit() { + return false; + } + +} \ No newline at end of file diff --git a/src/main/java/chacha/commands/Command.java b/src/main/java/chacha/commands/Command.java new file mode 100644 index 0000000000..0ca2dd7209 --- /dev/null +++ b/src/main/java/chacha/commands/Command.java @@ -0,0 +1,28 @@ +package chacha.commands; + +import chacha.Storage; +import chacha.TaskList; +import chacha.Ui; + +/** + * Represents a Chacha command. + */ +public abstract class Command { + + /** + * Executes command. + * + * @param taskList Task list to perform command on. + * @param ui Ui to print output message. + * @param storage Storage. + */ + public abstract void execute(TaskList taskList, Ui ui, Storage storage); + + /** + * Checks if Chacha can exit. + * + * @return Boolean if Chacha can exit. + */ + public abstract boolean isExit(); + +} diff --git a/src/main/java/chacha/commands/DeleteCommand.java b/src/main/java/chacha/commands/DeleteCommand.java new file mode 100644 index 0000000000..f56c26a302 --- /dev/null +++ b/src/main/java/chacha/commands/DeleteCommand.java @@ -0,0 +1,48 @@ +package chacha.commands; + +import chacha.Storage; +import chacha.TaskList; +import chacha.Ui; +import chacha.tasks.Task; + +/** + * Command to delete task. + */ +public class DeleteCommand extends Command { + private int taskIndex; + + /** + * Constructs DeleteCommand with input index to delete. + * + * @param taskIndex Task to be added. + */ + public DeleteCommand(int taskIndex) { + this.taskIndex = taskIndex; + } + + /** + * Deletes task from task list and saves to storage. + * + * @param taskList Task list to delete task from. + * @param ui Ui to handle printing message. + * @param storage Storage. + */ + @Override + public void execute(TaskList taskList, Ui ui, Storage storage) { + Task task = taskList.get(taskIndex); + assert task != null : "task should not be null"; + taskList.remove(taskIndex); + int size = taskList.getSize(); + ui.printDelete(task, size); + } + + + /** + * {@inheritDoc} + */ + @Override + public boolean isExit() { + return false; + } + +} \ No newline at end of file diff --git a/src/main/java/chacha/commands/ExitCommand.java b/src/main/java/chacha/commands/ExitCommand.java new file mode 100644 index 0000000000..7eec821cc1 --- /dev/null +++ b/src/main/java/chacha/commands/ExitCommand.java @@ -0,0 +1,32 @@ +package chacha.commands; + +import chacha.Storage; +import chacha.TaskList; +import chacha.Ui; + +/** + * Command to exit Chacha. + */ +public class ExitCommand extends Command { + + /** + * Executes exit command. + * + * @param taskList Task list. + * @param ui Ui to handle printing message. + * @param storage Storage. + */ + @Override + public void execute(TaskList taskList, Ui ui, Storage storage) { + ui.printExit(); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isExit() { + return true; + } + +} diff --git a/src/main/java/chacha/commands/FindCommand.java b/src/main/java/chacha/commands/FindCommand.java new file mode 100644 index 0000000000..13125049d0 --- /dev/null +++ b/src/main/java/chacha/commands/FindCommand.java @@ -0,0 +1,42 @@ +package chacha.commands; + +import chacha.Storage; +import chacha.TaskList; +import chacha.Ui; + +/** + * Represents Find Command. + */ +public class FindCommand extends Command { + private String[] keywords; + + /** + * Constructs FindCommand with keyword to find. + * + * @param keywords Keyword to use in find. + */ + public FindCommand(String[] keywords) { + this.keywords = keywords; + } + + /** + * Executes command to find keyword in task list. + * + * @param ui Ui to print output message. + * @param storage Storage. + */ + @Override + public void execute(TaskList taskList, Ui ui, Storage storage) { + TaskList newTasks = taskList.find(keywords); + ui.printFind(newTasks); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isExit() { + return false; + } + +} \ No newline at end of file diff --git a/src/main/java/chacha/commands/ListCommand.java b/src/main/java/chacha/commands/ListCommand.java new file mode 100644 index 0000000000..8b77f1ecd6 --- /dev/null +++ b/src/main/java/chacha/commands/ListCommand.java @@ -0,0 +1,32 @@ +package chacha.commands; + +import chacha.Storage; +import chacha.TaskList; +import chacha.Ui; + +/** + * Command to list tasks from task list. + */ +public class ListCommand extends Command { + + /** + * Lists all tasks in given task list. + * + * @param taskList Task list to print tasks from. + * @param ui Ui to handle printing message. + * @param storage Storage. + */ + @Override + public void execute(TaskList taskList, Ui ui, Storage storage) { + ui.printList(taskList); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isExit() { + return false; + } + +} diff --git a/src/main/java/chacha/commands/MarkCommand.java b/src/main/java/chacha/commands/MarkCommand.java new file mode 100644 index 0000000000..4710dce48b --- /dev/null +++ b/src/main/java/chacha/commands/MarkCommand.java @@ -0,0 +1,46 @@ +package chacha.commands; + +import chacha.Storage; +import chacha.TaskList; +import chacha.Ui; +import chacha.tasks.Task; + +/** + * Command to mark task. + */ +public class MarkCommand extends Command { + private int taskIndex; + + /** + * Constructs MarkCommand with task index to mark. + * + * @param task Task index of task to mark. + */ + public MarkCommand(int taskIndex) { + this.taskIndex = taskIndex; + } + + /** + * Marks task from task list. + * + * @param taskList Task list to mark task from. + * @param ui Ui to handle printing message. + * @param storage Storage. + */ + @Override + public void execute(TaskList taskList, Ui ui, Storage storage) { + Task task = taskList.get(taskIndex); + assert task != null : "task should not be null"; + task.markAsDone(); + ui.printMark(task); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isExit() { + return false; + } + +} \ No newline at end of file diff --git a/src/main/java/chacha/commands/SortCommand.java b/src/main/java/chacha/commands/SortCommand.java new file mode 100644 index 0000000000..06fc51d0bc --- /dev/null +++ b/src/main/java/chacha/commands/SortCommand.java @@ -0,0 +1,40 @@ +package chacha.commands; + +import chacha.Storage; +import chacha.TaskList; +import chacha.Ui; +import chacha.tasks.Task; + +import java.util.List; + +/** + * Command to list tasks from task list. + */ +public class SortCommand extends Command { + + /** + * Sorts all tasks in given task list in chronological order. + * + * @param taskList Task list to sort tasks from. + * @param ui Ui to handle printing message. + * @param storage Storage. + */ + @Override + public void execute(TaskList taskList, Ui ui, Storage storage) { + List newTasks = taskList.sort(); + TaskList newTaskList = new TaskList(); + for (Task task : newTasks) { + newTaskList.add(task); + } + ui.printList(newTaskList); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isExit() { + return false; + } + +} diff --git a/src/main/java/chacha/commands/UnmarkCommand.java b/src/main/java/chacha/commands/UnmarkCommand.java new file mode 100644 index 0000000000..ac5dfd7bea --- /dev/null +++ b/src/main/java/chacha/commands/UnmarkCommand.java @@ -0,0 +1,46 @@ +package chacha.commands; + +import chacha.Storage; +import chacha.TaskList; +import chacha.Ui; +import chacha.tasks.Task; + +/** + * Command to unmark task. + */ +public class UnmarkCommand extends Command { + private int taskIndex; + + /** + * Constructs UnmarkCommand with task index to unmark. + * + * @param task Task index of task to unmark. + */ + public UnmarkCommand(int taskIndex) { + this.taskIndex = taskIndex; + } + + /** + * Unmarks task from task list. + * + * @param taskList Task list to unmark task from. + * @param ui Ui to handle printing message. + * @param storage Storage. + */ + @Override + public void execute(TaskList taskList, Ui ui, Storage storage) { + Task task = taskList.get(taskIndex); + assert task != null : "task should not be null"; + task.unmarkAsDone(); + ui.printUnmark(task); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isExit() { + return false; + } + +} \ No newline at end of file diff --git a/src/main/java/chacha/tasks/Deadline.java b/src/main/java/chacha/tasks/Deadline.java new file mode 100644 index 0000000000..2da129d46b --- /dev/null +++ b/src/main/java/chacha/tasks/Deadline.java @@ -0,0 +1,88 @@ +package chacha.tasks; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +/** + * Represents a deadline task. + */ +public class Deadline extends Task { + private String description; + private LocalDateTime date; + private boolean isDone; + private String type; + private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM dd yyyy HH:mm"); + + /** + * Constructs a deadline. + * + * @param description Description of the deadline. + * @param date Date of the deadline. + */ + public Deadline(String description, LocalDateTime date) { + this.description = description; + this.date = date; + this.type = "D"; + } + + /** + * Marks deadline as done. + */ + public void markAsDone() { + this.isDone = true; + } + + /** + * Unmarks deadline as done. + */ + public void unmarkAsDone() { + this.isDone = false; + } + + /** + * Gets status icon of deadline. + * + * @return X if done and empty string if not done. + */ + public String getStatusIcon() { + return (isDone ? "X" : " "); + } + + /** + * Gets description of deadline. + * + * @return Description of deadline. + */ + public String getDescription() { + return description; + } + + /** + * Gets type of task. + * + * @return Type of task. + */ + public String getType() { + return type; + } + + /** + * Gets date of deadline. + * + * @return Date of deadline. + */ + public LocalDateTime getDate() { + return date; + } + + /** + * Formats deadline into a readable string. + * + * @return Deadline as a string. + */ + @Override + public String toString() { + return "[" + type + "]" + "[" + getStatusIcon() + "] " + description + " (by: " + date.format(formatter) + ")"; + } + +} diff --git a/src/main/java/chacha/tasks/Event.java b/src/main/java/chacha/tasks/Event.java new file mode 100644 index 0000000000..78489a40b2 --- /dev/null +++ b/src/main/java/chacha/tasks/Event.java @@ -0,0 +1,88 @@ +package chacha.tasks; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +/** + * Represents an event task. + */ +public class Event extends Task { + private String description; + private LocalDateTime date; + private boolean isDone; + private String type; + private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM dd yyyy HH:mm"); + + /** + * Constructs an event. + * + * @param description Description of the event. + * @param date Date of the event. + */ + public Event(String description, LocalDateTime date) { + this.description = description; + this.date = date; + this.type = "E"; + } + + /** + * Marks event as done. + */ + public void markAsDone() { + this.isDone = true; + } + + /** + * Unmarks event as done. + */ + public void unmarkAsDone() { + this.isDone = false; + } + + /** + * Gets status icon of event. + * + * @return X if done and empty string if not done. + */ + public String getStatusIcon() { + return (isDone ? "X" : " "); + } + + /** + * Gets description of event. + * + * @return Description of event. + */ + public String getDescription() { + return description; + } + + /** + * Gets type of task. + * + * @return Type of task. + */ + public String getType() { + return type; + } + + /** + * Gets date of event. + * + * @return Date of event. + */ + public LocalDateTime getDate() { + return date; + } + + /** + * Formats event into a readable string. + * + * @return Event as a string. + */ + @Override + public String toString() { + return "[" + type + "]" + "[" + getStatusIcon() + "] " + description + " (at: " + date.format(formatter) + ")"; + } + +} diff --git a/src/main/java/chacha/tasks/Task.java b/src/main/java/chacha/tasks/Task.java new file mode 100644 index 0000000000..f9dc8a0919 --- /dev/null +++ b/src/main/java/chacha/tasks/Task.java @@ -0,0 +1,79 @@ +package chacha.tasks; + +import java.time.LocalDateTime; + +/** + * Represents a task. + */ +public class Task { + private String description; + private boolean isDone; + private String type; + private LocalDateTime date = LocalDateTime.MAX; + + /** + * Constructs a task. + * + * @param description Description of task. + */ + public Task(String description) { + this.description = description; + this.isDone = false; + this.type = ""; + this.date = null; + } + + public Task() { + } + + /** + * Marks task as done. + */ + public void markAsDone() { + this.isDone = true; + } + + /** + * Unmarks task as done. + */ + public void unmarkAsDone() { + this.isDone = false; + } + + /** + * Gets status icon of task. + * + * @return X if done and empty string if not done. + */ + public String getStatusIcon() { + return (isDone ? "X" : " "); + } + + /** + * Gets description of task. + * + * @return Description of task. + */ + public String getDescription() { + return description; + } + + /** + * Gets type of task. + * + * @return Type of task. + */ + public String getType() { + return type; + } + + /** + * Gets date of task. + * + * @return Date of task. + */ + public LocalDateTime getDate() { + return date; + } + +} diff --git a/src/main/java/chacha/tasks/Todo.java b/src/main/java/chacha/tasks/Todo.java new file mode 100644 index 0000000000..7e0bbab068 --- /dev/null +++ b/src/main/java/chacha/tasks/Todo.java @@ -0,0 +1,73 @@ +package chacha.tasks; + +/** + * Represents a todo task. + */ +public class Todo extends Task { + private String description; + private boolean isDone; + private String type; + + /** + * Constructs a todo. + * + * @param description Description of the todo. + * + */ + public Todo(String description) { + this.description = description; + this.type = "T"; + } + + /** + * Marks todo as done. + */ + public void markAsDone() { + this.isDone = true; + } + + /** + * Unmarks todo as done. + */ + public void unmarkAsDone() { + this.isDone = false; + } + + /** + * Gets status icon of todo. + * + * @return X if done and empty string if not done. + */ + public String getStatusIcon() { + return (isDone ? "X" : " "); + } + + /** + * Gets description of todo. + * + * @return Description of todo. + */ + public String getDescription() { + return description; + } + + /** + * Gets type of task. + * + * @return Type of task. + */ + public String getType() { + return type; + } + + /** + * Formats todo into a readable string. + * + * @return Todo as a string. + */ + @Override + public String toString() { + return "[" + type + "]" + "[" + getStatusIcon() + "] " + description; + } + +} diff --git a/src/main/resources/images/DaChacha.png b/src/main/resources/images/DaChacha.png new file mode 100644 index 0000000000..8331f2a544 Binary files /dev/null and b/src/main/resources/images/DaChacha.png differ diff --git a/src/main/resources/images/DaUser.png b/src/main/resources/images/DaUser.png new file mode 100644 index 0000000000..cbd0125bad Binary files /dev/null and b/src/main/resources/images/DaUser.png differ diff --git a/src/main/resources/view/DialogBox.FXML b/src/main/resources/view/DialogBox.FXML new file mode 100644 index 0000000000..8a27682e14 --- /dev/null +++ b/src/main/resources/view/DialogBox.FXML @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + \ 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..ef0a6042ee --- /dev/null +++ b/src/main/resources/view/MainWindow.FXML @@ -0,0 +1,19 @@ + + + + + + + + + + + +