Skip to content

Commit

Permalink
Update the dialog box to display the complete text in the response.
Browse files Browse the repository at this point in the history
  • Loading branch information
Royxuzeng committed Sep 4, 2020
1 parent 95a252c commit 8dff7cd
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 27 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test {
}

application {
mainClassName = "seedu.duke.Duke"
mainClassName = "Launcher"
}

shadowJar {
Expand Down
42 changes: 27 additions & 15 deletions src/main/java/DialogBox.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
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;

public class DialogBox extends HBox {
import java.io.IOException;

private Label text;
private ImageView displayPicture;
public class DialogBox extends HBox {

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

text.setWrapText(true);
displayPicture.setFitWidth(100.0);
displayPicture.setFitHeight(100.0);
@FXML
private Label dialog;
@FXML
private ImageView displayPicture;

this.setAlignment(Pos.TOP_RIGHT);
this.getChildren().addAll(text, 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);
}

private void flip() {
Expand All @@ -30,12 +42,12 @@ private void flip() {
this.getChildren().setAll(tmp);
}

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

public static DialogBox getDukeDialog(Label l, ImageView iv) {
var db = new DialogBox(l, iv);
public static DialogBox getDukeDialog(String text, Image img) {
var db = new DialogBox(text, img);
db.flip();
return db;
}
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ public class Duke extends Application {
private Button sendButton;
private Scene scene;

private Image user = new Image(this.getClass().getResourceAsStream("/images/DaUser.png"));
private Image duke = new Image(this.getClass().getResourceAsStream("/images/DaDuke.png"));
private Duke duke;

private Image userImage = new Image(this.getClass().getResourceAsStream("/images/DaUser.png"));
private Image dukeImage = new Image(this.getClass().getResourceAsStream("/images/DaDuke.png"));

@Override
public void start(Stage stage) {
Expand Down Expand Up @@ -164,11 +166,11 @@ public void run() {
* the dialog container. Clears the user input after processing.
*/
private void handleUserInput() {
Label userText = new Label(userInput.getText());
Label dukeText = new Label(getResponse(userInput.getText()));
String input = userInput.getText();
String response = duke.getResponse(input);
dialogContainer.getChildren().addAll(
DialogBox.getUserDialog(userText, new ImageView(user)),
DialogBox.getDukeDialog(dukeText, new ImageView(duke))
DialogBox.getUserDialog(input, userImage),
DialogBox.getDukeDialog(response, dukeImage)
);
userInput.clear();
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public void setDuke(Duke d) {
*/
@FXML
private void handleUserInput() {
Label userText = new Label(userInput.getText());
Label dukeText = new Label(duke.getResponse(userInput.getText()));
String input = userInput.getText();
String response = duke.getResponse(input);
dialogContainer.getChildren().addAll(
DialogBox.getUserDialog(userText, new ImageView(userImage)),
DialogBox.getDukeDialog(dukeText, new ImageView(dukeImage))
DialogBox.getUserDialog(input, userImage),
DialogBox.getDukeDialog(response, dukeImage)
);
userInput.clear();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/view/DialogBox.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<fx:root alignment="TOP_RIGHT" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefWidth="400.0" type="javafx.scene.layout.HBox" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label fx:id="dialog" text="Label" wrapText="true" />
<Label fx:id="dialog" text="Label" wrapText="true" minHeight="-Infinity"/>
<ImageView fx:id="displayPicture" fitHeight="99.0" fitWidth="99.0" pickOnBounds="true" preserveRatio="true" />
</children>
<padding>
Expand Down

0 comments on commit 8dff7cd

Please sign in to comment.