diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml new file mode 100644 index 0000000000..391c46b4fe --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,34 @@ +name: Java CI + +on: [push, pull_request] + +jobs: + build: + strategy: + matrix: + platform: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.platform }} + + steps: + - name: Set up repository + uses: actions/checkout@master + + - name: Set up repository + uses: actions/checkout@master + with: + ref: master + + - name: Merge to master + run: git checkout --progress --force ${{ github.sha }} + + - name: Validate Gradle Wrapper + uses: gradle/wrapper-validation-action@v1 + + - name: Setup JDK 11 + uses: actions/setup-java@v1 + with: + java-version: '11' + java-package: jdk+fx + + - name: Build and check with Gradle + run: ./gradlew check diff --git a/README.md b/README.md index 8715d4d915..084e6623e5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,4 @@ -# 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. +# Dude ## Setting up in Intellij @@ -13,12 +11,12 @@ Prerequisites: JDK 11, update Intellij to the most recent version. 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: +3. After that, locate the `src/main/java/Dude.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 - ____ _ - | _ \ _ _| | _____ - | | | | | | | |/ / _ \ - | |_| | |_| | < __/ - |____/ \__,_|_|\_\___| + ____ _ + | _ \ _ _ ___| | ___ + | | | | | | | _ |/ _ \ + | |_| | |_| | |_| | __/ + |____/ \__,_|____/ \___| ``` diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..c5d483c2bd --- /dev/null +++ b/build.gradle @@ -0,0 +1,64 @@ +plugins { + id 'checkstyle' + id 'java' + id 'application' + id 'com.github.johnrengelman.shadow' version '7.1.2' +} + +checkstyle { + toolVersion = '10.2' +} + +repositories { + mavenCentral() +} + +dependencies { + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.10.0' + testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.10.0' + + String javaFxVersion = '17.0.7' + + 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 { + mainClass.set("dude.Launcher") +} + +shadowJar { + archiveBaseName = "dude" + archiveFileName = "dude.jar" + archiveClassifier = null + dependsOn("distZip", "distTar") +} + +run { + standardInput = System.in + enableAssertions = true +} diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml new file mode 100644 index 0000000000..eb761a9b9a --- /dev/null +++ b/config/checkstyle/checkstyle.xml @@ -0,0 +1,434 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/checkstyle/suppressions.xml b/config/checkstyle/suppressions.xml new file mode 100644 index 0000000000..39efb6e4ac --- /dev/null +++ b/config/checkstyle/suppressions.xml @@ -0,0 +1,10 @@ + + + + + + + + diff --git a/data/dude.txt b/data/dude.txt new file mode 100644 index 0000000000..b013d2085d --- /dev/null +++ b/data/dude.txt @@ -0,0 +1,9 @@ +T | 0 | watch lecture 5 +T | 0 | watch lecture 6 +D | 0 | ip | 2023-09-22T23:59 +D | 0 | ps3 | 2023-09-23T23:59 +E | 0 | ifg closing | 2023-09-22T19:00 | 2023-09-22T22:00 +T | 0 | revise for midterms +N | ip deadline extended +N | submit contest after finishing ps3 +N | helppls diff --git a/docs/README.md b/docs/README.md index 8077118ebe..afc253c7b9 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,144 @@ # User Guide +Dude is a desktop app for managing contacts, optimized for use via a Command Line Interface (CLI) +while still having the benefits of a Graphical User Interface (GUI). + +- [Quick start](https://vivienherq.github.io/ip/#quick-start) +- [Features](https://vivienherq.github.io/ip/#features) + - [Adding a todo: `todo`](https://vivienherq.github.io/ip/#adding-a-todo-todo) + - [Adding a deadline: `deadline`](https://vivienherq.github.io/ip/#adding-a-deadline-deadline) + - [Adding a event: `event`](https://vivienherq.github.io/ip/#adding-a-event-event) + - [Adding a note: `note`](https://vivienherq.github.io/ip/#adding-a-event-event) + - [Listing all notes and tasks: `list`](https://vivienherq.github.io/ip/#listing-all-tasks-list) + - [Deleting a task: `delete`](https://vivienherq.github.io/ip/#deleting-a-task-delete) + - [Deleting a note: `delete`](https://vivienherq.github.io/ip/#deleting-a-note-delete) + - [Finding tasks and notes: `find`](https://vivienherq.github.io/ip/#finding-tasks-find) + - [Marking a task: `mark`](https://vivienherq.io/ip/#marking-a-task-mark) + - [Unmarking a task: `unmark`](https://vivienherq.github.io/ip/#unmarking-a-task-unmark) + - [Exiting the program: `bye`](https://vivienherq.github.io/ip/#exiting-the-program-bye) +- [Command summary](https://vivienherq.github.io/ip/#command-summary) + ## Features -### Feature-ABC +Words in UPPER_CASE are the parameters to be supplied by the user. +e.g. in `todo DESCRIPTION`, `DESCRIPTION` is a parameter which can be used as `todo submit project`. + +Extraneous parameters for commands that do not take in parameters +(such as `list` and `bye`) will be ignored. + +### Adding a todo: `todo` + +Adds a todo to the list of tasks. + +Format: `todo DESCRIPTION` + +Examples: +- `todo watch lecture` +- `todo attempt tutorial` + +### Adding a deadline: `deadline` + +Adds a deadline to the list of tasks. + +Format: `deadline DESCRIPTION /by DD-MM-YYYY HH:mm` + +Examples: +- `deadline quiz 6 /by 22-09-2023 16:00` +- `deadline individual project /by 22-09-2023 23:59` + +### Adding an event: `event` + +Adds an event to the list of tasks. + +Format: `event DESCRIPTION /from DD-MM-YYYY HH:mm /to DD-MM-YYYY HH:mm` + +Examples: +- `event practical exam /from 17-11-2023 16:00 /to 17-11-2023 18:00` +- `event final exam /from 01-12-2023 09:00 /to 01-12-2023 11:00` + +### Adding a note: `note` + +Adds a note to the list of notes. + +Format: `note DESCRIPTION` + +Examples: +- `note individual project deadline extended by 3 days` +- `note second deadline extension is possible` + +### Listing all notes and tasks: `list` + +Lists all notes and tasks. + +Format: `list` + +### Deleting a task: `delete` + +Deletes a task (todo, deadline or event ) from the list of tasks. + +Format: `delete /t INDEX` + +Examples: +- `delete /t 1` +- `delete /t 2` + +### Deleting a note: `delete` + +Deletes a note from the list of notes. + +Format: `delete /n INDEX` + +Examples: +- `delete /n 1` +- `delete /n 2` + +### Finding tasks and notes: `find` + +Finds tasks or notes by keyword(s) from list of tasks and list of notes. + +Format: `find KEYWORD(S)` + +Examples: +- `find assignment` +- `find individual project` + +### Marking a task: `mark` + +Marks a task as done. -Description of the feature. +Format: `mark INDEX` -### Feature-XYZ +Examples: +- `mark 1` +- `mark 2` -Description of the feature. +### Unmarking a task: `unmark` -## Usage +Marks a task as not done. -### `Keyword` - Describe action +Format: `unmark INDEX` -Describe the action and its outcome. +Examples: +- `unmark 1` +- `unmark 2` -Example of usage: +### Exiting the program: `bye` -`keyword (optional arguments)` +Exits the programme -Expected outcome: +Format: `list` -Description of the outcome. +## Command summary -``` -expected output -``` +| **Action** | **Format, Examples** | +|------------|------------------------------------------------------------------------------------------------------------------------------------------| +| todo | `todo DESCRIPTION`
e.g. `todo watch lecture` | +| deadline | `deadline DESCRIPTION /by DD-MM-YYYY HH:mm`
e.g. `deadline individual project /by 22-09-2023 23:59` | +| event | `event DESCRIPTION /from DD-MM-YYYY HH:mm /to DD-MM-YYYY HH:mm`
e.g. `event final exam /from 01-12-2023 09:00 /to 01-12-2023 11:00` | +| note | `note DESCRIPTION`
e.g. `note individual project deadline extended by 3 days` | +| list | `list` | +| delete | `delete [/t INDEX] [/n INDEX]`
e.g. `delete /t 1` `delete /n 2` | +| find | `find KEYWORD`
e.g. `find project` | +| mark | `mark INDEX`
e.g. `mark 1` | +| unmark | `unmark INDEX`
e.g. `unmark 2` | +| bye | `bye` | diff --git a/docs/Ui.png b/docs/Ui.png new file mode 100644 index 0000000000..876176a638 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..afba109285 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..4e86b92707 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip +networkTimeout=10000 +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000000..65dcd68d65 --- /dev/null +++ b/gradlew @@ -0,0 +1,244 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original 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 POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +# 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 "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# 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 ;; #( + MSYS* | 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" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000000..6689b85bee --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,92 @@ +@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=. +@rem This is normally unused +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% equ 0 goto execute + +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 execute + +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 + +: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 %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 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! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +: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/dude/Dude.java b/src/main/java/dude/Dude.java new file mode 100644 index 0000000000..f1c325e8ca --- /dev/null +++ b/src/main/java/dude/Dude.java @@ -0,0 +1,53 @@ +package dude; + +import dude.command.Command; +import dude.exception.DudeException; +import dude.note.NoteList; +import dude.task.TaskList; +import dude.ui.Ui; +import dude.util.Parser; +import dude.util.Storage; + +/** + * Dude is a programme that allows users to manage their tasks. + */ + +public class Dude { + + private static final String DEFAULT_FILEPATH = "./data/dude.txt"; + private TaskList taskList; + private NoteList noteList; + private Storage storage; + private Ui ui; + + public Dude() { + this.storage = new Storage(DEFAULT_FILEPATH); + } + + /** + * Constructor for Dude that takes in a file path to storage file. + * @param filePath Path to storage file. + */ + public Dude(String filePath) { + this.ui = new Ui(); + this.storage = new Storage(filePath); + + taskList = storage.loadFromDisk(); + noteList = storage.loadNotesFromDisk(); + } + + /** + * Generates a response from Dude to user input. + */ + public String getResponse(String input) { + String output; + try { + Command c = Parser.parse(input); + output = c.execute(taskList, noteList, ui, storage); + } catch (DudeException e) { + output = e.getMessage(); + } + assert !output.trim().isEmpty() : "Dude output should not be empty"; + return output; + } +} diff --git a/src/main/java/dude/Launcher.java b/src/main/java/dude/Launcher.java new file mode 100644 index 0000000000..c97b4240eb --- /dev/null +++ b/src/main/java/dude/Launcher.java @@ -0,0 +1,12 @@ +package dude; + +import javafx.application.Application; + +/** + * A launcher class to workaround classpath issues. + */ +public class Launcher { + public static void main(String[] args) { + Application.launch(Main.class, args); + } +} diff --git a/src/main/java/dude/Main.java b/src/main/java/dude/Main.java new file mode 100644 index 0000000000..c77bed29a8 --- /dev/null +++ b/src/main/java/dude/Main.java @@ -0,0 +1,36 @@ +package dude; + +import java.io.IOException; + +import dude.ui.MainWindow; +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 { + + private static final String FILEPATH = "./data/dude.txt"; + private Dude dude = new Dude(FILEPATH); + + @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); + stage.setTitle("Dude"); + MainWindow mainWindow = fxmlLoader.getController(); + mainWindow.setDude(dude); + stage.show(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} + diff --git a/src/main/java/dude/command/AddDeadlineCommand.java b/src/main/java/dude/command/AddDeadlineCommand.java new file mode 100644 index 0000000000..b913cf4404 --- /dev/null +++ b/src/main/java/dude/command/AddDeadlineCommand.java @@ -0,0 +1,45 @@ +package dude.command; + +import java.time.LocalDateTime; + +import dude.note.NoteList; +import dude.task.Deadline; +import dude.task.TaskList; +import dude.ui.Ui; +import dude.util.Storage; + +/** + * Represents a command that adds a Deadline task. + */ +public class AddDeadlineCommand extends Command { + private String taskDescription; + private LocalDateTime byDateTime; + + /** + * Creates an Add Deadline Command to add a deadline to the list. + * @param taskDescription Short description of deadline to be added. + * @param byDateTime Time that task needs to be completed. + */ + public AddDeadlineCommand(String taskDescription, LocalDateTime byDateTime) { + this.taskDescription = taskDescription; + this.byDateTime = byDateTime; + } + + /** + * Executes the command to add a Deadline task. + * + * @param taskList List of tasks. + * @param storage Storage containing saved tasks, and saves and loads tasks. + * @param ui User interface of Dude. + */ + @Override + public String execute(TaskList taskList, NoteList noteList, Ui ui, Storage storage) { + Deadline newTask = new Deadline(taskDescription, byDateTime); + assert !newTask.isDone() : "Newly added Deadline should not be done."; + taskList.addTask(newTask); + int nTasks = taskList.getSize(); + String output = ui.showAddedTask(newTask, nTasks) + "\n"; + storage.saveToDisk(taskList, noteList); + return output; + } +} diff --git a/src/main/java/dude/command/AddEventCommand.java b/src/main/java/dude/command/AddEventCommand.java new file mode 100644 index 0000000000..b527ee7de4 --- /dev/null +++ b/src/main/java/dude/command/AddEventCommand.java @@ -0,0 +1,52 @@ +package dude.command; + +import java.time.LocalDateTime; + +import dude.exception.EventException; +import dude.note.NoteList; +import dude.task.Event; +import dude.task.TaskList; +import dude.ui.Ui; +import dude.util.Storage; + +/** + * Represents a command that adds an Event task. + */ +public class AddEventCommand extends Command { + private String taskDescription; + private LocalDateTime fromDateTime; + private LocalDateTime toDateTime; + + /** + * Creates an Add Event Command to add an event to the list. + * @param taskDescription Short description of event to be added. + * @param fromDateTime Starting time of event. + * @param toDateTime Ending time of event. + */ + public AddEventCommand(String taskDescription, LocalDateTime fromDateTime, LocalDateTime toDateTime) { + this.taskDescription = taskDescription; + this.fromDateTime = fromDateTime; + this.toDateTime = toDateTime; + } + + /** + * Executes the command to add an Event task. + * + * @param taskList List of tasks. + * @param storage Storage containing saved tasks, and saves and loads tasks. + * @param ui User interface of Dude. + */ + @Override + public String execute(TaskList taskList, NoteList noteList, Ui ui, Storage storage) { + if (fromDateTime.isAfter(toDateTime)) { + throw new EventException("bro. your event end before it starts?? do better."); + } + Event newTask = new Event(taskDescription, fromDateTime, toDateTime); + assert !newTask.isDone() : "Newly added Event should not be done."; + taskList.addTask(newTask); + int nTasks = taskList.getSize(); + String output = ui.showAddedTask(newTask, nTasks) + "\n"; + storage.saveToDisk(taskList, noteList); + return output; + } +} diff --git a/src/main/java/dude/command/AddNoteCommand.java b/src/main/java/dude/command/AddNoteCommand.java new file mode 100644 index 0000000000..30d017c248 --- /dev/null +++ b/src/main/java/dude/command/AddNoteCommand.java @@ -0,0 +1,40 @@ +package dude.command; + +import dude.note.Note; +import dude.note.NoteList; +import dude.task.TaskList; +import dude.ui.Ui; +import dude.util.Storage; + +/** + * Represents a command that adds an Note. + */ +public class AddNoteCommand extends Command { + + private String noteDescription; + + /** + * Creates an Add Note Command to add a note to the list. + * @param noteDescription Short description of note to be added. + */ + public AddNoteCommand(String noteDescription) { + this.noteDescription = noteDescription; + } + + /** + * Executes the command to add a Note. + * + * @param taskList List of tasks. + * @param storage Storage containing saved notes, and saves and loads notes. + * @param ui User interface of Dude. + */ + @Override + public String execute(TaskList taskList, NoteList noteList, Ui ui, Storage storage) { + Note newNote = new Note(noteDescription); + noteList.addNote(newNote); + int nTasks = noteList.getSize(); + String output = ui.showAddedNote(newNote, nTasks) + "\n"; + storage.saveToDisk(taskList, noteList); + return output; + } +} diff --git a/src/main/java/dude/command/AddToDoCommand.java b/src/main/java/dude/command/AddToDoCommand.java new file mode 100644 index 0000000000..c48041fbbc --- /dev/null +++ b/src/main/java/dude/command/AddToDoCommand.java @@ -0,0 +1,36 @@ +package dude.command; + +import dude.note.NoteList; +import dude.task.TaskList; +import dude.task.ToDo; +import dude.ui.Ui; +import dude.util.Storage; + +/** + * Represents a command that adds a ToDo task. + */ +public class AddToDoCommand extends Command { + private String taskDescription; + + public AddToDoCommand(String taskDescription) { + this.taskDescription = taskDescription; + } + + /** + * Executes the command to add a ToDo task. + * + * @param taskList List of tasks. + * @param storage Storage containing saved tasks, and saves and loads tasks. + * @param ui User interface of Dude. + */ + @Override + public String execute(TaskList taskList, NoteList noteList, Ui ui, Storage storage) { + ToDo newTask = new ToDo(taskDescription); + assert !newTask.isDone() : "Newly added ToDo should not be done."; + taskList.addTask(newTask); + int nTasks = taskList.getSize(); + String output = ui.showAddedTask(newTask, nTasks) + "\n"; + storage.saveToDisk(taskList, noteList); + return output; + } +} diff --git a/src/main/java/dude/command/Command.java b/src/main/java/dude/command/Command.java new file mode 100644 index 0000000000..b1ce1c6440 --- /dev/null +++ b/src/main/java/dude/command/Command.java @@ -0,0 +1,24 @@ +package dude.command; + +import dude.note.NoteList; +import dude.task.TaskList; +import dude.ui.Ui; +import dude.util.Storage; + +/** + * Abstract parents class of Commands that can be created by users. + */ +public abstract class Command { + + protected boolean isExit; + + public Command() { + this.isExit = false; + } + + public abstract String execute(TaskList taskList, NoteList noteList, Ui ui, Storage storage); + + public boolean isExit() { + return this.isExit; + } +} diff --git a/src/main/java/dude/command/DeleteNoteCommand.java b/src/main/java/dude/command/DeleteNoteCommand.java new file mode 100644 index 0000000000..5a154678d5 --- /dev/null +++ b/src/main/java/dude/command/DeleteNoteCommand.java @@ -0,0 +1,35 @@ +package dude.command; + +import dude.note.Note; +import dude.note.NoteList; +import dude.task.TaskList; +import dude.ui.Ui; +import dude.util.Storage; + +/** + * Represents a command that deletes note. + */ +public class DeleteNoteCommand extends Command { + private int noteIndex; + + public DeleteNoteCommand(int noteIndex) { + this.noteIndex = noteIndex; + } + + /** + * Executes the command to delete a note. + * + * @param taskList List of tasks. + * @param noteList List of notes. + * @param storage Storage containing saved tasks and notes, and handles saving and loading. + * @param ui User interface of Dude. + */ + @Override + public String execute(TaskList taskList, NoteList noteList, Ui ui, Storage storage) { + Note deletedNote = noteList.deleteNote(noteIndex); + int nNotes = noteList.getSize(); + String output = ui.showDeletedNote(deletedNote, nNotes) + "\n"; + storage.saveToDisk(taskList, noteList); + return output; + } +} diff --git a/src/main/java/dude/command/DeleteTaskCommand.java b/src/main/java/dude/command/DeleteTaskCommand.java new file mode 100644 index 0000000000..9fe21f43db --- /dev/null +++ b/src/main/java/dude/command/DeleteTaskCommand.java @@ -0,0 +1,35 @@ +package dude.command; + +import dude.note.NoteList; +import dude.task.Task; +import dude.task.TaskList; +import dude.ui.Ui; +import dude.util.Storage; + +/** + * Represents a command that deletes task. + */ +public class DeleteTaskCommand extends Command { + private int taskIndex; + + public DeleteTaskCommand(int taskIndex) { + this.taskIndex = taskIndex; + } + + /** + * Executes the command to delete a task. + * + * @param taskList List of tasks. + * @param noteList List of notes. + * @param storage Storage containing saved tasks, and saves and loads tasks. + * @param ui User interface of Dude. + */ + @Override + public String execute(TaskList taskList, NoteList noteList, Ui ui, Storage storage) { + Task deletedTask = taskList.deleteTask(taskIndex); + int nTasks = taskList.getSize(); + String output = ui.showDeletedTask(deletedTask, nTasks) + "\n"; + storage.saveToDisk(taskList, noteList); + return output; + } +} diff --git a/src/main/java/dude/command/ExitCommand.java b/src/main/java/dude/command/ExitCommand.java new file mode 100644 index 0000000000..615d6a8068 --- /dev/null +++ b/src/main/java/dude/command/ExitCommand.java @@ -0,0 +1,28 @@ +package dude.command; + +import dude.note.NoteList; +import dude.task.TaskList; +import dude.ui.Ui; +import dude.util.Storage; + +/** + * Represents a command that exits the programme. + */ +public class ExitCommand extends Command { + public ExitCommand() { + super.isExit = true; + } + + /** + * Executes the command to exit the programme. + * + * @param taskList List of tasks. + * @param storage Storage containing saved tasks, and saves and loads tasks. + * @param ui User interface of Dude. + */ + @Override + public String execute(TaskList taskList, NoteList noteList, Ui ui, Storage storage) { + String output = ui.showFarewell() + "\n"; + return output; + } +} diff --git a/src/main/java/dude/command/FindCommand.java b/src/main/java/dude/command/FindCommand.java new file mode 100644 index 0000000000..0bb023cdba --- /dev/null +++ b/src/main/java/dude/command/FindCommand.java @@ -0,0 +1,30 @@ +package dude.command; + +import dude.note.NoteList; +import dude.task.TaskList; +import dude.ui.Ui; +import dude.util.Storage; + +/** + * Represents a command that finds tasks by keywords. + */ +public class FindCommand extends Command { + + private String searchKeywords; + + /** + * Creates a Find Command that finds tasks by specified keywords. + * @param searchKeywords Keywords used in search for tasks. + */ + public FindCommand(String searchKeywords) { + this.searchKeywords = searchKeywords; + } + + @Override + public String execute(TaskList taskList, NoteList noteList, Ui ui, Storage storage) { + TaskList tasksSearchResults = taskList.findTasks(searchKeywords); + NoteList notesSearchResults = noteList.findNotes(searchKeywords); + String output = ui.showTaskList(tasksSearchResults) + ui.showNoteList(notesSearchResults) + "\n"; + return output; + } +} diff --git a/src/main/java/dude/command/ListCommand.java b/src/main/java/dude/command/ListCommand.java new file mode 100644 index 0000000000..47c38389dc --- /dev/null +++ b/src/main/java/dude/command/ListCommand.java @@ -0,0 +1,26 @@ +package dude.command; + +import dude.note.NoteList; +import dude.task.TaskList; +import dude.ui.Ui; +import dude.util.Storage; + +/** + * Represents a command that lists all the tasks. + */ +public class ListCommand extends Command { + + /** + * Executes the command to list all tasks. + * + * @param taskList List of tasks. + * @param noteList List of notes. + * @param storage Storage containing saved tasks, and saves and loads tasks. + * @param ui User interface of Dude. + */ + @Override + public String execute(TaskList taskList, NoteList noteList, Ui ui, Storage storage) { + String output = ui.showTaskList(taskList) + ui.showNoteList(noteList) + "\n"; + return output; + } +} diff --git a/src/main/java/dude/command/MarkCommand.java b/src/main/java/dude/command/MarkCommand.java new file mode 100644 index 0000000000..f046497c76 --- /dev/null +++ b/src/main/java/dude/command/MarkCommand.java @@ -0,0 +1,33 @@ +package dude.command; + +import dude.note.NoteList; +import dude.task.Task; +import dude.task.TaskList; +import dude.ui.Ui; +import dude.util.Storage; + +/** + * Represents a command that marks a task as done. + */ +public class MarkCommand extends Command { + private int taskIndex; + + public MarkCommand(int taskIndex) { + this.taskIndex = taskIndex; + } + + /** + * Executes the command to mark a task as done. + * + * @param taskList List of tasks. + * @param storage Storage containing saved tasks, and saves and loads tasks. + * @param ui User interface of Dude. + */ + @Override + public String execute(TaskList taskList, NoteList noteList, Ui ui, Storage storage) { + Task markedTask = taskList.markTask(taskIndex); + String output = ui.showMarkedTask(markedTask) + "\n"; + storage.saveToDisk(taskList, noteList); + return output; + } +} diff --git a/src/main/java/dude/command/UnknownCommand.java b/src/main/java/dude/command/UnknownCommand.java new file mode 100644 index 0000000000..1810fd65b0 --- /dev/null +++ b/src/main/java/dude/command/UnknownCommand.java @@ -0,0 +1,31 @@ +package dude.command; + +import dude.note.NoteList; +import dude.task.TaskList; +import dude.ui.Ui; +import dude.util.Storage; + +/** + * Represents a command that is not defined in Dude. + */ +public class UnknownCommand extends Command { + + private final String input; + + public UnknownCommand(String input) { + this.input = input; + } + + /** + * Executes the command to tell users the command is unknown. + * + * @param taskList List of tasks. + * @param storage Storage containing saved tasks, and saves and loads tasks. + * @param ui User interface of Dude. + */ + @Override + public String execute(TaskList taskList, NoteList noteList, Ui ui, Storage storage) { + String output = ui.showUnknownCommand(this.input) + "\n"; + return output; + } +} diff --git a/src/main/java/dude/command/UnmarkCommand.java b/src/main/java/dude/command/UnmarkCommand.java new file mode 100644 index 0000000000..831e36d00d --- /dev/null +++ b/src/main/java/dude/command/UnmarkCommand.java @@ -0,0 +1,32 @@ +package dude.command; + +import dude.note.NoteList; +import dude.task.Task; +import dude.task.TaskList; +import dude.ui.Ui; +import dude.util.Storage; + +/** + * Represents a command that marks a task as undone. + */ +public class UnmarkCommand extends Command { + private int taskIndex; + + public UnmarkCommand(int taskIndex) { + this.taskIndex = taskIndex; + } + + /** + * Executes the command to mark a task as undone. + * + * @param taskList List of tasks. + * @param storage Storage containing saved tasks, and saves and loads tasks. + * @param ui User interface of Dude. + */ + public String execute(TaskList taskList, NoteList noteList, Ui ui, Storage storage) { + Task unmarkedTask = taskList.unmarkTask(taskIndex); + String output = ui.showUnmarkedTask(unmarkedTask) + "\n"; + storage.saveToDisk(taskList, noteList); + return output; + } +} diff --git a/src/main/java/dude/exception/DudeException.java b/src/main/java/dude/exception/DudeException.java new file mode 100644 index 0000000000..456ab576a4 --- /dev/null +++ b/src/main/java/dude/exception/DudeException.java @@ -0,0 +1,10 @@ +package dude.exception; + +/** + * Class of Exceptions that might be found in the Dude programme. + */ +public class DudeException extends RuntimeException { + DudeException(String message) { + super(message); + } +} diff --git a/src/main/java/dude/exception/EventException.java b/src/main/java/dude/exception/EventException.java new file mode 100644 index 0000000000..3d7d3c06ab --- /dev/null +++ b/src/main/java/dude/exception/EventException.java @@ -0,0 +1,10 @@ +package dude.exception; + +/** + * Indicates that an exception is thrown during Event creation. + */ +public class EventException extends DudeException { + public EventException(String message) { + super(message); + } +} diff --git a/src/main/java/dude/exception/ParserException.java b/src/main/java/dude/exception/ParserException.java new file mode 100644 index 0000000000..b662d2532a --- /dev/null +++ b/src/main/java/dude/exception/ParserException.java @@ -0,0 +1,10 @@ +package dude.exception; + +/** + * Indicates that an exception is thrown in the Parser class. + */ +public class ParserException extends DudeException { + public ParserException(String message) { + super(message); + } +} diff --git a/src/main/java/dude/exception/StorageException.java b/src/main/java/dude/exception/StorageException.java new file mode 100644 index 0000000000..0624495f51 --- /dev/null +++ b/src/main/java/dude/exception/StorageException.java @@ -0,0 +1,10 @@ +package dude.exception; + +/** + * Indicates that an exception is thrown in the Storage class. + */ +public class StorageException extends DudeException { + public StorageException(String message) { + super(message); + } +} diff --git a/src/main/java/dude/note/Note.java b/src/main/java/dude/note/Note.java new file mode 100644 index 0000000000..d23feef5fc --- /dev/null +++ b/src/main/java/dude/note/Note.java @@ -0,0 +1,51 @@ +package dude.note; + +/** + * Represents a note. + * A Note object has a String description. + */ +public class Note { + + private String description; + + /** + * Constructs a new Note object with the specified description. + * + * @param description A short description of the note. + */ + public Note(String description) { + this.description = description; + } + + public String getDescription() { + return this.description; + } + + /** + * Converts task into format to be saved in file. + * @return format of task to be saved in file. + */ + public String saveNote() { + return "N | " + this.description + "\n"; + } + + /** + * Checks if note contains specified keyword. + * @return boolean to represent if note contains the keyword. + */ + public boolean containKeywords(String keywords) { + String lowercaseKeywords = keywords.toLowerCase(); + String lowercaseDescription = this.description.toLowerCase(); + return lowercaseDescription.contains(lowercaseKeywords); + } + + /** + * Returns a formatted string representation of the note. + * + * @return A formatted string describing the note. + */ + @Override + public String toString() { + return this.description; + } +} diff --git a/src/main/java/dude/note/NoteList.java b/src/main/java/dude/note/NoteList.java new file mode 100644 index 0000000000..3bca589444 --- /dev/null +++ b/src/main/java/dude/note/NoteList.java @@ -0,0 +1,72 @@ +package dude.note; + +import java.util.ArrayList; + +/** + * Represents a list of notes. + */ +public class NoteList { + + private ArrayList noteList; + + public NoteList() { + this.noteList = new ArrayList(); + } + + public NoteList(ArrayList noteList) { + this.noteList = noteList; + } + + // getters + public int getSize() { + return this.noteList.size(); + } + + public Note getNote(int index) { + return this.noteList.get(index); + } + + /** + * Adds a note to the list. + * + * @param note Note to be added to the list. + */ + public void addNote(Note note) { + int oldNoteListLength = this.getSize(); + noteList.add(note); + int newNoteListLength = this.getSize(); + assert newNoteListLength == oldNoteListLength + 1 + : "Length of note list after adding note should increase by length 1."; + } + + /** + * Removes a note from the list. + * + * @param index Index of the note to be removed from the list. + */ + public Note deleteNote(int index) { + int oldNoteListLength = this.getSize(); + Note removedNote = noteList.get(index); + noteList.remove(index); + int newNoteListLength = this.getSize(); + assert newNoteListLength == oldNoteListLength - 1 + : "Length of note list after deleting note should decrease by length 1."; + return removedNote; + } + + /** + * Finds notes in list that contain specified keyword(s). + * + * @param noteKeywords Keywords used to search for notes. + */ + public NoteList findNotes(String noteKeywords) { + NoteList searchResults = new NoteList(); + for (int i = 0; i < this.getSize(); i++) { + Note note = this.getNote(i); + if (note.containKeywords(noteKeywords)) { + searchResults.addNote(note); + } + } + return searchResults; + } +} diff --git a/src/main/java/dude/task/Deadline.java b/src/main/java/dude/task/Deadline.java new file mode 100644 index 0000000000..7470830430 --- /dev/null +++ b/src/main/java/dude/task/Deadline.java @@ -0,0 +1,48 @@ +package dude.task; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Locale; + +/** + * Represents a deadline that extends a task. + * A Deadline object has a String description, + * and LocalDateTime due time. + */ +public class Deadline extends Task { + private LocalDateTime by; + + /** + * Constructs a new Deadline object with the specified description and due time. + * + * @param description A short description of the event. + * @param by The time when the task is due. + */ + public Deadline(String description, LocalDateTime by) { + super(description); + this.by = by; + } + + @Override + public String getType() { + return "deadline"; + } + + @Override + public String saveTask() { + String data = "D " + super.saveTask() + " | " + this.by + "\n"; + return data; + } + + /** + * Returns a formatted string representation of the deadline. + * + * @return A formatted string describing the deadline. + */ + @Override + public String toString() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd MMM yyyy hh:mm a", Locale.ENGLISH); + String formattedDateTime = by.format(formatter); + return "[D]" + super.toString() + " (by: " + formattedDateTime + ")"; + } +} diff --git a/src/main/java/dude/task/Event.java b/src/main/java/dude/task/Event.java new file mode 100644 index 0000000000..0bebf43504 --- /dev/null +++ b/src/main/java/dude/task/Event.java @@ -0,0 +1,52 @@ +package dude.task; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Locale; + +/** + * Represents a scheduled event that extends a task. + * An Event object has a String description, + * LocalDateTime start time, and a LocalDateTime end time. + */ +public class Event extends Task { + private LocalDateTime from; + private LocalDateTime to; + + /** + * Constructs a new Event object with the specified description and event date and time. + * + * @param description A short description of the event. + * @param from The time when the event is scheduled to start. + * @param to The time when the event is scheduled to end. + */ + public Event(String description, LocalDateTime from, LocalDateTime to) { + super(description); + this.from = from; + this.to = to; + } + + @Override + public String getType() { + return "event"; + } + + @Override + public String saveTask() { + String data = "E " + super.saveTask() + " | " + this.from + " | " + this.to + "\n"; + return data; + } + + /** + * Returns a formatted string representation of the event. + * + * @return A formatted string describing the event. + */ + @Override + public String toString() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd MMM yyyy hh:mm a", Locale.ENGLISH); + String fromFormatted = from.format(formatter); + String toFormatted = to.format(formatter); + return "[E]" + super.toString() + " (from: " + fromFormatted + " to: " + toFormatted + ")"; + } +} diff --git a/src/main/java/dude/task/Task.java b/src/main/java/dude/task/Task.java new file mode 100644 index 0000000000..bd1d4b9575 --- /dev/null +++ b/src/main/java/dude/task/Task.java @@ -0,0 +1,66 @@ +package dude.task; + +/** + * Represents a task. + * A Task object has a String description. + */ +public class Task { + private String description; + private boolean isDone; + + /** + * Constructs a new Task object with the specified description. + * + * @param description A short description of the event. + */ + Task(String description) { + this.description = description; + this.isDone = false; + } + + public boolean isDone() { + return this.isDone; + } + + public String getDescription() { + return this.description; + } + + public void setDone(boolean done) { + this.isDone = done; + } + + public String getType() { + return "task"; + } + + /** + * Converts task into format to be saved in file. + * @return format of task to be saved in file. + */ + public String saveTask() { + String doneStatus = this.isDone() ? "| 1 | " : "| 0 | "; + return doneStatus + " " + this.description; + } + + /** + * Checks if task contains specified keyword. + * @return boolean to represent if task contains the keyword. + */ + public boolean containKeywords(String keywords) { + String lowercaseKeywords = keywords.toLowerCase(); + String lowercaseDescription = this.description.toLowerCase(); + return lowercaseDescription.contains(lowercaseKeywords); + } + + /** + * Returns a formatted string representation of the task. + * + * @return A formatted string describing the task. + */ + @Override + public String toString() { + String doneStatus = this.isDone() ? "[X]" : "[ ]"; + return doneStatus + " " + this.description; + } +} diff --git a/src/main/java/dude/task/TaskList.java b/src/main/java/dude/task/TaskList.java new file mode 100644 index 0000000000..8557cdd950 --- /dev/null +++ b/src/main/java/dude/task/TaskList.java @@ -0,0 +1,99 @@ +package dude.task; + +import java.util.ArrayList; + +/** + * Represents a list of tasks. + */ +public class TaskList { + private ArrayList taskList; + + public TaskList() { + this.taskList = new ArrayList(); + } + + public TaskList(ArrayList taskList) { + this.taskList = taskList; + } + + // getters + public int getSize() { + return this.taskList.size(); + } + + public Task getTask(int index) { + return this.taskList.get(index); + } + + private ArrayList getAllTasks() { + return this.taskList; + } + + /** + * Marks a task as done. + * + * @param index Index of the task to be marked as done. + */ + public Task markTask(int index) { + Task task = taskList.get(index); + task.setDone(true); + assert task.isDone() : "Marked task should be done."; + return task; + } + + /** + * Marks a task as undone. + * + * @param index Index of the task to be marked as undone. + */ + public Task unmarkTask(int index) { + Task task = taskList.get(index); + task.setDone(false); + assert !task.isDone() : "Unmarked task should not be done."; + return task; + } + + /** + * Adds a task to the list. + * + * @param task Task to be added to the list. + */ + public void addTask(Task task) { + int oldTaskListLength = this.getSize(); + taskList.add(task); + int newTaskListLength = this.getSize(); + assert newTaskListLength == oldTaskListLength + 1 + : "Length of task list after adding task should increase by length 1."; + } + + /** + * Removes a task from the list. + * + * @param index Index of the task to be removed from the list. + */ + public Task deleteTask(int index) { + int oldTaskListLength = this.getSize(); + Task removedTask = taskList.get(index); + taskList.remove(index); + int newTaskListLength = this.getSize(); + assert newTaskListLength == oldTaskListLength - 1 + : "Length of task list after deleting task should decrease by length 1."; + return removedTask; + } + + /** + * Finds tasks in list that contain specified keyword(s). + * + * @param taskKeywords Keywords used to search for tasks. + */ + public TaskList findTasks(String taskKeywords) { + TaskList searchResults = new TaskList(); + for (int i = 0; i < this.getSize(); i++) { + Task task = this.getTask(i); + if (task.containKeywords(taskKeywords)) { + searchResults.addTask(task); + } + } + return searchResults; + } +} diff --git a/src/main/java/dude/task/ToDo.java b/src/main/java/dude/task/ToDo.java new file mode 100644 index 0000000000..a7c398bfab --- /dev/null +++ b/src/main/java/dude/task/ToDo.java @@ -0,0 +1,38 @@ +package dude.task; + +/** + * Represents a todo that extends a task. + * A ToDo object has a String description. + */ +public class ToDo extends Task { + + /** + * Constructs a new ToDo object with the specified description. + * + * @param description A short description of the event. + */ + public ToDo(String description) { + super(description); + } + + @Override + public String getType() { + return "todo"; + } + + @Override + public String saveTask() { + String data = "T " + super.saveTask() + "\n"; + return data; + } + + /** + * Returns a formatted string representation of the todo. + * + * @return A formatted string describing the todo. + */ + @Override + public String toString() { + return "[T]" + super.toString(); + } +} diff --git a/src/main/java/dude/ui/DialogBox.java b/src/main/java/dude/ui/DialogBox.java new file mode 100644 index 0000000000..6fbb478f30 --- /dev/null +++ b/src/main/java/dude/ui/DialogBox.java @@ -0,0 +1,76 @@ +package dude.ui; + +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.Insets; +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.Background; +import javafx.scene.layout.BackgroundFill; +import javafx.scene.layout.CornerRadii; +import javafx.scene.layout.HBox; +import javafx.scene.layout.Region; +import javafx.scene.paint.Color; + +/** + * 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 { + + // private static final Color userColor = Color.web("#FFFFE0"); + + @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); + dialog.setMinHeight(Region.USE_PREF_SIZE); + 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) { + var db = new DialogBox(text, img); + db.setBackground(new Background(new BackgroundFill( + Color.LIGHTGOLDENRODYELLOW, CornerRadii.EMPTY, Insets.EMPTY))); + return db; + } + + public static DialogBox getDudeDialog(String text, Image img) { + var db = new DialogBox(text, img); + db.flip(); + db.setBackground(new Background(new BackgroundFill( + Color.LIGHTYELLOW, CornerRadii.EMPTY, Insets.EMPTY))); + return db; + } +} diff --git a/src/main/java/dude/ui/MainWindow.java b/src/main/java/dude/ui/MainWindow.java new file mode 100644 index 0000000000..30e35d9154 --- /dev/null +++ b/src/main/java/dude/ui/MainWindow.java @@ -0,0 +1,75 @@ +package dude.ui; + +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import dude.Dude; +import javafx.application.Platform; +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 Dude dude; + + private final Image userImage = new Image(this.getClass().getResourceAsStream("/images/User.png")); + private final Image dudeImage = new Image(this.getClass().getResourceAsStream("/images/Dude.png")); + + /** + * Initialises the main window of the GUI of Dude. + */ + @FXML + public void initialize() { + scrollPane.vvalueProperty().bind(dialogContainer.heightProperty()); + dialogContainer.getChildren().addAll( + DialogBox.getDudeDialog(Ui.showWelcome(), dudeImage) + ); + } + + public void setDude(Dude d) { + dude = d; + } + + /** + * 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 = dude.getResponse(input); + dialogContainer.getChildren().addAll( + DialogBox.getUserDialog(input, userImage), + DialogBox.getDudeDialog(response, dudeImage) + ); + + if (input.equals("bye")) { + // Schedule the exit task to run after 3 seconds + ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(); + executorService.schedule(() -> { + Platform.exit(); + executorService.shutdown(); // Shut down the executor service + }, 1, TimeUnit.SECONDS); + } + + userInput.clear(); + } +} diff --git a/src/main/java/dude/ui/Ui.java b/src/main/java/dude/ui/Ui.java new file mode 100644 index 0000000000..ac1f174157 --- /dev/null +++ b/src/main/java/dude/ui/Ui.java @@ -0,0 +1,144 @@ +package dude.ui; + +import java.util.Scanner; + +import dude.note.Note; +import dude.note.NoteList; +import dude.task.Task; +import dude.task.TaskList; + +/** + * Represents the UI of Dude and deals with interactions with the user. + */ +public class Ui { + + private Scanner sc; + public Ui() { + this.sc = new Scanner(System.in); + } + + /** + * Prints a welcome message for users. + */ + public static String showWelcome() { + String greeting = "sup dude, whatchu need?"; + return greeting; + } + + /** + * Prints a farewell message for users. + */ + public static String showFarewell() { + String greeting = "bye dude"; + return greeting; + } + + /** + * Prints the list of tasks. + */ + public String showTaskList(TaskList taskList) { + int nTasks = taskList.getSize(); + String taskListString = "---tasks---\n"; + + if (nTasks == 0) { + taskListString = "no tasks atm, you're a free fella.\n"; + } else { + for (int i = 0; i < nTasks; i++) { + Task task = taskList.getTask(i); + if (task != null) { + taskListString = taskListString + String.format("%d. %s\n", i + 1, task.toString()); + } + } + } + return taskListString; + } + + /** + * Prints the list of notes. + */ + public String showNoteList(NoteList noteList) { + int nNotes = noteList.getSize(); + String noteListString = "\n---notes---\n"; + + if (nNotes == 0) { + noteListString = "no thoughts head empty brotha.\n"; + } else { + for (int i = 0; i < nNotes; i++) { + Note note = noteList.getNote(i); + if (note != null) { + noteListString = noteListString + String.format("%d. %s\n", i + 1, note.toString()); + } + } + } + + return noteListString; + } + + /** + * Prints a statement to show the task that has been successfully marked. + */ + public String showMarkedTask(Task task) { + String confirmation = "noice. one task down:\n" + + task.toString() + "\n"; + return confirmation; + // task is already done? + } + + /** + * Prints a statement to show the task that has been successfully unmarked. + */ + public String showUnmarkedTask(Task task) { + String confirmation = "gosh darn... thought you were done:\n" + + task.toString() + "\n"; + return confirmation; + // task is already undone? + } + + /** + * Prints a statement to show the task that has been successfully deleted. + */ + public String showDeletedTask(Task task, int nTasks) { + String confirmation = "i mean that's also... one task down:\n" + + task.toString() + "\n" + + String.format("now just %d tasks to go.\n", nTasks); + return confirmation; + } + + /** + * Prints a statement to show the note that has been successfully deleted. + */ + public String showDeletedNote(Note note, int nNotes) { + String confirmation = "one less thought for the sole braincell:\n" + + note.toString() + "\n" + + String.format("%d thoughts left in brain.\n", nNotes); + return confirmation; + } + + /** + * Prints a statement to show the task that has been successfully added. + */ + public String showAddedTask(Task task, int nTasks) { + String confirmation = "i gotchu... one more task to do:\n" + + task.toString() + "\n" + + String.format("now that's %d tasks to be done.\n", nTasks); + return confirmation; + } + + /** + * Prints a statement to show the task that has been successfully added. + */ + public String showAddedNote(Note note, int nNotes) { + String confirmation = "uhhuh, hope i remember that:\n" + + note.toString() + "\n" + + String.format("%d thoughts currently in head.\n", nNotes); + return confirmation; + } + + /** + * Prints a statement to show the command is unknown. + */ + public String showUnknownCommand(String input) { + String reply = String.format("bruh, what %s supposed to mean :-(\n", input); + return reply; + } +} diff --git a/src/main/java/dude/util/Parser.java b/src/main/java/dude/util/Parser.java new file mode 100644 index 0000000000..306ff7f419 --- /dev/null +++ b/src/main/java/dude/util/Parser.java @@ -0,0 +1,191 @@ +package dude.util; + + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + +import dude.command.AddDeadlineCommand; +import dude.command.AddEventCommand; +import dude.command.AddNoteCommand; +import dude.command.AddToDoCommand; +import dude.command.Command; +import dude.command.DeleteNoteCommand; +import dude.command.DeleteTaskCommand; +import dude.command.ExitCommand; +import dude.command.FindCommand; +import dude.command.ListCommand; +import dude.command.MarkCommand; +import dude.command.UnknownCommand; +import dude.command.UnmarkCommand; +import dude.exception.ParserException; + +/** + * Represents a parser that parses user input and deals with making sense of the user command. + */ +public class Parser { + private static final DateTimeFormatter DATETIME_FORMATTER = + DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm"); + + private static final DateTimeFormatter DATE_FORMATTER = + DateTimeFormatter.ofPattern("dd-MM-yyyy"); + + /** + * Parses the user's input and returns the corresponding command. + * + * @param fullCommand The full user command input. + * @return A command object representing the user's intent. + */ + public static Command parse(String fullCommand) { + String commandType = getCommandType(fullCommand); + Command c; + + if (commandType.equals("bye")) { + + c = new ExitCommand(); + + } else if (commandType.equals("list")) { + + c = new ListCommand(); + + } else if (commandType.equals("mark")) { + + int taskIndex = parseIndex(fullCommand); + c = new MarkCommand(taskIndex); + + } else if (commandType.equals("unmark")) { + + int taskIndex = parseIndex(fullCommand); + c = new UnmarkCommand(taskIndex); + + } else if (commandType.equals("delete")) { + + int index = parseIndex(fullCommand); + + if (fullCommand.matches("(.+)/t(.+)")) { + c = new DeleteTaskCommand(index); + } else if (fullCommand.matches("(.+)/n(.+)")) { + c = new DeleteNoteCommand(index); + } else { + throw new ParserException("invalid command format. try: \n" + + "delete /t OR \n" + + "delete /n OR \n"); + } + + } else if (commandType.equals("todo")) { + + String taskDescription = parseDescription(fullCommand); + c = new AddToDoCommand(taskDescription); + + } else if (commandType.equals("deadline")) { + + String[] commandDetails = parseDeadline(fullCommand); + LocalDateTime byDateTime = parseDateTime(commandDetails[2]); + c = new AddDeadlineCommand(commandDetails[1], byDateTime); + + } else if (commandType.equals("event")) { + + String[] commandDetails = parseEvent(fullCommand); + + LocalDateTime fromDateTime = parseDateTime(commandDetails[2]); + LocalDateTime toDateTime = parseDateTime(commandDetails[3]); + c = new AddEventCommand(commandDetails[1], fromDateTime, toDateTime); + + } else if (commandType.equals("note")) { + + String noteDescription = parseDescription(fullCommand); + c = new AddNoteCommand(noteDescription); + + } else if (commandType.equals("find")) { + + String searchKeywords = parseDescription(fullCommand); + c = new FindCommand(searchKeywords); + + } else { + + c = new UnknownCommand(fullCommand); + + } + return c; + } + + private static String getCommandType(String fullCommand) { + String[] commandDetails = fullCommand.split(" ", 2); + String commandType = commandDetails[0]; + return commandType; + } + + private static int parseIndex(String fullCommand) throws ParserException { + String[] commandDetails = fullCommand.split("\\s+/n\\s+|\\s+/t\\s+|\\s+"); + + if (commandDetails.length < 2) { + throw new ParserException("something is missing... \n try again."); + } + + try { + return Integer.parseInt(commandDetails[1]) - 1; + } catch (NumberFormatException e) { + throw new ParserException("index" + commandDetails[1] + "is invalid... "); + } + } + + private static String parseDescription(String fullCommand) throws ParserException { + String[] commandDetails = fullCommand.split(" ", 2); + + if (commandDetails.length < 2) { + throw new ParserException("something is missing... a description?"); + } + + return commandDetails[1].trim(); + } + + private static String[] parseDeadline(String fullCommand) throws ParserException { + + if (!fullCommand.matches("deadline(.+)/by(.+)")) { + throw new ParserException("invalid command format. try: \n" + + "deadline /by dd-mm-yyyy hh:mm"); + } + + String[] commandDetails = fullCommand.split("deadline\\s+|\\s+/by\\s+"); + + if (commandDetails.length < 3) { + throw new ParserException("something is missing. try: \n" + + "deadline /by dd-mm-yyyy hh:mm"); + } + + return commandDetails; + } + + private static String[] parseEvent(String fullCommand) throws ParserException { + + if (!fullCommand.matches("event(.+)/from(.+)/to(.+)")) { + throw new ParserException("invalid command format. try: \n" + + "event /from dd-mm-yyyy hh:mm /to dd-mm-yyyy hh:mm"); + } + + String[] commandDetails = fullCommand.split("event\\s+|\\s+/from\\s+|\\s+/to\\s+"); + + if (commandDetails.length < 4) { + throw new ParserException("something is missing. try: \n" + + "event /from dd-mm-yyyy hh:mm /to dd-mm-yyyy hh:mm"); + } + + return commandDetails; + } + + private static LocalDateTime parseDateTime(String dateTimeString) throws ParserException { + try { + return LocalDateTime.parse(dateTimeString, DATETIME_FORMATTER); + } catch (DateTimeParseException e) { + try { + LocalDate date = LocalDate.parse(dateTimeString, DATE_FORMATTER); + return date.atTime(LocalTime.MIDNIGHT); + } catch (DateTimeParseException ex) { + throw new ParserException("invalid date time format. try: \n " + + "dd-mm-yyyy hh:mm OR dd-mm-yyyy"); + } + } + } +} diff --git a/src/main/java/dude/util/Storage.java b/src/main/java/dude/util/Storage.java new file mode 100644 index 0000000000..5f92f59a61 --- /dev/null +++ b/src/main/java/dude/util/Storage.java @@ -0,0 +1,221 @@ +package dude.util; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Scanner; + +import dude.exception.StorageException; +import dude.note.Note; +import dude.note.NoteList; +import dude.task.Deadline; +import dude.task.Event; +import dude.task.Task; +import dude.task.TaskList; +import dude.task.ToDo; + +/** + * Represents the Storage system of Dude and deals with loading tasks from + * the file and saving tasks in the file. + */ +public class Storage { + + private static final DateTimeFormatter DATETIME_FORMATTER = + DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm"); + private String filepath; + + /** + * Constructs a new Storage object with the specified filepath. + * + * @param filepath Path to the file. + */ + public Storage(String filepath) { + assert !this.filepath.trim().isEmpty() : "Filepath should not be empty"; + this.filepath = filepath; + } + + /** + * Saves the task list to the file specified by filepath. + * + * @param taskList List of tasks to be saved. + */ + public void saveToDisk(TaskList taskList, NoteList noteList) throws StorageException { + File file = new File(this.filepath); + try { + File parentDirectory = file.getParentFile(); + + if (!parentDirectory.exists()) { + parentDirectory.mkdirs(); + } + + if (!file.exists()) { + file.createNewFile(); + } + + String data = convertTaskListToString(taskList) + convertNoteListToString(noteList); + FileWriter fw = new FileWriter(file); + fw.write(data); + fw.close(); + } catch (IOException e) { + throw new StorageException("something is wrong: \n" + e.getMessage()); + } + } + + /** + * Converts task list into String for saving to file. + * @param taskList + * @return + */ + public String convertTaskListToString(TaskList taskList) { + String data = ""; + + for (int i = 0; i < taskList.getSize(); i++) { + Task task = taskList.getTask(i); + if (task != null) { + data += task.saveTask(); + } + } + + return data; + } + + /** + * Converts task list into String for saving to file. + * @param noteList + * @return + */ + public String convertNoteListToString(NoteList noteList) { + String data = ""; + + for (int i = 0; i < noteList.getSize(); i++) { + Note note = noteList.getNote(i); + if (note != null) { + data += note.saveNote(); + } + } + + return data; + } + + /** + * Loads the saved tasks from the file specified by filepath. + * + * @return List of tasks from the file. + * @throws FileNotFoundException If no file is not found in the filepath. + */ + public TaskList loadFromDisk() throws StorageException { + TaskList taskList = new TaskList(); + File file = new File(this.filepath); + + try { + File parentDirectory = file.getParentFile(); + + if (!parentDirectory.exists()) { + parentDirectory.mkdirs(); + } + + if (!file.exists()) { + file.createNewFile(); + } + + Scanner sc = new Scanner(file); + + while (sc.hasNext()) { + String storedTaskDetails = sc.nextLine(); + Task task = convertStringToTask(storedTaskDetails); + if (task != null) { + taskList.addTask(task); + } + } + } catch (IOException e) { + throw new StorageException("something is wrong: \n" + e.getMessage()); + } + + return taskList; + } + + /** + * Converts a string of task details into Task. + * @param storedTaskDetails + * @return + */ + public Task convertStringToTask(String storedTaskDetails) { + String[] taskDetails = storedTaskDetails.split("\\s+\\|\\s+"); + String taskType = taskDetails[0].trim(); + String taskIsDone = taskDetails[1].trim(); + + Task task = null; + + if (taskType.equals("T")) { + String taskDescription = taskDetails[2].trim(); + task = new ToDo(taskDescription); + task.setDone(taskIsDone.equals("1")); + } else if (taskType.equals("D")) { + String taskDescription = taskDetails[2].trim(); + LocalDateTime by = LocalDateTime.parse(taskDetails[3]); + task = new Deadline(taskDescription, by); + task.setDone(taskIsDone.equals("1")); + } else if (taskType.equals("E")) { + String taskDescription = taskDetails[2].trim(); + LocalDateTime from = LocalDateTime.parse(taskDetails[3]); + LocalDateTime to = LocalDateTime.parse(taskDetails[4]); + task = new Event(taskDescription, from, to); + task.setDone(taskIsDone.equals("1")); + } + + return task; + } + + /** + * Loads the saved notes from the file specified by filepath. + * + * @return List of notes from the file. + * @throws FileNotFoundException If no file is not found in the filepath. + */ + public NoteList loadNotesFromDisk() throws StorageException { + NoteList noteList = new NoteList(); + File file = new File(this.filepath); + + try { + if (!file.exists()) { + file.createNewFile(); + } + + Scanner sc = new Scanner(file); + + while (sc.hasNext()) { + String storedNoteDetails = sc.nextLine(); + Note note = convertStringToNote(storedNoteDetails); + if (note != null) { + noteList.addNote(note); + } + } + } catch (IOException e) { + throw new StorageException("something is wrong: \n" + e.getMessage()); + } + + return noteList; + } + + /** + * Converts a string of task details into Task. + * @param storedNoteDetails + * @return + */ + public Note convertStringToNote(String storedNoteDetails) { + String[] noteDetails = storedNoteDetails.split("\\s+\\|\\s+"); + String noteType = noteDetails[0].trim(); + String noteDescription = noteDetails[1].trim(); + + Note note = null; + + if (noteType.equals("N")) { + note = new Note(noteDescription); + } + + return note; + } +} diff --git a/src/main/resources/images/Dude.png b/src/main/resources/images/Dude.png new file mode 100644 index 0000000000..9ce5a19eef Binary files /dev/null and b/src/main/resources/images/Dude.png differ diff --git a/src/main/resources/images/User.png b/src/main/resources/images/User.png new file mode 100644 index 0000000000..29d02d74c8 Binary files /dev/null and b/src/main/resources/images/User.png differ diff --git a/src/main/resources/view/DialogBox.fxml b/src/main/resources/view/DialogBox.fxml new file mode 100644 index 0000000000..2fcb6ab7a7 --- /dev/null +++ b/src/main/resources/view/DialogBox.fxml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + \ 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..f74ac37a06 --- /dev/null +++ b/src/main/resources/view/MainWindow.fxml @@ -0,0 +1,19 @@ + + + + + + + + + + + +