forked from nus-tic4001-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.
Changed all commands and UI to return Strings for GUI
- Loading branch information
Showing
22 changed files
with
342 additions
and
154 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,11 @@ | ||
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 @@ | ||
import java.io.IOException; | ||
import duke.Duke; | ||
import duke.MainWindow; | ||
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(MainWindow.class.getResource("/view/MainWindow.fxml")); | ||
AnchorPane ap = fxmlLoader.load(); | ||
Scene scene = new Scene(ap); | ||
stage.setScene(scene); | ||
fxmlLoader.<MainWindow>getController().startDuke(duke); | ||
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,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,62 @@ | ||
package duke; | ||
|
||
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; | ||
|
||
/** | ||
* Controller for duke.MainWindow. Provides the layout for the other controls. | ||
*/ | ||
|
||
public class MainWindow extends AnchorPane { | ||
private final Image userImage = new Image(this.getClass().getResourceAsStream("/images/DaUser.png")); | ||
private final Image dukeImage = new Image(this.getClass().getResourceAsStream("/images/DaDuke.png")); | ||
@FXML | ||
private ScrollPane scrollPane; | ||
@FXML | ||
private VBox dialogContainer; | ||
@FXML | ||
private TextField userInput; | ||
@FXML | ||
private Button sendButton; | ||
private Duke duke; | ||
|
||
@FXML | ||
public void initialize() { | ||
scrollPane.vvalueProperty().bind(dialogContainer.heightProperty()); | ||
} | ||
|
||
public void startDuke(Duke d) { | ||
duke = d; | ||
initializeDuke(); | ||
} | ||
|
||
/** | ||
* 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(); | ||
String response = duke.getResponse(input); | ||
dialogContainer.getChildren().addAll( | ||
DialogBox.getUserDialog(input, userImage), | ||
DialogBox.getDukeDialog(response, dukeImage) | ||
|
||
); | ||
userInput.clear(); | ||
} | ||
|
||
@FXML | ||
public void initializeDuke() { | ||
String greetings = duke.getGreetingsAndTasks(); | ||
dialogContainer.getChildren().addAll( | ||
DialogBox.getDukeDialog(greetings, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,5 +35,5 @@ protected Command(Ui ui) { | |
this.ui = ui; | ||
} | ||
|
||
public abstract void execute(); | ||
public abstract String execute(); | ||
} |
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
Oops, something went wrong.