-
Notifications
You must be signed in to change notification settings - Fork 462
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
19 changed files
with
278 additions
and
76 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
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,52 +1,56 @@ | ||
package duke; | ||
|
||
import duke.commands.Command; | ||
import duke.controllers.MainWindow; | ||
import duke.tasks.*; | ||
import duke.ui.Ui; | ||
import duke.utils.InputParser; | ||
import duke.utils.Storage; | ||
import javafx.application.Application; | ||
import javafx.fxml.FXMLLoader; | ||
import javafx.scene.Scene; | ||
import javafx.scene.layout.AnchorPane; | ||
import javafx.stage.Stage; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.util.Scanner; | ||
|
||
public class Duke { | ||
public class Duke extends Application { | ||
|
||
private TaskList taskList; | ||
private Storage storage; | ||
|
||
private Ui ui; | ||
|
||
private InputParser inputParser; | ||
private static final File saveFile = new File("savedata.txt"); | ||
|
||
public static void main(String[] args) { | ||
Duke duke = new Duke(); | ||
duke.start(); | ||
} | ||
private static final File SAVE_FILE = new File("savedata.txt"); | ||
private static final URL MAIN_WINDOW_FXML = Duke.class.getResource("/view/MainWindow.fxml"); | ||
|
||
public Duke() { | ||
@Override | ||
public void start(Stage stage) throws Exception { | ||
inputParser = new InputParser(); | ||
ui = new Ui(); | ||
} | ||
|
||
public void start() { | ||
Scanner sc = new Scanner(System.in); | ||
storage = new Storage(saveFile); | ||
ui.showLogo(); | ||
storage = new Storage(SAVE_FILE); | ||
taskList = new TaskList(storage.loadFromFile()); | ||
ui.showWelcome(); | ||
loop(sc); | ||
loadMainWindow(stage); | ||
} | ||
|
||
public void loop(Scanner sc) { | ||
while (sc.hasNext()) { | ||
try { | ||
String input = sc.nextLine().trim(); | ||
Command cmd = inputParser.parse(input, taskList, storage, ui); | ||
cmd.execute(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
private void loadMainWindow(Stage stage) { | ||
try { | ||
FXMLLoader fxmlLoader = new FXMLLoader(MAIN_WINDOW_FXML); | ||
AnchorPane ap = fxmlLoader.load(); | ||
Scene scene = new Scene(ap); | ||
stage.setScene(scene); | ||
fxmlLoader.<MainWindow>getController().setDuke(this); | ||
stage.show(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public String getResponse(String input) { | ||
Command cmd = inputParser.parse(input, taskList, storage, ui); | ||
String response = cmd.execute(); | ||
return response; | ||
} | ||
} |
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 @@ | ||
package duke; | ||
|
||
import javafx.application.Application; | ||
|
||
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
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
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
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,69 @@ | ||
package duke.controllers; | ||
|
||
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.Background; | ||
import javafx.scene.layout.BackgroundFill; | ||
import javafx.scene.layout.HBox; | ||
import javafx.scene.paint.Paint; | ||
import javafx.scene.shape.Circle; | ||
|
||
/** | ||
* 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); | ||
displayPicture.setClip(new Circle(50, 50, 45)); | ||
} | ||
|
||
/** | ||
* 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) { | ||
var db = new DialogBox(text, img); | ||
db.setStyle("-fx-background-color: azure;"); | ||
return db; | ||
} | ||
|
||
public static DialogBox getDukeDialog(String text, Image img) { | ||
var db = new DialogBox(text, img); | ||
db.setStyle("-fx-background-color: blanchedalmond;"); | ||
db.flip(); | ||
return db; | ||
} | ||
} |
Oops, something went wrong.