From 4e4f49794024afe9658555027ee123663cd09094 Mon Sep 17 00:00:00 2001 From: Shaun Lee Date: Sat, 24 Feb 2024 03:26:09 +0800 Subject: [PATCH 1/2] Add text bubble for messages --- src/main/java/shon/component/DialogBox.java | 2 +- src/main/java/shon/task/TaskList.java | 2 +- src/main/resources/view/DialogBox.fxml | 9 ++++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/shon/component/DialogBox.java b/src/main/java/shon/component/DialogBox.java index c2f1080fca..6319150096 100644 --- a/src/main/java/shon/component/DialogBox.java +++ b/src/main/java/shon/component/DialogBox.java @@ -64,7 +64,7 @@ public static DialogBox getShonDialog(String text, Image img) { public static DialogBox getErrorDialog(String text, Image img) { DialogBox db = new DialogBox(text, img); - db.dialog.setTextFill(Paint.valueOf("#ff0000")); + db.dialog.setTextFill(Paint.valueOf("#CA0000")); db.flip(); return db; } diff --git a/src/main/java/shon/task/TaskList.java b/src/main/java/shon/task/TaskList.java index 0accc8d709..6999d35da2 100644 --- a/src/main/java/shon/task/TaskList.java +++ b/src/main/java/shon/task/TaskList.java @@ -118,7 +118,7 @@ public String[] getTasks() { String[] outputs = new String[this.tasks.size() + 1]; outputs[0] = "Here are the tasks in your list:"; for (int i = 1; i < this.tasks.size() + 1; i++) { - outputs[i] = i + "." + this.tasks.get(i - 1); + outputs[i] = i + ". " + this.tasks.get(i - 1); } return outputs; } diff --git a/src/main/resources/view/DialogBox.fxml b/src/main/resources/view/DialogBox.fxml index d64bccc860..5e95f62671 100644 --- a/src/main/resources/view/DialogBox.fxml +++ b/src/main/resources/view/DialogBox.fxml @@ -7,10 +7,13 @@ - From 7d5943e0933335cfebc47f07e92d4517774f9b03 Mon Sep 17 00:00:00 2001 From: Shaun Lee Date: Sat, 24 Feb 2024 03:45:25 +0800 Subject: [PATCH 2/2] Create new component for ShonDialogBox * Change color of ShonDialogBox to be grey --- src/main/java/shon/MainWindow.java | 11 ++--- .../{DialogBox.java => ShonDialogBox.java} | 33 ++++++--------- .../java/shon/component/UserDialogBox.java | 41 +++++++++++++++++++ src/main/resources/view/ShonDialogBox.fxml | 25 +++++++++++ .../{DialogBox.fxml => UserDialogBox.fxml} | 9 ++-- 5 files changed, 91 insertions(+), 28 deletions(-) rename src/main/java/shon/component/{DialogBox.java => ShonDialogBox.java} (62%) create mode 100644 src/main/java/shon/component/UserDialogBox.java create mode 100644 src/main/resources/view/ShonDialogBox.fxml rename src/main/resources/view/{DialogBox.fxml => UserDialogBox.fxml} (76%) diff --git a/src/main/java/shon/MainWindow.java b/src/main/java/shon/MainWindow.java index a21606f225..19b5f216f6 100644 --- a/src/main/java/shon/MainWindow.java +++ b/src/main/java/shon/MainWindow.java @@ -9,7 +9,8 @@ import javafx.scene.image.Image; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.VBox; -import shon.component.DialogBox; +import shon.component.ShonDialogBox; +import shon.component.UserDialogBox; import shon.exception.CommandException; import shon.exception.ParameterException; @@ -46,7 +47,7 @@ public void initialize() { */ public void setShon(Shon s) { shon = s; - dialogContainer.getChildren().addAll(DialogBox.getShonDialog(this.shon.greet(), shonImage)); + dialogContainer.getChildren().addAll(new ShonDialogBox(this.shon.greet(), shonImage)); } /** @@ -56,11 +57,11 @@ public void setShon(Shon s) { @FXML private void handleUserInput() { String input = userInput.getText().strip(); - dialogContainer.getChildren().addAll(DialogBox.getUserDialog(input, userImage)); + dialogContainer.getChildren().addAll(new UserDialogBox(input, userImage)); try { - dialogContainer.getChildren().addAll(DialogBox.getShonDialog(shon.getResponse(input), shonImage)); + dialogContainer.getChildren().addAll(new ShonDialogBox(shon.getResponse(input), shonImage)); } catch (ParameterException | CommandException | DateTimeParseException e) { - dialogContainer.getChildren().addAll(DialogBox.getErrorDialog(e.getMessage(), shonImage)); + dialogContainer.getChildren().addAll(ShonDialogBox.getErrorDialog(e.getMessage(), shonImage)); } userInput.clear(); } diff --git a/src/main/java/shon/component/DialogBox.java b/src/main/java/shon/component/ShonDialogBox.java similarity index 62% rename from src/main/java/shon/component/DialogBox.java rename to src/main/java/shon/component/ShonDialogBox.java index 6319150096..07c761424b 100644 --- a/src/main/java/shon/component/DialogBox.java +++ b/src/main/java/shon/component/ShonDialogBox.java @@ -18,22 +18,26 @@ import shon.MainWindow; /** - * 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. + * Represents the dialog box of Shon. */ -public class DialogBox extends HBox { +public class ShonDialogBox extends HBox { @FXML private Label dialog; @FXML private Circle circle; - private DialogBox(String text, Image img) { + /** + * Creates a dialog box for Shon. + * @param text The message to be displayed. + * @param img The image of Shon bot. + */ + public ShonDialogBox(String text, Image img) { try { - FXMLLoader fxmlLoader = new FXMLLoader(MainWindow.class.getResource("/view/DialogBox.fxml")); + FXMLLoader fxmlLoader = new FXMLLoader(MainWindow.class.getResource("/view/ShonDialogBox.fxml")); fxmlLoader.setController(this); fxmlLoader.setRoot(this); fxmlLoader.load(); + this.flip(); } catch (IOException e) { e.printStackTrace(); } @@ -52,20 +56,9 @@ private void flip() { setAlignment(Pos.TOP_LEFT); } - public static DialogBox getUserDialog(String text, Image img) { - return new DialogBox(text, img); - } - - public static DialogBox getShonDialog(String text, Image img) { - DialogBox db = new DialogBox(text, img); - db.flip(); - return db; - } - - public static DialogBox getErrorDialog(String text, Image img) { - DialogBox db = new DialogBox(text, img); - db.dialog.setTextFill(Paint.valueOf("#CA0000")); - db.flip(); + public static ShonDialogBox getErrorDialog(String text, Image img) { + ShonDialogBox db = new ShonDialogBox(text, img); + db.dialog.setTextFill(Paint.valueOf("#E70000")); return db; } } diff --git a/src/main/java/shon/component/UserDialogBox.java b/src/main/java/shon/component/UserDialogBox.java new file mode 100644 index 0000000000..8089ee0b4f --- /dev/null +++ b/src/main/java/shon/component/UserDialogBox.java @@ -0,0 +1,41 @@ +package shon.component; + +import java.io.IOException; + +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.control.Label; +import javafx.scene.image.Image; +import javafx.scene.layout.HBox; +import javafx.scene.paint.ImagePattern; +import javafx.scene.shape.Circle; +import shon.MainWindow; + +/** + * Represents the user's dialog box. + */ +public class UserDialogBox extends HBox { + @FXML + private Label dialog; + @FXML + private Circle circle; + + /** + * Creates a dialog box for user. + * @param text The message to be displayed. + * @param img The anon image of user. + */ + public UserDialogBox(String text, Image img) { + try { + FXMLLoader fxmlLoader = new FXMLLoader(MainWindow.class.getResource("/view/UserDialogBox.fxml")); + fxmlLoader.setController(this); + fxmlLoader.setRoot(this); + fxmlLoader.load(); + } catch (IOException e) { + e.printStackTrace(); + } + + dialog.setText(text); + circle.setFill(new ImagePattern(img)); + } +} diff --git a/src/main/resources/view/ShonDialogBox.fxml b/src/main/resources/view/ShonDialogBox.fxml new file mode 100644 index 0000000000..670cd4465b --- /dev/null +++ b/src/main/resources/view/ShonDialogBox.fxml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/view/DialogBox.fxml b/src/main/resources/view/UserDialogBox.fxml similarity index 76% rename from src/main/resources/view/DialogBox.fxml rename to src/main/resources/view/UserDialogBox.fxml index 5e95f62671..77e5b76476 100644 --- a/src/main/resources/view/DialogBox.fxml +++ b/src/main/resources/view/UserDialogBox.fxml @@ -12,11 +12,14 @@ - + - + + + + - +