Skip to content

Commit 14f74d2

Browse files
Merge pull request #75 from CSC207-2022F-UofT/feature-edit-main-page
Feature edit main page
2 parents 26d79e5 + 3620d57 commit 14f74d2

File tree

5 files changed

+57
-11
lines changed

5 files changed

+57
-11
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradlew

100755100644
File mode changed.

src/main/java/editor_main_page/EditorMainPage.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,19 @@
99
import java.util.ArrayList;
1010
import java.util.List;
1111

12+
/**
13+
* The main page to edit a flashcard set. Includes the view of all flashcards inside the flashcard set. Including
14+
* features of editing title and description of flashcard set, editing independent flashcards, deleting flashcards, and
15+
* add flashcards.
16+
*/
1217
public class EditorMainPage extends JFrame {
18+
/**
19+
* Constructs an EditorMainPage object which is a JFrame and constructor opens a new window and makes the frame
20+
* visible.
21+
* @param flashcardSetId the flashcard set id of the flashcard to edit
22+
*/
1323
public EditorMainPage(int flashcardSetId){
24+
//Declare and initialize the database gateway, DBGateway.
1425
IFlashcardSetDataAccess fcSetGateway;
1526
IFlashcardDataAccess fcGateway;
1627
IUserDataAccess userGateway;
@@ -22,22 +33,23 @@ public EditorMainPage(int flashcardSetId){
2233
catch(IOException error){
2334
throw new RuntimeException("error: file not found");
2435
}
25-
2636
DBGateway dbGateway = new DBGateway(fcGateway, fcSetGateway, userGateway);
2737

38+
//Get all the flashcards of the flashcard set.
2839
FlashcardSetDsRequestModel flashcardSet = fcSetGateway.getFlashcardSet(flashcardSetId);
29-
3040
List<FlashcardDsRequestModel> flashcardData = new ArrayList<>();
3141
for(int flashcardId: flashcardSet.getFlashcardIds()){
3242
FlashcardDsRequestModel flashcard = fcGateway.getFlashcard(flashcardId);
3343
flashcardData.add(flashcard);
3444
}
45+
46+
//Create a panel that includes all the flashcards in the flashcard set and a panel with editing buttons.
3547
ListOfFlashcardsDataPanel listOfFlashcardPanel = new ListOfFlashcardsDataPanel(dbGateway ,flashcardData, flashcardSet, this);
3648
JScrollPane scrollPane = new JScrollPane(listOfFlashcardPanel);
3749
//scrollPane.setPreferredSize(new Dimension(100, 100));
3850
this.add(scrollPane);
3951

40-
52+
//Customize this frame with the title of the flashcard, size of the panel, and setting frame to be visible.
4153
this.setTitle("Edit Set \"" + flashcardSet.getTitle() + "\"");
4254
this.setSize(1000, 800);
4355
this.setVisible(true);

src/main/java/editor_main_page/FlashcardDataPanel.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,34 @@
1212
import java.awt.event.WindowEvent;
1313
import java.awt.event.WindowListener;
1414

15+
/**
16+
* The panel for an individual flashcard. Includes buttons for deleting and editing flashcard for this flashcard.
17+
*/
1518
public class FlashcardDataPanel extends JPanel implements ActionListener, WindowListener {
1619
private final DBGateway dbGateway;
1720
private final FlashcardDsRequestModel flashcard;
1821
private final int flashcardSetId;
1922
JFrame frame;
23+
/**
24+
* Constructs a FlashcardDataPanel object that includes flashcard information and editing buttons.
25+
*/
2026
public FlashcardDataPanel(DBGateway dbGateway, FlashcardDsRequestModel flashcard, int flashcardSetId, JFrame frame){
2127
this.dbGateway = dbGateway;
2228
this.frame = frame;
2329
this.flashcard = flashcard;
2430
this.flashcardSetId = flashcardSetId;
2531

26-
32+
//Includes flashcard information.
2733
Border border = BorderFactory.createTitledBorder(flashcard.getTerm());
28-
2934
JLabel descriptionLabel = new JLabel(flashcard.getDefinition());
30-
3135
this.add(descriptionLabel);
3236

37+
//Buttons for this flashcard panel.
3338
JPanel buttons = new JPanel();
34-
3539
JButton edit = new JButton("Edit Flashcard");
3640
buttons.add(edit);
3741
JButton delete = new JButton("Delete Flashcard");
3842
buttons.add(delete);
39-
4043
edit.addActionListener(this);
4144
delete.addActionListener(this);
4245

@@ -45,7 +48,12 @@ public FlashcardDataPanel(DBGateway dbGateway, FlashcardDsRequestModel flashcard
4548
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
4649
}
4750

48-
51+
/**
52+
* Performs action when an event is listened to. When 'Edit flashcard' is clicked we create a FlashcardEditorMain
53+
* object, which we open the flashcard editing page. When delete flashcard is clicked we create a FcRMain object,
54+
* which we open the delete flashcard page.
55+
* @param event the event to be processed
56+
*/
4957
@Override
5058
public void actionPerformed(ActionEvent event) {
5159
if(event.getActionCommand().equals("Edit Flashcard")){
@@ -64,6 +72,7 @@ public void windowOpened(WindowEvent e) {}
6472
public void windowClosing(WindowEvent e) {}
6573
@Override
6674
public void windowClosed(WindowEvent e) {
75+
//When observing a window close we refresh the page.
6776
frame.dispose();
6877
new EditorMainPage(flashcardSetId);
6978
}

src/main/java/editor_main_page/ListOfFlashcardsDataPanel.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,33 @@
1515
import java.awt.event.WindowListener;
1616
import java.util.List;
1717

18+
/**
19+
* A panel that includes buttons for flashcard set editing and another JPanel that includes all the
20+
* FlashcardDataPanel objects.
21+
*/
1822
public class ListOfFlashcardsDataPanel extends JPanel implements ActionListener, WindowListener {
1923
private final DBGateway dbGateway;
2024
private final FlashcardSetDsRequestModel flashcardSet;
2125
JFrame frame;
2226

2327
JPanel flashcardPanels;
2428

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+
*/
2537
public ListOfFlashcardsDataPanel(DBGateway dbGateway, List<FlashcardDsRequestModel> flashcardData,
2638
FlashcardSetDsRequestModel flashcardSet, JFrame frame) {
2739
this.dbGateway = dbGateway;
2840
this.frame = frame;
2941
this.flashcardSet = flashcardSet;
30-
3142
flashcardPanels = new JPanel();
3243

44+
//Buttons for adding flashcard, editing flashcard set, and refresh.
3345
JPanel buttons = new JPanel();
3446
JButton addFlashcard = new JButton("Add Flashcard");
3547
buttons.add(addFlashcard);
@@ -44,6 +56,8 @@ public ListOfFlashcardsDataPanel(DBGateway dbGateway, List<FlashcardDsRequestMod
4456

4557
this.add(buttons);
4658

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.
4761
int numCards = flashcardData.size();
4862
if (numCards == 0){
4963
JLabel label = new JLabel("You have no Flashcards in this FlashcardSet.");
@@ -58,15 +72,25 @@ public ListOfFlashcardsDataPanel(DBGateway dbGateway, List<FlashcardDsRequestMod
5872
flashcardPanels.add(new FlashcardDataPanel(dbGateway, flashcard, flashcardSet.getFlashcardSetId(),frame));
5973
}
6074
}
75+
//flashcardPanels customization
6176
flashcardPanels.setLayout(new FlowLayout());
6277
flashcardPanels.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
6378
flashcardPanels.setPreferredSize(new Dimension(1000,500));
79+
80+
//This panel customization
6481
this.add(flashcardPanels);
6582
this.setLayout(new FlowLayout());
6683
this.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
6784
this.setPreferredSize(new Dimension(500, 1000));
6885
}
6986

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+
*/
7094
@Override
7195
public void actionPerformed(ActionEvent event) {
7296
if(event.getActionCommand().equals("Refresh")){
@@ -88,6 +112,7 @@ public void windowOpened(WindowEvent e) {}
88112
public void windowClosing(WindowEvent e) {}
89113
@Override
90114
public void windowClosed(WindowEvent e) {
115+
//When observing a window close we refresh the page
91116
frame.dispose();
92117
new EditorMainPage(flashcardSet.getFlashcardSetId());
93118
}

0 commit comments

Comments
 (0)