-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
276 additions
and
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package duke; | ||
|
||
import javafx.geometry.Pos; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.image.ImageView; | ||
import javafx.scene.layout.HBox; | ||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableList; | ||
import javafx.geometry.Pos; | ||
import javafx.scene.Node; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.image.ImageView; | ||
import javafx.scene.layout.HBox; | ||
|
||
public class DialogBox extends HBox { | ||
|
||
private Label text; | ||
private ImageView displayPicture; | ||
|
||
public DialogBox(Label l, ImageView iv) { | ||
text = l; | ||
displayPicture = iv; | ||
|
||
text.setWrapText(true); | ||
displayPicture.setFitWidth(100.0); | ||
displayPicture.setFitHeight(100.0); | ||
|
||
this.setAlignment(Pos.TOP_RIGHT); | ||
this.getChildren().addAll(text, displayPicture); | ||
} | ||
|
||
/** | ||
* Flips the dialog box such that the ImageView is on the left and text on the right. | ||
*/ | ||
private void flip() { | ||
this.setAlignment(Pos.TOP_LEFT); | ||
ObservableList<Node> tmp = FXCollections.observableArrayList(this.getChildren()); | ||
FXCollections.reverse(tmp); | ||
this.getChildren().setAll(tmp); | ||
} | ||
|
||
public static DialogBox getUserDialog(Label l, ImageView iv) { | ||
return new DialogBox(l, iv); | ||
} | ||
|
||
public static DialogBox getDukeDialog(Label l, ImageView iv) { | ||
var db = new DialogBox(l, iv); | ||
db.flip(); | ||
return db; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,23 +1,123 @@ | ||
package duke; | ||
|
||
import javafx.application.Application; | ||
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; | ||
|
||
|
||
/** | ||
* Application class for Duke. | ||
*/ | ||
public class Duke { | ||
public class Duke extends Application { | ||
private ScrollPane scrollPane; | ||
private VBox dialogContainer; | ||
private TextField userInput; | ||
private Button sendButton; | ||
private Scene scene; | ||
private Image user = new Image(this.getClass().getResourceAsStream("/resources/DaUser.png")); | ||
private Image duke = new Image(this.getClass().getResourceAsStream("/resources/DaDuke.png")); | ||
|
||
private Main main; | ||
|
||
/** | ||
* Main method for Duke. | ||
* | ||
* @param args Arguments entered when main method is executed. | ||
*/ | ||
public static void main(String[] args) { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
|
||
Main main = new Main("../../../data/duke.txt"); | ||
main.run(); | ||
Main duke = new Main("data/duke.txt"); | ||
duke.run(); | ||
} | ||
|
||
@Override | ||
public void start(Stage stage) { | ||
//Step 1. Setting up required components | ||
|
||
//The container for the content of the chat to scroll. | ||
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(); | ||
|
||
//Step 2. Formatting the window to look as expected | ||
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); | ||
|
||
// You will need to import `javafx.scene.layout.Region` for this. | ||
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); | ||
|
||
main = new Main("data/duke.txt"); | ||
|
||
//Part 3. Add functionality to handle user input. | ||
sendButton.setOnMouseClicked((event) -> { | ||
handleUserInput(); | ||
}); | ||
|
||
userInput.setOnAction((event) -> { | ||
handleUserInput(); | ||
}); | ||
//Scroll down to the end every time dialogContainer's height changes. | ||
dialogContainer.heightProperty().addListener((observable) -> scrollPane.setVvalue(1.0)); | ||
} | ||
|
||
/** | ||
* Iteration 2: | ||
* Creates two dialog boxes, one echoing user input and the other containing Duke's reply and then appends them to | ||
* 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())); | ||
dialogContainer.getChildren().addAll( | ||
DialogBox.getUserDialog(userText, new ImageView(user)), | ||
DialogBox.getDukeDialog(dukeText, new ImageView(duke)) | ||
); | ||
userInput.clear(); | ||
} | ||
|
||
private String getResponse(String input) { | ||
return main.step(input); | ||
} | ||
} |
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,12 @@ | ||
package duke; | ||
|
||
import javafx.application.Application; | ||
|
||
/** | ||
* A launcher class to workaround classpath issues. | ||
*/ | ||
public class Launcher { | ||
public static void main(String[] args) { | ||
Application.launch(Duke.class, args); | ||
} | ||
} |
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
10 changes: 5 additions & 5 deletions
10
src/main/java/AddCommand.java → src/main/java/command/AddCommand.java
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
8 changes: 4 additions & 4 deletions
8
src/main/java/Command.java → src/main/java/command/Command.java
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
10 changes: 5 additions & 5 deletions
10
src/main/java/DeleteCommand.java → src/main/java/command/DeleteCommand.java
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
10 changes: 5 additions & 5 deletions
10
src/main/java/DoneCommand.java → src/main/java/command/DoneCommand.java
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
6 changes: 3 additions & 3 deletions
6
src/main/java/ExitCommand.java → src/main/java/command/ExitCommand.java
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
10 changes: 5 additions & 5 deletions
10
src/main/java/FindCommand.java → src/main/java/command/FindCommand.java
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
6 changes: 3 additions & 3 deletions
6
src/main/java/ListCommand.java → src/main/java/command/ListCommand.java
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file renamed
BIN
+1.55 KB
src/main/java/duke/TaskList.class → src/main/java/duke/task/TaskList.class
Binary file not shown.
Binary file not shown.
Binary file renamed
BIN
+1.19 KB
src/main/java/duke/Storage.class → src/main/java/duke/util/Storage.class
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion
2
src/main/java/DukeException.java → src/main/java/exception/DukeException.java
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package duke; | ||
package duke.exception; | ||
|
||
/** | ||
* Exception class for Duke. | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.