diff --git a/.gitignore b/.gitignore index 2873e189e1..82a1da1a40 100644 --- a/.gitignore +++ b/.gitignore @@ -13,5 +13,8 @@ src/main/resources/docs/ *.iml bin/ +# file for saved task list +/list.txt + /text-ui-test/ACTUAL.TXT text-ui-test/EXPECTED-UNIX.TXT diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..4be9733df7 --- /dev/null +++ b/build.gradle @@ -0,0 +1,56 @@ +plugins { + id 'java' + id 'application' + id 'com.github.johnrengelman.shadow' version '7.1.2' +} + +repositories { + mavenCentral() +} + +dependencies { + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.10.0' + testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.10.0' + + String javaFxVersion = '17.0.7' + + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'linux' + implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'linux' + implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'linux' + implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'linux' +} + +test { + useJUnitPlatform() + + testLogging { + events "passed", "skipped", "failed" + + showExceptions true + exceptionFormat "full" + showCauses true + showStackTraces true + showStandardStreams = false + } +} + +application { + mainClass.set("awex.Launcher") +} + +shadowJar { + archiveBaseName = "awex" + archiveClassifier = null +} + +run{ + standardInput = System.in +} \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index 8077118ebe..b744937ed1 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,60 @@ -# User Guide +# AWEX User Guide -## Features +AWEX (A Wonderful Experience) provides you a simple, yet interactive experience while making your list of things to do, so you'll never feel alone on the path to peak productivity! -### Feature-ABC +![Screenshot of AWEX's first messages](Ui.png) -Description of the feature. +## Features -### Feature-XYZ +### Add Tasks -Description of the feature. +Input Format: -## Usage +`todo ` -### `Keyword` - Describe action +`deadline /by ` -Describe the action and its outcome. +`event /from /to ` -Example of usage: +### Mark/Unmark Tasks -`keyword (optional arguments)` +Input Format: -Expected outcome: +`mark ` -Description of the outcome. +`unmark ` + +### Find Tasks + +Input Format: + +`find ` + +### List Tasks + +Input Format: `list` + +### Delete Tasks + +Input Format: + +`delete ` + +### User Manual + +Input Format: `help` + +Response: ``` -expected output +Input type must be one of: + 1. list + 2. mark + 3. unmark + 4. todo + 5. deadline /by + 6. event /from /to + 7. delete + 8. find \n" +Type 'bye' to exit. ``` diff --git a/docs/Ui.png b/docs/Ui.png new file mode 100644 index 0000000000..4653c51683 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..033e24c4cd 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..66c01cfeba --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000000..fcb6fca147 --- /dev/null +++ b/gradlew @@ -0,0 +1,248 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + 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 +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# 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"' + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000000..6689b85bee --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java deleted file mode 100644 index 5d313334cc..0000000000 --- a/src/main/java/Duke.java +++ /dev/null @@ -1,10 +0,0 @@ -public class Duke { - public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - } -} diff --git a/src/main/java/awex/Awex.java b/src/main/java/awex/Awex.java new file mode 100644 index 0000000000..a70d28a1db --- /dev/null +++ b/src/main/java/awex/Awex.java @@ -0,0 +1,46 @@ +package awex; + +import java.io.IOException; + +public class Awex { + private Storage storage; + private TaskList tasks; + private Ui ui; + + /** + * Constructor for Awex object + */ + public Awex() { + this.storage = new Storage("./list.txt"); + this.ui = new Ui(); + try { + this.tasks = new TaskList(storage.load()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + //@@author {alex-setyawan}-reused + //adapted from https://github.com/nus-cs2103-AY2324S2/ip/pull/4/files + public String sendGreeting() { + return this.ui.greeting(); + } + //@@author + + public String getResponse(String input) { + String[] arr = input.split(" ", 2); + if (input.equals("bye")) { + return Parser.byeParser(this.storage, this.tasks, this.ui); + } else if (input.equals("help")) { + return Parser.helpParser(this.ui); + } else if (input.equals("list")) { + return Parser.listParser(arr, this.tasks, this.ui); + } else if (arr[0].equals("find")) { + return Parser.findParser(arr, this.tasks, this.ui); + } else if (arr[0].equals("mark") || arr[0].equals("unmark") || arr[0].equals("delete")) { + return Parser.markAndDeleteParser(input, arr, this.tasks, this.ui); + } else { + return Parser.taskParser(input, arr, this.tasks, this.ui); + } + } +} \ No newline at end of file diff --git a/src/main/java/awex/DialogBox.java b/src/main/java/awex/DialogBox.java new file mode 100644 index 0000000000..0c49c784e8 --- /dev/null +++ b/src/main/java/awex/DialogBox.java @@ -0,0 +1,60 @@ +package awex; + +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.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.layout.HBox; +import javafx.scene.Node; +import javafx.scene.shape.Circle; +import javafx.scene.text.Text; + +/** + * 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 Text dialog; + @FXML + private ImageView displayPicture; + + private DialogBox(String text, Image img, boolean isUser) { + try { + FXMLLoader fxmlLoader; + if (isUser) { + fxmlLoader = new FXMLLoader(MainWindow.class.getResource("/view/DialogBox.fxml")); + } else { + fxmlLoader = new FXMLLoader(MainWindow.class.getResource("/view/AwexBox.fxml")); + } + fxmlLoader.setController(this); + fxmlLoader.setRoot(this); + fxmlLoader.load(); + } catch (IOException e) { + e.printStackTrace(); + } + + Circle clip = new Circle(42, 42, 42); + dialog.setText(text); + dialog.setWrappingWidth(330); + displayPicture.setImage(img); + displayPicture.setClip(clip); + } + + //@@author {alex-setyawan}-reused + //adapted from https://github.com/nus-cs2103-AY2324S2/ip/pull/4/files + public static DialogBox getUserDialog(String text, Image img) { + return new DialogBox(text, img, true); + } + + public static DialogBox getAwexDialog(String text, Image img) { + return new DialogBox(text, img, false); + } + //@@author +} \ No newline at end of file diff --git a/src/main/java/awex/Launcher.java b/src/main/java/awex/Launcher.java new file mode 100644 index 0000000000..e6829df563 --- /dev/null +++ b/src/main/java/awex/Launcher.java @@ -0,0 +1,12 @@ +package awex; + +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/awex/Main.java b/src/main/java/awex/Main.java new file mode 100644 index 0000000000..e70b16ed1b --- /dev/null +++ b/src/main/java/awex/Main.java @@ -0,0 +1,29 @@ +package awex; + +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; +public class Main extends Application { + + private Awex awex = new Awex(); + + @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(awex); + fxmlLoader.getController().showGreeting(awex.sendGreeting()); + stage.setTitle("AWEX - A Wonderful Experience"); + stage.show(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/src/main/java/awex/MainWindow.java b/src/main/java/awex/MainWindow.java new file mode 100644 index 0000000000..f8e5204869 --- /dev/null +++ b/src/main/java/awex/MainWindow.java @@ -0,0 +1,61 @@ +package awex; + +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 Awex awex; + + private Image userImage = new Image(this.getClass().getResourceAsStream("/images/user.png")); + private Image dukeImage = new Image(this.getClass().getResourceAsStream("/images/awex.png")); + + @FXML + public void initialize() { + scrollPane.vvalueProperty().bind(dialogContainer.heightProperty()); + } + + public void setDuke(Awex a) { + awex = a; + } + + //@@author {alex-setyawan}-reused + //adapted from https://github.com/nus-cs2103-AY2324S2/ip/pull/4/files + public void showGreeting(String str) { + dialogContainer.getChildren().addAll( + DialogBox.getAwexDialog(str, dukeImage) + ); + } + //@@author + + /** + * 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 = awex.getResponse(input); + dialogContainer.getChildren().addAll( + DialogBox.getUserDialog(input, userImage), + DialogBox.getAwexDialog(response, dukeImage) + ); + userInput.clear(); + } +} \ No newline at end of file diff --git a/src/main/java/awex/Parser.java b/src/main/java/awex/Parser.java new file mode 100644 index 0000000000..273394f142 --- /dev/null +++ b/src/main/java/awex/Parser.java @@ -0,0 +1,135 @@ +package awex; + +import java.io.IOException; +import tasks.*; + +public class Parser { + + /** + * Parses user input if it is "bye" + * + * @param s Storage + * @param t TaskList + * @param ui Ui + * @return String of farewell message + */ + public static String byeParser(Storage s, TaskList t, Ui ui) { + try { + s.store(t); + } catch (IOException e) { + e.printStackTrace(); + } + return ui.farewell(); + } + + /** + * Parses user input if it is "help" + * + * @param ui Ui + * @return String of user manual + */ + public static String helpParser(Ui ui) { + return ui.allInstructions(); + } + + /** + * Parses user input if it is "list" + * + * @param arr split String of user input + * @param tasks TaskList + * @param ui Ui + * @return String of relevant response + */ + public static String listParser(String[] arr, TaskList tasks, Ui ui) { + if (arr.length > 1) { + return ui.helpMessage(); + } else if (tasks.isEmpty()) { + return ui.emptyListMessage(); + } else { + return ui.showListMessage(tasks); + } + } + + /** + * Parses user input if it starts with "find" + * + * @param arr split String array of user input + * @param tasks TaskList + * @param ui Ui + * @return String of relevant response + */ + public static String findParser(String[] arr, TaskList tasks, Ui ui) { + if (arr.length < 2) { + return ui.helpMessage(); + } else if (tasks.isEmpty()) { + return ui.emptyListMessage(); + } else { + return ui.showFindMessage(tasks, arr[1]); + } + } + + /** + * Parses user input if it starts with "mark" or "delete" + * + * @param input String of user input + * @param arr split String of user input + * @param tasks TaskList + * @param ui Ui + * @return String of relevant response + */ + public static String markAndDeleteParser(String input, String[] arr, TaskList tasks, Ui ui) { + String[] array = input.split(" "); + if (array.length != 2) { + return ui.wrongMarkDeleteFormatMessage(arr[0]); + } else { + int i = Integer.parseInt(array[1]); + int len = tasks.size(); + if (i == 0 || i > len) { + return ui.wrongIndexMessage(i, len); + } else { + if (arr[0].equals("delete")) { + return ui.deleteTaskMessage(i, tasks); + } else { + Task t = tasks.get(i - 1); + t.changeStatus(arr[0]); + return ui.changeStatusMessage(arr[0], t); + } + } + } + } + + /** + * Parses user input if it starts with "todo", "deadline" or "event" + * + * @param input String of user input + * @param arr split String of user input + * @param tasks TaskList + * @param ui Ui + * @return String of relevant response + */ + public static String taskParser(String input, String[] arr, TaskList tasks, Ui ui) { + Task t; + if (arr[0].equals("todo")) { + if (arr.length == 1) { + return ui.failedTaskCreationMessage("todo"); + } + t = TodoTask.of(arr[1]); + } else if (arr[0].equals("deadline")) { + String[] array = input.split("/"); + if (array.length != 2) { + return ui.failedTaskCreationMessage("deadline"); + } + t = DeadlineTask.of(arr[1]); + } else if (arr[0].equals("event")) { + String[] array = input.split("/"); + if (array.length != 3) { + return ui.failedTaskCreationMessage("event"); + } + t = EventTask.of(arr[1]); + } else { + return ui.helpMessage(); + } + tasks.add(t); + return ui.newTaskAddedMessage(tasks.size(), t); + } +} \ No newline at end of file diff --git a/src/main/java/awex/Storage.java b/src/main/java/awex/Storage.java new file mode 100644 index 0000000000..aeb5a55eb3 --- /dev/null +++ b/src/main/java/awex/Storage.java @@ -0,0 +1,47 @@ +package awex; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + +public class Storage { + private String filepath; + + /** + * Constructor for Storage object + * + * @param filepath path of file TaskList is saved to + */ + public Storage(String filepath) { + this.filepath = filepath; + } + + /** + * Retrieves saved TaskList information from given filepath + * + * @return File object from filepath + * @throws IOException + */ + + public File load() throws IOException { + return new File(this.filepath); + } + + /** + * Saves updated TaskList into file from given filepath + * + * @param t list of tasks + * @throws IOException + */ + public void store(TaskList t) throws IOException { + FileWriter fw = new FileWriter(this.filepath); + int len = t.size(); + assert len >= 0; + String str = ""; + for (int i = 0; i < len; i++) { + str += t.get(i).toString() + "\n"; + } + fw.write(str); + fw.close(); + } +} diff --git a/src/main/java/awex/TaskList.java b/src/main/java/awex/TaskList.java new file mode 100644 index 0000000000..44d1c0bf20 --- /dev/null +++ b/src/main/java/awex/TaskList.java @@ -0,0 +1,103 @@ +package awex; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.LinkedList; +import java.util.Scanner; +import tasks.*; + +/** + * Represents a list of saved tasks. + */ +public class TaskList { + private LinkedList tasks; + + /** + * Constructor for TaskList object + * + * @param f file object with saved tasks + */ + public TaskList(File f) throws IOException { + this.tasks = new LinkedList<>(); + if (!f.createNewFile()) { + Scanner sc = new Scanner(f); + while (sc.hasNext()) { + String[] arr = sc.nextLine().split(" / "); + if (arr[0].equals("T")) { + this.tasks.add(new TodoTask(arr[2], arr[1])); + } else if (arr[0].equals("D")) { + this.tasks.add(new DeadlineTask(arr[2], arr[1], arr[3])); + } else { + this.tasks.add(new EventTask(arr[2], arr[1], arr[3], arr[4])); + } + } + } + } + + /** + * Adds Task to TaskList + * + * @param t Task to be added + */ + public void add(Task t) { + this.tasks.add(t); + } + + /** + * Returns LinkedList of tasks that have a given string as a substring + * + * @param str + * @return list of matching tasks + */ + public LinkedList find(String str) { + LinkedList list = new LinkedList<>(); + int len = this.tasks.size(); + assert len >= 0; + for (int i = 0; i < len; i++) { + Task t = this.tasks.get(i); + if (t.isPartOfDesc(str)) { + list.add(t); + } + } + return list; + } + + /** + * Returns Task of a certain index + * + * @param i index of requested task + * @return requested task + */ + public Task get(int i) { + return this.tasks.get(i); + } + + /** + * Returns whether TaskList is empty + * + * @return true if empty, false otherwise + */ + public boolean isEmpty() { + return this.tasks.isEmpty(); + } + + /** + * Returns Task removed from TaskList + * + * @param i index of removed task + * @return removed Task + */ + public Task remove(int i) { + return this.tasks.remove(i); + } + + /** + * Returns length of TaskList + * + * @return TaskList length + */ + public int size() { + return this.tasks.size(); + } +} \ No newline at end of file diff --git a/src/main/java/awex/Ui.java b/src/main/java/awex/Ui.java new file mode 100644 index 0000000000..6ce96f986c --- /dev/null +++ b/src/main/java/awex/Ui.java @@ -0,0 +1,181 @@ +package awex; + +import java.util.LinkedList; +import tasks.Task; + +/** + * Represents an object providing all possible UI responses to the user. + */ +public class Ui { + /** + * Returns String of first message when user activates Awex. + * + * @return String of greeting message + */ + public String greeting() { + return "Hello! I'm AWEX!\n" + + "What can I do for you?"; + } + + /** + * Returns String of last message after user deactivates Awex. + * + * @return String of farewell message + */ + public String farewell() { + return "Bye. Hope to see you again soon!"; + } + + /** + * Returns explainer message with user manual. + * + * @return String of instructions + */ + public String allInstructions() { + return "Input type must be one of:\n" + + " 1. list\n" + + " 2. mark \n" + + " 3. unmark \n" + + " 4. todo \n" + + " 5. deadline /by \n" + + " 6. event /from /to \n" + + " 7. delete \n" + + " 8. find \n" + + "Type 'bye' to exit."; + } + + /** + * Returns String of uncertainty message when user gives erroneous inputs + * + * @return String of uncertainty message + */ + public String helpMessage() { + return "Sorry, I didn't understand that.\nType 'help' for instructions!"; + } + + /** + * Returns String of error message if list is empty. + * + * @return String of error message + */ + public String emptyListMessage() { + return "List is empty."; + } + + /** + * Returns String of tasks saved in list and their details + * + * @param list TaskList with saved tasks + * @return String of all tasks + */ + public String showListMessage(TaskList list) { + String str = "Here are the tasks in your list:\n"; + int len = list.size(); + assert len >= 0; + for (int i = 1; i <= len; i++) { + str += i + "." + list.get(i - 1).showAll() + "\n"; + } + return str; + } + + /** + * Returns String of tasks with a given string as a substring + * + * @param tasks TaskList with saved tasks + * @param str String each task description to be compared to + * @return String of tasks resembling substring + */ + public String showFindMessage(TaskList tasks, String str) { + String stri = "Here are the matching tasks in your list:\n"; + LinkedList list = tasks.find(str); + int len = list.size(); + assert len >= 0; + for (int i = 1; i <= len; i++) { + stri += i + "." + list.get(i - 1).showAll() + "\n"; + } + return stri; + } + + /** + * Returns String of explainer message when user gives erroneous inputs when marking, unmarking or deleting tasks. + * + * @param str the word "mark", "unmark", or "delete" + * @return String of explainer message + */ + public String wrongMarkDeleteFormatMessage(String str) { + return "Format should be '" + str + " '"; + } + + /** + * Returns String of explainer message when user provides inaccessible list index. + * + * @param i index given by user + * @param len length of TaskList + * @return String of explainer message + */ + public String wrongIndexMessage(int i, int len) { + assert len >= 0; + if (i == 0) { + return "Pick a value between 1 and " + len + "."; + } else { + return "List has only " + len + " tasks."; + } + } + + /** + * Returns String of notification message when task deleted successfully. + * + * @param i index given by user + * @param list list of tasks + * @return String of notification message + */ + public String deleteTaskMessage(int i, TaskList list) { + return "Noted. I've removed this task:\n" + + " " + list.remove(i - 1).showAll() + "\n" + + "Now you have " + list.size() + " tasks in the list."; + } + + /** + * Returns String of notification message when task marked/unmarked successfully. + * + * @param str the word "mark" or "unmark" + * @param t Task to be marked or unmarked + * @return String of notification message + */ + public String changeStatusMessage(String str, Task t) { + if (str.equals("mark")) { + return "Nice! I've marked this task as done:\n" + " " + t.showAll(); + } else { + return "OK, I've marked this task as not done yet:\n" + " " + t.showAll(); + } + } + + /** + * Returns explainer message when user provides erroneous inputs while making tasks. + * + * @param str type of tasks + * @return String of explainer message + */ + public String failedTaskCreationMessage(String str) { + if (str.equals("todo")) { + return "Format should be 'todo '"; + } else if (str.equals("deadline")) { + return "Format should be 'deadline /by '"; + } else { + return "Format should be 'event /from /to '"; + } + } + + /** + * Returns String of notification message when task saved successfully. + * + * @param i new length of list + * @param t new Task added + * @return String of notification message + */ + public String newTaskAddedMessage(int i, Task t) { + return "Got it. I've added this task:\n" + + " " + t.showAll() + "\n" + + "Now you have " + i + " tasks in the list."; + } +} \ No newline at end of file diff --git a/src/main/java/tasks/DeadlineTask.java b/src/main/java/tasks/DeadlineTask.java new file mode 100644 index 0000000000..4415f78fe4 --- /dev/null +++ b/src/main/java/tasks/DeadlineTask.java @@ -0,0 +1,58 @@ +package tasks; + +import java.time.LocalDateTime; + +/** + * Represents a task of type Deadline, + * with task description, completion status, task type, + * and deadline as available details. + */ +public class DeadlineTask extends Task { + private LocalDateTime deadline; + + /** + * Constructor for Task object of type "deadline". + * + * @param what description of the task + * @param status completion status of task + * @param deadline deadline of task + */ + public DeadlineTask(String what, String status, String deadline) { + super(what, status, "[D]"); + String[] arr = deadline.split(" "); + this.deadline = LocalDateTime.parse(arr[0] + "T" + arr[1] + ":00"); + } + + /** + * Factory method for DeadlineTask object + * + * @param str String array with task details + * @return DeadlineTask object with task details in fields + */ + public static DeadlineTask of(String str) { + String[] hasWhat = str.split("/", 2); + String[] hasWhen = hasWhat[1].split(" ", 2); + return new DeadlineTask(hasWhat[0], "f", hasWhen[1]); + } + + /** + * Returns string showing task details. + * + * @return string of task type, marked/unmarked status, description and deadline + */ + public String showAll() { + String[] arr = this.deadline.toString().split("T"); + return super.showAll() + "(by: " + arr[0] + " " + arr[1] + ")"; + } + + /** + * Returns DeadlineTask details in table row form + * + * @return String representation of DeadlineTask to be saved into txt file + */ + @Override + public String toString() { + String[] arr = this.deadline.toString().split("T"); + return "D / " + super.toString() + " / " + arr[0] + " " + arr[1]; + } +} diff --git a/src/main/java/tasks/EventTask.java b/src/main/java/tasks/EventTask.java new file mode 100644 index 0000000000..cc86b6d0e3 --- /dev/null +++ b/src/main/java/tasks/EventTask.java @@ -0,0 +1,70 @@ +package tasks; + +import java.time.LocalDateTime; + +/** + * Represents a task of type Event, + * with task description, completion status, task type, + * start time and end time as available details. + */ +public class EventTask extends Task { + private LocalDateTime start; + private LocalDateTime end; + + /** + * Constructor for EventTask object of type "event". + * + * @param what description of task + * @param status completion status of task + * @param start start time of task + * @param end end time of task + */ + public EventTask(String what, String status, String start, String end) { + super(what, status, "[E]"); + String[] startArr = start.split(" "); + String[] endArr = end.split(" "); + this.start = LocalDateTime.parse(startArr[0] + "T" + startArr[1] + ":00"); + this.end = LocalDateTime.parse(endArr[0] + "T" + endArr[1] + ":00"); + } + + /** + * Factory method for EventTask object + * + * @param str String array with task details + * @return EventTask object with task details in fields + */ + public static EventTask of(String str) { + String[] hasWhat = str.split("/", 2); + String[] hasTimes = hasWhat[1].split("/", 2); + String[] hasStart = hasTimes[0].split(" ", 2); + String[] hasEnd = hasTimes[1].split(" ", 2); + return new EventTask(hasWhat[0], "f", hasStart[1], hasEnd[1]); + } + + /** + * Returns string showing task details. + * + * @return string of task type, marked/unmarked status, description, and start and end times. + */ + public String showAll() { + String[] startArr = this.start.toString().split("T"); + String[] endArr = this.end.toString().split("T"); + return super.showAll() + + "(from: " + startArr[0] + " " + startArr[1] + + " to: " + endArr[0] + " " + endArr[1] + ")"; + } + + /** + * Returns EventTask details in table row form + * + * @return String representation of EventTask to be saved into txt file + */ + @Override + public String toString() { + String[] startArr = this.start.toString().split("T"); + String[] endArr = this.end.toString().split("T"); + return "E / " + super.toString() + + " / " + startArr[0] + " " + startArr[1] + + " / " + endArr[0] + " " + endArr[1]; + } +} diff --git a/src/main/java/tasks/Task.java b/src/main/java/tasks/Task.java new file mode 100644 index 0000000000..6e047cc34b --- /dev/null +++ b/src/main/java/tasks/Task.java @@ -0,0 +1,72 @@ +package tasks; + +/** + * Represents a task with task description, completion status and task type as available details. + */ +public class Task { + private String what; + private String status; + private String type; + + /** + * Constructor for Task object. + * + * @param what description of the task + */ + public Task(String what, String status, String type) { + this.what = what; + this.type = type; + assert status.equals("t") || status.equals("f"); + if (status.equals("t")) { + this.status = "[X]"; + } else { + this.status = "[ ]"; + } + } + + /** + * Returns string showing task details. + * + * @return string of marked/unmarked status and task description + */ + public String showAll() { + return this.type + this.status + " " + this.what; + } + + /** + * Marks tasks as done or undone. + * + * @param status completion status of task + */ + public void changeStatus(String status) { + assert status.equals("mark") || status.equals("unmark"); + if (status.equals("mark")) { + this.status = "[X]"; + } else { + this.status = "[ ]"; + } + } + + /** + * Returns boolean result of whether task description contains a given substring + * + * @param str String to be compared with task description + * @return true if String is substring of task description, false otherwise + */ + public boolean isPartOfDesc(String str) { + if (this.what.contains(str)) { + return true; + } + return false; + } + + /** + * Returns task details in table row form + * + * @return String representation of Task to be saved into txt file + */ + @Override + public String toString() { + return (this.status.equals("[X]") ? "t" : "f") + " / " + this.what; + } +} \ No newline at end of file diff --git a/src/main/java/tasks/TodoTask.java b/src/main/java/tasks/TodoTask.java new file mode 100644 index 0000000000..6574b02466 --- /dev/null +++ b/src/main/java/tasks/TodoTask.java @@ -0,0 +1,47 @@ +package tasks; + +/** + * Represents a task of type Todo, + * with task description, completion status and task type as available details. + */ +public class TodoTask extends Task { + /** + * Constructor for TodoTask object. + * + * @param what description of the task + * @param status completion status of task + */ + public TodoTask(String what, String status) { + super(what, status, "[T]"); + } + + /** + * Factory method for TodoTask object + * + * @param str String array with task description + * @return TodoTask object with task details in fields + */ + public static TodoTask of(String str) { + return new TodoTask(str, "f"); + } + + /** + * Returns string showing task details. + * + * @return string of task type, marked/unmarked status, description and deadline + */ + + public String showAll() { + return super.showAll(); + } + + /** + * Returns TodoTask details in table row form + * + * @return String representation of TodoTask to be saved into txt file + */ + @Override + public String toString() { + return "T / " + super.toString(); + } +} \ No newline at end of file diff --git a/src/main/resources/images/awex.png b/src/main/resources/images/awex.png new file mode 100644 index 0000000000..045d737ea8 Binary files /dev/null and b/src/main/resources/images/awex.png differ diff --git a/src/main/resources/images/user.png b/src/main/resources/images/user.png new file mode 100644 index 0000000000..a34571800c Binary files /dev/null and b/src/main/resources/images/user.png differ diff --git a/src/main/resources/view/AwexBox.fxml b/src/main/resources/view/AwexBox.fxml new file mode 100644 index 0000000000..e2adf4adb4 --- /dev/null +++ b/src/main/resources/view/AwexBox.fxml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/view/DialogBox.fxml b/src/main/resources/view/DialogBox.fxml new file mode 100644 index 0000000000..64baff4450 --- /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..ae91029dd9 --- /dev/null +++ b/src/main/resources/view/MainWindow.fxml @@ -0,0 +1,19 @@ + + + + + + + + + + + +