diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..92043f2ac1 --- /dev/null +++ b/build.gradle @@ -0,0 +1,58 @@ +plugins { + id 'java' + id 'application' + id 'checkstyle' + id 'com.github.johnrengelman.shadow' version '5.1.0' +} + +repositories { + mavenCentral() +} + +dependencies { + String javaFxVersion = '11' + + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'linux' + implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'linux' + implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'linux' + implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'linux' +} + +test { + useJUnitPlatform() + + testLogging { + events "passed", "skipped", "failed" + + showExceptions true + exceptionFormat "full" + showCauses true + showStackTraces true + showStandardStreams = false + } +} + +application { + mainClassName = "duke.Launcher" +} + +shadowJar { + archiveBaseName = "duke" + archiveClassifier = null +} + +checkstyle { + toolVersion = '8.29' +} + +run{ + standardInput = System.in +} diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml new file mode 100644 index 0000000000..4c001417ae --- /dev/null +++ b/config/checkstyle/checkstyle.xml @@ -0,0 +1,403 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/docs/README.md b/docs/README.md index 8077118ebe..4499d24248 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,153 @@ # User Guide +This is the User Guide for PinkPandaBot your personal task +manager. + +## Quick Start +1. Ensure that Java `11` or above is installed +your computer. +2. Download the latest `PinkPandaBot.jar` from +[here](https://github.com/SimJM/ip/releases). +3. Copy the file to a folder you want to use as the +home folder for PinkPandaBot. +4. (Either) Double-click on the file to start the app. +5. (OR) Open terminal, cd into folder with PinkPandaBot.jar and enter the following command +`java -jar PinkPandaBot.jar` ## Features +- Listing all tasks: `list` +- Exiting PinkPandaBot: `bye` +- Deleting a specific task: `delete` +- Finding a specific task: `find` +- Marking a task as completed: `mark` +- Un-marking a task as incomplete: `unmark` +- Adding new todo task: `todo` +- Adding new deadline task: `deadline` +- Adding new event task: `event` +- Edit task details: `update` -### Feature-ABC +## Usage -Description of the feature. +### `list` +Shows a list of all the tasks in PinkPandaBot. -### Feature-XYZ +Example of **usage**: +`list` -Description of the feature. -## Usage +### `bye` +Closes and exits the application PinkPandaBot. + +Example of **usage**: +`bye` + +Expected outcome: +PinkPandaBot displays a bye message. + +### `delete` + +Deletes the task determined by the number from +the list. + +Example of usage: +`delete 2` + +Expected outcome: +Deletes the task number 2 from the list. + -### `Keyword` - Describe action +### `find` -Describe the action and its outcome. +Finds and lists all the tasks from the list that +matches the provided keyword (case-sensitive) -Example of usage: +Example of usage: +`find sleep` -`keyword (optional arguments)` +Expected outcome: +Finds and lists all the tasks that have the keyword +"sleep" in its description. + + +### `mark` + +Marks the task specified by the number and places +a tick on the left. + +Example of usage: +`mark 4` + +Expected outcome: +Marks the task number 4 and places a tick. + + +### `unmark` + +Unmark the task specified by the number and +removes any tick placed on the left. + +Example of usage: +`unmark 1` Expected outcome: +Unmarks and removes the tick (if any) from task +number 1. + -Description of the outcome. +### `todo` + +Creates a new todo task that has no date or time +limit. Details after the `todo` keyword is the +task description. + +Example of usage: +`todo Buy apples` + +Expected outcome: +Adds a new todo task to the list with description +"Buy Apples". + + +### `deadline` + +Creates a new deadline task with date and/or time +tracking for reminder feature. Date and/or time +entered after **/by** keyword. + +* Date Format: yyyy-mm-dd (Year-month-day, in numbers) +* Time Format: hh:mm (hours:minutes, 24-hour clock) + +Example of usage: +`deadline CS2103T iP submission /by 2022-02-17` + +Expected outcome: +Creates new deadline task with description "CS2103T iP submission" +to be completed by 17 Feb 2022. + + +### `event` + +Creates a new event task with date and/or time tracking +for reminder feature. Date and/or time entered after +**/at** keyword. + +* Date Format: yyyy-mm-dd (Year-month-day, in numbers) +* Time Format: hh:mm (hours:minutes, 24-hour clock) + +Example of usage: +`event Birthday celebration /at 2022-02-18 06:00` + +Expected outcome: +Creates a new event task that has "Birthday celebration" as +description and occurs on 18 Feb 2020 at 6:00am. + +### `update` + +Updates the task description determined by the number from +the list. + +Example of usage: +`update 2 Dad's Birthday` + +Expected outcome: +Updates the description of task number 2 to "Dad's Birthday". -``` -expected output -``` diff --git a/docs/Ui.png b/docs/Ui.png new file mode 100644 index 0000000000..2e290ee221 Binary files /dev/null and b/docs/Ui.png differ diff --git a/docs/_config.yml b/docs/_config.yml new file mode 100644 index 0000000000..c50ff38dab --- /dev/null +++ b/docs/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-merlot \ No newline at end of file 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/.idea/.gitignore b/src/main/java/.idea/.gitignore new file mode 100644 index 0000000000..26d33521af --- /dev/null +++ b/src/main/java/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/src/main/java/.idea/misc.xml b/src/main/java/.idea/misc.xml new file mode 100644 index 0000000000..e0844bc7be --- /dev/null +++ b/src/main/java/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/.idea/modules.xml b/src/main/java/.idea/modules.xml new file mode 100644 index 0000000000..122a9054e1 --- /dev/null +++ b/src/main/java/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/main/java/.idea/vcs.xml b/src/main/java/.idea/vcs.xml new file mode 100644 index 0000000000..c2365ab11f --- /dev/null +++ b/src/main/java/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file 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..6e864153e8 --- /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/Action.java b/src/main/java/duke/Action.java new file mode 100644 index 0000000000..2fbaf01d65 --- /dev/null +++ b/src/main/java/duke/Action.java @@ -0,0 +1,86 @@ +package duke; + +import java.util.ArrayList; + +/** + * Represents an Action + */ +public class Action { + + Action() {} + + /** + * Greets the user + * @return greeting + */ + public static String greet() { + String logo = "---------------------------------------------------\n" + + "P P P P A N N D D D A\n" + + "P P P P A A A N N N D D A A A\n" + + "P A A N N D D D A A\n" + + "---------------------------------------------------"; + String greeting = "Hello! I am PinkPandaBot aka\n" + logo + + "\nWelcome to my ChatBot\nTip: use 'help' for help\n"; + return greeting; + } + + /** + * prints out the input by the user. + * + * @param phrase The input by the user + */ + public static void echo(String phrase) { + System.out.println(phrase); + } + + /** + * farewell to user. + */ + public static String bye() { + String bye = "Bye. Hope to see you again soon!\n"; + return bye; + } + + /** + * Prints out the list of tasks + * + * @param arrlst List of tasks + */ + public static String showList(ArrayList arrlst) { + String output = "Here are the tasks in your list:\n"; + for (int i = 0; i < arrlst.size(); i++) { + output = output + String.format("%d.%s\n", i + 1, arrlst.get(i)); + } + return output; + } + + /** + * Find keyword in every task inside task bank. + * @param keyword The word that is being searched. + */ + public static String find(String keyword) { + boolean hasMatches = false; + String output = ""; + if (keyword.equals("")) { + output = "find description cannot be empty!\n"; + } else { + System.out.println("Here are the matching tasks in your list:"); + for (int i = 0; i < TaskBank.getSize(); i++) { + Task t = TaskBank.getBank().get(i); + if (t.getDescription().contains(keyword)) { + hasMatches = true; + output += String.format("%d. %s\n", i + 1, t); + } + } + } + + if (hasMatches) { + System.out.println(output); + return output; + } else { + System.out.println("no results found"); + return output; + } + } + +} diff --git a/src/main/java/duke/Deadline.java b/src/main/java/duke/Deadline.java new file mode 100644 index 0000000000..f363a27442 --- /dev/null +++ b/src/main/java/duke/Deadline.java @@ -0,0 +1,46 @@ +package duke; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.format.FormatStyle; + +/** + * Represents a Task of type Deadline with a day. + */ +public class Deadline extends Task { + private final String sym = "D"; + private LocalDate day; + private String dayString; + + /** + * Constructor for a Deadline + * + * @param description The details of the task + * @param day The deadline of the task in the format "yyyy-mm-dd" + */ + Deadline (String description, String day) { + super(description); + this.day = LocalDate.parse(day); + this.dayString = day; + } + + /** + * Retreives the symbol of Task + */ + public String getSym() { + return sym; + } + + /** + * Retreives the day of Task + */ + public String getDayString() { + return dayString; + } + + @Override + public String toString() { + return String.format("[%s][%s]%s (by:%s)", sym, super.getStatusIcon(), super.getDescription(), + day.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL))); + } +} diff --git a/src/main/java/duke/DialogBox.java b/src/main/java/duke/DialogBox.java new file mode 100644 index 0000000000..02597b878a --- /dev/null +++ b/src/main/java/duke/DialogBox.java @@ -0,0 +1,62 @@ +package duke; + +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; + +import java.io.IOException; +import java.util.Collections; + +/** + * An example of a custom control using FXML. + * This control represents a dialog box consisting of an ImageView to represent the speaker's face and a label + * containing text from the speaker. + */ +public class DialogBox extends HBox { + @FXML + private Label dialog; + @FXML + private ImageView displayPicture; + + private DialogBox(String text, Image img) { + try { + FXMLLoader fxmlLoader = new FXMLLoader(MainWindow.class.getResource("/view/DialogBox.fxml")); + fxmlLoader.setController(this); + fxmlLoader.setRoot(this); + fxmlLoader.load(); + } catch (IOException e) { + e.printStackTrace(); + } + + dialog.setText(text); + displayPicture.setImage(img); + } + + /** + * Flips the dialog box such that the ImageView is on the left and text on the right. + */ + private void flip() { + ObservableList tmp = FXCollections.observableArrayList(this.getChildren()); + Collections.reverse(tmp); + getChildren().setAll(tmp); + setAlignment(Pos.TOP_LEFT); + } + + public static DialogBox getUserDialog(String text, Image img) { + return new DialogBox(text, img); + } + + public static DialogBox getDukeDialog(String text, Image img) { + DialogBox db = new DialogBox(text, img); + db.flip(); + return db; + } +} + diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java new file mode 100644 index 0000000000..f18529c149 --- /dev/null +++ b/src/main/java/duke/Duke.java @@ -0,0 +1,39 @@ +package duke; + +import java.util.ArrayList; + +/** + * Duke is a bot that helps to keep track of tasks + */ +public class Duke { + /** + * Constructor for Duke + */ + public Duke() {} + + /** + * Main method + * @param args + */ + public static void main(String[] args) { + Storage storage = new Storage(); + ArrayList listOfTask = storage.readFile(); + for (int i = 0; i < listOfTask.size(); i++) { + TaskBank.getBank().add(listOfTask.get(i)); + } + Ui.start(); + storage.writeToFile(TaskBank.getBank()); + } + + /** + * You should have your own function to generate a response to user input. + * Replace this stub with your completed method. + */ + String getResponse(String input) { + Parser parser = new Parser(); + String displayMessage = parser.parse(input); + return displayMessage; + } + + +} diff --git a/src/main/java/duke/Event.java b/src/main/java/duke/Event.java new file mode 100644 index 0000000000..ff5b8e5269 --- /dev/null +++ b/src/main/java/duke/Event.java @@ -0,0 +1,48 @@ +package duke; + +import java.time.DateTimeException; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.format.FormatStyle; + +/** + * Represents a Task of type Event, includes the date. + */ + +public class Event extends Task { + private final String sym = "E"; + private final LocalDate dayAndTime; + private String dayString; + + /** + * Constructor for Event + * + * @param description - description of the task + * @param dayAndTime - The date of the task in this format "yyyy-mm-dd" + */ + Event (String description, String dayAndTime) throws DateTimeException { + super(description); + this.dayAndTime = LocalDate.parse(dayAndTime); + this.dayString = dayAndTime; + } + + /** + * Retreives the symbol of Task + */ + public String getSym() { + return sym; + } + + /** + * Retreives the day of Task + */ + public String getDayString() { + return dayString; + } + + @Override + public String toString() { + return String.format("[%s][%s] %s (at:%s)", sym, super.getStatusIcon(), super.getDescription(), + this.dayAndTime.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL))); + } +} 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..1ef5e91e76 --- /dev/null +++ b/src/main/java/duke/Main.java @@ -0,0 +1,32 @@ +package duke; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.scene.layout.AnchorPane; +import javafx.stage.Stage; + +import java.io.IOException; + +/** + * A GUI for Duke using FXML. + */ +public class Main extends Application { + + private Duke duke = new Duke(); + + @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.show(); + stage.setTitle("PinkPandaBot"); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/duke/MainWindow.java b/src/main/java/duke/MainWindow.java new file mode 100644 index 0000000000..87d99fa254 --- /dev/null +++ b/src/main/java/duke/MainWindow.java @@ -0,0 +1,52 @@ +package duke; + +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 Duke duke; + + private Image userImage = new Image(this.getClass().getResourceAsStream("/images/DaUser.png")); + private Image dukeImage = new Image(this.getClass().getResourceAsStream("/images/DaDuke.png")); + + @FXML + public void initialize() { + scrollPane.vvalueProperty().bind(dialogContainer.heightProperty()); + dialogContainer.getChildren().add(DialogBox.getDukeDialog(Action.greet(), dukeImage)); + } + + public void setDuke(Duke d) { + duke = 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 = duke.getResponse(input); + dialogContainer.getChildren().addAll( + DialogBox.getUserDialog(input, userImage), + DialogBox.getDukeDialog(response, dukeImage) + ); + userInput.clear(); + } +} diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java new file mode 100644 index 0000000000..21adf8fd63 --- /dev/null +++ b/src/main/java/duke/Parser.java @@ -0,0 +1,168 @@ +package duke; + +import java.time.format.DateTimeParseException; +import java.util.ArrayList; + +/** + * Represents a Parser + */ +public class Parser { + Parser() {} + + /** + * + * @param input The command to carry out + * @return A String that describes the command + */ + public String parse(String input) { + String dash = "____________________________________________________________"; + String[] inputArr = input.split(" "); + String output = ""; + String command = inputArr[0]; + ArrayList taskList = TaskBank.getBank(); + + switch(command) { + case "list": + output = Action.showList(taskList); + break; + case "bye": + output = Action.bye(); + break; + case "mark": + try { + int num = Integer.valueOf(inputArr[1]) - 1; + taskList.get(num).markAsDone(); + output = String.format("Nice! I've marked this task as done: %s\n", taskList.get(num)); + } catch (NumberFormatException error) { + output = "The index you have entered is not a number.\n"; + } catch (ArrayIndexOutOfBoundsException error) { + output = "The index you have entered is out of range.\n"; + } + break; + case "unmark": + try { + int num = Integer.valueOf(inputArr[1]) - 1; + taskList.get(num).markAsNotDone(); + output = String.format("OK, I've marked this task as not done yet: %s\n", taskList.get(num)); + } catch (NumberFormatException error) { + output = "The index you have entered is not a number.\n"; + } catch (ArrayIndexOutOfBoundsException error) { + output = "The index you have entered is out of range.\n"; + } + break; + case "todo": + String remainingWordsTodo = ""; + for (int i = 1; i < inputArr.length; i++) { + remainingWordsTodo = remainingWordsTodo + " " + inputArr[i]; + } + Todo td = new Todo(remainingWordsTodo); + taskList.add(td); + output = String.format("Got it. I've added this task:\n %s\n", td); + String noOfTaskTodo = String.format("Now you have %d tasks in the list.\n", taskList.size()); + output = output + noOfTaskTodo; + break; + + case "deadline": + try { + String remainingWordsDeadline = ""; + String deadline = ""; + for (int i = 1; i < inputArr.length; i++) { + if (inputArr[i].equals("/by")) { + deadline = inputArr[i + 1]; + break; + } else { + remainingWordsDeadline = remainingWordsDeadline + " " + inputArr[i]; + } + } + Deadline dl = new Deadline(remainingWordsDeadline, deadline); + taskList.add(dl); + output = String.format("Got it. I've added this task:\n %s\n", dl); + String noOfTaskDeadline = String.format("Now you have %d tasks in the list.\n", taskList.size()); + output = output + noOfTaskDeadline; + } catch (DateTimeParseException error) { + System.out.println(error); + output = "Please follow this format:\ndeadline /by YYYY-MM-DD\nUse 'help' for help"; + } catch (Exception error) { + output = "Please follow this format:\ndeadline /by YYYY-MM-DD\nUse 'help' for help"; + } + break; + case "event": + try { + String remainingWordsEvent = ""; + String dayAndTime = ""; + for (int i = 1; i < inputArr.length; i++) { + if (inputArr[i].equals("/at")) { + dayAndTime = inputArr[i + 1]; + break; + } else { + remainingWordsEvent = remainingWordsEvent + " " + inputArr[i]; + } + } + Event e = new Event(remainingWordsEvent, dayAndTime); + taskList.add(e); + output = String.format("Got it. I've added this task:\n %s\n", e); + String noOfTaskEvent = String.format("Now you have %d tasks in the list.\n", taskList.size()); + output = output + noOfTaskEvent; + } catch (DateTimeParseException error) { + output = "Please follow this format:\nevent /at YYYY-MM-DD\nUse 'help' for help"; + } catch (Exception error) { + output = "Please follow this format:\ndeadline /by YYYY-MM-DD\nUse 'help' for help"; + } + break; + case "delete": + int num = Integer.valueOf(inputArr[1]) - 1; + try { + Task d = taskList.get(num); + taskList.remove(num); + output = String.format("Noted. I've removed this task:\n %s\n", d); + String noOfTaskDelete = String.format("Now you have %d tasks in the list.\n", taskList.size()); + output = output + noOfTaskDelete; + } catch (NumberFormatException error) { + output = "The index you have entered is not a number.\n"; + } catch (ArrayIndexOutOfBoundsException error) { + output = "The index you have entered is out of range.\n"; + } catch (Exception error) { + output = "Use 'help' for help\n"; + } + break; + case "help": + output = "Please visit PinkPanda User Guide for help.\nhttps://simjm.github.io/ip/"; + break; + case "find": + try { + output = Action.find(inputArr[1]); + } catch (NumberFormatException error) { + output = "The index you have entered is not a number.\n"; + } catch (ArrayIndexOutOfBoundsException error) { + output = "The index you have entered is out of range.\n"; + } catch (Exception error) { + output = "Use 'help' for help\n"; + } + if (output.isBlank()) { + output = "No results found\n"; + } + break; + case "update": + int numToUpdate = Integer.valueOf(inputArr[1]) - 1; + String remainingWordsUpdate = ""; + try { + for (int i = 2; i < inputArr.length; i++) { + remainingWordsUpdate = remainingWordsUpdate + " " + inputArr[i]; + } + TaskBank.updateTask(numToUpdate, remainingWordsUpdate); + Task d = taskList.get(numToUpdate); + output = String.format("Noted. I've updated this task:\n %s\n", d); + } catch (NumberFormatException error) { + output = "The index you have entered is not a number.\n"; + } catch (ArrayIndexOutOfBoundsException error) { + output = "The index you have entered is out of range.\n"; + } catch (Exception error) { + output = "Use 'help' for help\n"; + } + break; + default: + output = "invalid command! Use 'help' for help"; + } + return output; + } +} diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java new file mode 100644 index 0000000000..a520b76f9e --- /dev/null +++ b/src/main/java/duke/Storage.java @@ -0,0 +1,134 @@ +package duke; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Path; +import java.util.ArrayList; + +/** + * Represents a storage that loads and save user data + */ +public class Storage { + //@@author SimJM-reused + //Reused from https://github.com/eugenechiaay/ip/blob/master/src/main/java/gene/component/TaskStorage.java + // with minor modifications + private String currentDir = System.getProperty("user.dir"); + private Path currentPath = Path.of(currentDir + File.separator + "data"); + private final File folderPath = new File(currentPath.toString()); + private final File dataPath = new File(currentPath.toString() + File.separator + "duke.txt"); + + /** + * Constructor for a Storage object + */ + public Storage(){} + + /** + * Loads the users task list from file + */ + @SuppressWarnings("Unchecked") + public ArrayList readFile() { + ArrayList toDoList = new ArrayList<>(); + try { + if (folderPath.mkdir()) { + System.out.println("Folder is created!"); + } else { + System.out.println("Folder already exists."); + } + + if (dataPath.createNewFile()) { + System.out.println("File is created!"); + } else { + System.out.println("File already exists."); + try { + FileReader fileReader = new FileReader(dataPath); + BufferedReader bufferedReader = new BufferedReader(fileReader); + String line = ""; + while ((line = bufferedReader.readLine()) != null) { + String[] tokens = line.split(" / "); + String taskDescription = tokens[1]; + switch(tokens[0]) { + case "todo": + Todo todo = new Todo(taskDescription); + toDoList.add(todo); + break; + case "deadline": + String dateDeadline = tokens[2]; + Deadline deadline = new Deadline(taskDescription, dateDeadline); + String isDone = tokens[3]; + if (isDone.equals("X")) { + deadline.markAsDone(); + } + toDoList.add(deadline); + break; + case "event": + String dateEvent = tokens[2]; + Event event = new Event(taskDescription, dateEvent); + String isMarked = tokens[3]; + if (isMarked.equals("X")) { + event.markAsDone(); + } + toDoList.add(event); + break; + default: + break; + } + } + fileReader.close(); + bufferedReader.close(); + System.out.println("file read and data transferred"); + + } catch (Exception e) { + e.printStackTrace(); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + return toDoList; + } + + /** + * Save the users tasklist to file + */ + public void writeToFile(ArrayList bank) { + try { + FileWriter fileWriter = new FileWriter(dataPath); + BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); + for (int i = 0; i < bank.size(); i++) { + Task t = bank.get(i); + String taskSym = t.getSym(); + String toWrite = ""; + switch(taskSym) { + case "T": + toWrite = "todo / " + t.getDescription() + " / " + t.getStatusIcon() + "\n"; + bufferedWriter.append(toWrite); + break; + case "D": + toWrite = "deadline / " + t.getDescription() + " / " + t.getDayString() + " / " + + t.getStatusIcon() + "\n"; + bufferedWriter.append(toWrite); + break; + case "E": + toWrite = "event / " + t.getDescription() + " / " + t.getDayString() + " / " + + t.getStatusIcon() + "\n"; + bufferedWriter.append(toWrite); + break; + default: + break; + } + } + bufferedWriter.close(); + System.out.println("saved successfully!"); + } catch (FileNotFoundException e) { + System.out.println("file not found"); + } catch (IOException e) { + System.out.println("unable to write file"); + } + } + //@@author +} diff --git a/src/main/java/duke/Task.java b/src/main/java/duke/Task.java new file mode 100644 index 0000000000..3ce59ce441 --- /dev/null +++ b/src/main/java/duke/Task.java @@ -0,0 +1,86 @@ +package duke; + +/** + * Represents a Task + */ +public class Task { + private String description; + private final String sym = "task"; + private boolean isDone; + private String dayString; + + /** + * Constructor for a task. + * + * @param description The description of the task. + */ + public Task(String description) { + this.description = description; + this.isDone = false; + this.dayString = ""; + } + + /** + * Returns the status of the task. + * + * @return A String "X" if task is done. + */ + public String getStatusIcon() { + if (isDone) { + return "X"; + } else { + assert(isDone == false); + return " "; + } + } + + /** + * Retreives the symbol of Task + */ + public String getSym() { + return sym; + } + + /** + * Retreives the day of Task + */ + public String getDayString() { + return dayString; + } + + /** + * Changes the description of the task + * @param newDescription The new description of the Task. + */ + public void updateDescription(String newDescription) { + this.description = newDescription; + } + + /** + * Returns the description of the task. + * + * @return The description of the task. + */ + public String getDescription() { + return this.description; + } + + /** + * Marks a task as done. + */ + public void markAsDone() { + this.isDone = true; + } + + /** + * Marks a task as not done. + */ + public void markAsNotDone() { + this.isDone = false; + } + + @Override + public String toString() { + return String.format("[%s] added: %s", this.getStatusIcon(), this.getDescription()); + } +} diff --git a/src/main/java/duke/TaskBank.java b/src/main/java/duke/TaskBank.java new file mode 100644 index 0000000000..72d086ba80 --- /dev/null +++ b/src/main/java/duke/TaskBank.java @@ -0,0 +1,53 @@ +package duke; + +import java.util.ArrayList; + +/** + * Represents a bank that contains tasks + */ +public class TaskBank { + private static ArrayList bank = new ArrayList<>(); + + /** + * Construtor for TaskBank + */ + public TaskBank(Storage storage) { + ArrayList memory = storage.readFile(); + for (int i = 0; i < bank.size(); i++) { + bank.add(memory.get(i)); + } + } + + /** + * Adds a task to the task bank + * @param task The task object to be added + */ + public static void addTask(Task task) { + bank.add(task); + } + + /** + * Removes a task from the task bank + * @param index The index of the task to be removed. + */ + public static void deleteTask(int index) { + bank.remove(index); + } + + /** + * Updates a task's description + * @param index + * @param newDescription + */ + public static void updateTask(int index, String newDescription) { + bank.get(index).updateDescription(newDescription); + } + + public static int getSize() { + return bank.size(); + } + + public static ArrayList getBank() { + return bank; + } +} diff --git a/src/main/java/duke/Todo.java b/src/main/java/duke/Todo.java new file mode 100644 index 0000000000..d717603c24 --- /dev/null +++ b/src/main/java/duke/Todo.java @@ -0,0 +1,28 @@ +package duke; + +/** + * Represents a Task which only has a description + */ +public class Todo extends Task { + private final String sym = "T"; + + /** + * Constructor for Todo + * @param description The description of the todo Task + */ + Todo (String description) { + super(description); + } + + /** + * Retreives the symbol of Task + */ + public String getSym() { + return sym; + } + + @Override + public String toString() { + return String.format("[%s][%s]%s", sym, super.getStatusIcon(), super.getDescription()); + } +} diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java new file mode 100644 index 0000000000..11b79f5c37 --- /dev/null +++ b/src/main/java/duke/Ui.java @@ -0,0 +1,27 @@ +package duke; + +import java.util.Scanner; + +/** + * The Ui class is responsible for dealing with user interactions. + */ +public class Ui { + /** + * Method to start the app + */ + public static void start() { + Action.greet(); + Scanner sc = new Scanner(System.in); + String input = sc.nextLine(); + Parser parser = new Parser(); + while (true) { + String displayMessage = parser.parse(input); + System.out.println(displayMessage); + if (input.equals("bye")) { + break; + } + input = sc.nextLine(); + } + sc.close(); + } +} diff --git a/src/main/java/out/production/main/.idea/.gitignore b/src/main/java/out/production/main/.idea/.gitignore new file mode 100644 index 0000000000..26d33521af --- /dev/null +++ b/src/main/java/out/production/main/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/src/main/java/out/production/main/.idea/misc.xml b/src/main/java/out/production/main/.idea/misc.xml new file mode 100644 index 0000000000..e0844bc7be --- /dev/null +++ b/src/main/java/out/production/main/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/out/production/main/.idea/modules.xml b/src/main/java/out/production/main/.idea/modules.xml new file mode 100644 index 0000000000..122a9054e1 --- /dev/null +++ b/src/main/java/out/production/main/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/main/java/out/production/main/.idea/vcs.xml b/src/main/java/out/production/main/.idea/vcs.xml new file mode 100644 index 0000000000..c2365ab11f --- /dev/null +++ b/src/main/java/out/production/main/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/out/production/main/Duke.class b/src/main/java/out/production/main/Duke.class new file mode 100644 index 0000000000..28803b4d6a Binary files /dev/null and b/src/main/java/out/production/main/Duke.class differ diff --git a/src/main/resources/images/DaDuke.png b/src/main/resources/images/DaDuke.png new file mode 100644 index 0000000000..7f971833b1 Binary files /dev/null and b/src/main/resources/images/DaDuke.png differ diff --git a/src/main/resources/images/DaUser.png b/src/main/resources/images/DaUser.png new file mode 100644 index 0000000000..1b15c48c1c Binary files /dev/null and b/src/main/resources/images/DaUser.png differ diff --git a/src/main/resources/images/DukeLogo.png b/src/main/resources/images/DukeLogo.png new file mode 100644 index 0000000000..7644de8f92 Binary files /dev/null and b/src/main/resources/images/DukeLogo.png differ diff --git a/src/main/resources/images/DukeWord.png b/src/main/resources/images/DukeWord.png new file mode 100644 index 0000000000..0eea1ac144 Binary files /dev/null and b/src/main/resources/images/DukeWord.png differ diff --git a/src/main/resources/view/DialogBox.fxml b/src/main/resources/view/DialogBox.fxml new file mode 100644 index 0000000000..9656ad5cd7 --- /dev/null +++ b/src/main/resources/view/DialogBox.fxml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/view/MainWindow.fxml b/src/main/resources/view/MainWindow.fxml new file mode 100644 index 0000000000..bad86abd4f --- /dev/null +++ b/src/main/resources/view/MainWindow.fxml @@ -0,0 +1,19 @@ + + + + + + + + + + + +