Skip to content

Commit

Permalink
Merge branch 'branch-A-BetterGui'
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunlxw committed Feb 23, 2024
2 parents fa5bcc8 + 7d5943e commit 25142b6
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 45 deletions.
11 changes: 6 additions & 5 deletions src/main/java/shon/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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("#ff0000"));
db.flip();
public static ShonDialogBox getErrorDialog(String text, Image img) {
ShonDialogBox db = new ShonDialogBox(text, img);
db.dialog.setTextFill(Paint.valueOf("#E70000"));
return db;
}
}
41 changes: 41 additions & 0 deletions src/main/java/shon/component/UserDialogBox.java
Original file line number Diff line number Diff line change
@@ -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));
}
}
2 changes: 1 addition & 1 deletion src/main/java/shon/task/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
19 changes: 0 additions & 19 deletions src/main/resources/view/DialogBox.fxml

This file was deleted.

25 changes: 25 additions & 0 deletions src/main/resources/view/ShonDialogBox.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.shape.Circle?>

<fx:root alignment="TOP_RIGHT" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefWidth="400.0" type="javafx.scene.layout.HBox" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label fx:id="dialog" minHeight="-Infinity" minWidth="250.0" style="-fx-background-color: #E0E0E0; -fx-background-radius: 10;" text="Label" wrapText="true">
<padding>
<Insets bottom="10.0" left="12.0" right="10.0" top="10.0" />
</padding>
<HBox.margin>
<Insets left="5.0" right="5.0" />
</HBox.margin></Label>
<Circle fx:id="circle" fill="#1f93ff" radius="20.0" stroke="BLACK" strokeType="INSIDE" HBox.hgrow="ALWAYS">
<HBox.margin>
<Insets left="5.0" right="5.0" />
</HBox.margin></Circle>
</children>
<padding>
<Insets bottom="10.0" left="7.0" right="7.0" top="10.0" />
</padding>
</fx:root>
25 changes: 25 additions & 0 deletions src/main/resources/view/UserDialogBox.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.shape.Circle?>

<fx:root alignment="TOP_RIGHT" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefWidth="400.0" type="javafx.scene.layout.HBox" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label fx:id="dialog" minHeight="-Infinity" minWidth="250.0" style="-fx-background-color: #B1D9FE; -fx-background-radius: 10;" text="Label" wrapText="true">
<padding>
<Insets bottom="10.0" left="12.0" right="10.0" top="10.0" />
</padding>
<HBox.margin>
<Insets left="5.0" right="5.0" />
</HBox.margin></Label>
<Circle fx:id="circle" fill="#1f93ff" radius="20.0" stroke="BLACK" strokeType="INSIDE" HBox.hgrow="ALWAYS">
<HBox.margin>
<Insets left="5.0" right="5.0" />
</HBox.margin></Circle>
</children>
<padding>
<Insets bottom="10.0" left="7.0" right="7.0" top="10.0" />
</padding>
</fx:root>

0 comments on commit 25142b6

Please sign in to comment.