1
1
package MainPage ;
2
2
3
+ import EditorMainPage .EditorMainPage ;
3
4
import create_flashcardset_use_case .*;
4
5
import dataAccess .*;
5
6
import entities .FlashcardSetFactory ;
@@ -24,27 +25,25 @@ public class HomePage extends JFrame implements WindowListener {
24
25
UserLoginResponseModel user ;
25
26
DBGateway gateway ;
26
27
27
- public HomePage (UserLoginResponseModel user ) throws IOException {
28
+ public HomePage (UserLoginResponseModel user , DBGateway gateway ) throws IOException {
28
29
super (user .getSignedInUsername () + "'s home page" );
29
-
30
+ this . gateway = gateway ;
30
31
this .user = user ;
31
32
// home page layout
32
33
getContentPane ().setLayout (new BoxLayout (getContentPane (),BoxLayout .Y_AXIS ));
33
34
34
- // initialize DBGateway
35
- IFlashcardSetDataAccess flashcardSetDataAccess = new FlashcardSetDataAccess (DBGateway .getFlashcardSetPath ());
36
- IFlashcardDataAccess flashcardDataAccess = new FlashcardDataAccess (DBGateway .getFlashcardPath ());
37
- IUserDataAccess userDataAccess = new CommonUserDataAccess (DBGateway .getUserPath ());
38
- DBGateway gateway = new DBGateway (flashcardDataAccess ,
39
- flashcardSetDataAccess , userDataAccess );
40
- this .gateway = gateway ;
41
35
// top bar
42
36
JPanel topBar = new JPanel ();
43
37
topBar .setLayout (new FlowLayout (FlowLayout .CENTER , 20 , 20 ));
44
38
45
39
JButton searchButton = new JButton ("Search" );
46
40
JButton addFlashcardSetButton = new JButton ("Add Flashcard Set" );
47
41
JButton logOff = new JButton ("Log Off" );
42
+ JButton refresh = new JButton ("Refresh" );
43
+
44
+ refresh .addActionListener (e -> {
45
+ refresh ();
46
+ });
48
47
49
48
searchButton .addActionListener (e -> {
50
49
SearchOutputBoundary presenter = new SearchPresenter ();
@@ -63,7 +62,6 @@ public HomePage(UserLoginResponseModel user) throws IOException {
63
62
creationScreen .addWindowListener (this );
64
63
});
65
64
66
-
67
65
logOff .addActionListener (e -> {
68
66
this .setVisible (false );
69
67
this .dispose ();
@@ -77,6 +75,7 @@ public HomePage(UserLoginResponseModel user) throws IOException {
77
75
topBar .add (searchButton );
78
76
topBar .add (addFlashcardSetButton );
79
77
topBar .add (logOff );
78
+ topBar .add (refresh );
80
79
topBar .setSize (1000 ,20 );
81
80
this .add (topBar );
82
81
@@ -93,27 +92,43 @@ public HomePage(UserLoginResponseModel user) throws IOException {
93
92
this .add (labelPanel );
94
93
}
95
94
else {
96
- this .add (new ListOfFlashcardSetsDataPanel (idsToFlashcardSetData , gateway , user ));
95
+ this .add (new ListOfFlashcardSetsDataPanel (idsToFlashcardSetData , gateway , user , this ));
97
96
}
97
+
98
+ // for (Component component : comp) {
99
+ // if (component instanceof JButton) {
100
+ // if (((JButton) component).getText().equals("Edit")){
101
+ //
102
+ // }
103
+ // else if (((JButton) component).getText().equals("Delete")){
104
+ //
105
+ // }
106
+ // }
107
+ // }
108
+
98
109
this .setSize (1000 , 800 );
99
110
this .setVisible (true );
100
111
this .setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
101
112
}
102
113
103
114
104
- private void refresh () {
115
+ public void refresh () {
105
116
try {
117
+ IFlashcardSetDataAccess flashcardSetDataAccess = new FlashcardSetDataAccess (DBGateway .getFlashcardSetPath ());
118
+ IFlashcardDataAccess flashcardDataAccess = new FlashcardDataAccess (DBGateway .getFlashcardPath ());
119
+ IUserDataAccess userDataAccess = new CommonUserDataAccess (DBGateway .getUserPath ());
120
+ DBGateway gateway = new DBGateway (flashcardDataAccess ,
121
+ flashcardSetDataAccess , userDataAccess );
106
122
UserLoginOutputBoundary presenter = new UserLoginPresenter ();
107
123
UserLoginInputBoundary interactor = new UserLoginInteractor (
108
124
gateway , presenter );
109
125
UserLoginController userLoginController = new UserLoginController (interactor );
110
126
setVisible (false );
111
- dispose ();
112
127
113
128
user = userLoginController .create (user .getSignedInUsername (),
114
129
user .getPassword ());
115
130
this .dispose ();
116
- new HomePage (user );
131
+ new HomePage (user , gateway );
117
132
} catch (Exception e ) {
118
133
JOptionPane .showMessageDialog (this , e .getMessage ());
119
134
}
0 commit comments