Skip to content

Commit

Permalink
Add GUI and Level-10 requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
shunjieee committed Feb 29, 2024
1 parent b975ff1 commit f5313e0
Show file tree
Hide file tree
Showing 21 changed files with 372 additions and 106 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ text-ui-test/EXPECTED-UNIX.TXT
*.class
duke.txt
tasks.txt
data.txt
19 changes: 17 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ repositories {
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 {
Expand All @@ -29,11 +44,11 @@ test {
}

application {
mainClass.set("Duke")
mainClass.set("xavier/Launcher")
}

shadowJar {
archiveBaseName = "duke"
archiveBaseName = "xavier"
archiveClassifier = null
dependsOn("distZip", "distTar")
}
Expand Down
69 changes: 0 additions & 69 deletions src/main/java/Duke.java

This file was deleted.

36 changes: 21 additions & 15 deletions src/main/java/command/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public AddCommand(String command, TaskList taskList, StringTokenizer st) {
* @throws DukeException If the command cannot be executed.
*/
@Override
public void execute() throws DukeException {
public String execute() throws DukeException {
try {
String taskName = "";

Expand All @@ -51,11 +51,13 @@ public void execute() throws DukeException {
ToDo td = new ToDo(taskName.strip());
taskList.add(td);

System.out.println("Got it. I've added this task:");
System.out.println(" " + td.toString());
System.out.println("Now you have " + taskList.size() + " tasks in the list.");
String s = "Got it. I've added this task:\n"
+ " " + td.toString()
+ "\nNow you have " + taskList.size() + " tasks in the list.";

System.out.println(s);
return s;
}
break;

case "deadline":
String deadline = "";
Expand All @@ -79,11 +81,13 @@ public void execute() throws DukeException {
Deadline d = new Deadline(taskName.strip(), deadline);
taskList.add(d);

System.out.println("Got it. I've added this task:");
System.out.println(" " + d.toString());
System.out.println("Now you have " + taskList.size() + " tasks in the list.");
String s = "Got it. I've added this task:\n"
+ " " + d.toString()
+ "\nNow you have " + taskList.size() + " tasks in the list.";

System.out.println(s);
return s;
}
break;

case "event":
String startTime = "";
Expand Down Expand Up @@ -113,20 +117,22 @@ public void execute() throws DukeException {
Event e = new Event(taskName.strip(), startTime, endTime);
taskList.add(e);

System.out.println("Got it. I've added this task:");
System.out.println(" " + e.toString());
System.out.println("Now you have " + taskList.size() + " tasks in the list.");
String s = "Got it. I've added this task:\n"
+ " " + e.toString()
+ "\nNow you have " + taskList.size() + " tasks in the list.";

System.out.println(s);
return s;
}
break;

default:
// Unreachable line
return "Missing field(s) / incorrect input(s). :(";
}

} catch (NoSuchElementException e) {
System.out.println("Missing field(s) / incorrect input(s). :(");
return "Missing field(s) / incorrect input(s). :(";
}

}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/command/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public abstract class Command {
*
* @throws DukeException If command cannot be executed.
*/
public abstract void execute() throws DukeException;
public abstract String execute() throws DukeException;

/**
* Returns true if the command executed exits the program.
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/command/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ public DeleteCommand(TaskList taskList, int taskIndex) {
* @throws DukeException If the command cannot be executed.
*/
@Override
public void execute() {
public String execute() {
Task t = taskList.remove(taskIndex);

System.out.println("Noted, I've removed this task:");
System.out.println(" " + t.toString());
System.out.println("Now you have " + taskList.size() + " tasks in the list.");
String s = "Noted, I've removed this task:\n"
+ " " + t.toString()
+ "\nNow you have " + taskList.size() + " tasks in the list.";

System.out.println(s);
return s;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/command/ExitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ public class ExitCommand extends Command {
* Exits the program.
*/
@Override
public void execute() {
public String execute() {
String exitMessage = "Bye. Hope to see you again soon!";
System.out.println(exitMessage);
return exitMessage;
}

/**
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/command/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,22 @@ public FindCommand(TaskList taskList, StringTokenizer st) {
* Finds a task by searching for a keyword.
*/
@Override
public void execute() {
System.out.println("Here are the matching tasks in your list:");
public String execute() {
String result = "Here are the matching tasks in your list:\n";
System.out.print(result);
LinkedList<Task> tl = taskList.getList();

int counter = 1;
for (Task t : tl) {
if (t.hasKeyword(keyword)) {
System.out.println(counter + ". " + t.toString());
String taskString = counter + ". " + t.toString();
System.out.print(taskString);
result += taskString + "\n";
counter++;
}
}

return result;
}

/**
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/command/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ public ListCommand(TaskList taskList) {
* List all the tasks in the task list.
*/
@Override
public void execute() {
System.out.println("Here are the tasks in your list:");
public String execute() {
String result = "Here are the tasks in your list:\n";
System.out.print(result);

for (int i = 1; i <= taskList.size(); i++) {
Task t = taskList.get(i);
System.out.println(i + ". " + t.toString());
String taskString = i + ". " + t.toString();
System.out.println(taskString);
result += taskString + "\n";
}

return result;
}

/**
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/command/MarkCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ public MarkCommand(TaskList taskList, int taskIndex) {
* Marks a task as done.
*/
@Override
public void execute() {
public String execute() {
Task t = taskList.get(taskIndex);
t.markAsDone();

System.out.println("Nice! I've marked this task as done:");
System.out.println(" " + t.toString());
String s = "Nice! I've marked this task as done:\n"
+ " " + t.toString();

System.out.println(s);

return s;
}

/**
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/command/UnmarkCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ public UnmarkCommand(TaskList taskList, int taskIndex) {
* Marks a task as undone.
*/
@Override
public void execute() {
public String execute() {
Task t = taskList.get(taskIndex);
t.unmark();

System.out.println("OK, I've marked this task as not done yet:");
System.out.println(" " + t.toString());
String s = "OK, I've marked this task as not done yet:\n"
+ " " + t.toString();

System.out.println(s);

return s;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/common/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ public String readCommand() {
/**
* Shows the start up message upon successful loading of the program.
*/
public void showWelcome() {
String welcomeMessage = "Hello! I'm NextGenerationJarvis.\n"
public String showWelcome() {
String welcomeMessage = "Good Morning, Hustler! I'm Xavier.\n"
+ "What can I do for you?";
System.out.println(welcomeMessage);
showLine();

return welcomeMessage;
}

/**
Expand Down
61 changes: 61 additions & 0 deletions src/main/java/xavier/DialogBox.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package xavier;
import java.io.IOException;
import java.util.Collections;

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

/**
* An example of a custom control using FXML.
* This control represents a dialog box consisting of an ImageView to represent the speaker's face and a label
* containing text from the speaker.
*/
public class DialogBox extends HBox {
@FXML
private Label dialog;
@FXML
private ImageView displayPicture;

private DialogBox(String text, Image img) {
try {
FXMLLoader fxmlLoader = new FXMLLoader(MainWindow.class.getResource("/view/DialogBox.fxml"));
fxmlLoader.setController(this);
fxmlLoader.setRoot(this);
fxmlLoader.load();

} catch (IOException e) {
e.printStackTrace();
}

dialog.setText(text);
displayPicture.setImage(img);
}

/**
* Flips the dialog box such that the ImageView is on the left and text on the right.
*/
private void flip() {
ObservableList<Node> 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 getXavierDialog(String text, Image img) {
var db = new DialogBox(text, img);
db.flip();
return db;
}
}
Loading

0 comments on commit f5313e0

Please sign in to comment.