diff --git a/README.md b/README.md index 8715d4d915..cff53353d5 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,35 @@ -# Duke project template - -This is a project template for a greenfield Java project. It's named after the Java mascot _Duke_. Given below are instructions on how to use it. - -## Setting up in Intellij - -Prerequisites: JDK 11, update Intellij to the most recent version. - -1. Open Intellij (if you are not in the welcome screen, click `File` > `Close Project` to close the existing project first) -1. Open the project into Intellij as follows: - 1. Click `Open`. - 1. Select the project directory, and click `OK`. - 1. If there are any further prompts, accept the defaults. -1. Configure the project to use **JDK 11** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).
- In the same dialog, set the **Project language level** field to the `SDK default` option. -3. After that, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: - ``` - Hello from - ____ _ - | _ \ _ _| | _____ - | | | | | | | |/ / _ \ - | |_| | |_| | < __/ - |____/ \__,_|_|\_\___| - ``` +# Tick Pro + +> "For every minute spent organising, an hour is earned" - Tick from Brawl Stars + +"Tick OP" - every salty brawl stars player + +![This is an image](/assets/tick.png) + +Tick Pro frees your mind of having to remember things you need to do. It's, +- text-based +- easy to learn +- ~~FAST~~ SUPER FAST to learn + +## Setting it up +1. download **Tick Pro (v0.2)** from [here](https://github.com/bryanongjx/ip/releases/tag/A-Release) +2. double-click it +3. add your tasks +4. let it manage tasks for you :wink: + +and it's **FREE**!! :money_mouth_face: + +Features: +- [x] Managing tasks +- [x] Managing deadlines +- [ ] Reminders (coming soon) + +If you are a java programmer, you can use it to practice java too. Here's +the main method: +``` +public class Main { + public static void main(String[] args) { + Application.launch(MainApp.class, args); + } +} +``` diff --git a/assets/tick.png b/assets/tick.png new file mode 100644 index 0000000000..9481095ea9 Binary files /dev/null and b/assets/tick.png differ diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..c7c9acd2c2 --- /dev/null +++ b/build.gradle @@ -0,0 +1,55 @@ +plugins { + id 'java' + id 'application' + id 'com.github.johnrengelman.shadow' version '5.1.0' +} + +repositories { + mavenCentral() +} + +dependencies { + String javaFxVersion = '11' + 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' + + 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 = "duke.Launcher" +} + +shadowJar { + archiveBaseName = "duke" + archiveClassifier = null +} + +run{ + standardInput = System.in +} diff --git a/data/duke.txt b/data/duke.txt new file mode 100644 index 0000000000..dc82c625a4 --- /dev/null +++ b/data/duke.txt @@ -0,0 +1,7 @@ +[D]/!@#&/ /!@#&/high/!@#&/hello/!@#&/02/01/2021 +[T]/!@#&/ /!@#&/ /!@#&/hello +[T]/!@#&/ /!@#&/ /!@#&/hello +[T]/!@#&/ /!@#&/ /!@#&/hello +[T]/!@#&/ /!@#&/ /!@#&/hello +[T]/!@#&/ /!@#&/ /!@#&/hello +[T]/!@#&/ /!@#&/ /!@#&/hello diff --git a/docs/README.md b/docs/README.md index 8077118ebe..992ecdba4d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,171 @@ -# User Guide +# User Guide for Tick Pro -## Features +![This is an image](Ui.png) -### Feature-ABC +## Getting Started -Description of the feature. +1. Have Java 11 installed on your device. +2. Download the latest version of Duke from here. +3. Copy the file to the folder you want to use as the home folder for Duke. +4. Double click the application to run +5. Enter your command in the text box and press enter to execute command. Refer to the features below on the various commands. -### Feature-XYZ +## Features -Description of the feature. +### Feature - Adding Tasks +*Adds a task into the list* -## Usage +#### Usage - Todo +Command: +``` +todo +Eg. todo Read Book +``` + +Expected output: +``` +Got it. I've added this task: +[T][] Read Book +Priority: +Now you have 1 tasks in the list. +``` + +#### Usage - Deadline +Command: +``` +deadline /by +Eg. deadline Finish CS2100 Quiz /by 2021-01-02 +``` + +Expected output: +``` +Got it. I've added this task: +[D][] Finish CS2100 Quiz (02/01/2021) +Priority: +Now you have 2 tasks in the list. +``` + +#### Usage - Event +Command: +``` +event /from /to +Eg. event Industry Talk /from 03/06/2021 2pm /to 03/06/2021 4pm +``` +Expected output: +``` +Got it. I've added this task: +[E][] Industry Talk (from: 03/06/2021 2pm to: 03/06/2021 4pm) +Priority: +Now you have 3 tasks in the list. +``` + +### Feature - List +*Displays all tasks in your list* +#### Usage +Command: +`list` + +Expected output: +``` +Here are the tasks in your list: +1. [T][] Read Book +Priority: +2. [D][] CS2100 Quiz (02/01/2021) +Priority: +3. [E][] Industry Talk (from: 03/06/2021 2pm to: 03/06/2021 4pm) +``` + +### Feature - Mark +*Marks a task in your list as completed* +#### Usage +Command: +``` +mark +Eg. mark 2 +``` + +Expected output: +``` +Nice! I've marked this task as done: +[D][X] CS2100 Quiz (02/01/2021) +Priority: +``` -### `Keyword` - Describe action +### Feature - Unmark +*Marks a task in your list as not completed* +#### Usage +Command: +``` +unmark +Eg. unmark 2 +``` -Describe the action and its outcome. +Expected output: +``` +Nice! I've marked this task as not done: +[D][ ] CS2100 Quiz (02/01/2021) +Priority: +``` + +### Feature - Delete +*Deletes a task in your list* +#### Usage +Command: +``` +delete +Eg. delete 1 +``` -Example of usage: +Expected output: +``` +Noted. I've removed this task: +[T][ ] Read Book +Priority: +``` -`keyword (optional arguments)` +### Feature - Find +*Searches for matching tasks in your list based on a keyword* +#### Usage +Command: +``` +find +Eg. find talk +``` -Expected outcome: +Expected output: +``` +Here are the matching tasks in your list with the keyword "talk": +1. [E][ ] Industry Talk (from: 23/12/2023 10am to: 23/12/2023 12pm) +Priority: +2. [E][ ] Career Talk (from: 02/03/2023 12pm to: 02/03/2023 2pm) +Priority +3. [T][ ] Talk with friends +Priority: +``` -Description of the outcome. +### Feature - Priority +*Sets the priority for a task (low / medium / high)* +#### Usage +Command: +``` +priority +Eg. priority 1 high +``` +Expected output: +``` +Nice! I've assigned this task: +[D] CS2100 Quiz (02/03/2021) +Priority: high +as high priority ``` -expected output + +### Feature - Bye +*Exits the application* +#### Usage +Command: `bye` + +Expected output: ``` +Bye! Hope to see you again soon! +``` \ No newline at end of file diff --git a/docs/Ui.png b/docs/Ui.png new file mode 100644 index 0000000000..47f494ce77 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/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..2c9a9745c5 --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: duke.Duke + diff --git a/src/main/java/duke/Deadline.java b/src/main/java/duke/Deadline.java new file mode 100644 index 0000000000..0a28f5c733 --- /dev/null +++ b/src/main/java/duke/Deadline.java @@ -0,0 +1,46 @@ +package duke; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +/** + * Deadline class + */ +public class Deadline extends Task { + private static final String TASK_TYPE = "[D]"; + private LocalDate dueDate; + + /** + * Constructor for instantiating a deadline object + * @param description description of the event + * @param dueDate due date of the event + */ + public Deadline(String description, LocalDate dueDate) { + super(description); + this.dueDate = dueDate; + } + + /** + * Returns the string representation of the deadline object + * @return String string representation of the deadline, which includes type of task, completion status, task + * description and due date + */ + @Override + public String toString() { + return "[D]" + super.toString() + " (" + this.dueDate.format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + ')' + + "\nPriority: " + getPriority(); + } + + /** + * Returns the string representation of the deadline object to be stored in the data.txt file + * @return the string representation with dividers of the deadline object to be stored in the data.txt file + */ + @Override + public String toStorageData() { + String completionStatus = this.getStatusIcon(); + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); + String dueDateString = this.dueDate.format(dateFormatter); + return TASK_TYPE + DIVIDER + completionStatus + DIVIDER + getPriority() + DIVIDER + super.description + + DIVIDER + dueDateString; + } +} diff --git a/src/main/java/duke/DialogBox.java b/src/main/java/duke/DialogBox.java new file mode 100644 index 0000000000..b6022d37f0 --- /dev/null +++ b/src/main/java/duke/DialogBox.java @@ -0,0 +1,64 @@ +package duke; + +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) { + DialogBox db = new DialogBox(text, img); + db.dialog.getStyleClass().add("user-dialog"); + return db; + } + + public static DialogBox getDukeDialog(String text, Image img) { + var db = new DialogBox(text, img); + db.dialog.getStyleClass().add("duke-dialog"); + db.flip(); + return db; + } +} \ No newline at end of file diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java new file mode 100644 index 0000000000..2f24ba04c2 --- /dev/null +++ b/src/main/java/duke/Duke.java @@ -0,0 +1,49 @@ +package duke; + +import java.util.Scanner; + +/** + * Duke class + */ +public class Duke{ + + private Storage storage; + private TaskList tasks; + private Ui ui; + + /** + * Constructor for duke + * @param filePath file path of existing txt file with tasks stored inside + */ + public Duke(String filePath) { + ui = new Ui(); + storage = new Storage(filePath); + try { + tasks = new TaskList(storage.load()); + } catch (DukeException e) { + ui.showLoadingError(); + tasks = new TaskList(); + } + + } + + public String getResponse(String input) { + String response = ""; + if (input.equals("bye")) { + try { + response = Parser.parse(input, tasks); + } catch (DukeException e) { + response = e.getMessage(); + } + } else { + try { + response = Parser.parse(input, tasks); + storage.save(tasks); + } catch (DukeException e) { + response = e.getMessage(); + } + } + return response; + } +} + diff --git a/src/main/java/duke/DukeException.java b/src/main/java/duke/DukeException.java new file mode 100644 index 0000000000..1074413926 --- /dev/null +++ b/src/main/java/duke/DukeException.java @@ -0,0 +1,24 @@ +package duke; + +/** + * DukeException class thrown by Duke application + */ +public class DukeException extends Exception{ + + /** + * Constructor for instantiating a DukeException object + * @param message error message to be displayed + */ + public DukeException(String message) { + super(message); + } + + /** + * Returns error message + * @return String error message + */ + public String getMessage() { + return super.getMessage(); + } + +} diff --git a/src/main/java/duke/Event.java b/src/main/java/duke/Event.java new file mode 100644 index 0000000000..5f17a36370 --- /dev/null +++ b/src/main/java/duke/Event.java @@ -0,0 +1,43 @@ +package duke; + +/** + * Event class + */ +public class Event extends Task { + private static final String TASK_TYPE = "[E]"; + private String from; + private String to; + + /** + * constructor for an instantiating an event object + * @param description description of the event + * @param from start time of the event + * @param to end time of the event + */ + public Event(String description, String from, String to) { + super(description); + this.from = from; + this.to = to; + } + + /** + * Returns the string representation of the event object + * @return String string representation of the event object, which includes task type, completion status, from date + * and to date + */ + @Override + public String toString() { + return TASK_TYPE + super.toString() + " (from: " + this.from + " to: " + this.to + ")" + + "\nPriority: " + getPriority(); + } + + /** + * Returns the string representation of the event object to be stored into the data.txt file + * @return String string representation with dividers to be stored in the data.txt file + */ + @Override + public String toStorageData() { + return TASK_TYPE + DIVIDER + this.getStatusIcon() + DIVIDER + getPriority() + DIVIDER + super.description + + DIVIDER + this.from + DIVIDER + this.to; + } +} diff --git a/src/main/java/duke/Launcher.java b/src/main/java/duke/Launcher.java new file mode 100644 index 0000000000..e4ef6b4628 --- /dev/null +++ b/src/main/java/duke/Launcher.java @@ -0,0 +1,12 @@ +package duke; + +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/duke/Main.java b/src/main/java/duke/Main.java new file mode 100644 index 0000000000..f9a8c1ac20 --- /dev/null +++ b/src/main/java/duke/Main.java @@ -0,0 +1,32 @@ +package duke; + +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 { + + private Duke duke = new Duke("./data/duke.txt"); + + @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().setDuke(duke); + stage.setResizable(false); + stage.show(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/src/main/java/duke/MainWindow.java b/src/main/java/duke/MainWindow.java new file mode 100644 index 0000000000..39f913f7ef --- /dev/null +++ b/src/main/java/duke/MainWindow.java @@ -0,0 +1,64 @@ +package duke; + +import javafx.animation.PauseTransition; +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; +import javafx.util.Duration; +/** + * 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 Duke duke; + private Ui ui; + + private Image userImage = new Image(this.getClass().getResourceAsStream("/images/otis.png")); + private Image dukeImage = new Image(this.getClass().getResourceAsStream("/images/jesse.png")); + + @FXML + public void initialize() { + scrollPane.vvalueProperty().bind(dialogContainer.heightProperty()); + } + + public void setDuke(Duke d) { + ui = new Ui(); + duke = d; + dialogContainer.getChildren().addAll( + DialogBox.getDukeDialog(ui.greet(), dukeImage) + ); + } + + /** + * 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 = duke.getResponse(input); + dialogContainer.getChildren().addAll( + DialogBox.getUserDialog(input, userImage), + DialogBox.getDukeDialog(response, dukeImage) + ); + userInput.clear(); + if (input.equals("bye")) { + PauseTransition delay = new PauseTransition(Duration.seconds(1.5)); + delay.setOnFinished(event -> Platform.exit()); + delay.play(); + } + } +} \ No newline at end of file diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java new file mode 100644 index 0000000000..caf90d15e2 --- /dev/null +++ b/src/main/java/duke/Parser.java @@ -0,0 +1,42 @@ +package duke; + +/** + * Parser class + */ +public class Parser { + private static Ui ui = new Ui(); + + /** + * Parses the user's input and executes the corresponding actions + * @param userInput user's input + * @param lst user's task list + * @return String response from parse + * @throws DukeException + */ + public static String parse(String userInput, TaskList lst) throws DukeException { + if (userInput.equals("bye")) { + return ui.exit(); + } else if (userInput.equals("list")) { + return ui.listCommandMessage() + lst.getTaskList(); + } else if (userInput.startsWith("mark")) { + return lst.markTask(userInput); + } else if (userInput.startsWith("unmark")) { + return lst.unmarkTask(userInput); + } else if (userInput.startsWith("todo")) { + return lst.addToDo(userInput); + } else if (userInput.startsWith("deadline")) { + return lst.addDeadline(userInput); + } else if (userInput.startsWith("event")) { + return lst.addEvent(userInput); + } else if (userInput.startsWith("delete")) { + return lst.deleteTask(userInput); + } else if (userInput.startsWith("find")) { + return lst.findTask(userInput); + } else if (userInput.startsWith("priority")) { + return lst.markPriority(userInput); + } else { + throw new DukeException("OOPS!!! I'm sorry, but I don't know what that means :-("); + } + } +} + diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java new file mode 100644 index 0000000000..37d904ab38 --- /dev/null +++ b/src/main/java/duke/Storage.java @@ -0,0 +1,115 @@ +package duke; + +import java.util.Scanner; +import java.util.ArrayList; + +import java.io.File; +import java.io.FileWriter; +import java.io.FileNotFoundException; +import java.io.IOException; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +/** + * Storage class + */ +public class Storage { + String filePath; + ArrayList loadedTasks = new ArrayList<>(); + + /** + * Constructor for instantiating a Storage object + * @param filePath path of file to save the storage in + */ + public Storage(String filePath) { + this.filePath = filePath; + } + + private Task createTask(String data) throws DukeException{ + String[] dataArr = data.split(Task.DIVIDER); + String taskType = dataArr[0]; + String completionStatus = dataArr[1]; + String priority = dataArr[2]; + String description = dataArr[3]; + Task task; + + switch (taskType) { + case "[T]": + task = new Todo(description); + break; + case "[D]": + String dueDateString = dataArr[4]; + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); + LocalDate dueDate = LocalDate.parse(dueDateString, dateFormatter); + task = new Deadline(description, dueDate); + break; + case "[E]": + String from = dataArr[4]; + String to = dataArr[5]; + task = new Event(description, from, to); + break; + default: + throw new DukeException("Unknown task type found in data.txt file"); + } + if (completionStatus.equals("X")) { + task.mark(); + } + task.assignPriority(priority); + return task; + } + + private void createFile() throws DukeException { + try { + File data = new File("./data"); + File f_new = new File(filePath); + data.mkdir(); + f_new.createNewFile(); + } catch (IOException e) { + throw new DukeException("Error creating file"); + } + } + + /** + * Loads the file at the specified file path into the storage object + * @return ArrayList an arraylist of tasks loaded from the file + * @throws DukeException + */ + public ArrayList load() throws DukeException { + File f = new File(filePath); + if (f.exists()) { + try { + Scanner sc = new Scanner(f); + while (sc.hasNext()) { + String data = sc.nextLine(); + System.out.println(data); + Task taskToAdd = createTask(data); + loadedTasks.add(taskToAdd); + } + sc.close(); + } catch (FileNotFoundException e) { + System.out.println("File could not be found"); + } + } else { + createFile(); + } + return this.loadedTasks; + } + + /** + * Takes the input task list and updates the task list in the storage + * @param tasks updated task list + * @throws DukeException + */ + public void save(TaskList tasks) throws DukeException { + try { + File f = new File(filePath); + f.createNewFile(); + FileWriter fw = new FileWriter(filePath, false); + fw.write(tasks.toStorageData()); + fw.close(); + } catch (IOException e) { + System.out.println("error writing into file"); + } + } +} \ No newline at end of file diff --git a/src/main/java/duke/Task.java b/src/main/java/duke/Task.java new file mode 100644 index 0000000000..ee478c3a59 --- /dev/null +++ b/src/main/java/duke/Task.java @@ -0,0 +1,88 @@ +package duke; + +/** + * Task class + */ +public class Task { + protected static final String DIVIDER = "/!@#&/"; + protected String description; + protected boolean isDone; + + private String priority = " "; + + /** + * Constructor for instantiating a Task object + * @param description description of the task + */ + public Task(String description) { + this.description = description; + this.isDone = false; + } + + /** + * Returns the completion status of the task + * @return String completion status + */ + public String getStatusIcon() { + return (isDone ? "X": " "); + } + + /** + * Returns the description of the task + * @return String description + */ + public String getDescription() { + return this.description; + } + + /** + * Returns the priority of the task + * @return String priority + */ + public String getPriority() { + return this.priority; + } + + public void assignPriority(String priority) { + try { + if (priority.equals("low") || priority.equals("medium") || priority.equals("high")) { + this.priority = priority; + } else { + throw new DukeException("Please input a valid priority: low / medium / high"); + } + } catch (DukeException e) { + e.getMessage(); + } + } + + /** + * Marks the task as done + */ + public void mark() { + this.isDone = true; + } + + /** + * Marks the task as not done + */ + public void unMark() { + this.isDone = false; + } + + /** + * Returns the string representation of a Task + * @return String string representation of a task, which includes completion status and description + */ + @Override + public String toString() { + return "[" + this.getStatusIcon() + "] " + this.description; + } + + /** + * Returns string representation of a task to be stored in the data.txt file + * @return String string representation of a task to be stored in the data.txt file + */ + public String toStorageData() { + return this.toString(); + } +} diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java new file mode 100644 index 0000000000..cbde844900 --- /dev/null +++ b/src/main/java/duke/TaskList.java @@ -0,0 +1,215 @@ +package duke; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.time.format.DateTimeParseException; + +/** + * Task List class + */ +public class TaskList { + private ArrayList tasks; + + /** + * Constructor for instantiating a task list + * @param tasks array of tasks to be added to the task list + */ + public TaskList(ArrayList tasks) { + this.tasks = new ArrayList<>(); + for (Task t : tasks) { + this.tasks.add(t); + } + } + + /** + * Constructor for instantiating an empty task list + */ + public TaskList() { + this.tasks = new ArrayList<>(); + } + + /** + * + * @param input input command to add a To Do + * @return new task list after adding the To Do + */ + public String addToDo(String input) { + String details = input.split(" ", 2)[1]; + String response = ""; + try { + if (details.equals("")) { + throw new DukeException("OOPS!!! The description of a todo cannot be empty."); + } + Todo newTodo = new Todo(details); + tasks.add(newTodo); + response = "Got it. I've added this task:" + '\n' + newTodo + '\n' + "Now you have " + + tasks.size() + " tasks in the list"; + } catch (DukeException e) { + response = e.getMessage(); + } + return response; + } + + /** + * + * @param input input command to add a deadline + * @return new task list after adding the deadline + */ + public String addDeadline(String input) { + String details = input.split(" ", 2)[1]; + String response = ""; + try { + String[] detailsAndDate = details.split(" /by "); + String description = detailsAndDate[0]; + LocalDate date = LocalDate.parse(detailsAndDate[1]); + Deadline newDeadline = new Deadline(description, date); + tasks.add(newDeadline); + response = "Got it. I've added this task:" + '\n' + newDeadline + '\n' + "Now you have " + + tasks.size() + " tasks in the list"; + } catch (DateTimeParseException e) { + response = "Please input date in YYYY-MM-DD format!"; + } + return response; + } + + /** + * + * @param input input command to add an event + * @return new task list after adding the event + */ + public String addEvent(String input) { + String details = input.split(" ", 2)[1]; + String response; + String[] detailsAndTime = details.split(" /from "); + String description = detailsAndTime[0]; + String[] time = detailsAndTime[1].split(" /to "); + String to = time[0]; + String from = time[1]; + Event newEvent = new Event(description, to, from); + tasks.add(newEvent); + response = "Got it. I've added this task:" + '\n' + newEvent + '\n' + "Now you have " + + tasks.size() + " tasks in the list"; + return response; + } + + /** + * Returns a string representation of the task list + * @return String string representation of the task list + */ + public String getTaskList() { + String res = ""; + if (tasks.isEmpty()) { + return "You have no tasks as of now. Try adding some!"; + } + for (int i = 0; i < tasks.size(); i ++) { + res += Integer.toString(i + 1) + ". "; + res += tasks.get(i).toString(); + res += '\n'; + } + assert !res.isEmpty() : "Tasklist should not be empty!"; + return res; + } + + /** + * Marks a specific task as done + * @param input input command to mark task + * @return task list after marking the task + */ + public String markTask(String input) { + String details = input.split(" ", 2)[1]; + int index = Integer.parseInt(details); + Task currTask = tasks.get(index - 1); + currTask.mark(); + return "Nice! I've marked this task as done" + '\n' + currTask; + } + + /** + * Marks a specific task as not done + * @param input input command to mark task + * @return task list after un-marking the task + */ + public String unmarkTask(String input) { + String details = input.split(" ", 2)[1]; + int index = Integer.parseInt(details); + Task currTask = tasks.get(index - 1); + currTask.unMark(); + return "Nice! I've marked this task as not done yet" + '\n' + currTask; + } + + /** + * Deletes a task from the task list + * @param input input command to delete task + * @return String task list after deletion + */ + public String deleteTask(String input) { + String details = input.split(" ", 2)[1]; + int index = Integer.parseInt(details); + Task currTask = tasks.get(index - 1); + tasks.remove(index - 1); + return "Noted. I've removed this task:" + '\n' + currTask + '\n' + "Now you have " + tasks.size() + " tasks in the list"; + } + + /** + * Returns the size of the task list + * @return Integer size of task list + */ + public int getSize() { + return this.tasks.size(); + } + + /** + * Returns a task list filtered by a keyword + * @param input input command to find a specific task with a keyword + * @return String filtered task list + */ + public String findTask(String input) { + String keyword = input.split(" ", 2)[1]; + try { + ArrayList res = new ArrayList<>(); + for (Task task : tasks) { + if (task.getDescription().contains(keyword)) { + res.add(task); + } + } + if (res.isEmpty()) { + return "There are no matching tasks with the keyword: " + keyword; + } + TaskList result = new TaskList(res); + assert !(result.getSize() == 0); + return "Here are the matching tasks in your list:\n" + result.getTaskList(); + } catch (ArrayIndexOutOfBoundsException e) { + return "Please input the keyword"; + } + } + + public String markPriority(String input) { + String response = ""; + try { + String inputArr[] = input.split(" ", 3); + String taskNum = inputArr[1]; + String priority = inputArr[2]; + int index = Integer.parseInt(taskNum); + Task currTask = tasks.get(index - 1); + currTask.assignPriority(priority); + response = "Nice! I have assigned this task:\n" + currTask + "\nas " + priority + " priority"; + + } catch (ArrayIndexOutOfBoundsException e) { + response = "Please input a valid index"; + } + return response; + + } + + /** + * Converts task list to storage data + * @return String task list in storage data format with dividers + */ + public String toStorageData() { + String storageData = ""; + for (Task task : tasks) { + storageData += task.toStorageData(); + storageData += "\n"; + } + return storageData; + } +} diff --git a/src/main/java/duke/Todo.java b/src/main/java/duke/Todo.java new file mode 100644 index 0000000000..90d6549796 --- /dev/null +++ b/src/main/java/duke/Todo.java @@ -0,0 +1,37 @@ +package duke; + +/** + * To do class + */ +public class Todo extends Task { + + private static final String TASK_TYPE = "[T]"; + + /** + * Constructor for instantiating a to do object + * @param description description of the to do + */ + public Todo(String description) { + super(description); + } + + /** + * Returns the string representation of the to do object + * @return String string representation of the to do object, which includes task type, completion status and + * description + */ + @Override + public String toString() { + return "[T]" + super.toString() + "\nPriority: " + getPriority(); + } + + /** + * Returns the string representation of the to do object to be stored in the data.txt file + * @return string representation with dividers of to do object to be stored in the data.txt file + */ + @Override + public String toStorageData() { + String completionStatus = this.getStatusIcon(); + return TASK_TYPE + DIVIDER + completionStatus + DIVIDER + getPriority() + DIVIDER + super.description; + } +} diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java new file mode 100644 index 0000000000..b5743e9870 --- /dev/null +++ b/src/main/java/duke/Ui.java @@ -0,0 +1,32 @@ +package duke; + +/** + * Ui class + */ +public class Ui { + + /** + * Displays a greeting to the user when he first opens the application + */ + public String greet() { + return "Hello! I'm Duke" + "\n" + "What can I do for you?"; + } + + /** + * Displays a goodbye message to the user when he closes the application + */ + public String exit() { + return "Bye. Hope to see you again soon!"; + } + + /** + * Displays an error in loading the file + */ + public void showLoadingError() { + System.out.println("There was an error in loading your file"); + } + + public String listCommandMessage() { + return "Here are the tasks in your list:\n"; + } +} diff --git a/src/main/resources/images/bea.png b/src/main/resources/images/bea.png new file mode 100644 index 0000000000..a58907136a Binary files /dev/null and b/src/main/resources/images/bea.png differ diff --git a/src/main/resources/images/beahd.png b/src/main/resources/images/beahd.png new file mode 100644 index 0000000000..d5ddb16ab2 Binary files /dev/null and b/src/main/resources/images/beahd.png differ diff --git a/src/main/resources/images/brawler-otis-brawl-render-3d-241x300-1.png b/src/main/resources/images/brawler-otis-brawl-render-3d-241x300-1.png new file mode 100644 index 0000000000..3991b5c621 Binary files /dev/null and b/src/main/resources/images/brawler-otis-brawl-render-3d-241x300-1.png differ diff --git a/src/main/resources/images/brawlstars2.jpg b/src/main/resources/images/brawlstars2.jpg new file mode 100644 index 0000000000..09cbd23ed2 Binary files /dev/null and b/src/main/resources/images/brawlstars2.jpg differ diff --git a/src/main/resources/images/emz.png b/src/main/resources/images/emz.png new file mode 100644 index 0000000000..6f8dfc5832 Binary files /dev/null and b/src/main/resources/images/emz.png differ diff --git a/src/main/resources/images/jesse.png b/src/main/resources/images/jesse.png new file mode 100644 index 0000000000..ec167332b7 Binary files /dev/null and b/src/main/resources/images/jesse.png differ diff --git a/src/main/resources/images/leon.png b/src/main/resources/images/leon.png new file mode 100644 index 0000000000..766cb38d1e Binary files /dev/null and b/src/main/resources/images/leon.png differ diff --git a/src/main/resources/images/leonhd.png b/src/main/resources/images/leonhd.png new file mode 100644 index 0000000000..87ff4bbe67 Binary files /dev/null and b/src/main/resources/images/leonhd.png differ diff --git a/src/main/resources/images/mrp.png b/src/main/resources/images/mrp.png new file mode 100644 index 0000000000..eb957a7506 Binary files /dev/null and b/src/main/resources/images/mrp.png differ diff --git a/src/main/resources/images/otis.png b/src/main/resources/images/otis.png new file mode 100644 index 0000000000..15c37e67ee Binary files /dev/null and b/src/main/resources/images/otis.png differ diff --git a/src/main/resources/images/stu.png b/src/main/resources/images/stu.png new file mode 100644 index 0000000000..b4dc09cf6e Binary files /dev/null and b/src/main/resources/images/stu.png differ diff --git a/src/main/resources/images/tick.png b/src/main/resources/images/tick.png new file mode 100644 index 0000000000..9481095ea9 Binary files /dev/null and b/src/main/resources/images/tick.png differ diff --git a/src/main/resources/stylesheet/dialogBoxStyle.css b/src/main/resources/stylesheet/dialogBoxStyle.css new file mode 100644 index 0000000000..0ab0dba47a --- /dev/null +++ b/src/main/resources/stylesheet/dialogBoxStyle.css @@ -0,0 +1,13 @@ +.user-dialog { + -fx-background-color: #c6e2ff; + -fx-background-radius: 10; + -fx-padding: 10, 10, 15, 15; + -fx-font-family: Trebuchet MS; +} + +.duke-dialog { + -fx-background-color: #e2b095; + -fx-background-radius: 10; + -fx-padding: 10, 10, 15, 15; + -fx-font-family: Trebuchet MS; +} \ No newline at end of file diff --git a/src/main/resources/view/DialogBox.fxml b/src/main/resources/view/DialogBox.fxml new file mode 100644 index 0000000000..58bf6a3a0d --- /dev/null +++ b/src/main/resources/view/DialogBox.fxml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/view/MainWindow.fxml b/src/main/resources/view/MainWindow.fxml new file mode 100644 index 0000000000..b2385f799a --- /dev/null +++ b/src/main/resources/view/MainWindow.fxml @@ -0,0 +1,19 @@ + + + + + + + + + + + +