-
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
41 changed files
with
277 additions
and
125 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,24 @@ | ||
package duke; | ||
|
||
import javafx.geometry.Pos; | ||
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); | ||
} | ||
} |
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,183 @@ | ||
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; | ||
|
||
import duke.exception.DukeException; | ||
import duke.util.Parser; | ||
import duke.util.Ui; | ||
import duke.util.Storage; | ||
import duke.task.TaskList; | ||
import duke.command.Command; | ||
import java.util.Scanner; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.ObjectInputStream; | ||
import java.io.ObjectOutputStream; | ||
import java.util.ArrayList; | ||
|
||
|
||
/** | ||
* 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 Storage storage; | ||
private TaskList tasks; | ||
private Ui ui; | ||
private static Duke main; | ||
|
||
/** | ||
* Constructor of Duke class. | ||
* | ||
* @param filePath Path to text file where save data is stored. | ||
*/ | ||
public Duke(String filePath) { | ||
this.ui = new Ui(); | ||
this.storage = new Storage(filePath); | ||
try { | ||
this.tasks = this.storage.load(); | ||
} catch (DukeException e) { | ||
this.ui.showLoadingError(); | ||
this.tasks = new TaskList(); | ||
} | ||
} | ||
/** | ||
* Main method for Duke. | ||
* | ||
* @param args Arguments entered when main method is executed. | ||
*/ | ||
public static void main(String[] args) { | ||
Duke duke = new Duke("data/duke.txt"); | ||
duke.run(); | ||
} | ||
|
||
/** | ||
* Run method of Duke. | ||
*/ | ||
public void run() { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
this.ui.showWelcome(); | ||
|
||
boolean isExit = false; | ||
while (!isExit) { | ||
try { | ||
String fullCommand = ui.readCommand(); | ||
Command c = Parser.parse(fullCommand); | ||
c.execute(tasks, ui, storage); | ||
storage.save(tasks); | ||
isExit = c.isExit(); | ||
} catch (DukeException e) { | ||
ui.showError(e.getMessage()); | ||
} | ||
} | ||
} | ||
|
||
@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 Duke("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( | ||
new DialogBox(userText, new ImageView(user)), | ||
new DialogBox(dukeText, new ImageView(duke)) | ||
); | ||
userInput.clear(); | ||
} | ||
|
||
Main main = new Main("../../../data/duke.txt"); | ||
main.run(); | ||
private String getResponse(String input) { | ||
Command c = Parser.parse(input); | ||
c.execute(tasks, ui, storage); | ||
main.storage.save(tasks); | ||
isExit = c.isExit(); | ||
return main.ui.getOutput(); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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 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.