27
27
import java .io .IOException ;
28
28
import java .util .Map ;
29
29
30
- public class HomeScreen extends Screen implements WindowListener {
30
+ /**
31
+ * The home page of a user. Includes the list of all their flashcard sets panels including their buttons.
32
+ * Also include a top bar with a search, add flashcard set, and log off button.
33
+ * Frameworks & Drivers.
34
+ * @author Justin Li
35
+ */
31
36
37
+ public class HomeScreen extends Screen implements WindowListener {
38
+ /**
39
+ * The logged-in user
40
+ */
32
41
UserLoginResponseModel user ;
42
+ /**
43
+ * The gateway object to access the entire database.
44
+ */
33
45
DBGateway gateway ;
34
46
47
+ /**
48
+ * Creates the home screen.
49
+ * @param user the logged-in user.
50
+ * @param gateway the gateway object to access the entire database.
51
+ */
35
52
public HomeScreen (UserLoginResponseModel user , DBGateway gateway ) throws IOException {
36
53
super (user .getSignedInUsername () + "'s home page" );
37
54
this .gateway = gateway ;
@@ -43,10 +60,12 @@ public HomeScreen(UserLoginResponseModel user, DBGateway gateway) throws IOExcep
43
60
JPanel topBar = new JPanel ();
44
61
topBar .setLayout (new FlowLayout (FlowLayout .CENTER , 20 , 20 ));
45
62
63
+ // button creation
46
64
JButton searchButton = new JButton ("Search" );
47
65
JButton addFlashcardSetButton = new JButton ("Add Flashcard Set" );
48
66
JButton logOff = new JButton ("Log Off" );
49
67
68
+ // action listeners for search, add flashcard set, and log off buttons.
50
69
searchButton .addActionListener (e -> {
51
70
SearchOutputBoundary presenter = new SearchPresenter ();
52
71
SearchInteractor interactor = new SearchInteractor (presenter , gateway );
@@ -80,6 +99,7 @@ public HomeScreen(UserLoginResponseModel user, DBGateway gateway) throws IOExcep
80
99
topBar .setSize (1000 ,20 );
81
100
this .add (topBar );
82
101
102
+ // adding list of flashcard set data panels to the home screen
83
103
Map <Integer , String []> idsToFlashcardSetData = user .getFlashcardSets ();
84
104
85
105
int numSets = idsToFlashcardSetData .size ();
@@ -100,7 +120,10 @@ public HomeScreen(UserLoginResponseModel user, DBGateway gateway) throws IOExcep
100
120
this .setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
101
121
}
102
122
103
-
123
+ /**
124
+ * A function used to refresh the home page by calling the user login again.
125
+ * The current home page is dispose and a new home page is created.
126
+ */
104
127
public void refresh () {
105
128
try {
106
129
IFlashcardSetDataAccess flashcardSetDataAccess = new FlashcardSetDataAccess (DBGateway .getFlashcardSetPath ());
@@ -124,37 +147,20 @@ public void refresh() {
124
147
}
125
148
126
149
@ Override
127
- public void windowOpened (WindowEvent e ) {
128
-
129
- }
130
-
150
+ public void windowOpened (WindowEvent e ) {}
131
151
@ Override
132
- public void windowClosing (WindowEvent e ) {
133
-
134
- }
135
-
152
+ public void windowClosing (WindowEvent e ) {}
136
153
@ Override
137
154
public void windowClosed (WindowEvent e ) {
155
+ // When a window is closed the page will be refreshed.
138
156
refresh ();
139
157
}
140
-
141
158
@ Override
142
- public void windowIconified (WindowEvent e ) {
143
-
144
- }
145
-
159
+ public void windowIconified (WindowEvent e ) {}
146
160
@ Override
147
- public void windowDeiconified (WindowEvent e ) {
148
-
149
- }
150
-
161
+ public void windowDeiconified (WindowEvent e ) {}
151
162
@ Override
152
- public void windowActivated (WindowEvent e ) {
153
-
154
- }
155
-
163
+ public void windowActivated (WindowEvent e ) {}
156
164
@ Override
157
- public void windowDeactivated (WindowEvent e ) {
158
-
159
- }
165
+ public void windowDeactivated (WindowEvent e ) {}
160
166
}
0 commit comments