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.
Merge branch 'branch-Level-10' into master
- Loading branch information
Showing
20 changed files
with
315 additions
and
34 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,3 @@ | ||
Manifest-Version: 1.0 | ||
Main-Class: duke.Duke | ||
|
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,61 @@ | ||
package duke; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
|
||
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; | ||
|
||
/** | ||
* An example of a custom control using FXML. | ||
* This control represents a dialog box consisting of an ImageView to represent the speaker's face and a label | ||
* containing text from the speaker. | ||
*/ | ||
public class DialogBox extends HBox { | ||
@FXML | ||
private Label dialog; | ||
@FXML | ||
private ImageView 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); | ||
} | ||
|
||
/** | ||
* Flips the dialog box such that the ImageView is on the left and text on the right. | ||
*/ | ||
private void flip() { | ||
ObservableList<Node> tmp = FXCollections.observableArrayList(this.getChildren()); | ||
Collections.reverse(tmp); | ||
getChildren().setAll(tmp); | ||
setAlignment(Pos.TOP_LEFT); | ||
} | ||
|
||
public static DialogBox getUserDialog(String text, Image img) { | ||
return new DialogBox(text, img); | ||
} | ||
|
||
public static DialogBox getDukeDialog(String text, Image img) { | ||
var db = new DialogBox(text, img); | ||
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
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(Main.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package duke; | ||
|
||
import java.io.IOException; | ||
|
||
import javafx.application.Application; | ||
import javafx.fxml.FXMLLoader; | ||
import javafx.scene.Scene; | ||
import javafx.scene.layout.AnchorPane; | ||
import javafx.stage.Stage; | ||
|
||
/** | ||
* A GUI for Duke using FXML. | ||
*/ | ||
public class Main extends Application { | ||
|
||
private final Duke duke = new Duke(); | ||
|
||
@Override | ||
public void start(Stage stage) { | ||
try { | ||
FXMLLoader fxmlLoader = new FXMLLoader(Main.class.getResource("/view/MainWindow.fxml")); | ||
AnchorPane ap = fxmlLoader.load(); | ||
Scene scene = new Scene(ap); | ||
stage.setScene(scene); | ||
fxmlLoader.<MainWindow>getController().setDuke(duke); | ||
fxmlLoader.<MainWindow>getController().showGreeting(); | ||
stage.show(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
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,67 @@ | ||
package duke; | ||
|
||
import javafx.animation.PauseTransition; | ||
import javafx.fxml.FXML; | ||
import javafx.scene.control.Button; | ||
import javafx.scene.control.ScrollPane; | ||
import javafx.scene.control.TextField; | ||
import javafx.scene.image.Image; | ||
import javafx.scene.layout.AnchorPane; | ||
import javafx.scene.layout.VBox; | ||
import javafx.stage.Stage; | ||
import javafx.util.Duration; | ||
|
||
/** | ||
* Controller for MainWindow. Provides the layout for the other controls. | ||
*/ | ||
public class MainWindow extends AnchorPane { | ||
@FXML | ||
private ScrollPane scrollPane; | ||
@FXML | ||
private VBox dialogContainer; | ||
@FXML | ||
private TextField userInput; | ||
@FXML | ||
private Button sendButton; | ||
|
||
private Duke duke; | ||
|
||
private Image userImage = new Image(this.getClass().getResourceAsStream("/images/User.png")); | ||
private Image dukeImage = new Image(this.getClass().getResourceAsStream("/images/Duke.png")); | ||
|
||
@FXML | ||
public void initialize() { | ||
scrollPane.vvalueProperty().bind(dialogContainer.heightProperty()); | ||
} | ||
|
||
public void setDuke(Duke d) { | ||
duke = d; | ||
} | ||
|
||
/** | ||
* 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. | ||
*/ | ||
@FXML | ||
private void handleUserInput() { | ||
String input = userInput.getText(); | ||
if (input.equals("bye")) { | ||
Stage stage = (Stage) scrollPane.getScene().getWindow(); | ||
PauseTransition delay = new PauseTransition(Duration.seconds(2)); | ||
delay.setOnFinished( event -> stage.close() ); | ||
delay.play(); | ||
} | ||
String response = duke.getResponse(input); | ||
dialogContainer.getChildren().addAll( | ||
DialogBox.getUserDialog(input, userImage), | ||
DialogBox.getDukeDialog(response, dukeImage) | ||
); | ||
userInput.clear(); | ||
} | ||
|
||
public void showGreeting() { | ||
dialogContainer.getChildren().addAll( | ||
DialogBox.getDukeDialog(Ui.getGreeting(), dukeImage) | ||
); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package duke.command; | ||
|
||
import duke.Duke; | ||
import duke.Storage; | ||
import duke.TaskListHandler; | ||
import duke.Ui; | ||
|
Oops, something went wrong.