Skip to content

Commit 56ae262

Browse files
Changed main page to have a similar UI design as the edit main page.
1 parent 428656a commit 56ae262

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

src/main/java/frameworks_and_drivers/components/FlashcardSetDataPanel.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import javax.swing.*;
2121
import javax.swing.border.Border;
22+
import java.awt.*;
2223
import java.awt.event.WindowAdapter;
2324
import java.awt.event.WindowEvent;
2425
import java.awt.event.WindowListener;
@@ -48,12 +49,15 @@ public class FlashcardSetDataPanel extends JPanel implements WindowListener {
4849
public FlashcardSetDataPanel(String title, String description,
4950
int flashcardSetId, DBGateway gateway,
5051
UserLoginResponseModel user, HomeScreen home) {
52+
this.home = home;
53+
5154
// Panel Construction
52-
Border border = BorderFactory.createTitledBorder(title);
55+
Border border = BorderFactory.createTitledBorder("<html>"+title+"<html>");
5356

54-
JLabel descriptionLabel = new JLabel(description);
55-
this.add(descriptionLabel);
56-
this.home = home;
57+
JLabel descriptionLabel = new JLabel("<html>"+description+"<html>");
58+
JPanel descriptionPanel = new JPanel();
59+
descriptionLabel.setPreferredSize(new Dimension(300,200));
60+
descriptionPanel.add(descriptionLabel);
5761

5862
// Button Construction
5963
JPanel buttons = new JPanel();
@@ -100,7 +104,7 @@ public void windowClosing(WindowEvent event) {
100104
DeleteFlashcardSetScreen deleter = new DeleteFlashcardSetScreen(flashcardSetId, controller, user, gateway);
101105
deleter.addWindowListener(this);
102106
});
103-
107+
this.add(descriptionPanel);
104108
this.add(buttons);
105109
this.setBorder(border);
106110
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

src/main/java/frameworks_and_drivers/components/ListOfFlashcardSetsDataPanel.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,28 @@ public class ListOfFlashcardSetsDataPanel extends JPanel {
2828
public ListOfFlashcardSetsDataPanel(Map<Integer, String[]> idsToFlashcardSetData,
2929
DBGateway gateway, UserLoginResponseModel user, HomeScreen home) {
3030
Set<Integer> flashcardSetIds = idsToFlashcardSetData.keySet();
31-
31+
JPanel flashcardSets = new JPanel();
3232
for (int flashcardSetId : flashcardSetIds) {
3333
String[] data = idsToFlashcardSetData.get(flashcardSetId);
3434
String title = data[0];
3535
String description = data[1];
3636

37-
this.add(new FlashcardSetDataPanel(title, description, flashcardSetId, gateway, user, home));
37+
flashcardSets.add(new FlashcardSetDataPanel(title, description, flashcardSetId, gateway, user, home));
38+
}
39+
int size = flashcardSetIds.size();
40+
int rows;
41+
if (size % 2 == 0){
42+
rows = size/2;
43+
}
44+
else{
45+
rows = size/2 + 1;
3846
}
47+
flashcardSets.setLayout(new GridLayout(rows, 2));
48+
Dimension flashcardSetPanelSize = flashcardSets.getPreferredSize();
49+
flashcardSets.setPreferredSize(new Dimension(flashcardSetPanelSize.width, flashcardSetPanelSize.height + 200));
3950

51+
this.add(flashcardSets);
4052
this.setLayout (new FlowLayout());
4153
this.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
42-
this.setPreferredSize(new Dimension(500, 1000));
4354
}
4455
}

src/main/java/frameworks_and_drivers/components/ListOfFlashcardsDataPanel.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ public ListOfFlashcardsDataPanel(DBGateway dbGateway, List<FlashcardDsRequestMod
7777
int size = flashcardData.size();
7878
int rows;
7979
if (size % 3 == 0){
80-
rows = flashcardData.size()/3;
80+
rows = size/3;
8181
}
8282
else{
83-
rows = flashcardData.size()/3 + 1;
83+
rows = size/3 + 1;
8484
}
85-
flashcardPanels.setLayout(new GridLayout( rows, 3));
85+
flashcardPanels.setLayout(new GridLayout(rows, 3));
8686

8787
//This panel customization
8888
this.add(flashcardPanels);

src/main/java/frameworks_and_drivers/screens/HomeScreen.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ public HomeScreen(UserLoginResponseModel user, DBGateway gateway) throws IOExcep
113113
this.add(labelPanel);
114114
}
115115
else {
116-
this.add(new ListOfFlashcardSetsDataPanel(idsToFlashcardSetData, gateway, user, this));
116+
ListOfFlashcardSetsDataPanel listOfFCSet = new ListOfFlashcardSetsDataPanel(idsToFlashcardSetData, gateway, user, this);
117+
this.add(new JScrollPane(listOfFCSet));
117118
}
118119
this.setSize(1000, 800);
119120
this.setVisible(true);

0 commit comments

Comments
 (0)