-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.java
More file actions
163 lines (137 loc) · 6.31 KB
/
Copy pathMain.java
File metadata and controls
163 lines (137 loc) · 6.31 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package app;
import java.awt.CardLayout;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import data_access.*;
import entity.Pet;
import entity.user.AdopterUser;
import entity.user.User;
import interface_adapter.ViewManagerModel;
import interface_adapter.get_notifis.NotifViewModel;
import interface_adapter.bookmark.BookmarkViewModel;
import interface_adapter.logged_in.LoggedInViewModel;
import interface_adapter.login.LoginViewModel;
import interface_adapter.display_pets.DisplayPetsViewModel;
import interface_adapter.pet_bio.PetBioViewModel;
import interface_adapter.preference.PreferenceViewModel;
import interface_adapter.signup.SignupViewModel;
import utils.DatabaseInitializer;
import utils.DatabaseSeeder;
import view.*;
import static app.NotifViewUseCaseFactory.createNotifView;
/**
* The Main class serves as the entry point to the Pet Adoption application.
* It initializes the application's main window, sets up the different views
* using a CardLayout, and creates instances of the necessary view models
* and data access objects.
* <p>
* The application displays a series of views to the user, including login,
* signup, pet display, bookmarks, notifications, and user profile.
* </p>
*/
public class Main {
/**
* The main method initializes and launches the Pet Adoption application.
*
* @param args command-line arguments (not used)
*/
public static void main(String[] args) {
JFrame application = new JFrame("Pet Adoption");
application.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
application.setResizable(true);
application.setExtendedState(JFrame.MAXIMIZED_BOTH);
CardLayout cardLayout = new CardLayout();
JPanel views = new JPanel(cardLayout);
application.add(views);
ViewManagerModel viewManagerModel = new ViewManagerModel();
new ViewManager(views, cardLayout, viewManagerModel);
LoginViewModel loginViewModel = new LoginViewModel();
DisplayPetsViewModel displayPetsViewModel = new DisplayPetsViewModel();
LoggedInViewModel loggedInViewModel = new LoggedInViewModel();
SignupViewModel signupViewModel = new SignupViewModel();
BookmarkViewModel bookmarkViewModel = new BookmarkViewModel();
NotifViewModel notifViewModel = new NotifViewModel();
PreferenceViewModel preferenceViewModel = new PreferenceViewModel();
PetBioViewModel petBioViewModel = new PetBioViewModel();
UserDAOInterface userDAO = null;
PetDAOInterface petDAO = null;
APIInfoInterface infoDAO = null;
/**
* SQL DATA STORAGE IMPLEMENTATION INITIALIZATION
*/
Connection conn = null;
String dbURL = "jdbc:sqlite:data.db";
try {
conn = DriverManager.getConnection(dbURL);
new DatabaseInitializer(conn).initializeSchema();
}catch(SQLException e) {
e.printStackTrace();
}
try{
userDAO = new SQLUserDAO(conn);
} catch(SQLException e) {
System.out.println("Could not create user database \n " + e.getMessage());
}
try{
infoDAO = new SQLAPIInfoDao(conn);
} catch(SQLException e) {
System.out.println("Could not create API info database \n " + e.getMessage());
}
petDAO = new SQLPetDAO(conn);
/**
* FILE DATA STORAGE IMPLEMENTATION INITIALIZATION
*/
// try{
// userDAO = new FileUserDAO("./users.json");
// } catch (IOException e) {
// System.out.println("Could not open user data file.");
// }
// try{
// petDAO = new FilePetDAO("./pets.json");
// } catch (IOException e) {
// System.out.println(e.getMessage());
// }
// try{
// infoDAO = new FileApiInfoDAO("./data.json");
// } catch (IOException e) {
// System.out.println(e.getMessage());
// }
SignupView signupView = SignupUseCaseFactory.create(viewManagerModel, loginViewModel, signupViewModel,
preferenceViewModel, userDAO, displayPetsViewModel);
views.add(signupView, signupView.viewName);
LoginView loginView = LoginUseCaseFactory.create(viewManagerModel, loginViewModel, displayPetsViewModel,
signupViewModel, userDAO, petDAO);
views.add(loginView, loginView.viewName);
DisplayPetsView displayPetsView = DisplayPetsUseCaseFactory.create(viewManagerModel, displayPetsViewModel,
loggedInViewModel, userDAO, petDAO);
views.add(displayPetsView, displayPetsView.viewName);
LoggedInView loggedInView = LoggedInUseCaseFactory.create(viewManagerModel, loggedInViewModel,
bookmarkViewModel, preferenceViewModel, loginViewModel, notifViewModel,
userDAO, petDAO, petBioViewModel, displayPetsViewModel);
views.add(loggedInView, loggedInView.viewName);
PetDetailView petDetailView = PetDetailUseCaseFactory.create(viewManagerModel, petBioViewModel,
loggedInViewModel, userDAO, petDAO);
views.add(petDetailView, petDetailView.viewName);
BookmarkView bookmarkView = RemoveBookmarkUseCaseFactory.create(bookmarkViewModel, loggedInViewModel,
preferenceViewModel, loginViewModel, petBioViewModel, viewManagerModel, notifViewModel,
displayPetsViewModel, userDAO,petDAO);
views.add(bookmarkView, bookmarkView.viewName);
NotifView notifView = createNotifView(loggedInViewModel, viewManagerModel, notifViewModel);
views.add(notifView, notifView.viewName);
ProfileView profileView = new ProfileView();
views.add(profileView, profileView.viewName);
PreferenceView preferenceView = PreferenceUsecaseFactory.create(viewManagerModel, loggedInViewModel,
preferenceViewModel, userDAO, displayPetsViewModel, petDAO, infoDAO);
views.add(preferenceView, preferenceView.viewName);
viewManagerModel.setActiveView(loginView.viewName);
viewManagerModel.firePropertyChanged();
application.setLocationRelativeTo(null);
application.setVisible(true);
}
}