15
15
import java .awt .event .WindowListener ;
16
16
import java .util .List ;
17
17
18
+ /**
19
+ * A panel that includes buttons for flashcard set editing and another JPanel that includes all the
20
+ * FlashcardDataPanel objects.
21
+ */
18
22
public class ListOfFlashcardsDataPanel extends JPanel implements ActionListener , WindowListener {
19
23
private final DBGateway dbGateway ;
20
24
private final FlashcardSetDsRequestModel flashcardSet ;
21
25
JFrame frame ;
22
26
23
27
JPanel flashcardPanels ;
24
28
29
+ /**
30
+ * Constructs a ListOfFlashcardsDataPanel object. Includes buttons for adding flashcards, editing flashcards and
31
+ * refreshing the page.
32
+ * @param dbGateway The database gateway to access the database information
33
+ * @param flashcardData All the flashcard information that was retrieved from the database
34
+ * @param flashcardSet The flashcard set information of this flashcard set
35
+ * @param frame The EditorMainPage in which this panel lies
36
+ */
25
37
public ListOfFlashcardsDataPanel (DBGateway dbGateway , List <FlashcardDsRequestModel > flashcardData ,
26
38
FlashcardSetDsRequestModel flashcardSet , JFrame frame ) {
27
39
this .dbGateway = dbGateway ;
28
40
this .frame = frame ;
29
41
this .flashcardSet = flashcardSet ;
30
-
31
42
flashcardPanels = new JPanel ();
32
43
44
+ //Buttons for adding flashcard, editing flashcard set, and refresh.
33
45
JPanel buttons = new JPanel ();
34
46
JButton addFlashcard = new JButton ("Add Flashcard" );
35
47
buttons .add (addFlashcard );
@@ -44,6 +56,8 @@ public ListOfFlashcardsDataPanel(DBGateway dbGateway, List<FlashcardDsRequestMod
44
56
45
57
this .add (buttons );
46
58
59
+ //If there are no flashcards we show a label that states that there are no flashcards.
60
+ //If there are flashcards we show the flashcard information with a FlashcardDataPanel object.
47
61
int numCards = flashcardData .size ();
48
62
if (numCards == 0 ){
49
63
JLabel label = new JLabel ("You have no Flashcards in this FlashcardSet." );
@@ -58,15 +72,25 @@ public ListOfFlashcardsDataPanel(DBGateway dbGateway, List<FlashcardDsRequestMod
58
72
flashcardPanels .add (new FlashcardDataPanel (dbGateway , flashcard , flashcardSet .getFlashcardSetId (),frame ));
59
73
}
60
74
}
75
+ //flashcardPanels customization
61
76
flashcardPanels .setLayout (new FlowLayout ());
62
77
flashcardPanels .setComponentOrientation (ComponentOrientation .LEFT_TO_RIGHT );
63
78
flashcardPanels .setPreferredSize (new Dimension (1000 ,500 ));
79
+
80
+ //This panel customization
64
81
this .add (flashcardPanels );
65
82
this .setLayout (new FlowLayout ());
66
83
this .setComponentOrientation (ComponentOrientation .LEFT_TO_RIGHT );
67
84
this .setPreferredSize (new Dimension (500 , 1000 ));
68
85
}
69
86
87
+ /**
88
+ * Performs action when an event is listened to. When 'Refresh is clicked we close this frame and open a new
89
+ * EditorMainPage. 'When 'Add flashcard' is clicked we create a FcCMain object, which we open the adding flashcard
90
+ * page. When 'Edit Flashcard Set' is clicked we create a FCSetEditorMain object, which we open the edit flashcard
91
+ * set page.
92
+ * @param event the event to be processed
93
+ */
70
94
@ Override
71
95
public void actionPerformed (ActionEvent event ) {
72
96
if (event .getActionCommand ().equals ("Refresh" )){
@@ -88,6 +112,7 @@ public void windowOpened(WindowEvent e) {}
88
112
public void windowClosing (WindowEvent e ) {}
89
113
@ Override
90
114
public void windowClosed (WindowEvent e ) {
115
+ //When observing a window close we refresh the page
91
116
frame .dispose ();
92
117
new EditorMainPage (flashcardSet .getFlashcardSetId ());
93
118
}
0 commit comments