diff --git a/.gitignore b/.gitignore index 2873e189e1..b50afce371 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ bin/ /text-ui-test/ACTUAL.TXT text-ui-test/EXPECTED-UNIX.TXT + +*.class \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..a1b00de3af --- /dev/null +++ b/build.gradle @@ -0,0 +1,58 @@ +plugins { + id 'java' + id 'application' + id 'com.github.johnrengelman.shadow' version '5.1.0' + id 'org.openjfx.javafxplugin' version '0.0.13' +} + +repositories { + mavenCentral() +} + +dependencies { + String javaFxVersion = '11' + + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'linux' + implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'linux' + implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'linux' + implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'linux' + 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' + +} + +test { + useJUnitPlatform() + + testLogging { + events "passed", "skipped", "failed" + + showExceptions true + exceptionFormat "full" + showCauses true + showStackTraces true + showStandardStreams = false + } +} + +application { + mainClassName = "duke.Launcher" +} + +shadowJar { + archiveBaseName = "t4skiezxc" + archiveClassifier = null +} + +run{ + standardInput = System.in + enableAssertions = true +} diff --git a/docs/README.md b/docs/README.md index 8077118ebe..4c81f83a3e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,144 @@ # User Guide +t4skiezxc is a nostalgic chatbot that helps you manage your tasks. -## Features +1. [Quick Start](#quick-start) +2. [Features](#features) +3. [Usage](#usage) -### Feature-ABC +## Quick Start +1. Ensure that you have Java 11 or above installed +2. Download the program from [here](https://github.com/randallnhr/ip/releases) +3. Move the file into a new folder +4. Open your command terminal in the folder and run the command `java -jar t4skiezxc.jar` -Description of the feature. +## Features +> **:information_source: Note on command format** +> - All commands should be in lower-case +>- Words in `<>` are the parameters to be supplied by the user
+e.g. in `todo `, name is a parameter which can be used as `todo Homework` +>- All dates provided should be in the form of `yyyy-mm-dd`
+e.g. `deadline Assignment /by 2023-05-25` -### Feature-XYZ -Description of the feature. +| Command | Format | Example | +|:--------------------------------------------------------:|:-------------------------------------------------------------------|---------------------------------------| +| [**help**](#help---view-help) | `help` || +| [**list**](#list---list-of-tasks) | `list` || +| [**todo**](#todo---add-todo-task) | `todo ` | `todo Chores` | +| [**deadline**](#deadline---add-deadline-task) | `deadline /by ` | `deadline Homework /by 2023-05-20` | +| [**reschedule**](#reschedule---reschedule-a-task-date) | `reschedule ` | `reschedule event 2 /from 2023-05-22` | +| [**mark**](#mark---mark-task) | `mark ` | `mark 1` | +| [**unmark**](#unmark---unmark-task) | `unmark ` | `unmark 1` | +| [**find**](#find---find-similar-tasks) | `find ` | `find Homework` | ## Usage -### `Keyword` - Describe action +### `help` - View help -Describe the action and its outcome. +Displays a list of commands with its format. -Example of usage: +Format: `help` -`keyword (optional arguments)` +Example: +``` +help +``` + +### `list` - List of tasks + +Displays a list of tasks added. + +Format: `list` + +Example: +``` +list +``` + +### `todo` - Add todo task -Expected outcome: +Adds a todo task that has to be completed with no deadline. -Description of the outcome. +Format: `todo ` +Example: ``` -expected output +todo Chores +``` + +### `deadline` - Add deadline task + +Adds a deadline task that has to be completed by a given date.
+ +Format: `deadline /by ` +- Date has to be in the format yyyy-mm-dd. + +Example: +``` +deadline Homework /by 2023-05-20 +``` + +### `event` - Add event task + +Adds an event task that is happening within two given dates.
+ +Format: `event /from /to ` +- Date has to be in the format yyyy-mm-dd. + +Example: +``` +event Camping /from 2023-05-25 /to 2023-05-28 +``` + +### `reschedule` - Reschedule a task date + +Change the date of deadline or event task.
+ +Format: `reschedule ` +- Date has to be in the format yyyy-mm-dd. +- `` refers to the type of task you wish to reschedule, **deadline or event only**. +- `` refers to the index of the task as shown in the `list` command. **Must be a positive integer** +- `` refers to the date you wish to change, `/by` for deadline tasks and `/from` or `/to` for event tasks + +Example: +``` +reschedule deadline 1 /by 2023-05-20 +reschedule event 2 /from 2023-05-22 +reschedule event 3 /to 2023-05-24 +``` + +### `mark` - Mark task + +Marks a task as completed. + +Format: `mark ` +- `` refers to the index of the task as shown in the `list` command. **Must be a positive integer and within number of tasks added** + +Example: +``` +mark 1 +``` + +### `unmark` - Unmark task + +Marks a task as not completed. + +Format: `unmark ` +- `` refers to the index of the task as shown in the `list` command. **Must be a positive integer and within number of tasks added** + +Example: +``` +unmark 1 +``` + +### `find` - Find similar tasks + +Displays a list of task similar to the provided keyword. + +Format: `find ` + + +Example: ``` +find Homework +``` \ No newline at end of file diff --git a/docs/Ui.png b/docs/Ui.png new file mode 100644 index 0000000000..b5fe167a76 Binary files /dev/null and b/docs/Ui.png differ diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000..f3d88b1c2f Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..b7c8c5dbf5 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000000..2fe81a7d95 --- /dev/null +++ b/gradlew @@ -0,0 +1,183 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000000..62bd9b9cce --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,103 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java deleted file mode 100644 index 5d313334cc..0000000000 --- a/src/main/java/Duke.java +++ /dev/null @@ -1,10 +0,0 @@ -public class Duke { - public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - } -} diff --git a/src/main/java/duke/DialogBox.java b/src/main/java/duke/DialogBox.java new file mode 100644 index 0000000000..96d4d6b300 --- /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); + dialog.setWrapText(true); + 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/Duke.java b/src/main/java/duke/Duke.java new file mode 100644 index 0000000000..84d60156d5 --- /dev/null +++ b/src/main/java/duke/Duke.java @@ -0,0 +1,58 @@ +package duke; + +import java.io.IOException; + +/** + * Represents the main Duke class. + */ +public class Duke { + + private static final String SAVE_PATH = "./taskList.txt"; + private Storage storage; + private TaskList taskList; + private static final Ui UI = new Ui(); + private static final Parser PARSER = new Parser(); + + /** + * Constructor for a Duke object. + */ + public Duke() { + try { + this.storage = new Storage(SAVE_PATH); + this.taskList = storage.loadData(); + } catch (DukeException e) { + System.out.println(e.getMessage()); + } + } + + public String getResponse(String input) { + String[] inputArr = input.strip().split(" ",2); + try { + String toPrint = PARSER.readInput(inputArr, taskList); + storage.storeData(this.taskList.getTasks()); + return toPrint; + } catch (DukeException e) { + return e.getMessage(); + } + } + + public void run() throws IOException, DukeException{ + UI.start(); + String[] input = UI.readLine(); + while (!input[0].equals("bye")) { + try { + UI.displayLine(); + PARSER.readInput(input, taskList); + UI.displayLine(); + input = UI.readLine(); + } catch (DukeException e) { + System.out.println(e.getMessage()); + UI.displayLine(); + input = UI.readLine(); + } + } + UI.goodbye(); + storage.storeData(this.taskList.getTasks()); + } + +} diff --git a/src/main/java/duke/DukeException.java b/src/main/java/duke/DukeException.java new file mode 100644 index 0000000000..37aef45abc --- /dev/null +++ b/src/main/java/duke/DukeException.java @@ -0,0 +1,7 @@ +package duke; + +public class DukeException extends Exception{ + public DukeException(String m) { + super(m); + } +} diff --git a/src/main/java/duke/Launcher.java b/src/main/java/duke/Launcher.java new file mode 100644 index 0000000000..b8c0f9c373 --- /dev/null +++ b/src/main/java/duke/Launcher.java @@ -0,0 +1,9 @@ +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..9b56f8bb1b --- /dev/null +++ b/src/main/java/duke/Main.java @@ -0,0 +1,36 @@ +package duke; + +import java.io.IOException; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.scene.image.Image; +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(); + + private Image dukeImage = new Image(this.getClass().getResourceAsStream("/images/ligne-icon.png")); + + @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.setTitle("t4skiezxc"); + stage.getIcons().add(dukeImage); + 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..da892d3404 --- /dev/null +++ b/src/main/java/duke/MainWindow.java @@ -0,0 +1,59 @@ +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.*; + +/** + * 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/buddy, bleu icon.png")); + private Image dukeImage = new Image(this.getClass().getResourceAsStream("/images/ligne-icon.png")); +// +// private Image dukeBackground = new Image(this.getClass().getResourceAsStream("/images/wp10320823.jpg")); +// +// private BackgroundImage backgroundImage = new BackgroundImage(dukeBackground, BackgroundRepeat.REPEAT, BackgroundRepeat.REPEAT, BackgroundPosition.CENTER, BackgroundSize.DEFAULT); +// +// private Background background = new Background(backgroundImage); + @FXML + public void initialize() { + scrollPane.vvalueProperty().bind(dialogContainer.heightProperty()); +// scrollPane.setBackground(background); + dialogContainer.getChildren().addAll(DialogBox.getDukeDialog("Wassup! I'm your new friend, t4skiezxc!\n" + + "What poppin'?", dukeImage)); + } + + public void setDuke(Duke d) { + duke = d; + } + + /** + * Creates two dialog boxes, one echoing user input and the other containing Duke's reply and then appends them to + * the dialog container. Clears the user input after processing. + */ + @FXML + private void handleUserInput() { + String input = userInput.getText(); + String response = duke.getResponse(input); + dialogContainer.getChildren().addAll( + DialogBox.getUserDialog(input, userImage), + DialogBox.getDukeDialog(response, dukeImage) + ); + userInput.clear(); + } +} diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java new file mode 100644 index 0000000000..926d15ce8e --- /dev/null +++ b/src/main/java/duke/Parser.java @@ -0,0 +1,302 @@ +package duke; + +import java.time.LocalDate; +import java.time.format.DateTimeParseException; + +import duke.task.Task; +import duke.task.Todo; +import duke.task.Deadline; +import duke.task.Event; +import javafx.application.Platform; + +/** + * Represents a class to decipher user's commands. + */ +public class Parser { + public Parser() {}; + + /** + * Reads the command that the user input, calls the respective functions. + * @param input User's input command. + * @param taskList User's TaskList. + * @throws DukeException If user enters invalid input. + */ + public String readInput(String[] input, TaskList taskList) throws DukeException { + switch (input[0]) { + case "list": + return taskList.list(); + case "mark": + return mark(input, taskList); + case "unmark": + return unmark(input, taskList); + case "todo": + return todo(input, taskList); + case "deadline": + return deadline(input, taskList); + case "event": + return event(input, taskList); + case "delete": + return delete(input, taskList); + case "find": + return find(input, taskList); + case "reschedule": + return reschedule(input, taskList); + case "help": + return help(); + case "bye": + Platform.exit(); + return "Peace out!"; + default: + throw new DukeException("Sorry I do not understand the command :("); + } + } + + /** + * Marks a specific task as done and returns a String to notify user. + * @param input User's input + * @param taskList User's TaskList + * @return String Message to update user upon success + * @throws DukeException If user enters invalid number or task that has not been created. + */ + public String mark(String[] input, TaskList taskList) throws DukeException { + if (input.length == 1) { + throw new DukeException("Mark needs a number."); + } + int index; + try { + index = Integer.parseInt(input[1]); + } catch (NumberFormatException e) { + throw new DukeException("Invalid number."); + } + boolean isNotWithinTaskListSize = index > taskList.size(); + boolean isSmallerThan1 = index <= 0; + if (isNotWithinTaskListSize || isSmallerThan1) { + throw new DukeException("Invalid task."); + } + assert index > 0 : "Number less than equal 0."; + return taskList.markTask(index - 1); + } + + /** + * Marks a specific task as not done and returns a String to notify user. + * @param input User's input + * @param taskList User's TaskList + * @return String Message to update user upon success + * @throws DukeException If user enters invalid number or task that has not been created. + */ + public String unmark(String[] input, TaskList taskList) throws DukeException { + if (input.length == 1) { + throw new DukeException("Unmark needs a number."); + } + int index; + try { + index = Integer.parseInt(input[1]); + } catch (NumberFormatException e) { + throw new DukeException("Invalid number."); + } + boolean isNotWithinTaskListSize = index > taskList.size(); + boolean isSmallerThan1 = index <= 0; + if (isNotWithinTaskListSize || isSmallerThan1) { + throw new DukeException("Invalid task."); + } + assert index > 0 : "Number less than equal 0."; + return taskList.unmarkTask(index - 1); + } + + /** + * Adds a Todo task into the users TaskList. + * @param input User's input + * @param taskList User's TaskList + * @return String Message to update user upon success + * @throws DukeException If user did not provide name of Todo. + */ + public String todo(String[] input, TaskList taskList) throws DukeException { + if (input.length == 1) { + throw new DukeException("todo needs a description"); + } + Task t = new Todo(input[1].strip()); + taskList.addTask(t); + return "I have added a new todo:\n " + t + "\nNumber of tasks: " + taskList.size(); + } + + /** + * Adds a Deadline task into the users TaskList. + * @param input User's input + * @param taskList User's TaskList + * @return String Message to update user upon success + * @throws DukeException If user did not enter /by date or invalid date format. + */ + public String deadline(String[] input, TaskList taskList) throws DukeException { + boolean isWithoutInput = input.length == 1; + boolean isWithoutBy = !input[1].contains("/by"); + if (isWithoutInput || isWithoutBy) { + throw new DukeException("Deadline needs a /by."); + } + String[] tempInput = input[1].strip().split("/by "); + if (tempInput.length == 1) { + throw new DukeException("/by needs a date/time."); + } + try { + Task t = new Deadline(tempInput[0].strip(), tempInput[1].strip()); + taskList.addTask(t); + return "I have added a new deadline:\n " + t + "\nNumber of tasks: " + taskList.size(); + } catch (DateTimeParseException e) { + throw new DukeException("Date after /by needs to be in format yyyy-mm-dd."); + } + } + + /** + * Adds an Event task into the users TaskList. + * @param input User's input + * @param taskList User's TaskList + * @return String Message to update user upon success + * @throws DukeException If user did not enter /from or /to or invalid date format. + */ + public String event(String[] input, TaskList taskList) throws DukeException { + boolean isWithoutInput = input.length == 1; + boolean isWithoutFrom = !input[1].contains("/from"); + boolean isWithoutTo = !input[1].contains("/to"); + if (isWithoutInput || isWithoutFrom || isWithoutTo ) { + throw new DukeException("Event needs a /from and /to."); + } + String[] tempInput = input[1].split("/"); + String[] from = tempInput[1].split(" ",2); + String[] to = tempInput[2].split(" ",2); + if (from.length == 1 || to.length == 1) { + throw new DukeException("/from and /to needs a date."); + } + try { + Task t = new Event(tempInput[0].strip(), from[1].strip(), to[1].strip()); + taskList.addTask(t); + return "I have added a new event:\n " + t + "\nNumber of tasks: " + taskList.size(); + } catch (DateTimeParseException e) { + throw new DukeException("Date after /from and /to needs to be in format yyyy-mm-dd."); + } + } + + /** + * Deletes a task from the user's TaskList. + * @param input User's input + * @param taskList User's TaskList + * @return String Message to update user upon success + * @throws DukeException If user enters invalid number. + */ + public String delete(String[] input, TaskList taskList) throws DukeException { + if (input.length == 1) { + throw new DukeException("Delete needs a number."); + } + int index; + try { + index = Integer.parseInt(input[1]); + } catch (NumberFormatException e) { + throw new DukeException("Invalid number."); + } + boolean isNotWithinTaskListSize = index > taskList.size(); + boolean isSmallerThan1 = index <= 0; + if (isNotWithinTaskListSize || isSmallerThan1) { + throw new DukeException("Invalid task."); + } + assert index > 0 : "Number less than equal 0."; + return taskList.deleteTask(index - 1); + } + + /** + * Returns a String containing the user's task that matches the given keyword. + * @param input User's input + * @param taskList User's TaskList + * @return String User's task that match given keyword + * @throws DukeException If user did not enter a keyword. + */ + public String find(String[] input, TaskList taskList) throws DukeException { + if (input.length == 1) { + throw new DukeException("Find needs a keyword."); + } + return "I have found these matching tasks in your list:\n" + taskList.findTask(input[1].strip()); + } + + public String reschedule(String[] input, TaskList taskList) throws DukeException { + if (input.length == 1) { + throw new DukeException("Format: reschedule "); + } + + String[] commandArgs = input[1].split(" "); + if (commandArgs.length < 4) { + throw new DukeException("Format: reschedule "); + } + + String taskType = commandArgs[0]; + if (taskType.equals("deadline")) { + return changeDeadline(commandArgs, taskList); + } else if (taskType.equals("event")) { + return changeEvent(commandArgs, taskList); + } else { + throw new DukeException("You can only reschedule dates for deadline or event."); + } + } + + private String changeDeadline(String[] commandArgs, TaskList taskList) throws DukeException { + int index = Integer.parseInt(commandArgs[1]); + if (index > taskList.size()) { + throw new DukeException("Invalid deadline task given."); + } + + Task task = taskList.get(index - 1); + if (task instanceof Deadline == false) { + throw new DukeException("Index given not a deadline."); + } + + Deadline deadline = (Deadline) task; + if (!commandArgs[2].equals("/by")) { + throw new DukeException("Reschedule deadline needs a /by."); + } + + try { + LocalDate date = LocalDate.parse(commandArgs[3]); + return deadline.changeDate(date); + } catch (DateTimeParseException e) { + throw new DukeException("Date after /by needs to be in format yyyy-mm-dd."); + } + } + + private String changeEvent(String[] commandArgs, TaskList taskList) throws DukeException { + int index = Integer.parseInt(commandArgs[1]); + if (index > taskList.size()) { + throw new DukeException("Invalid event task given."); + } + + Task task = taskList.get(index - 1); + if (task instanceof Event == false) { + throw new DukeException("Index given not an event."); + } + + Event event = (Event) task; + String dateToChange = commandArgs[2]; + + try { + LocalDate date = LocalDate.parse(commandArgs[3]); + if (dateToChange.equals("/from")) { + return event.changeFrom(date); + } else if (dateToChange.equals("/to")) { + return event.changeTo(date); + } else { + throw new DukeException("Reschedule event needs a /from or /to."); + } + } catch (DateTimeParseException e) { + throw new DukeException("Date after /from or /to needs to be in format yyyy-mm-dd."); + } + } + + public String help() { + return "I only understand these commands:\n" + + "list\n" + + "bye\n" + + "todo \n" + + "deadline /by \n" + + "event /from /to \n" + + "reschedule \n" + + "mark \n" + + "unmark \n" + + "find \n" + + "help"; + } +} diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java new file mode 100644 index 0000000000..4ecbafef08 --- /dev/null +++ b/src/main/java/duke/Storage.java @@ -0,0 +1,100 @@ +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; + +import duke.task.Task; +import duke.task.Todo; +import duke.task.Deadline; +import duke.task.Event; + +/** + * Represents a class used to store and load user's tasks from Duke chatbot. + */ +public class Storage { + private String filePath; + + /** + * Constructor for a Storage object. + * @param filePath Relative path of taskList.txt file. + */ + public Storage(String filePath) { + this.filePath = filePath; + } + + /** + * Loads a TaskList from taskList.txt. + * @return TaskList containing user's saved tasks. + * @throws DukeException If file could not be read. + */ + public TaskList loadData() throws DukeException { + TaskList taskList = new TaskList(); + File file = new File(this.filePath); + try { + if (file.createNewFile()){ + return taskList; + } + assert file.exists() : "File was not successfully created."; + } catch (IOException e) { + throw new DukeException("Something went wrong when accessing file"); + } + Scanner sc; + try { + sc = new Scanner(file); + } catch (FileNotFoundException e) { + throw new DukeException("Unable to read file"); + } + + while (sc.hasNextLine()) { + try { + Task task; + String[] line = sc.nextLine().split("\\|"); + if (line[0].equals("T")) { + task = new Todo(line[2].strip()); + } else if (line[0].equals("D")) { + task = new Deadline(line[2], line[3]); + } else { + task = new Event(line[2], line[3], line[4]); + } + + if (line[1].equals("1")) { + task.mark(); + } + + taskList.addTask(task); + } catch (DukeException e) { + System.out.println(e.getMessage()); + } + } + sc.close(); + return taskList; + } + + /** + * Store user's tasks in a taskList.txt file in given relative file path. + * @param t User's tasks to store. + * @throws DukeException If unable to save file. + */ + public void storeData(ArrayList t) throws DukeException { + File file = new File(this.filePath); + try { + if (file.createNewFile()) { + System.out.println("Created new file taskList.txt"); + } + assert file.exists() : "File was not successfully created."; + FileWriter fw = new FileWriter(file); + String taskString = ""; + for (int i = 0; i < t.size(); i++){ + taskString += t.get(i).getFileDesc() + "\n"; + } + fw.write(taskString); + fw.close(); + } catch (IOException e) { + throw new DukeException("Unable to save to file"); + } + } +} diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java new file mode 100644 index 0000000000..fcabac58a4 --- /dev/null +++ b/src/main/java/duke/TaskList.java @@ -0,0 +1,112 @@ +package duke; + +import java.util.ArrayList; +import java.util.Iterator; + +import duke.task.Task; + +/** + * Represents a class to store a user's tasks. + */ +public class TaskList { + private ArrayList tasks; + private int count; + + /** + * Constructor for a TaskList object. + */ + public TaskList() { + this.tasks = new ArrayList<>(); + } + + /** + * Prints the user's tasks in list form. + */ + public String list() { + int curr = 1; + String toPrint = "Here are your tasks:\n"; + Iterator iter = this.tasks.iterator(); + while (iter.hasNext()) { + Task task = iter.next(); + toPrint += curr + ". " + task + "\n"; + curr++; + } + return toPrint; + } + + /** + * Prints the user's tasks that matches keyword in list form. + */ + public String findTask(String keyword) { + int curr = 1; + String toPrint = ""; + Iterator iter = this.tasks.iterator(); + while (iter.hasNext()) { + Task task = iter.next(); + if (task.getName().contains(keyword)) { + toPrint += curr + ". " + task + "\n"; + curr++; + } + } + return toPrint; + } + + /** + * Adds a task to the user's TaskList. + * @param t Task to be added. + */ + public void addTask(Task t) { + this.tasks.add(t); + count++; + } + + /** + * Removes a task from the user's TaskList. + * @param i Index of task to be deleted. + */ + public String deleteTask(int i) { + Task t = this.tasks.remove(i); + count--; + return "I have deleted the task:\n " + t + "\nNumber of tasks: " + count; + } + + /** + * Marks the given task as completed. + * @param i Index of task to be marked. + */ + public String markTask(int i) { + Task t = this.tasks.get(i); + t.mark(); + return "Sick! I have marked the task as done:\n " + t; + } + + /** + * Unmarks the given task as completed. + * @param i Index of task to be unmarked. + */ + public String unmarkTask(int i) { + Task t = this.tasks.get(i); + t.unmark(); + return "Nuuu! I have marked the task as not done:\n " + t; + } + + /** + * Returns the number of tasks in the user's TaskList. + * @return int Number of tasks + */ + public int size() { + return count; + } + + /** + * Returns the user's tasks in an ArrayList. + * @return ArrayList User's task + */ + public ArrayList getTasks() { + return this.tasks; + } + + public Task get(int i) { + return this.tasks.get(i); + } +} diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java new file mode 100644 index 0000000000..64560a4102 --- /dev/null +++ b/src/main/java/duke/Ui.java @@ -0,0 +1,44 @@ +package duke; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class Ui { + private BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + /** + * Prints a greeting message when the program starts. + */ + public void start() { + System.out.println("Hello! I'm Duke!\n" + + "What can I do for you?"); + displayLine(); + } + + /** + * Reads the input from the command line and returns an array of String with index 0 as the first word. + * @return array of String with index 0 as the first word + * @throws IOException On input error + */ + public String[] readLine() throws IOException { + System.out.print("Type your command: "); + return br.readLine().strip().split(" ",2); + } + + /** + * Returns a line to separate user commands and output. + * @return String Line + */ + public String displayLine() { + return "_________________________________________\n"; + } + + /** + * Prints a goodbye message when a bye command is entered. + */ + public void goodbye() { + displayLine(); + System.out.println("Goodbye!"); + } +} diff --git a/src/main/java/duke/task/Deadline.java b/src/main/java/duke/task/Deadline.java new file mode 100644 index 0000000000..d7f8cd6068 --- /dev/null +++ b/src/main/java/duke/task/Deadline.java @@ -0,0 +1,27 @@ +package duke.task; + +import java.time.LocalDate; + +public class Deadline extends Task { + private LocalDate deadline; + public Deadline(String name, String start) { + super(name); + this.deadline = LocalDate.parse(start); + } + + public String changeDate(LocalDate date) { + this.deadline = date; + return "I have changed the date:\n" + + this.toString(); + } + + @Override + public String getFileDesc() { + return "D|" + super.getFileDesc() + "|" + convertFileDate(this.deadline); + } + + @Override + public String toString() { + return "[D]" + super.toString() + " (by: " + getDate(this.deadline) + ")"; + } +} \ No newline at end of file diff --git a/src/main/java/duke/task/Event.java b/src/main/java/duke/task/Event.java new file mode 100644 index 0000000000..3a01e9157f --- /dev/null +++ b/src/main/java/duke/task/Event.java @@ -0,0 +1,40 @@ +package duke.task; + +import java.time.LocalDate; + +import duke.DukeException; + +public class Event extends Task { + private LocalDate from; + private LocalDate to; + public Event(String name, String start, String end) throws DukeException { + super(name); + this.from = LocalDate.parse(start); + this.to = LocalDate.parse(end); + if (this.from.isAfter(this.to)) { + throw new DukeException("/to date is before /from date"); + } + } + + public String changeFrom(LocalDate date) { + this.from = date; + return "I have changed the /from date:\n" + + this.toString(); + } + + public String changeTo(LocalDate date) { + this.to = date; + return "I have changed the /to date\n" + + this.toString(); + } + + @Override + public String getFileDesc() { + return "E|" + super.getFileDesc() + "|" + convertFileDate(this.from) + "|" + convertFileDate(this.to); + } + + @Override + public String toString() { + return "[E]" + super.toString() + " (from: " + getDate(this.from) + " to: " + getDate(this.to) + ")"; + } +} \ No newline at end of file diff --git a/src/main/java/duke/task/Task.java b/src/main/java/duke/task/Task.java new file mode 100644 index 0000000000..a543e0c877 --- /dev/null +++ b/src/main/java/duke/task/Task.java @@ -0,0 +1,50 @@ +package duke.task; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +public class Task { + protected String name; + protected boolean isDone; + + public Task(String name) { + this.name = name; + this.isDone = false; + } + + public String getDate(LocalDate date) { + DateTimeFormatter format = DateTimeFormatter.ofPattern("MMM dd yyy"); + return date.format(format); + } + + public String getName() { + return this.name; + } + + public String convertFileDate(LocalDate date) { + DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + return date.format(format); + } + + public void mark() { + this.isDone = true; + } + + + public void unmark() { + this.isDone = false; + } + + public String getFileDesc() { + return this.isDone + ? "1|" + this.name + : "0|" + this.name; + } + + @Override + public String toString() { + return this.isDone + ? "[X] " + this.name + : "[ ] " + this.name; + } +} \ No newline at end of file diff --git a/src/main/java/duke/task/Todo.java b/src/main/java/duke/task/Todo.java new file mode 100644 index 0000000000..5e271ae320 --- /dev/null +++ b/src/main/java/duke/task/Todo.java @@ -0,0 +1,17 @@ +package duke.task; + +public class Todo extends Task { + public Todo(String name) { + super(name); + } + + @Override + public String getFileDesc() { + return "T|" + super.getFileDesc(); + } + + @Override + public String toString() { + return "[T]" + super.toString(); + } +} \ No newline at end of file diff --git a/src/main/resources/images/DaDuke.png b/src/main/resources/images/DaDuke.png new file mode 100644 index 0000000000..d893658717 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..3c82f45461 Binary files /dev/null and b/src/main/resources/images/DaUser.png differ diff --git a/src/main/resources/images/buddy, bleu icon.png b/src/main/resources/images/buddy, bleu icon.png new file mode 100644 index 0000000000..6f56e025e8 Binary files /dev/null and b/src/main/resources/images/buddy, bleu icon.png differ diff --git a/src/main/resources/images/ligne-icon.png b/src/main/resources/images/ligne-icon.png new file mode 100644 index 0000000000..7d45bc3399 Binary files /dev/null and b/src/main/resources/images/ligne-icon.png differ diff --git a/src/main/resources/images/wp10320823.jpg b/src/main/resources/images/wp10320823.jpg new file mode 100644 index 0000000000..1f2172fce2 Binary files /dev/null and b/src/main/resources/images/wp10320823.jpg differ diff --git a/src/main/resources/view/DialogBox.fxml b/src/main/resources/view/DialogBox.fxml new file mode 100644 index 0000000000..5d75ab8bf6 --- /dev/null +++ b/src/main/resources/view/DialogBox.fxml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/view/Duke.css b/src/main/resources/view/Duke.css new file mode 100644 index 0000000000..65e38b6cb1 --- /dev/null +++ b/src/main/resources/view/Duke.css @@ -0,0 +1,36 @@ +#dialog { + -fx-background-color: #f8f8ff; + -fx-background-radius: 8px; + -fx-border-color: black; + -fx-border-width: 2px; + -fx-padding: 7px; + -fx-border-radius: 6px; + -fx-scale-shape: true; + -fx-font-weight: bold; + -fx-font-size: 15; + -fx-font-family: "Comic Sans MS"; + -fx-effect: dropshadow(gaussian, black, 5,0,0,0); +} + +#pictureBorder { + -fx-background-color: #f8f8ff; + -fx-background-radius: 8px; + -fx-border-color: #0000cd; + -fx-border-width: 2px; + -fx-border-radius: 6px; + -fx-border-style: solid; + -fx-effect: dropshadow(gaussian, black, 5,0,0,0); +} + +#dialogContainer { + -fx-background-image: url("https://wallpapercave.com/wp/wp10320826.jpg"); + -fx-background-size: stretch; +} + +#userInput { + -fx-background-color: #f8f8ff; +} + +#sendButton { + -fx-font-family: "Comic Sans MS"; +} diff --git a/src/main/resources/view/MainWindow.fxml b/src/main/resources/view/MainWindow.fxml new file mode 100644 index 0000000000..9b4071db18 --- /dev/null +++ b/src/main/resources/view/MainWindow.fxml @@ -0,0 +1,26 @@ + + + + + + + + + + + +