Skip to content

Commit

Permalink
Level-10: Fixed the response handling to now be linked to the GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhl2000 committed Sep 19, 2022
1 parent dca98d2 commit 6f856c9
Show file tree
Hide file tree
Showing 25 changed files with 205 additions and 128 deletions.
13 changes: 7 additions & 6 deletions src/main/java/command/ByeCommand.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package command;

import duke.Storage;
import duke.TaskList;
import duke.Ui;
import exception.DukeException;
import exception.DukeFileAddressInvalidException;
import main.Storage;
import main.TaskList;
import main.Ui;
import task.Task;

/**
Expand All @@ -15,6 +15,7 @@
public class ByeCommand extends Command {

private String logFileAddress = "";
private Ui ui;

public ByeCommand() {
}
Expand Down Expand Up @@ -42,15 +43,15 @@ public boolean isEnd() {
* @param storage
* @throws DukeException
*/
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
public String execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
if (!this.verifyAddress(this.logFileAddress)) {
throw new DukeFileAddressInvalidException("User file address invalid, please check pathing");
}
try {
if (this.logFileAddress.equals("")) {
storage.cleanUp();
return ui.bye(storage.cleanUp());
} else {
storage.cleanUp(this.logFileAddress);
return ui.bye(storage.cleanUp(this.logFileAddress));
}
} catch (DukeException e) {
throw e;
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/command/Command.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package command;

import duke.Storage;
import duke.TaskList;
import duke.Ui;
import exception.DukeException;
import main.Storage;
import main.TaskList;
import main.Ui;
import task.Task;
/**
* Abstract class thats represents a user inputted command to the chatbot.
Expand All @@ -22,8 +22,7 @@ public boolean isEnd() {
return false;
}

public abstract void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException; //Referenced from Marcus Ong Wee's code
public abstract String execute(TaskList tasks, Ui ui, Storage storage) throws DukeException; //Referenced from Marcus Ong Wee's code

public abstract Task getTask() throws DukeException;

}
10 changes: 5 additions & 5 deletions src/main/java/command/DeadlineCommand.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package command;

import duke.Storage;
import duke.TaskList;
import duke.Ui;
import exception.DukeException;
import exception.InvalidDateException;
import exception.MissingArgumentException;
import main.Storage;
import main.TaskList;
import main.Ui;
import task.Deadline;
import task.Task;

Expand Down Expand Up @@ -52,11 +52,11 @@ public boolean isEnd() {
* @param storage
* @throws DukeException
*/
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
public String execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
try {
Task newDeadline = this.getTask();
tasks.add(newDeadline);
ui.add(newDeadline);
return ui.add(newDeadline);
} catch (DukeException e) {
throw e;
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/command/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package command;

import duke.Storage;
import duke.TaskList;
import duke.Ui;
import exception.DukeException;
import exception.TaskListOutOfBoundsException;
import main.Storage;
import main.TaskList;
import main.Ui;
import task.Task;

/**
Expand Down Expand Up @@ -37,10 +37,10 @@ public boolean isEnd() {
* @param storage
* @throws DukeException
*/
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException{
try {
ui.delete(this.pos);
public String execute(TaskList tasks, Ui ui, Storage storage) throws DukeException{
try {
tasks.delete(this.pos);
return ui.delete(this.pos);
} catch (TaskListOutOfBoundsException e) {
throw new DukeException(e.getLocalizedMessage());
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/command/EventCommand.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package command;

import duke.Storage;
import duke.TaskList;
import duke.Ui;
import exception.DukeException;
import exception.InvalidDateException;
import exception.MissingArgumentException;
import main.Storage;
import main.TaskList;
import main.Ui;
import task.Event;
import task.Task;

Expand Down Expand Up @@ -48,11 +48,11 @@ public boolean isEnd() {
* @param storage
* @throws DukeException
*/
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
public String execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
try {
Task newEvent = this.getTask();
tasks.add(newEvent);
ui.add(newEvent);
return ui.add(newEvent);
} catch (DukeException e) {
throw e;
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/command/FindCommand.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package command;

import main.Storage;
import main.TaskList;
import main.Ui;
import duke.Storage;
import duke.TaskList;
import duke.Ui;
import task.Task;

public class FindCommand extends Command{
Expand All @@ -19,8 +19,8 @@ public boolean isEnd() {
return false;
}

public void execute(TaskList tasks, Ui ui, Storage storage) {
ui.list(tasks.search(keyword), true);
public String execute(TaskList tasks, Ui ui, Storage storage) {
return ui.list(tasks.search(keyword), true);
}

@Override
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/command/ListCommand.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package command;

import main.Storage;
import main.TaskList;
import main.Ui;
import duke.Storage;
import duke.TaskList;
import duke.Ui;
import task.Task;

public class ListCommand extends Command {
Expand All @@ -29,9 +29,8 @@ public boolean isEnd() {
* @param ui
* @param storage
*/
public void execute(TaskList tasks, Ui ui, Storage storage) {
ui.list(tasks, false);

public String execute(TaskList tasks, Ui ui, Storage storage) {
return ui.list(tasks, false);
}


Expand Down
12 changes: 6 additions & 6 deletions src/main/java/command/LoadCommand.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package command;

import duke.Storage;
import duke.TaskList;
import duke.Ui;
import exception.DukeException;
import main.Storage;
import main.TaskList;
import main.Ui;
import task.Task;

public class LoadCommand extends Command{
Expand Down Expand Up @@ -36,12 +36,12 @@ public boolean isEnd() {
* @param storage
* @throws DukeException
*/
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException{
public String execute(TaskList tasks, Ui ui, Storage storage) throws DukeException{
try {
if (this.logFileAddress.equals("")) {
storage.loadLog();
return ui.load(storage.loadLog());
} else {
storage.loadLog(this.logFileAddress);
return ui.load(storage.loadLog(this.logFileAddress));
}
} catch (DukeException e) {
throw e;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/command/MarkCommand.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package command;

import duke.Storage;
import duke.TaskList;
import duke.Ui;
import exception.DukeException;
import exception.TaskListOutOfBoundsException;
import main.Storage;
import main.TaskList;
import main.Ui;
import task.Task;

public class MarkCommand extends Command{
Expand Down Expand Up @@ -35,10 +35,10 @@ public boolean isEnd() {
* @param storage
* @throws DukeException
*/
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException{
public String execute(TaskList tasks, Ui ui, Storage storage) throws DukeException{
try {
tasks.mark(this.pos);
ui.mark(this.pos);
return ui.mark(this.pos);
} catch (TaskListOutOfBoundsException e) {
throw new DukeException(e.getLocalizedMessage());
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/command/TodoCommand.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package command;

import duke.Storage;
import duke.TaskList;
import duke.Ui;
import exception.DukeException;
import exception.MissingArgumentException;
import main.Storage;
import main.TaskList;
import main.Ui;
import task.Task;
import task.ToDo;

Expand Down Expand Up @@ -45,11 +45,11 @@ public boolean isEnd() {
* @param storage
* @throws DukeException
*/
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException{
public String execute(TaskList tasks, Ui ui, Storage storage) throws DukeException{
try {
Task newEvent = this.getTask();
tasks.add(newEvent);
ui.add(newEvent);
return ui.add(newEvent);
} catch (DukeException e) {
throw e;
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/command/UnmarkCommand.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package command;

import duke.Storage;
import duke.TaskList;
import duke.Ui;
import exception.DukeException;
import exception.TaskListOutOfBoundsException;
import main.Storage;
import main.TaskList;
import main.Ui;
import task.Task;

public class UnmarkCommand extends Command{
Expand Down Expand Up @@ -35,10 +35,10 @@ public boolean isEnd() {
* @param storage
* @throws DukeException
*/
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
public String execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
try {
tasks.unmark(this.pos);
ui.unmark(this.pos);
return ui.unmark(this.pos);
} catch (TaskListOutOfBoundsException e) {
throw new DukeException(e.getLocalizedMessage());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main;
package duke;

enum CommandType {
LOAD("load"),
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/duke/DialogBox.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package duke;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;

public class DialogBox extends HBox {

private Label text;
private ImageView displayPicture;

public DialogBox(Label l, ImageView iv) {
text = l;
displayPicture = iv;

text.setWrapText(true);
displayPicture.setFitWidth(100.0);
displayPicture.setFitHeight(100.0);

this.setAlignment(Pos.TOP_RIGHT);
this.getChildren().addAll(text, displayPicture);
}

/**
* Flips the dialog box such that the ImageView is on the left and text on the right.
*/
private void flip() {
this.setAlignment(Pos.TOP_LEFT);
ObservableList<Node> tmp = FXCollections.observableArrayList(this.getChildren());
FXCollections.reverse(tmp);
this.getChildren().setAll(tmp);
}

public static DialogBox getUserDialog(Label l, ImageView iv) {
return new DialogBox(l, iv);
}

public static DialogBox getDukeDialog(Label l, ImageView iv) {
var db = new DialogBox(l, iv);
db.flip();
return db;
}
}
Loading

0 comments on commit 6f856c9

Please sign in to comment.