Skip to content

Commit 6f856c9

Browse files
committed
Level-10: Fixed the response handling to now be linked to the GUI
1 parent dca98d2 commit 6f856c9

25 files changed

+205
-128
lines changed

src/main/java/command/ByeCommand.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package command;
22

3+
import duke.Storage;
4+
import duke.TaskList;
5+
import duke.Ui;
36
import exception.DukeException;
47
import exception.DukeFileAddressInvalidException;
5-
import main.Storage;
6-
import main.TaskList;
7-
import main.Ui;
88
import task.Task;
99

1010
/**
@@ -15,6 +15,7 @@
1515
public class ByeCommand extends Command {
1616

1717
private String logFileAddress = "";
18+
private Ui ui;
1819

1920
public ByeCommand() {
2021
}
@@ -42,15 +43,15 @@ public boolean isEnd() {
4243
* @param storage
4344
* @throws DukeException
4445
*/
45-
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
46+
public String execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
4647
if (!this.verifyAddress(this.logFileAddress)) {
4748
throw new DukeFileAddressInvalidException("User file address invalid, please check pathing");
4849
}
4950
try {
5051
if (this.logFileAddress.equals("")) {
51-
storage.cleanUp();
52+
return ui.bye(storage.cleanUp());
5253
} else {
53-
storage.cleanUp(this.logFileAddress);
54+
return ui.bye(storage.cleanUp(this.logFileAddress));
5455
}
5556
} catch (DukeException e) {
5657
throw e;

src/main/java/command/Command.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package command;
22

3+
import duke.Storage;
4+
import duke.TaskList;
5+
import duke.Ui;
36
import exception.DukeException;
4-
import main.Storage;
5-
import main.TaskList;
6-
import main.Ui;
77
import task.Task;
88
/**
99
* Abstract class thats represents a user inputted command to the chatbot.
@@ -22,8 +22,7 @@ public boolean isEnd() {
2222
return false;
2323
}
2424

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

2727
public abstract Task getTask() throws DukeException;
28-
2928
}

src/main/java/command/DeadlineCommand.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package command;
22

3+
import duke.Storage;
4+
import duke.TaskList;
5+
import duke.Ui;
36
import exception.DukeException;
47
import exception.InvalidDateException;
58
import exception.MissingArgumentException;
6-
import main.Storage;
7-
import main.TaskList;
8-
import main.Ui;
99
import task.Deadline;
1010
import task.Task;
1111

@@ -52,11 +52,11 @@ public boolean isEnd() {
5252
* @param storage
5353
* @throws DukeException
5454
*/
55-
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
55+
public String execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
5656
try {
5757
Task newDeadline = this.getTask();
5858
tasks.add(newDeadline);
59-
ui.add(newDeadline);
59+
return ui.add(newDeadline);
6060
} catch (DukeException e) {
6161
throw e;
6262
}

src/main/java/command/DeleteCommand.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package command;
22

3+
import duke.Storage;
4+
import duke.TaskList;
5+
import duke.Ui;
36
import exception.DukeException;
47
import exception.TaskListOutOfBoundsException;
5-
import main.Storage;
6-
import main.TaskList;
7-
import main.Ui;
88
import task.Task;
99

1010
/**
@@ -37,10 +37,10 @@ public boolean isEnd() {
3737
* @param storage
3838
* @throws DukeException
3939
*/
40-
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException{
41-
try {
42-
ui.delete(this.pos);
40+
public String execute(TaskList tasks, Ui ui, Storage storage) throws DukeException{
41+
try {
4342
tasks.delete(this.pos);
43+
return ui.delete(this.pos);
4444
} catch (TaskListOutOfBoundsException e) {
4545
throw new DukeException(e.getLocalizedMessage());
4646
}

src/main/java/command/EventCommand.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package command;
22

3+
import duke.Storage;
4+
import duke.TaskList;
5+
import duke.Ui;
36
import exception.DukeException;
47
import exception.InvalidDateException;
58
import exception.MissingArgumentException;
6-
import main.Storage;
7-
import main.TaskList;
8-
import main.Ui;
99
import task.Event;
1010
import task.Task;
1111

@@ -48,11 +48,11 @@ public boolean isEnd() {
4848
* @param storage
4949
* @throws DukeException
5050
*/
51-
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
51+
public String execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
5252
try {
5353
Task newEvent = this.getTask();
5454
tasks.add(newEvent);
55-
ui.add(newEvent);
55+
return ui.add(newEvent);
5656
} catch (DukeException e) {
5757
throw e;
5858
}

src/main/java/command/FindCommand.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package command;
22

3-
import main.Storage;
4-
import main.TaskList;
5-
import main.Ui;
3+
import duke.Storage;
4+
import duke.TaskList;
5+
import duke.Ui;
66
import task.Task;
77

88
public class FindCommand extends Command{
@@ -19,8 +19,8 @@ public boolean isEnd() {
1919
return false;
2020
}
2121

22-
public void execute(TaskList tasks, Ui ui, Storage storage) {
23-
ui.list(tasks.search(keyword), true);
22+
public String execute(TaskList tasks, Ui ui, Storage storage) {
23+
return ui.list(tasks.search(keyword), true);
2424
}
2525

2626
@Override

src/main/java/command/ListCommand.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package command;
22

3-
import main.Storage;
4-
import main.TaskList;
5-
import main.Ui;
3+
import duke.Storage;
4+
import duke.TaskList;
5+
import duke.Ui;
66
import task.Task;
77

88
public class ListCommand extends Command {
@@ -29,9 +29,8 @@ public boolean isEnd() {
2929
* @param ui
3030
* @param storage
3131
*/
32-
public void execute(TaskList tasks, Ui ui, Storage storage) {
33-
ui.list(tasks, false);
34-
32+
public String execute(TaskList tasks, Ui ui, Storage storage) {
33+
return ui.list(tasks, false);
3534
}
3635

3736

src/main/java/command/LoadCommand.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package command;
22

3+
import duke.Storage;
4+
import duke.TaskList;
5+
import duke.Ui;
36
import exception.DukeException;
4-
import main.Storage;
5-
import main.TaskList;
6-
import main.Ui;
77
import task.Task;
88

99
public class LoadCommand extends Command{
@@ -36,12 +36,12 @@ public boolean isEnd() {
3636
* @param storage
3737
* @throws DukeException
3838
*/
39-
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException{
39+
public String execute(TaskList tasks, Ui ui, Storage storage) throws DukeException{
4040
try {
4141
if (this.logFileAddress.equals("")) {
42-
storage.loadLog();
42+
return ui.load(storage.loadLog());
4343
} else {
44-
storage.loadLog(this.logFileAddress);
44+
return ui.load(storage.loadLog(this.logFileAddress));
4545
}
4646
} catch (DukeException e) {
4747
throw e;

src/main/java/command/MarkCommand.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package command;
22

3+
import duke.Storage;
4+
import duke.TaskList;
5+
import duke.Ui;
36
import exception.DukeException;
47
import exception.TaskListOutOfBoundsException;
5-
import main.Storage;
6-
import main.TaskList;
7-
import main.Ui;
88
import task.Task;
99

1010
public class MarkCommand extends Command{
@@ -35,10 +35,10 @@ public boolean isEnd() {
3535
* @param storage
3636
* @throws DukeException
3737
*/
38-
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException{
38+
public String execute(TaskList tasks, Ui ui, Storage storage) throws DukeException{
3939
try {
4040
tasks.mark(this.pos);
41-
ui.mark(this.pos);
41+
return ui.mark(this.pos);
4242
} catch (TaskListOutOfBoundsException e) {
4343
throw new DukeException(e.getLocalizedMessage());
4444
}

src/main/java/command/TodoCommand.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package command;
22

3+
import duke.Storage;
4+
import duke.TaskList;
5+
import duke.Ui;
36
import exception.DukeException;
47
import exception.MissingArgumentException;
5-
import main.Storage;
6-
import main.TaskList;
7-
import main.Ui;
88
import task.Task;
99
import task.ToDo;
1010

@@ -45,11 +45,11 @@ public boolean isEnd() {
4545
* @param storage
4646
* @throws DukeException
4747
*/
48-
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException{
48+
public String execute(TaskList tasks, Ui ui, Storage storage) throws DukeException{
4949
try {
5050
Task newEvent = this.getTask();
5151
tasks.add(newEvent);
52-
ui.add(newEvent);
52+
return ui.add(newEvent);
5353
} catch (DukeException e) {
5454
throw e;
5555
}

src/main/java/command/UnmarkCommand.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package command;
22

3+
import duke.Storage;
4+
import duke.TaskList;
5+
import duke.Ui;
36
import exception.DukeException;
47
import exception.TaskListOutOfBoundsException;
5-
import main.Storage;
6-
import main.TaskList;
7-
import main.Ui;
88
import task.Task;
99

1010
public class UnmarkCommand extends Command{
@@ -35,10 +35,10 @@ public boolean isEnd() {
3535
* @param storage
3636
* @throws DukeException
3737
*/
38-
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
38+
public String execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
3939
try {
4040
tasks.unmark(this.pos);
41-
ui.unmark(this.pos);
41+
return ui.unmark(this.pos);
4242
} catch (TaskListOutOfBoundsException e) {
4343
throw new DukeException(e.getLocalizedMessage());
4444
}

src/main/java/main/CommandType.java renamed to src/main/java/duke/CommandType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main;
1+
package duke;
22

33
enum CommandType {
44
LOAD("load"),

src/main/java/duke/DialogBox.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package duke;
2+
3+
import javafx.collections.FXCollections;
4+
import javafx.collections.ObservableList;
5+
import javafx.geometry.Pos;
6+
import javafx.scene.Node;
7+
import javafx.scene.control.Label;
8+
import javafx.scene.image.ImageView;
9+
import javafx.scene.layout.HBox;
10+
11+
public class DialogBox extends HBox {
12+
13+
private Label text;
14+
private ImageView displayPicture;
15+
16+
public DialogBox(Label l, ImageView iv) {
17+
text = l;
18+
displayPicture = iv;
19+
20+
text.setWrapText(true);
21+
displayPicture.setFitWidth(100.0);
22+
displayPicture.setFitHeight(100.0);
23+
24+
this.setAlignment(Pos.TOP_RIGHT);
25+
this.getChildren().addAll(text, displayPicture);
26+
}
27+
28+
/**
29+
* Flips the dialog box such that the ImageView is on the left and text on the right.
30+
*/
31+
private void flip() {
32+
this.setAlignment(Pos.TOP_LEFT);
33+
ObservableList<Node> tmp = FXCollections.observableArrayList(this.getChildren());
34+
FXCollections.reverse(tmp);
35+
this.getChildren().setAll(tmp);
36+
}
37+
38+
public static DialogBox getUserDialog(Label l, ImageView iv) {
39+
return new DialogBox(l, iv);
40+
}
41+
42+
public static DialogBox getDukeDialog(Label l, ImageView iv) {
43+
var db = new DialogBox(l, iv);
44+
db.flip();
45+
return db;
46+
}
47+
}

0 commit comments

Comments
 (0)