forked from nus-cs2103-AY2324S2/ip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FluffyApp.java
61 lines (53 loc) · 1.45 KB
/
FluffyApp.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package fluffy;
import fluffy.command.Command;
import fluffy.parser.Parser;
import fluffy.storage.Storage;
import fluffy.tasklist.TaskList;
import fluffy.ui.Ui;
import javafx.application.Application;
import javafx.stage.Stage;
/**
* The Main app for Fluffy.
*/
public class FluffyApp extends Application {
private Storage storage;
private TaskList tasks;
private Ui ui;
private String filePath = "data/fluffy.txt";
/**
* Constructor for FluffyApp.
*/
public FluffyApp() {
ui = new Ui(this::handler);
storage = new Storage(filePath);
try {
tasks = new TaskList(storage.load());
} catch (FluffyException e) {
ui.showLoadingError();
tasks = new TaskList();
}
}
/**
* A function for dealing with user input.
* @param input the input from a user.
*/
public void handler(String input) {
assert tasks != null : "tasks should not be null";
assert ui != null : "ui should not be null";
assert storage != null : "storage should not be null";
try {
Command c = Parser.parse(input);
c.execute(tasks, ui, storage);
storage.save(tasks);
if (c.isExit()) {
ui.exit();
}
} catch (FluffyException e) {
ui.showError(e.getMessage());
}
}
@Override
public void start(Stage stage) {
ui.start(stage);
}
}