diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..2384643c75 --- /dev/null +++ b/build.gradle @@ -0,0 +1,57 @@ +plugins { + id 'java' + id 'application' + id 'com.github.johnrengelman.shadow' version '5.1.0' + id 'checkstyle' +} + +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 { + enableAssertions = true + standardInput = System.in +} diff --git a/docs/List.png b/docs/List.png new file mode 100644 index 0000000000..f30791a36f Binary files /dev/null and b/docs/List.png differ diff --git a/docs/README.md b/docs/README.md index 8077118ebe..f95b3b181c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,150 @@ # User Guide +Introducing RoboTask, our friendly robot that helps you manage and keep track of your tasks ## Features -### Feature-ABC +### GUI Based Application -Description of the feature. +Simple to use GUI-Based command line experience + +### Task flexibility + +Compatible with 3 types of tasks - Todos, Deadlines, and Events. + +### Easy task management +Add, delete, find and mark tasks as complete with simple commands -### Feature-XYZ -Description of the feature. ## Usage -### `Keyword` - Describe action +### `list` - Displays list of tasks + -Describe the action and its outcome. Example of usage: -`keyword (optional arguments)` +`list` + +Expected outcome: + +![This is an image](List.png) + + +RoboTask provides a list of tasks + + + +### `todo` - Creates a new todo task + + +Example of usage: + +`todo ES2660 Assignment` + +Expected outcome: + +![This is an image](todo.png) + +RoboTasks creates a new todo + + + +### `deadline` - Creates a new deadline + +Creates a new deadline task with a provided date and time + +Example of usage: + +`deadline Assignment /by 2022-09-20 23:59` + +Expected outcome: + +![This is an image](deadline.png) + +RoboTask creates a new deadline + + + + +### `event` - Creates a new event + +creates a new event with a provided date and time + +Example of usage: + +`event homecoming /at 2022-02-02 12:00` + +Expected outcome: + +![This is an image](event.png) + +Robotask creats a new event + + + + +### `delete` - Deletes a task from the list + + +Example of usage: + +`delete 3` Expected outcome: -Description of the outcome. +![This is an image](delete.png) + +Robotask deletes the task + + + + +### `done` - Marks a task as complete + + +Example of usage: + +`done 2` + +Expected outcome: + +![This is an image](done.png) + +RoboTask marks a task as complete + + + + +### `find` - Finds tasks with names matching keywords + +Finds any tasks with keyword provided. + +Example of usage: + +`find homework` + +Expected outcome: + +![This is an image](find.png) + +Robotask finds tasks with matching keyword + + + + +### `view` - Views the schedule of each day + +Finds any task scheduled on a specified date + +Example of usage: + +`view 2022-02-02` + +Expected outcome: + +![This is an image](View.png) + +RoboTask shows the tasks occuring on the date + -``` -expected output -``` diff --git a/docs/Ui.png b/docs/Ui.png new file mode 100644 index 0000000000..d741a82055 Binary files /dev/null and b/docs/Ui.png differ diff --git a/docs/View.png b/docs/View.png new file mode 100644 index 0000000000..af5699727b Binary files /dev/null and b/docs/View.png differ diff --git a/docs/deadline.png b/docs/deadline.png new file mode 100644 index 0000000000..4686a28d1e Binary files /dev/null and b/docs/deadline.png differ diff --git a/docs/delete.png b/docs/delete.png new file mode 100644 index 0000000000..5548a6f6a2 Binary files /dev/null and b/docs/delete.png differ diff --git a/docs/done.png b/docs/done.png new file mode 100644 index 0000000000..2651b7e796 Binary files /dev/null and b/docs/done.png differ diff --git a/docs/event.png b/docs/event.png new file mode 100644 index 0000000000..6cfffa3d05 Binary files /dev/null and b/docs/event.png differ diff --git a/docs/find.png b/docs/find.png new file mode 100644 index 0000000000..defd1e4cad Binary files /dev/null and b/docs/find.png differ diff --git a/docs/todo.png b/docs/todo.png new file mode 100644 index 0000000000..840eebeea7 Binary files /dev/null and b/docs/todo.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/duke/Deadline.java b/src/main/java/duke/Deadline.java new file mode 100644 index 0000000000..42552e5871 --- /dev/null +++ b/src/main/java/duke/Deadline.java @@ -0,0 +1,37 @@ +package duke; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +/** + * Represents a deadline that can be created by the user + */ +public class Deadline extends Task { + private LocalDateTime date; + + /** + * Constructor used to create a new deadline object + * @param s Command containing task message and time + * @param isCompleted whether the task is completed + */ + public Deadline (String s , boolean isCompleted) { + super(s.split("/by")[0].substring(8).strip(), isCompleted); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + date = LocalDateTime.parse(s.split("/by")[1].strip(), formatter); + } + + public String toString() { + String completion = this.isComplete() ? "[X]" : "[ ]"; + return "[D]" + completion + " " + this.getTaskName() + " (by: " + + date.format(DateTimeFormatter.ofPattern("MMM d yyyy HH:mm")) + ")"; + } + /** + * Returns a formatted version of the task to store in memory + * @return formatted string representation of task + */ + public String toFormattedString() { + String completion = this.isComplete() ? "1" : "0"; + return "D | " + completion + " | " + this.getTaskName() + " | " + + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm").format(date); + } +} \ No newline at end of file diff --git a/src/main/java/duke/DialogBox.java b/src/main/java/duke/DialogBox.java new file mode 100644 index 0000000000..76196f1f5d --- /dev/null +++ b/src/main/java/duke/DialogBox.java @@ -0,0 +1,62 @@ +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) { + return new DialogBox(text, img); + } + + public static DialogBox getDukeDialog(String text, Image img) { + var 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..8ff1a51367 --- /dev/null +++ b/src/main/java/duke/Duke.java @@ -0,0 +1,63 @@ +package duke; + +/** + * Main java class to create a new Duke object + */ + +public class Duke { + private Storage storage; + private TaskList tasks; + private Ui ui; + private Parser parser; + + /** + * Consturctor to create new Duke object + * @param filePath the specified filepath to store Tasks after the program exits + */ + 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(); + } + parser = new Parser(storage, ui, tasks); + } + + /** + * Runs the Duke program + */ + public void run() { + ui.showWelcome(); + while (true) { + String command = ui.getCommand(); + try { + if (command.equals("bye")) { + break; + } else { + parser.parse(command); + } + } catch (DukeException e) { + System.out.println(e.getMessage()); + } + } + ui.showGoodbye(); + } + public String getResponse(String input) throws DukeException{ + return parser.parse(input); + } + + public String showWelcome() { + return ui.showWelcome(); + } + + public String showGoodbye() { + return ui.showGoodbye(); + } + public static void main(String[] args) { + new Duke("data/tasks.txt").run(); + } + +} diff --git a/src/main/java/duke/DukeException.java b/src/main/java/duke/DukeException.java new file mode 100644 index 0000000000..4361e957c3 --- /dev/null +++ b/src/main/java/duke/DukeException.java @@ -0,0 +1,10 @@ +package duke; + +/** + * Exception class used to customise errors specific to Duke + */ +public class DukeException extends Exception { + public DukeException (String s) { + super(s); + } +} diff --git a/src/main/java/duke/Event.java b/src/main/java/duke/Event.java new file mode 100644 index 0000000000..c7dbfe5d04 --- /dev/null +++ b/src/main/java/duke/Event.java @@ -0,0 +1,38 @@ +package duke; + +/** + * Represents an Event that can be created by the user + */ +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +public class Event extends Task { + private LocalDateTime date; + + /** + * Constructor used to create a new event object + * @param s Command containing task message and time + * @param isCompleted whether the task is completed + */ + public Event(String s, boolean isCompleted) { + super(s.split("/at")[0].substring(5).strip(), isCompleted); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + date = LocalDateTime.parse(s.split("/at")[1].strip(), formatter); + } + @Override + public String toString() { + String completion = this.isComplete() ? "[X]" : "[ ]"; + return "[E]" + completion + " " + this.getTaskName() + " (at: " + + date.format(DateTimeFormatter.ofPattern("MMM d yyyy HH:mm")) + ")"; + } + + /** + * Returns a formatted version of the task to store in memory + * @return formatted string representation of task + */ + public String toFormattedString() { + String completion = this.isComplete() ? "1" : "0"; + return "E | " + completion + " | " + this.getTaskName() + " | " + + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm").format(date); + } +} diff --git a/src/main/java/duke/Launcher.java b/src/main/java/duke/Launcher.java new file mode 100644 index 0000000000..12e9014290 --- /dev/null +++ b/src/main/java/duke/Launcher.java @@ -0,0 +1,7 @@ +package duke; +import javafx.application.Application; +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..d1dcf1d4e1 --- /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/tasks.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.show(); + } 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..31301124d8 --- /dev/null +++ b/src/main/java/duke/MainWindow.java @@ -0,0 +1,65 @@ +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().addAll( + DialogBox.getDukeDialog("Hello! I'm RoboTask\nWhat can I do for you?" + + "\n" + "(icons provided by Freepik and Trazobanana)", 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() { + try { + String input = userInput.getText(); + String response = duke.getResponse(input); + dialogContainer.getChildren().addAll( + DialogBox.getUserDialog(input, userImage), + DialogBox.getDukeDialog(response, dukeImage) + ); + userInput.clear(); + } catch (DukeException e) { + String input = userInput.getText(); + dialogContainer.getChildren().addAll( + DialogBox.getUserDialog(input, userImage), + DialogBox.getDukeDialog(e.getMessage(), dukeImage)); + userInput.clear(); + } + + } +} \ 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..e53ea6e931 --- /dev/null +++ b/src/main/java/duke/Parser.java @@ -0,0 +1,145 @@ +package duke; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +/** + * Used to parse user's commands entered and execute the command + */ +public class Parser { + private Storage s; + private Ui ui; + private TaskList tasks; + + public Parser(Storage s, Ui ui, TaskList taskList) { + this.s = s; + this.ui = ui; + this.tasks = taskList; + } + + public String parse(String command) throws DukeException { + if (command.equals("bye")) { + return executeBye(); + } else if (command.equals("list")) { + return executeList(); + } else if (command.startsWith("done")) { + return executeDone(command); + } else if (command.startsWith("delete")) { + return executeDelete(command); + } else if (command.startsWith("find")) { + return executeFind(command); + } else if (command.startsWith("todo")) { + return executeTodo(command); + } else if (command.startsWith("event")) { + return executeEvent(command); + } else if (command.startsWith("deadline")) { + return executeDeadline(command); + } else if (command.startsWith("view")) { + return executeViewShedule(command); + } else { + throw new DukeException("Sorry, I don't know what that means"); + } + } + + public String executeBye() { + return ui.showGoodbye(); + } + + public String executeList() { + String result = ""; + for (int i = 0; i < tasks.getSize(); i++) { + Task nextTask = tasks.get(i); + result += "\n" + ((i + 1) + ". " + nextTask.toString()); + } + return result; + } + + public String executeDone(String command) { + int completedIndex = Character.getNumericValue(command.charAt(5)); + Task currentTask = tasks.get(completedIndex - 1); + currentTask.setComplete(true); + s.writeFile(tasks); + return("Nice! I've marked this task as done: [X] " + currentTask.getTaskName()); + } + + public String executeDelete(String command) { + int deleteIndex = Character.getNumericValue(command.charAt(7)); + Task deletedTask = tasks.get(deleteIndex - 1); + tasks.delete(deleteIndex - 1); + s.writeFile(tasks); + return("Noted. I've removed this task:" + deletedTask.toString() + + "\nNow you have " + tasks.getSize() + " tasks in the list."); + } + + public String executeFind(String command) { + String result = ""; + result += "Here are the matching tasks in your list"; + String keyword = command.substring(5); + for (int i = 0; i < tasks.getSize(); i++) { + if(tasks.get(i).toString().contains(keyword)) { + result += "\n"+ tasks.get(i).toString() ; + } + } + return result; + } + + public String executeTodo(String command) { + try { + if (command.length() == 4) { + throw new DukeException("OOPS!!! The description of a todo cannot be empty."); + } + Task newTask = new Todo(command, false); + tasks.add(newTask); + return AddTask(); + } catch (DukeException e) { + return (e.getMessage()); + } + } + + public String executeDeadline(String command) { + try { + if (command.length() == 8) { + throw new DukeException("OOPS!!! The description of a deadline cannot be empty."); + } + Task newTask = new Deadline(command, false); + tasks.add(newTask); + return AddTask(); + } catch (DukeException e) { + return(e.getMessage()); + } + } + + public String executeEvent(String command) { + try { + if (command.length() == 5) { + throw new DukeException("OOPS!!! The description of an event cannot be empty."); + } + Task newTask = new Event(command, false); + tasks.add(newTask); + return AddTask(); + } catch (DukeException e) { + return (e.getMessage()); + } + } + + public String executeViewShedule(String command) { + String dateString = command.substring(5); + LocalDate date = LocalDate.parse(dateString); + String formattedDate = date.format(DateTimeFormatter.ofPattern("MMM d yyyy")); + String result = ""; + for (int i = 0; i < tasks.getSize(); i++) { + String taskString = tasks.get(i).toString(); + if (taskString.contains(formattedDate)) { + result += (i+1) + ". " + taskString + "\n"; + } + } + return "Here are the tasks on " + formattedDate + ":" + "\n" + result; + } + + public String AddTask() { + Task addedTask = tasks.get(tasks.getSize() - 1); + s.writeFile(tasks); + return ("Got it. I've added this task: \n" + addedTask.toString() + + "\nNow you have " + tasks.getSize() + " tasks in the list."); + } +} diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java new file mode 100644 index 0000000000..bc2204c0c3 --- /dev/null +++ b/src/main/java/duke/Storage.java @@ -0,0 +1,77 @@ +package duke; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Scanner; + +public class Storage { + private String filePath; + public Storage(String file) { + this.filePath = file; + this.checkDirectory(); + this.createFile(); + } + public void checkDirectory() { + String PATH = "./data"; + File directory = new File(PATH); + if (!directory.exists()) { + directory.mkdir(); + } + } + public void createFile() { + try { + File myObj = new File(this.filePath); + if (myObj.createNewFile()) { + System.out.println("File created: " + myObj.getName()); + } + } catch (IOException e) { + System.out.println("An error has occured"); + } + } + public ArrayList load() throws DukeException { + ArrayList tasks = new ArrayList<>(); + try { + File myObj = new File(this.filePath); + Scanner myReader = new Scanner(myObj); + while (myReader.hasNextLine()) { + String data = myReader.nextLine(); + String[] taskBreakdown = data.split("\\| "); + String taskType = taskBreakdown[0].trim(); + boolean isTaskCompleted = taskBreakdown[1].trim().equals("1"); + String taskMessage = taskBreakdown[2].trim(); + String taskDate = taskBreakdown.length > 3 ? taskBreakdown[3].trim(): ""; + + if (taskType.equals("T")) { + tasks.add(new Todo("todo " + taskMessage, isTaskCompleted)); + } + else if (taskType.equals("E")) { + tasks.add(new Event("event " + taskMessage + "/at " + taskDate, isTaskCompleted)); + } + else if (taskType.equals("D")) { + tasks.add(new Deadline("deadline" + taskMessage + "/by " + taskDate, isTaskCompleted)); + } + } + myReader.close(); + } catch (FileNotFoundException e) { + System.out.println("An error occurred. File is not found."); + } + return tasks; + } + public void writeFile(TaskList tasks) { + assert tasks != null : "Task should not be null"; + try { + FileWriter myWriter = new FileWriter(this.filePath); + for (int i = 0; i < tasks.getSize(); i++) { + Task nextTask = tasks.get(i); + myWriter.write(( nextTask.toFormattedString()) + "\n"); + } + myWriter.close(); + } catch (IOException e) { + System.out.println("An error occurred."); + e.printStackTrace(); + } + } +} diff --git a/src/main/java/duke/Task.java b/src/main/java/duke/Task.java new file mode 100644 index 0000000000..571ea7813e --- /dev/null +++ b/src/main/java/duke/Task.java @@ -0,0 +1,35 @@ +package duke; +/** + * Represents a task that can be created by the user. + */ +public class Task { + private String taskName; + private boolean isComplete; + /** + * Constructor used to create a new Task object + * @param s Command containing task message and time + * @param isComplete whether the task is completed + */ + public Task (String s, boolean isComplete) { + this.taskName = s; + this.isComplete = isComplete; + } + + public String getTaskName() { + return taskName; + } + + public boolean isComplete() { + return isComplete; + } + + public void setComplete(boolean status) { + isComplete = status; + } + + public String toFormattedString() { + String completion = this.isComplete() ? "1" : "0"; + return "- | " + completion + " | " + this.getTaskName(); + } + +} diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java new file mode 100644 index 0000000000..a2d3cd32dc --- /dev/null +++ b/src/main/java/duke/TaskList.java @@ -0,0 +1,65 @@ +package duke; +import java.util.ArrayList; + +/** + * Data structure to keep track of user's tasks + */ +public class TaskList { + private ArrayList tasks; + /** + * Constructor to create a new TaskList given an arrayList of tasks + * @param tasks ArrayList of Task objects + */ + public TaskList(ArrayList tasks) { + this.tasks = tasks; + } + /** + * Constructor to create an empty TaskList + */ + public TaskList() { + this.tasks = new ArrayList(); + } + + /** + * functional method to add a Task + * @param task + */ + public void add(Task task) { + assert task != null: "task cannot be null"; + tasks.add(task); + } + + /** + * functional method to delete a task + * @param index Index at which to delete the task at + */ + public void delete(int index) { + tasks.remove(index); + } + + /** + * functional method to retrieve a specific Task + * @param index Index where the Task is stored + * @return the Task stored at the index + */ + public Task get(int index) { + assert index < tasks.size(): "Invalid index passed"; + return tasks.get(index); + } + + /** + * Returns all Tasks stored in the data structure + * @return an ArrayList of Tasks + */ + public ArrayList getTasks() { + return tasks; + } + + /** + * Returns the number of Tasks currently stored + * @return number of Tasks + */ + public int getSize() { + return tasks.size(); + } +} diff --git a/src/main/java/duke/Todo.java b/src/main/java/duke/Todo.java new file mode 100644 index 0000000000..85972eb3b4 --- /dev/null +++ b/src/main/java/duke/Todo.java @@ -0,0 +1,29 @@ +package duke; +/** + * Represents a todo that can be created by the user + */ +public class Todo extends Task { + /** + * Constructor used to create a new todo object + * @param s Command containing task message and time + * @param isCompleted whether the task is completed + */ + public Todo (String s, boolean isCompleted) { + super(s.substring(5), isCompleted); + } + + @Override + public String toString() { + String completion = this.isComplete() ? "[X]" : "[ ]"; + return "[T]" + completion + " " + this.getTaskName(); + } + + /** + * Returns a formatted version of the task to store in memory + * @return formatted string representation of task + */ + public String toFormattedString() { + String completion = this.isComplete() ? "1" : "0"; + return "T | " + completion + " | " + this.getTaskName(); + } +} diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java new file mode 100644 index 0000000000..cc015fab43 --- /dev/null +++ b/src/main/java/duke/Ui.java @@ -0,0 +1,38 @@ +package duke; + +/** + * Used to interact with the user + */ +import java.util.Scanner; +public class Ui { + /** + * Prints welcome message for user + */ + public static String showWelcome() { + return("Hello! I'm RoboTask\nWhat can I do for you?" + + "\n" + "icons provided by Freepik and Trazobanana"); + } + + /** + * Prints error message for user + */ + public static void showLoadingError() { + System.out.println("Sorry, an error has occured"); + } + + /** + * Obtains command from user + * @return command from user + */ + public static String getCommand() { + Scanner nextCommand = new Scanner(System.in); + return nextCommand.nextLine(); + } + + /** + * Prints exit message for user + */ + public static String showGoodbye() { + return("Bye. Hope to see you again soon!"); + } +} diff --git a/src/main/resources/images/DaDuke.png b/src/main/resources/images/DaDuke.png new file mode 100644 index 0000000000..7d0b10ea2b 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..a560d75e40 Binary files /dev/null and b/src/main/resources/images/DaUser.png differ diff --git a/src/main/resources/view/DialogBox.fxml b/src/main/resources/view/DialogBox.fxml new file mode 100644 index 0000000000..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..ecde92a22d --- /dev/null +++ b/src/main/resources/view/MainWindow.fxml @@ -0,0 +1,19 @@ + + + + + + + + + + + +