Skip to content

Commit

Permalink
Update code quality and exit functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
ChanWeiJie committed Feb 6, 2022
1 parent 62bf365 commit 2b91d13
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/duke/functionality/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public TaskList readFileDataAndStoreInList(File file) throws FileNotFoundExcepti
* @param task the Task object to be checked.
*/
public Task checkTaskDone(int mark, Task task) {
if(mark == 1){
if (mark == 1) {
task.setTaskDone();
}
return task;
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/duke/main/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
public class Duke {
protected Storage storage;
protected TaskList taskList;

protected boolean isExit;
/**
* Default constructor for Duke class.
*/
public Duke() {
this.taskList = new TaskList(); //default task list
this.isExit = false;
}

/**
Expand All @@ -35,6 +36,10 @@ public void initializeStorage(String pwd, String filePath) throws IOException {
this.taskList = storage.load();
}

public boolean getExitStatus() {
return this.isExit;
}

/**
* Returns a message that corresponds to the action taken by the input of the user.
* @param input user's input.
Expand All @@ -46,6 +51,10 @@ public String getResponse(String input) {
Command command = Parser.parse(input);
output = command.execute(taskList);
Storage.updateTextFile(taskList);

if (command.isExit()) {
this.isExit = true;
}
return output;
} catch (DukeException e) {
return e.getMessage();
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/duke/main/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import java.io.IOException;

import javafx.animation.PauseTransition;
import javafx.application.Platform;
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.util.Duration;

/**
* Controller for MainWindow. Provides the layout for the other controls.
Expand All @@ -25,6 +28,7 @@ public class MainWindow extends AnchorPane {

private Duke duke;


private Image userImage = new Image(this.getClass().getResourceAsStream("/images/DaUser.png"));
private Image dukeImage = new Image(this.getClass().getResourceAsStream("/images/DaJamie.png"));

Expand Down Expand Up @@ -53,6 +57,7 @@ public void setDuke(Duke duke) {
}
}


/**
* 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.
Expand All @@ -66,5 +71,10 @@ private void handleUserInput() {
DialogBox.getDukeDialog(response, dukeImage)
);
userInput.clear();
if (duke.getExitStatus()) {
PauseTransition delay = new PauseTransition(Duration.seconds(1.2));
delay.setOnFinished(event -> Platform.exit());
delay.play();
}
}
}

0 comments on commit 2b91d13

Please sign in to comment.