diff --git a/README.md b/README.md index 8715d4d915..63d0ad6ba4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Duke project template +# Duke.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. @@ -13,7 +13,7 @@ Prerequisites: JDK 11, update Intellij to the most recent version. 1. If there are any further prompts, accept the defaults. 1. Configure the project to use **JDK 11** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).
In the same dialog, set the **Project language level** field to the `SDK default` option. -3. After that, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: +3. After that, locate the `src/main/java/Duke.Duke.java` file, right-click it, and choose `Run Duke.Duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: ``` Hello from ____ _ diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..68296c7ae7 --- /dev/null +++ b/build.gradle @@ -0,0 +1,56 @@ +plugins { + id 'java' + id 'application' + id 'com.github.johnrengelman.shadow' version '5.1.0' +} + +repositories { + mavenCentral() +} + +dependencies { + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.5.0' + testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.5.0' + + String javaFxVersion = '11' + + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'linux' + implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'linux' + implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'linux' + implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'linux' +} + +test { + useJUnitPlatform() + + testLogging { + events "passed", "skipped", "failed" + + showExceptions true + exceptionFormat "full" + showCauses true + showStackTraces true + showStandardStreams = false + } +} + +application { + mainClassName = "Duke.Launcher" +} + +shadowJar { + archiveBaseName = "duke" + archiveClassifier = null +} + +run{ + standardInput = System.in +} diff --git a/docs/README.md b/docs/README.md index 8077118ebe..172c5e4ca4 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,179 @@ # User Guide +Hello! My name is Thanos, your personal task manager. -## Features +

+ +

