This repository has been archived by the owner on Jul 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TeoskantaUi.java
80 lines (71 loc) · 2.34 KB
/
TeoskantaUi.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package teoskanta.ui;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;
import teoskanta.title.TitleService;
import teoskanta.user.UserService;
import teoskanta.user.dao.DBUserDao;
import teoskanta.title.dao.DBTitleDao;
/**
* Main graphical user interface class for the app
*/
public class TeoskantaUi extends Application {
private Scene newUserScene;
private Label menuLabel = new Label();
private Scene loginScene;
private UserService userService;
private TitleService titleService;
private DBUserDao userDao;
private DBTitleDao titleDao;
private SceneSwitcherUi sceneSwitcherUi;
private String loginTitle = "Teoskanta - Login";
/**
* Method to start the graphical user interface of the application
*
* @param primaryStage Stage-type variable to set the main stage
*/
@Override
public void start(Stage primaryStage) throws Exception {
userDao = new DBUserDao();
userService = new UserService(userDao);
titleDao = new DBTitleDao();
titleService = new TitleService(titleDao);
sceneSwitcherUi = new SceneSwitcherUi(primaryStage);
// check database exists
userService.checkDatabase();
titleService.checkDatabase();
// login scene
this.loginScene = sceneSwitcherUi.switchToLogin(loginTitle);
// main scene
// setup primary stage
primaryStage.setTitle("Teoskanta");
primaryStage.setScene(loginScene);
primaryStage.show();
closeRequest(primaryStage);
}
/**
* Method to check if the user is logged in and to clear the user object of
* values
*
* @param stage Stage-type variable for setting the close request
*/
public void closeRequest(Stage stage) {
stage.setOnCloseRequest(e -> {
System.out.println("closing");
System.out.println(userService.getLoggedInUser());
if (userService.getLoggedInUser() != null) {
userService.logout();
}
System.out.println(userService.getLoggedInUser());
Platform.exit();
});
}
/**
* Main method to launch the app
*/
public static void main(String[] args) {
launch(args);
}
}