forked from nus-cs2103-AY2021S1/ip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Level 10 (basic GUI functionality; to be polished)
- Loading branch information
Illio Suardi
committed
Sep 7, 2020
1 parent
6963ea0
commit dcd857d
Showing
7 changed files
with
365 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import javafx.application.Application; | ||
import javafx.application.Platform; | ||
import javafx.scene.Scene; | ||
import javafx.scene.control.Button; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.control.ScrollPane; | ||
import javafx.scene.control.TextField; | ||
import javafx.scene.image.Image; | ||
import javafx.scene.image.ImageView; | ||
import javafx.scene.layout.AnchorPane; | ||
import javafx.scene.layout.Region; | ||
import javafx.scene.layout.VBox; | ||
import javafx.stage.Stage; | ||
|
||
import duke.Command; | ||
import duke.resource.Parser; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class DukeGui extends Application { | ||
|
||
private Image userImage = new Image(this.getClass().getResourceAsStream("/images/DaUser.png")); | ||
private Image dukeImage = new Image(this.getClass().getResourceAsStream("/images/DaDuke.png")); | ||
private ScrollPane scrollPane; | ||
private VBox dialogContainer; | ||
private TextField userInput; | ||
private Button sendButton; | ||
private Scene scene; | ||
private Duke duke; | ||
|
||
private Label getDialogLabel(String text) { | ||
Label textToAdd = new Label(text); | ||
textToAdd.setWrapText(true); | ||
|
||
return textToAdd; | ||
} | ||
|
||
private void displayIntro() { | ||
Label introText = new Label(duke.welcome()); | ||
dialogContainer.getChildren().addAll( | ||
DialogBox.getDukeDialog(introText, new ImageView(dukeImage))); | ||
} | ||
|
||
private void handleUserInput() { | ||
Label userText = new Label(userInput.getText()); | ||
Command c = Parser.parse(userInput.getText()); | ||
Label dukeText = new Label(c.parse(duke.getTaskList(), duke.getUi(), duke.getStorage())); | ||
dialogContainer.getChildren().addAll( | ||
DialogBox.getUserDialog(userText, new ImageView(userImage)), | ||
DialogBox.getDukeDialog(dukeText, new ImageView(dukeImage)) | ||
); | ||
if (c.shouldExit()) { | ||
CompletableFuture.runAsync(Platform::exit); | ||
} | ||
userInput.clear(); | ||
} | ||
|
||
@Override | ||
public void start(Stage stage) { | ||
scrollPane = new ScrollPane(); | ||
dialogContainer = new VBox(); | ||
scrollPane.setContent(dialogContainer); | ||
|
||
userInput = new TextField(); | ||
sendButton = new Button("Send"); | ||
|
||
AnchorPane mainLayout = new AnchorPane(); | ||
mainLayout.getChildren().addAll(scrollPane, userInput, sendButton); | ||
|
||
scene = new Scene(mainLayout); | ||
|
||
stage.setScene(scene); | ||
stage.show(); | ||
|
||
stage.setTitle("Duke"); | ||
stage.setResizable(false); | ||
stage.setMinHeight(600.0); | ||
stage.setMinWidth(400.0); | ||
|
||
mainLayout.setPrefSize(400.0, 600.0); | ||
|
||
scrollPane.setPrefSize(385, 535); | ||
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); | ||
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS); | ||
|
||
scrollPane.setVvalue(1.0); | ||
scrollPane.setFitToWidth(true); | ||
|
||
dialogContainer.setPrefHeight(Region.USE_COMPUTED_SIZE); | ||
|
||
userInput.setPrefWidth(325.0); | ||
|
||
sendButton.setPrefWidth(55.0); | ||
|
||
AnchorPane.setTopAnchor(scrollPane, 1.0); | ||
|
||
AnchorPane.setBottomAnchor(sendButton, 1.0); | ||
AnchorPane.setRightAnchor(sendButton, 1.0); | ||
|
||
AnchorPane.setLeftAnchor(userInput , 1.0); | ||
AnchorPane.setBottomAnchor(userInput, 1.0); | ||
|
||
sendButton.setOnMouseClicked(event -> { | ||
handleUserInput(); | ||
}); | ||
|
||
userInput.setOnAction(event -> { | ||
handleUserInput(); | ||
}); | ||
|
||
dialogContainer.heightProperty().addListener(observable -> scrollPane.setVvalue(1.0)); | ||
|
||
duke = new Duke(); | ||
|
||
displayIntro(); | ||
|
||
} | ||
|
||
public static void main(String[] args) { | ||
Application.launch(args); | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
DukeGui.main(args); | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.