-### Feature-ABC +## Table of Content +* Quick Start +* Features +* Usage -Description of the feature. +## Quick Start +* Install Java 11 or above is installed in your computer. +* Download the jar file from the repository. +* Copy the file to the preferred location you want to use and run the application. +* You can also try running the application by opening the terminal and typing `java -jar duke.jar`. +* Please press *Enter* after that. -### Feature-XYZ - -Description of the feature. +## Features + Add a ToDo task
+ Add a Deadline task
+ Add an Event task
+ Add a period task
+ View a list of your tasks
+ Mark task as done
+ Mark task as not done
+ Delete a task
+ Find the task by keyword
+ Exit chatbot ## Usage -### `Keyword` - Describe action +### `todo` - Add a ToDo task + +Adds a To Do kind of task to your list of tasks. + +**Command Format :** todo [task description] + +**Example of usage:** + +``` +todo play video game +> Got it. I've added this task: +> [T][ ] play video game +> Now you have 1 tasks in the list +``` +---- +### `deadline` - Add a Deadline task + +Adds task with deadline. + +**Command Format :** deadline [task desc] /by [yyyy-mm-dd] + +**Example of usage:** + +``` +deadline go on a date /by 2019-10-15 +> [D][ ] go on a date Oct 15 2019 +> Now you have 2 tasks in the list +``` +---- +### `event` - Add an Event task + +Adds an Event task to your task manager. + +**Command Format :** event [task desc] /from [yyyy-mm-dd] /to [yyyy-mm-dd] + +**Example of usage:** + +``` +event wedding /from 2023-09-12 /to 2023-10-12 +> [E][ ] wedding Sep 12 2023-Oct 12 2023 +> Now you have 3 tasks in the list + +``` +---- +### `periodTask` - Add a period task + +Adds a period task to your task manager. + +**Command Format :** periodTask [task desc] /between [yyyy-mm-dd] /and [yyyy-mm-dd] + +**Example of usage:** + +``` +periodTask submit book /between 2023-09-12 /and 2023-10-12 +> [E][ ] submit book Sep 12 2023-Oct 12 2023 +> Now you have 3 tasks in the list + +``` +---- +### `list` - View a list of your tasks + +Shows the list of all tasks. + +**Command Format :** list + +**Example of usage:** -Describe the action and its outcome. +``` +list +> 1.[D][ ] go on a date Oct 15 2019 +> 2.[E][ ] wedding Sep 12 2023-Oct 12 2023 + +``` +---- +### `mark` - Mark task as done + +Marks the task as done. + +**Command Format :** mark [index] + +**Example of usage:** + +``` +mark 1 +> Nice! I've marked this task as done: +> [T][X] eat +``` +---- +### `unmark` - Mark task as not done + +Marks the task as not done by replacing "X" sign with " ". + +**Command Format :** unmark [index] + +**Example of usage:** + +``` +unmark 1 +> OK, I've marked this task as not done yet: +> [T][ ] eat +``` +---- +### `delete` - Delete a task -Example of usage: +Removes the task from the task manager. -`keyword (optional arguments)` +**Command Format :** delete [index] -Expected outcome: +**Example of usage:** -Description of the outcome. +``` +delete 1 +> Noted. I've removed this task: +> [T][ ] eat +> Now you have 2 tasks in the list + +``` +---- +### `find` - Find the task by keyword + +Finds the tasks with the specified keyword. + +**Command Format :** find [keyword] + +**Example of usage:** ``` -expected output +find eat +> 1.[E][ ] eat + ``` +---- +### `bye` - Exit chatbot + +Closes the application. + +**Command Format :** bye + +**Example of usage:** + +``` +bye +> Bye mortal, I will get back to destroying galaxies +``` + + diff --git a/docs/Ui.png b/docs/Ui.png new file mode 100644 index 0000000000..db4dedd534 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/lists/taskList.txt b/lists/taskList.txt new file mode 100644 index 0000000000..eca8bc6350 --- /dev/null +++ b/lists/taskList.txt @@ -0,0 +1,6 @@ +todo can +todo ssjhfgfg +todo sfkhf +todo shf +periodTask submit notebook /between 2019-10-12 /and 2019-12-04 +deadline jfhgjhg /by 2019-12-02 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/Duke/Controllers/DialogBox.java b/src/main/java/Duke/Controllers/DialogBox.java new file mode 100644 index 0000000000..43f4ac0f0e --- /dev/null +++ b/src/main/java/Duke/Controllers/DialogBox.java @@ -0,0 +1,61 @@ +package Duke.Controllers; + +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) { + var db = new DialogBox(text, img); + db.flip(); + return db; + } +} \ No newline at end of file diff --git a/src/main/java/Duke/Controllers/MainWindow.java b/src/main/java/Duke/Controllers/MainWindow.java new file mode 100644 index 0000000000..4631d7b089 --- /dev/null +++ b/src/main/java/Duke/Controllers/MainWindow.java @@ -0,0 +1,60 @@ +package Duke.Controllers; + +import Duke.Ui; +import Duke.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 { + + private Image userImage = new Image(this.getClass().getResourceAsStream("/images/dogface.png")); + private Image dukeImage = new Image(this.getClass().getResourceAsStream("/images/thanos1.png")); + + @FXML + private ScrollPane scrollPane; + @FXML + private VBox dialogContainer; + @FXML + private TextField userInput; + @FXML + private Button sendButton; + + private Duke duke; + + + @FXML + public void initialize() { + scrollPane.vvalueProperty().bind(dialogContainer.heightProperty()); + DialogBox display = DialogBox.getDukeDialog(Ui.greet(), dukeImage); + dialogContainer.getChildren().addAll( + display + ); + } + + 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(); + } +} \ 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..ac4919b3ef --- /dev/null +++ b/src/main/java/Duke/Duke.java @@ -0,0 +1,38 @@ +package Duke; + +import javafx.application.Application; +import javafx.stage.Stage; + +/** + * Manages all initial actions to be taken before the application starts. + */ +public class Duke extends Application { + + + /** + * includes all the processes to be executed in the beginning before taking input + */ + + public Duke() { + Storage.loadData(); + } + public static void run() { + Ui.greet(); + boolean stillOn = true; + Storage.loadData(); + while(stillOn) { + Parser.makeSense(Ui.getInput()); + stillOn = Parser.parserStatus; + } + } + + @Override + public void start(Stage stage) { + } + + public String getResponse(String input) { + String result = Parser.makeSense(input.strip()); + return result; + } + +} \ No newline at end of file diff --git a/src/main/java/Duke/Exception/DukeException.java b/src/main/java/Duke/Exception/DukeException.java new file mode 100644 index 0000000000..ced22647bd --- /dev/null +++ b/src/main/java/Duke/Exception/DukeException.java @@ -0,0 +1,15 @@ +package Duke.Exception; + +/** + * handles command exception. + */ +public class DukeException extends Exception { + private String message; + + /** + * Handles command exception. + */ + public DukeException() { + this.message = "bogus"; + } +} diff --git a/src/main/java/Duke/Exception/InvalidCommandException.java b/src/main/java/Duke/Exception/InvalidCommandException.java new file mode 100644 index 0000000000..a0231c864b --- /dev/null +++ b/src/main/java/Duke/Exception/InvalidCommandException.java @@ -0,0 +1,10 @@ +package Duke.Exception; + +/** + * handles exception where the command is invalid. + */ +public class InvalidCommandException extends DukeException { + public InvalidCommandException() { + super(); + } +} diff --git a/src/main/java/Duke/Exception/NoDescriptionException.java b/src/main/java/Duke/Exception/NoDescriptionException.java new file mode 100644 index 0000000000..257e171aa2 --- /dev/null +++ b/src/main/java/Duke/Exception/NoDescriptionException.java @@ -0,0 +1,10 @@ +package Duke.Exception; + +/** + * handles an excpetion where description does not exist. + */ +public class NoDescriptionException extends DukeException { + public NoDescriptionException() { + super(); + } +} diff --git a/src/main/java/Duke/Launcher.java b/src/main/java/Duke/Launcher.java new file mode 100644 index 0000000000..488cf1d68f --- /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); + } +} \ No newline at end of file diff --git a/src/main/java/Duke/Main.java b/src/main/java/Duke/Main.java new file mode 100644 index 0000000000..f52559100e --- /dev/null +++ b/src/main/java/Duke/Main.java @@ -0,0 +1,40 @@ +package Duke; + +import Duke.Controllers.MainWindow; +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(); + + /** + * The beginning of the application. + * @param stage the primary stage for this application, onto which + * the application scene can be set. + * Applications may create other stages, if needed, but they will not be + * primary stages. + */ + @Override + public void start(Stage stage) { + try { + FXMLLoader fxmlLoader = new FXMLLoader(Main.class.getResource("/view/MainWindow.fxml")); + AnchorPane ap = fxmlLoader.load(); + Scene scene = new Scene(ap); + stage.setScene(scene); + stage.setTitle("Thanos"); + fxmlLoader.getController().setDuke(duke); + stage.show(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} \ 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..3cc7b9a356 --- /dev/null +++ b/src/main/java/Duke/Parser.java @@ -0,0 +1,97 @@ +package Duke; + +import Duke.Exception.InvalidCommandException; +import Duke.Exception.NoDescriptionException; + +/** + * A class that makes sense of all the commands and executes them + * as the appropriate function. + */ +public class Parser { + + public static Boolean parserStatus = true; //comment + + /** + * Makes sense of the string command and takes suitable action. + * @param str takes in the command + */ + public static String makeSense(String str) { + String[] forAssertion = str.split(" "); + String key = str.split(" ", 2)[0]; + String toGive=""; + switch (key) { + case "bye": + toGive = pBye(); + break; + // need to switch off service + case "list": + assert forAssertion.length == 1 : "forAssertion doesn't have a length of 1"; + toGive = TaskList.printList(); + break; + case "mark": + assert forAssertion.length == 2 : "forAssertion doesn't have a length of 2"; + toGive = pMark(Integer.parseInt(str.split(" ", 2)[1])); // function handles index + break; + case "unmark": + assert forAssertion.length == 2 : "forAssertion doesn't have a length of 2"; + toGive = pUnmark(Integer.parseInt(str.split(" ", 2)[1])); // function handles index + break; + case "delete": + assert forAssertion.length == 2 : "forAssertion doesn't have a length of 2"; + toGive = pDelete(Integer.parseInt(str.split(" ", 2)[1])); + break; + case "find": + toGive = pFind(str.split(" ", 2)[1]); + break; + default: + toGive = pAdd(str); + } + return toGive; + } + + public static String pBye() { + parserStatus = false; + return "Bye mortal, I will get back to destroying" + + " galaxies"; + } + + public static String pMark(int i) { + String str = TaskList.mark(i); + Storage.storeData(); + return str; + } + + public static String pUnmark(int i) { + String str = TaskList.unmark(i); + Storage.storeData(); + return str; + } + + public static String pDelete(int i) { + String str = TaskList.delete((i)); + Storage.storeData(); + return str; + } + + public static String pFind(String str) { + return TaskList.find(str); + } + + public static String pAdd(String str) { + String ret; + try { + ret = TaskList.add_to_list(str); + Storage.storeData(); + } + catch (InvalidCommandException e) { + ret = "the command is invalid"; + } + catch (NoDescriptionException e) { + ret = "the task needs to have a description"; + } + + return ret; + + } + +} diff --git a/src/main/java/Duke/Storage.java b/src/main/java/Duke/Storage.java new file mode 100644 index 0000000000..0411d6bc04 --- /dev/null +++ b/src/main/java/Duke/Storage.java @@ -0,0 +1,72 @@ +package Duke; + +import Duke.Exception.InvalidCommandException; +import Duke.Exception.NoDescriptionException; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +/** + * Class to store all the data in appropriate location. + */ +public class Storage { + public static File dataDir = new File(System.getProperty("user.dir") + + System.getProperty("file.separator") + "lists"); + public static File fileAddress = new File(System.getProperty("user.dir") + + System.getProperty("file.separator") + "lists" + System.getProperty("file.separator") + "taskList.txt"); + + /** + * Loads all the data in the beginning. + */ + public static void loadData() { //initialise in the beginning + try { + if (!dataDir.exists()) { + dataDir.mkdir(); + } + if (!fileAddress.exists()) { + fileAddress.createNewFile(); + } + } catch (IOException e) { + System.out.println("Something is wrong with the universe"); + } + + try { + Scanner sf = new Scanner(fileAddress); + while (sf.hasNext()) { + TaskList.add_to_list(sf.nextLine()); + } + } catch (IOException e) { + System.out.println("Something is wrong with the universe"); + } catch (InvalidCommandException e) { + System.out.println("Something is wrong with the universe"); + } catch (NoDescriptionException e) { + System.out.println("Something is wrong with the universe"); + } + } + + /** + * Stores all the data from the main storage arraylist. + */ + public static void storeData() { + try { + FileWriter fb = new FileWriter(fileAddress); + fb.write(""); + fb.close(); + + FileWriter fw = new FileWriter(fileAddress, true); + + for (int i = 0; i < TaskList.list.size(); i++) { + fw.write(TaskList.list.get(i).task_name + "\n"); + } + + fw.close(); + } catch (IOException e) { + System.out.println("Something is wrong with the universe"); + } + + } + + +} diff --git a/src/main/java/Duke/TaskList.java b/src/main/java/Duke/TaskList.java new file mode 100644 index 0000000000..8516788f5a --- /dev/null +++ b/src/main/java/Duke/TaskList.java @@ -0,0 +1,128 @@ +package Duke; + +import Duke.Exception.InvalidCommandException; +import Duke.Exception.NoDescriptionException; +import Duke.Tasks.Deadline; +import Duke.Tasks.Event; +import Duke.Tasks.PeriodTask; +import Duke.Tasks.Task; +import Duke.Tasks.Todo; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * Abstraction of an arrayList that stores all the tasks. + */ +public class TaskList { + public static ArrayList list = new ArrayList(); + + public static String printList() { + String storeTask = ""; + for(int i = 0; i < list.size(); i++) { + storeTask = storeTask + (i+1) + ". " + list.get(i).toString() + "\n"; + } + return storeTask; + } + + /** + * Gives length of arrayList. + * @return size of the arrayList. + */ + public static int getLength() { + return list.size(); + } + + /** + * marks a task as done + * @param num takes the ith number task starting from 1 + * @return string mentioning the task that has been editted. + */ + public static String mark(int num) { //Takes ith number task as argument + list.get(num - 1).toggleTrue(); + return "Nice! I've marked this task as done:\n" + list.get(num - 1).toString(); + } + + /** + * marks a task as undone + * @param num takes the ith number task starting from 1 + * @return string mentioning the task that has been editted. + */ + public static String unmark(int num) { + list.get(num - 1).toggleFalse(); + return "OK, I've marked this task as not done yet:\n" + list.get(num - 1).toString(); + } + + /** + * Deletes a task in the ArrayList. + * @param num ith number task starting from 1. + * @return string mentioning the task that has been removed. + */ + public static String delete(int num) { + String temp = "Noted. I've removed this task:\n" + " " + list.get(num-1).toString() + "\n" + + "Now you have " + (list.size() - 1) + " tasks in the list."; + list.remove(num-1); + return temp; + + } + + /** + * finds tasks with matching keywords. + * @param keyword keyword to find matching task. + * @return string listing down all the tasks. + */ + public static String find(String keyword) { + int index = 0; + String tempstr = ""; + for (Task t : list) { + String[] sample = t.toString().split(" "); + List temp = new ArrayList<>(Arrays.asList(sample)); + + if (temp.contains(keyword)) { + index++; + tempstr = tempstr + (index + "." + t.toString()); + } + } + if (index == 0) { + tempstr = ("Could not find the given word"); + } + return tempstr; + } + + /** + * adds the required task to be added + * @param str the command mentionin the type of task to be added. + * @return string affirming that the task has been added. + * @throws InvalidCommandException + * @throws NoDescriptionException + */ + public static String add_to_list(String str) throws InvalidCommandException, NoDescriptionException { + + if ((str.split(" ", 2).length == 1)) { + throw new NoDescriptionException(); + } + else if ((str.split(" ", 2)[0]).equals("todo")) { + + list.add(new Todo(str)); + } + else if ((str.split(" ", 2)[0]).equals("deadline")) { + list.add(new Deadline(str)); + } + else if ((str.split(" ", 2)[0]).equals("event")) { + list.add(new Event(str)); + } + else if ((str.split(" ", 2)[0]).equals("periodTask")) { + list.add(new PeriodTask(str)); + } + else { + throw new InvalidCommandException(); + } + int size = list.size(); + return "Got it. I've added this task:\n" + + " " + list.get(size-1).toString() + "\n" + "Now you have " + size + " tasks in the list"; + } + + +} + diff --git a/src/main/java/Duke/Tasks/Deadline.java b/src/main/java/Duke/Tasks/Deadline.java new file mode 100644 index 0000000000..e61312c0bd --- /dev/null +++ b/src/main/java/Duke/Tasks/Deadline.java @@ -0,0 +1,31 @@ +package Duke.Tasks; + +import Duke.Tasks.Task; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +public class Deadline extends Task { + + + public Deadline(String str1) { + super(str1); + } + + String[] mainSplit = super.task_name.split(" ", 2); + String name = mainSplit[1]; // gives "return book /by 2019-10-15" + String[] StrList = name.split(" /by ", 2); //gives ["return book", "2019-10-15"] + String nameMain = StrList[0]; //gives "return book" + private LocalDate byDate = LocalDate.parse(StrList[1]); //gives "2019-10-15" + + + @Override + public String toString() { + if (super.status == true) { + return "[D][X] " + nameMain + " " + byDate.format(DateTimeFormatter.ofPattern("MMM dd yyyy")); + } + else { + return "[D][ ] " + nameMain + " " + byDate.format(DateTimeFormatter.ofPattern("MMM dd yyyy")); + } + } +} diff --git a/src/main/java/Duke/Tasks/Event.java b/src/main/java/Duke/Tasks/Event.java new file mode 100644 index 0000000000..d0f188b436 --- /dev/null +++ b/src/main/java/Duke/Tasks/Event.java @@ -0,0 +1,34 @@ +package Duke.Tasks; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +public class Event extends Task { + + public Event(String str1) { + super(str1); + } + + String[] mainSplit = super.task_name.split(" ", 2); //original : "event project meeting /from 2019-10-15 /to 2019-10-15" + String name = mainSplit[1]; // gives "project meeting /from Mon 2pm /to 4pm" + String[] StrList1 = name.split(" /from ", 2); //gives ["project meeting","2019-10-15 /to 2019-10-15"] + String nameMain = StrList1[0]; //gives "project meeting" + String[] StrList2 = StrList1[1].split(" /to ", 2); //gives ["2019-10-15", "2019-10-15"] + LocalDate frm = LocalDate.parse(StrList2[0]); //gives "2019-12-01" + LocalDate to = LocalDate.parse(StrList2[1]); //gives "2019-12-02" + String finalTime = "from " + frm + " to " + to; + + + @Override + public String toString() { + if (super.status == true) { + return "[E][X] " + nameMain + " " + frm.format(DateTimeFormatter.ofPattern("MMM dd yyyy")) + + "-" + to.format(DateTimeFormatter.ofPattern("MMM dd yyyy")); + } + else { + return "[E][ ] " + nameMain + " " + frm.format(DateTimeFormatter.ofPattern("MMM dd yyyy")) + + "-" + to.format(DateTimeFormatter.ofPattern("MMM dd yyyy")); + } + } + +} diff --git a/src/main/java/Duke/Tasks/PeriodTask.java b/src/main/java/Duke/Tasks/PeriodTask.java new file mode 100644 index 0000000000..4e750a20e1 --- /dev/null +++ b/src/main/java/Duke/Tasks/PeriodTask.java @@ -0,0 +1,35 @@ +package Duke.Tasks; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +public class PeriodTask extends Task { + // Format : periodTask submit notebook /between 2019-10-15 /and 2019-10-15 + public PeriodTask(String str1) { + super(str1); + } + + String[] mainSplit = super.task_name.split(" ", 2); //original : "event project meeting /from 2019-10-15 /to 2019-10-15" + String name = mainSplit[1]; // gives submit notebook /between 2019-10-15 /and 2019-10-15 + String[] StrList1 = name.split(" /between ", 2); //gives ["submit notebook","2019-10-15 /and 2019-10-15"] + String nameMain = StrList1[0]; //gives "submit notebook" + String[] StrList2 = StrList1[1].split(" /and ", 2); //gives ["2019-10-15", "2019-10-15"] + LocalDate frm = LocalDate.parse(StrList2[0]); //gives "2019-12-01" + LocalDate to = LocalDate.parse(StrList2[1]); //gives "2019-12-02" + String finalTime = "from " + frm + " to " + to; + + + @Override + public String toString() { + if (super.status == true) { + return "[E][X] " + nameMain + " " + frm.format(DateTimeFormatter.ofPattern("MMM dd yyyy")) + + "-" + to.format(DateTimeFormatter.ofPattern("MMM dd yyyy")); + } + else { + return "[E][ ] " + nameMain + " " + frm.format(DateTimeFormatter.ofPattern("MMM dd yyyy")) + + "-" + to.format(DateTimeFormatter.ofPattern("MMM dd yyyy")); + } + } + + +} diff --git a/src/main/java/Duke/Tasks/Task.java b/src/main/java/Duke/Tasks/Task.java new file mode 100644 index 0000000000..dd6d0e314d --- /dev/null +++ b/src/main/java/Duke/Tasks/Task.java @@ -0,0 +1,25 @@ +package Duke.Tasks; + +public abstract class Task { + + public String task_name; + public boolean status; + public Task(String str) { + task_name = str; + status = false; + } + + /** + * Changes status of work done to true. + */ + public void toggleTrue() { + status = true; + } + + /** + * Changes status of work done to false. + */ + public void toggleFalse() { + status = false; + } +} diff --git a/src/main/java/Duke/Tasks/Todo.java b/src/main/java/Duke/Tasks/Todo.java new file mode 100644 index 0000000000..7117d60a30 --- /dev/null +++ b/src/main/java/Duke/Tasks/Todo.java @@ -0,0 +1,25 @@ +package Duke.Tasks; + +import Duke.Tasks.Task; + +public class Todo extends Task { + + public Todo(String str1) { + super(str1); + } + String[] mainSplit = super.task_name.split(" ", 2); + String name = mainSplit[1]; + + + @Override + public String toString() { + if(super.status == true) { + return "[T][X] " + name; + } + else { + return "[T][ ] " + name; + } + } + + +} diff --git a/src/main/java/Duke/Ui.java b/src/main/java/Duke/Ui.java new file mode 100644 index 0000000000..fcc71dccbf --- /dev/null +++ b/src/main/java/Duke/Ui.java @@ -0,0 +1,38 @@ +package Duke; + +import java.util.Scanner; + +/** + * handles all input and output of the program. + */ +public class Ui { + + private static Scanner sc = new Scanner(System.in); + + /** + * greets with welcome message when the program starts + */ + public static String greet() { + return ("Hello my name is Thanos, my hobbies are helping people maintain their schedule and " + + "destroying galaxies."); + } + + /** + * takes in string and gives output. + * @param str string to be printed + */ + public static void giveOutput(String str) { + System.out.println(str); + } + + /** + * scans for input + * @return returns input string + */ + public static String getInput() { + return sc.nextLine(); + } + + + +} diff --git a/src/main/resources/images/DaUser.png b/src/main/resources/images/DaUser.png new file mode 100644 index 0000000000..3c82f45461 Binary files /dev/null and b/src/main/resources/images/DaUser.png differ diff --git a/src/main/resources/images/dogface.png b/src/main/resources/images/dogface.png new file mode 100644 index 0000000000..ecf4a401b9 Binary files /dev/null and b/src/main/resources/images/dogface.png differ diff --git a/src/main/resources/images/thanos.jpg b/src/main/resources/images/thanos.jpg new file mode 100644 index 0000000000..8c30694682 Binary files /dev/null and b/src/main/resources/images/thanos.jpg differ diff --git a/src/main/resources/images/thanos1.png b/src/main/resources/images/thanos1.png new file mode 100644 index 0000000000..5bfd1a2c5b Binary files /dev/null and b/src/main/resources/images/thanos1.png differ diff --git a/src/main/resources/view/DialogBox.fxml b/src/main/resources/view/DialogBox.fxml new file mode 100644 index 0000000000..e433809947 --- /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..5bb5aed783 --- /dev/null +++ b/src/main/resources/view/MainWindow.fxml @@ -0,0 +1,19 @@ + + + + + + + + + + + +