Skip to content

Commit

Permalink
Make GUI resizable (#60)
Browse files Browse the repository at this point in the history
* Make conversation history resizable

* Set minimum window size

* Add anchors to text field and button

* Fix mouse wheel scrolling not working

* Add mention of 'help' command on startup
  • Loading branch information
ianyong committed Sep 18, 2020
1 parent 9b540c3 commit 07d3d01
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/main/java/duke/Gui.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ public void start(Stage stage) {
stage.setScene(scene);
stage.setTitle("Duke");
stage.getIcons().add(new Image(this.getClass().getResourceAsStream("/images/Dog Emoji.png")));
stage.setResizable(false);
stage.show();
stage.setMinWidth(stage.getWidth());
stage.setMinHeight(stage.getHeight());
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
22 changes: 16 additions & 6 deletions src/main/java/duke/controllers/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ public class MainWindow extends AnchorPane {
*/
@FXML
public void initialize() {
// Bind the scroll pane's height to that of the dialog container.
scrollPane.vvalueProperty().bind(dialogContainer.heightProperty());

// Disable the send button when the user input is empty.
BooleanBinding isUserInputEmpty = Bindings.isEmpty(userInput.textProperty());
sendButton.disableProperty().bind(isUserInputEmpty);
Expand All @@ -56,6 +53,10 @@ public void initialize() {
// Display greetings.
dialogContainer.getChildren().add(
DialogBox.getDukeDialog(Store.getResourceHandler().getString("repl.greeting"), dukeImage));

// Scroll to bottom of scroll pane on update.
dialogContainer.heightProperty().addListener((observable, oldValue, newValue) ->
scrollPane.setVvalue(1.0d));
}

/**
Expand All @@ -75,22 +76,31 @@ private void handleUserInput() {
// Push user input into command history.
commandHistory.addCommand(input);

// Process the user input.
// Execute the inputted command.
DukeResponse dukeResponse = Repl.getResponse(input);

// Display the response from command execution.
dialogContainer.getChildren().addAll(
DialogBox.getUserDialog(input, userImage),
DialogBox.getDukeDialog(dukeResponse.toString(), dukeImage)
);

userInput.clear();

// Terminate the application if the signal to exit is received.
if (dukeResponse.shouldExit()) {
Stage stage = (Stage) userInput.getScene().getWindow();
stage.close();
}

// Clear the user input.
userInput.clear();
}

/**
* Handles key presses for `userInput`, displaying the command history on
* {@code KeyCode.UP} and {@code KeyCode.DOWN}.
*
* @param keyCode the key that was pressed by the user.
*/
private void handleKeyPress(KeyCode keyCode) {
switch (keyCode) {
case UP:
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/Strings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ exception.noArgs = No arguments are accepted by command ''{0}''.

# Repl
repl.farewell = Bye. Hope to see you again soon!
repl.greeting = Hello! I'm Duke.\nWhat can I do for you?
repl.greeting = Hello! I'm Duke.\nWhat can I do for you?\nEnter 'help' for a list of available commands.
repl.internalError = An internal error occurred.
repl.invalidTaskIndex = Inputted task index does not exist!
repl.unknownCommand = Inputted command does not exist!
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/Strings_en_SG.properties
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ exception.noArgs = No arguments are accepted by command ''{0}''.

# Repl
repl.farewell = Bye. Hope to see you again soon!
repl.greeting = Hello! I'm Duke.\nWhat can I do for you?
repl.greeting = Hello! I'm Duke.\nWhat can I do for you?\nEnter 'help' for a list of available commands.
repl.internalError = An internal error occurred.
repl.invalidTaskIndex = Inputted task index does not exist!
repl.unknownCommand = Inputted command does not exist!
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/Strings_zh_SG.properties
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ exception.noArgs = 命令 ''{0}'' 不接受任何参数。

# Repl
repl.farewell = 再见。希望很快再见到你!
repl.greeting = 你好!我叫公爵。\n我能为你做什么?
repl.greeting = 你好!我叫公爵。\n我能为你做什么?\n输入 'help' 以获取可用命令的列表。
repl.internalError = 发生了内部错误。
repl.invalidTaskIndex = 输入的任务索引不存在!
repl.unknownCommand = 输入的命令不存在!
Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/styles/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@
-fx-padding: 0.0 10.0 0.0 0.0;
}

.scroll-bar .increment-arrow,
.scroll-bar .decrement-arrow{
.scroll-bar .increment-arrow,
.scroll-bar .decrement-arrow {
-fx-shape: "";
-fx-padding: 0.15em 0.0;
}

.scroll-bar:vertical .increment-arrow,
.scroll-bar:vertical .decrement-arrow{
.scroll-bar:vertical .increment-arrow,
.scroll-bar:vertical .decrement-arrow {
-fx-shape: "";
-fx-padding: 0.0 0.15em;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/views/MainWindow.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="400.0" stylesheets="@../styles/base.css" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="duke.controllers.MainWindow">
<children>
<TextField fx:id="userInput" layoutY="558.0" onAction="#handleUserInput" prefHeight="41.0" prefWidth="324.0" AnchorPane.bottomAnchor="1.0" />
<Button fx:id="sendButton" layoutX="324.0" layoutY="558.0" mnemonicParsing="false" onAction="#handleUserInput" prefHeight="41.0" prefWidth="76.0" text="Send" />
<ScrollPane fx:id="scrollPane" hbarPolicy="NEVER" hvalue="1.0" prefHeight="557.0" prefWidth="400.0" vvalue="1.0">
<ScrollPane fx:id="scrollPane" fitToHeight="true" fitToWidth="true" hbarPolicy="NEVER" hvalue="1.0" vvalue="1.0" AnchorPane.bottomAnchor="42.39999999999998" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<content>
<VBox fx:id="dialogContainer" prefHeight="552.0" prefWidth="388.0" />
<VBox fx:id="dialogContainer" alignment="TOP_CENTER" />
</content>
</ScrollPane>
<TextField fx:id="userInput" layoutY="558.0" onAction="#handleUserInput" prefHeight="41.0" prefWidth="324.0" AnchorPane.bottomAnchor="1.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="76.0" />
<Button fx:id="sendButton" layoutX="324.0" layoutY="558.0" mnemonicParsing="false" onAction="#handleUserInput" prefHeight="41.0" prefWidth="76.0" text="Send" AnchorPane.bottomAnchor="0.3999999999999986" AnchorPane.rightAnchor="0.0" />
</children>
</AnchorPane>

0 comments on commit 07d3d01

Please sign in to comment.