-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDashboard.java
More file actions
1935 lines (1603 loc) · 78.5 KB
/
Copy pathDashboard.java
File metadata and controls
1935 lines (1603 loc) · 78.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package dashboard;
import auth.Login;
import java.io.File;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.URI;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.List;
import java.io.PrintWriter;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import javax.swing.border.Border;
public class Dashboard extends JFrame {
private final String username;
private JPanel mainContentPanel;
private Map<String, JPanel> pages = new HashMap<>();
private DefaultListModel<String> courseListModel = new DefaultListModel<>();
// Dashboard stat card references for dynamic updates
private JLabel totalCoursesValue;
private JLabel studyResourcesValue;
private JLabel dueThisWeekValue;
private JProgressBar totalCoursesProgress;
private JProgressBar studyResourcesProgress;
private JProgressBar dueThisWeekProgress;
JProgressBar progressBar = new JProgressBar(0, 100);
// Shared events map for calendar and assessments
private Map<LocalDate, List<String[]>> events = new HashMap<>();
// Assessment data storage
private List<String[]> assessmentDataList = new ArrayList<>();
// Components for Assessments panel
private DefaultListModel<String> assessmentListModel;
private JList<String> assessmentList;
// Components for dashboard stats update
private JLabel progressCardValueLabel; // New JLabel for completion rate card -> link to progress card in stats panel
private JProgressBar progressCardProgressBar; // New JProgressBar for completion card
// For calendar navigation
private JLabel calendarMonthLabel;
private JPanel calendarGridPanel;
private YearMonth calendarCurrentMonth;
// Dynamic content areas
private JPanel deadlinesContentPanel;
private JPanel activityContentPanel;
private DefaultListModel<String> deadlinesList = new DefaultListModel<>();
private DefaultListModel<String> activityList = new DefaultListModel<>();
private static class Resource {
String name;
String type;
String pathOrUrl;
Resource(String name, String type, String pathOrUrl) {
this.name = name;
this.type = type;
this.pathOrUrl = pathOrUrl;
}
@Override
public String toString() {
return name + " (" + type + ")";
}
}
// Deadline class for better management
private static class Deadline {
String title;
String dueDate;
String type;
boolean urgent;
Deadline(String title, String dueDate, String type, boolean urgent) {
this.title = title;
this.dueDate = dueDate;
this.type = type;
this.urgent = urgent;
}
@Override
public String toString() {
return title + "|" + dueDate + "|" + type + "|" + urgent;
}
public static Deadline fromString(String str) {
String[] parts = str.split("\\|");
if (parts.length == 4) {
return new Deadline(parts[0], parts[1], parts[2], Boolean.parseBoolean(parts[3]));
}
return null;
}
}
// Activity class for better management
private static class Activity {
String description;
String time;
String icon;
String color;
Activity(String description, String time, String icon, String color) {
this.description = description;
this.time = time;
this.icon = icon;
this.color = color;
}
@Override
public String toString() {
return description + "|" + time + "|" + icon + "|" + color;
}
public static Activity fromString(String str) {
String[] parts = str.split("\\|");
if (parts.length == 4) {
return new Activity(parts[0], parts[1], parts[2], parts[3]);
}
return null;
}
}
private Map<String, DefaultListModel<Resource>> courseResourcesMap = new HashMap<>();
private List<Deadline> deadlines = new ArrayList<>();
private List<Activity> activities = new ArrayList<>();
private JTextArea dashboardMyCoursesArea;
private JTextArea dashboardResourcesDueArea;
// File names for this user
private final String coursesFile;
private final String resourcesFile;
private final String deadlinesFile;
private final String activitiesFile;
public Dashboard(String username) {
this.username = username;
coursesFile = "courses_" + username + ".txt";
resourcesFile = "resources_" + username + ".txt";
deadlinesFile = "deadlines_" + username + ".txt";
activitiesFile = "activities_" + username + ".txt";
setTitle("Study Resource Management Dashboard");
setExtendedState(JFrame.MAXIMIZED_BOTH);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new BorderLayout());
mainContentPanel = new JPanel(new BorderLayout());
loadCoursesAndResources();
loadDeadlines();
loadActivities();
pages.put("Dashboard", createDashboardPanel());
pages.put("Courses", createCoursesPanel());
pages.put("Assessments", createAssessmentsPanel());
pages.put("Classes", createClassesPanel());
pages.put("Students", createStudentsPanel());
pages.put("Calendar", createCalendarPanel());
pages.put("Reports", createReportsPanel());
add(createSidebar(), BorderLayout.WEST);
add(createTopPanel(), BorderLayout.NORTH);
add(mainContentPanel, BorderLayout.CENTER);
showPage("Dashboard");
this.revalidate();
this.repaint();
setVisible(true);
}
// --- Enhanced Persistence methods ---
private void loadCoursesAndResources() {
courseListModel.clear();
courseResourcesMap.clear();
// Load courses
File cFile = new File(coursesFile);
if (cFile.exists()) {
try (BufferedReader br = new BufferedReader(new FileReader(cFile))) {
String line;
while ((line = br.readLine()) != null) {
if (!line.trim().isEmpty()) {
courseListModel.addElement(line.trim());
courseResourcesMap.put(line.trim(), new DefaultListModel<>());
}
}
} catch (IOException e) {
JOptionPane.showMessageDialog(this, "Error loading courses: " + e.getMessage());
}
}
// Load resources
File rFile = new File(resourcesFile);
if (rFile.exists()) {
try (BufferedReader br = new BufferedReader(new FileReader(rFile))) {
String line;
while ((line = br.readLine()) != null) {
if (!line.trim().isEmpty()) {
// Format: courseName|resourceName|resourceType|resourcePathOrUrl
String[] parts = line.split("\\|");
if (parts.length == 4) {
String courseName = parts[0];
String resourceName = parts[1];
String resourceType = parts[2];
String resourcePath = parts[3];
Resource resource = new Resource(resourceName, resourceType, resourcePath);
courseResourcesMap.computeIfAbsent(courseName, k -> new DefaultListModel<>()).addElement(resource);
}
}
}
} catch (IOException e) {
JOptionPane.showMessageDialog(this, "Error loading resources: " + e.getMessage());
}
}
}
private void loadDeadlines() {
deadlines.clear();
File file = new File(deadlinesFile);
if (file.exists()) {
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
String line;
while ((line = br.readLine()) != null) {
if (!line.trim().isEmpty()) {
Deadline deadline = Deadline.fromString(line.trim());
if (deadline != null) {
deadlines.add(deadline);
}
}
}
} catch (IOException e) {
JOptionPane.showMessageDialog(this, "Error loading deadlines: " + e.getMessage());
}
}
}
private void loadActivities() {
activities.clear();
File file = new File(activitiesFile);
if (file.exists()) {
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
String line;
while ((line = br.readLine()) != null) {
if (!line.trim().isEmpty()) {
Activity activity = Activity.fromString(line.trim());
if (activity != null) {
activities.add(activity);
}
}
}
} catch (IOException e) {
JOptionPane.showMessageDialog(this, "Error loading activities: " + e.getMessage());
}
}
}
private void saveCourses() {
try (BufferedWriter bw = new BufferedWriter(new FileWriter(coursesFile))) {
for (int i = 0; i < courseListModel.size(); i++) {
bw.write(courseListModel.get(i));
bw.newLine();
}
} catch (IOException e) {
JOptionPane.showMessageDialog(this, "Error saving courses: " + e.getMessage());
}
}
private void saveResources() {
try (BufferedWriter bw = new BufferedWriter(new FileWriter(resourcesFile))) {
for (String course : courseResourcesMap.keySet()) {
DefaultListModel<Resource> resources = courseResourcesMap.get(course);
for (int i = 0; i < resources.size(); i++) {
Resource r = resources.get(i);
bw.write(course + "|" + r.name + "|" + r.type + "|" + r.pathOrUrl);
bw.newLine();
}
}
} catch (IOException e) {
JOptionPane.showMessageDialog(this, "Error saving resources: " + e.getMessage());
}
}
private void saveDeadlines() {
try (BufferedWriter bw = new BufferedWriter(new FileWriter(deadlinesFile))) {
for (Deadline deadline : deadlines) {
bw.write(deadline.toString());
bw.newLine();
}
} catch (IOException e) {
JOptionPane.showMessageDialog(this, "Error saving deadlines: " + e.getMessage());
}
}
private void saveActivities() {
try (BufferedWriter bw = new BufferedWriter(new FileWriter(activitiesFile))) {
for (Activity activity : activities) {
bw.write(activity.toString());
bw.newLine();
}
} catch (IOException e) {
JOptionPane.showMessageDialog(this, "Error saving activities: " + e.getMessage());
}
}
// --- UI Creation methods remain the same until createStatsPanel ---
private JPanel createSidebar() {
JPanel sidebar = new JPanel();
sidebar.setPreferredSize(new Dimension(280, getHeight()));
sidebar.setLayout(new BoxLayout(sidebar, BoxLayout.Y_AXIS));
sidebar.setBackground(new Color(45, 45, 45));
String[] buttons = {"Dashboard", "Courses", "Assessments", "Classes", "Students", "Calendar", "Reports", "Logout"};
for (String text : buttons) {
JButton btn = new JButton(text);
btn.setAlignmentX(Component.CENTER_ALIGNMENT);
btn.setMaximumSize(new Dimension(250, 50));
btn.setFont(new Font("Segoe UI", Font.BOLD, 18));
btn.setBackground(new Color(60, 63, 65));
btn.setForeground(Color.WHITE);
btn.setFocusPainted(false);
btn.setCursor(new Cursor(Cursor.HAND_CURSOR));
btn.addActionListener(e -> {
if (text.equals("Logout")) {
saveCourses();
saveResources();
saveDeadlines();
saveActivities();
dispose();
new Login();
} else {
showPage(text);
}
});
sidebar.add(Box.createRigidArea(new Dimension(0, 10)));
sidebar.add(btn);
}
return sidebar;
}
private JPanel createTopPanel() {
JPanel topPanel = new JPanel(new BorderLayout());
topPanel.setBackground(new Color(240, 240, 240));
topPanel.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20));
JLabel welcomeLabel = new JLabel("Welcome back, " + username + "!", SwingConstants.CENTER);
welcomeLabel.setFont(new Font("Segoe UI", Font.BOLD, 32));
topPanel.add(welcomeLabel, BorderLayout.CENTER);
JTextField searchField = new JTextField();
searchField.setPreferredSize(new Dimension(300, 40));
searchField.setFont(new Font("Segoe UI", Font.PLAIN, 16));
topPanel.add(searchField, BorderLayout.EAST);
return topPanel;
}
private JLabel createColorPanel(String text, Color bgColor) {
JLabel label = new JLabel(text, SwingConstants.CENTER);
label.setOpaque(true);
label.setBackground(bgColor);
label.setForeground(Color.WHITE);
label.setFont(new Font("Segoe UI", Font.BOLD, 20));
label.setBorder(BorderFactory.createEmptyBorder(40, 10, 40, 10));
return label;
}
private JPanel createDashboardPanel() {
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.setBackground(new Color(245, 247, 250));
// Create main scroll pane for the entire dashboard
JScrollPane mainScrollPane = new JScrollPane();
mainScrollPane.setBorder(null);
mainScrollPane.getVerticalScrollBar().setUnitIncrement(16);
JPanel mainContent = new JPanel();
mainContent.setLayout(new BoxLayout(mainContent, BoxLayout.Y_AXIS));
mainContent.setBackground(new Color(245, 247, 250));
mainContent.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
// Header Section
JPanel headerPanel = createHeaderPanel();
mainContent.add(headerPanel);
mainContent.add(Box.createRigidArea(new Dimension(0, 25)));
// Stats Cards Section
JPanel statsPanel = createStatsPanel();
mainContent.add(statsPanel);
mainContent.add(Box.createRigidArea(new Dimension(0, 25)));
// Quick Actions Section
JPanel quickActionsPanel = createQuickActionsPanel();
mainContent.add(quickActionsPanel);
mainContent.add(Box.createRigidArea(new Dimension(0, 25)));
// Content Grid Section
JPanel contentGrid = createContentGrid();
mainContent.add(contentGrid);
mainContent.add(Box.createRigidArea(new Dimension(0, 25)));
// Study Streak Section
JPanel studyStreakPanel = createStudyStreakPanel();
mainContent.add(studyStreakPanel);
mainScrollPane.setViewportView(mainContent);
panel.add(mainScrollPane, BorderLayout.CENTER);
return panel;
}
private JPanel createHeaderPanel() {
JPanel header = new JPanel(new BorderLayout());
header.setBackground(new Color(245, 247, 250));
header.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0));
JLabel titleLabel = new JLabel("Study Dashboard", SwingConstants.CENTER);
titleLabel.setFont(new Font("Segoe UI", Font.BOLD, 36));
titleLabel.setForeground(new Color(51, 51, 51));
JLabel subtitleLabel = new JLabel("Welcome back! Here's your learning progress overview", SwingConstants.CENTER);
subtitleLabel.setFont(new Font("Segoe UI", Font.PLAIN, 16));
subtitleLabel.setForeground(new Color(102, 102, 102));
JPanel titlePanel = new JPanel();
titlePanel.setLayout(new BoxLayout(titlePanel, BoxLayout.Y_AXIS));
titlePanel.setBackground(new Color(245, 247, 250));
titlePanel.add(titleLabel);
titlePanel.add(Box.createRigidArea(new Dimension(0, 5)));
titlePanel.add(subtitleLabel);
header.add(titlePanel, BorderLayout.CENTER);
return header;
}
private JPanel createStatsPanel() {
JPanel statsPanel = new JPanel(new GridLayout(1, 4, 20, 0));
statsPanel.setBackground(new Color(245, 247, 250));
// Course Stats Card
JPanel coursesCard = createStatCard("📚", "Total Courses", "0", new Color(76, 175, 80), 0);
// Resources Stats Card
JPanel resourcesCard = createStatCard("📄", "Study Resources", "0", new Color(33, 150, 243), 0);
// Assessments Stats Card
JPanel assessmentsCard = createStatCard("📝", "Due This Week", "0", new Color(255, 152, 0), 0);
// Progress Stats Card - Completion Rate
JPanel progressCard = createStatCard("⭐", "Completion Rate", "0%", new Color(156, 39, 176), 0); // Initial 0%
statsPanel.add(coursesCard);
statsPanel.add(resourcesCard);
statsPanel.add(assessmentsCard);
statsPanel.add(progressCard);
return statsPanel;
}
private JPanel createStatCard(String icon, String label, String value, Color accentColor, int progressValue) {
JPanel card = new JPanel(new BorderLayout());
card.setBackground(Color.WHITE);
card.setBorder(BorderFactory.createCompoundBorder(
new RoundedBorder(15, new Color(230, 230, 230)),
BorderFactory.createEmptyBorder(20, 20, 20, 20)
));
JPanel headerPanel = new JPanel(new BorderLayout());
headerPanel.setBackground(Color.WHITE);
JLabel iconLabel = new JLabel(icon);
iconLabel.setFont(new Font("Segoe UI Emoji", Font.PLAIN, 28));
iconLabel.setHorizontalAlignment(SwingConstants.CENTER);
iconLabel.setPreferredSize(new Dimension(50, 50));
JLabel valueLabel = new JLabel(value, SwingConstants.RIGHT);
valueLabel.setFont(new Font("Segoe UI", Font.BOLD, 32));
valueLabel.setForeground(new Color(51, 51, 51));
// Create a NEW progress bar for EACH card
JProgressBar progressBar = new JProgressBar(0, 100);
progressBar.setValue(progressValue);
progressBar.setStringPainted(false);
progressBar.setPreferredSize(new Dimension(0, 8));
progressBar.setBorderPainted(false);
progressBar.setBackground(new Color(240, 240, 240));
progressBar.setForeground(accentColor);
// Save references accordingly
if (label.equals("Total Courses")) {
totalCoursesProgress = progressBar;
totalCoursesValue = valueLabel;
} else if (label.equals("Study Resources")) {
studyResourcesProgress = progressBar;
studyResourcesValue = valueLabel;
} else if (label.equals("Due This Week")) {
dueThisWeekProgress = progressBar;
dueThisWeekValue = valueLabel;
} else if (label.equals("Completion Rate")) {
progressCardProgressBar = progressBar;
progressCardValueLabel = valueLabel;
}
headerPanel.add(iconLabel, BorderLayout.WEST);
headerPanel.add(valueLabel, BorderLayout.CENTER);
JLabel labelText = new JLabel(label);
labelText.setFont(new Font("Segoe UI", Font.PLAIN, 14));
labelText.setForeground(new Color(102, 102, 102));
JPanel progressPanel = new JPanel(new BorderLayout());
progressPanel.setBackground(Color.WHITE);
progressPanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
progressPanel.add(progressBar, BorderLayout.CENTER); // Always add the current progressBar
card.add(headerPanel, BorderLayout.NORTH);
card.add(labelText, BorderLayout.CENTER);
card.add(progressPanel, BorderLayout.SOUTH);
// Hover effect
card.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
card.setBackground(new Color(248, 249, 250));
}
@Override
public void mouseExited(MouseEvent e) {
card.setBackground(Color.WHITE);
}
});
return card;
}
private JPanel createQuickActionsPanel() {
JPanel quickActions = new JPanel(new BorderLayout());
quickActions.setBackground(new Color(102, 126, 234));
quickActions.setBorder(new RoundedBorder(15, new Color(102, 126, 234)));
JPanel contentPanel = new JPanel(new BorderLayout());
contentPanel.setBackground(new Color(102, 126, 234));
contentPanel.setBorder(BorderFactory.createEmptyBorder(25, 25, 25, 25));
JLabel titleLabel = new JLabel("Quick Actions");
titleLabel.setFont(new Font("Segoe UI", Font.BOLD, 20));
titleLabel.setForeground(Color.WHITE);
JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 15, 15));
buttonsPanel.setBackground(new Color(102, 126, 234));
JButton addCourseBtn = createQuickActionButton("➕ Add Course");
JButton addResourceBtn = createQuickActionButton("📎 Add Resource");
JButton addDeadlineBtn = createQuickActionButton("📝 Add Deadline");
JButton addActivityBtn = createQuickActionButton("📈 Add Activity");
// Add action listeners
addCourseBtn.addActionListener(e -> showPage("Courses"));
addResourceBtn.addActionListener(e -> showPage("Courses"));
addDeadlineBtn.addActionListener(e -> showAddDeadlineDialog());
addActivityBtn.addActionListener(e -> showAddActivityDialog());
buttonsPanel.add(addCourseBtn);
buttonsPanel.add(addResourceBtn);
buttonsPanel.add(addDeadlineBtn);
buttonsPanel.add(addActivityBtn);
contentPanel.add(titleLabel, BorderLayout.NORTH);
contentPanel.add(buttonsPanel, BorderLayout.CENTER);
quickActions.add(contentPanel);
return quickActions;
}
private void showAddDeadlineDialog() {
JPanel panel = new JPanel(new GridLayout(4, 2, 10, 10));
JTextField titleField = new JTextField();
JTextField dueDateField = new JTextField("YYYY-MM-DD");
String[] types = {"📝 Assignment", "📊 Quiz", "💻 Project", "📋 Exam"};
JComboBox<String> typeCombo = new JComboBox<>(types);
JCheckBox urgentCheck = new JCheckBox("Urgent");
panel.add(new JLabel("Title:"));
panel.add(titleField);
panel.add(new JLabel("Due Date:"));
panel.add(dueDateField);
panel.add(new JLabel("Type:"));
panel.add(typeCombo);
panel.add(new JLabel("Urgent:"));
panel.add(urgentCheck);
int result = JOptionPane.showConfirmDialog(this, panel, "Add Deadline", JOptionPane.OK_CANCEL_OPTION);
if (result == JOptionPane.OK_OPTION) {
String title = titleField.getText().trim();
String dueDate = dueDateField.getText().trim();
String type = typeCombo.getSelectedItem().toString();
boolean urgent = urgentCheck.isSelected();
if (!title.isEmpty() && !dueDate.isEmpty()) {
deadlines.add(new Deadline(title, dueDate, type, urgent));
saveDeadlines();
updateDashboardData();
refreshDeadlinesPanel();
}
}
}
private void showAddActivityDialog() {
JPanel panel = new JPanel(new GridLayout(4, 2, 10, 10));
JTextField descField = new JTextField();
JTextField timeField = new JTextField("Just now");
String[] icons = {"+", "✓", "✏", "📚", "🎯", "💡"};
JComboBox<String> iconCombo = new JComboBox<>(icons);
String[] colors = {"76,175,80", "156,39,176", "33,150,243", "255,152,0", "244,67,54", "96,125,139"};
JComboBox<String> colorCombo = new JComboBox<>(new String[]{"Green", "Purple", "Blue", "Orange", "Red", "Gray"});
panel.add(new JLabel("Description:"));
panel.add(descField);
panel.add(new JLabel("Time:"));
panel.add(timeField);
panel.add(new JLabel("Icon:"));
panel.add(iconCombo);
panel.add(new JLabel("Color:"));
panel.add(colorCombo);
int result = JOptionPane.showConfirmDialog(this, panel, "Add Activity", JOptionPane.OK_CANCEL_OPTION);
if (result == JOptionPane.OK_OPTION) {
String description = descField.getText().trim();
String time = timeField.getText().trim();
String icon = iconCombo.getSelectedItem().toString();
String color = colors[colorCombo.getSelectedIndex()];
if (!description.isEmpty()) {
activities.add(new Activity(description, time, icon, color));
saveActivities();
refreshActivityPanel();
}
}
}
private JButton createQuickActionButton(String text) {
JButton button = new JButton(text);
button.setFont(new Font("Segoe UI", Font.BOLD, 14));
button.setForeground(Color.WHITE);
button.setBackground(new Color(255, 255, 255, 40));
button.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(new Color(255, 255, 255, 60), 2),
BorderFactory.createEmptyBorder(12, 20, 12, 20)
));
button.setFocusPainted(false);
button.setCursor(new Cursor(Cursor.HAND_CURSOR));
button.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
button.setBackground(new Color(255, 255, 255, 60));
}
@Override
public void mouseExited(MouseEvent e) {
button.setBackground(new Color(255, 255, 255, 40));
}
});
return button;
}
private JPanel createContentGrid() {
JPanel contentGrid = new JPanel(new GridLayout(2, 2, 20, 20));
contentGrid.setBackground(new Color(245, 247, 250));
// My Courses Panel
JPanel coursesPanel = createSectionCard("📚 My Courses", createCoursesListPanel());
// Upcoming Deadlines Panel
JPanel deadlinesPanel = createSectionCard("🎯 Upcoming Deadlines", createDeadlinesPanel());
// Recent Activity Panel
JPanel activityPanel = createSectionCard("📈 Recent Activity", createActivityPanel());
// Recent Resources Panel
JPanel resourcesPanel = createSectionCard("📚 Recent Resources", createResourcesListPanel());
contentGrid.add(coursesPanel);
contentGrid.add(deadlinesPanel);
contentGrid.add(activityPanel);
contentGrid.add(resourcesPanel);
return contentGrid;
}
private JPanel createSectionCard(String title, JPanel content) {
JPanel card = new JPanel(new BorderLayout());
card.setBackground(Color.WHITE);
card.setBorder(new RoundedBorder(15, new Color(230, 230, 230)));
JPanel headerPanel = new JPanel(new BorderLayout());
headerPanel.setBackground(Color.WHITE);
headerPanel.setBorder(BorderFactory.createEmptyBorder(20, 25, 15, 25));
JLabel titleLabel = new JLabel(title);
titleLabel.setFont(new Font("Segoe UI", Font.BOLD, 18));
titleLabel.setForeground(new Color(51, 51, 51));
// Add management buttons for deadlines and activities
if (title.contains("Deadlines")) {
JButton manageBtn = new JButton("Manage");
manageBtn.setFont(new Font("Segoe UI", Font.PLAIN, 12));
manageBtn.addActionListener(e -> showManageDeadlinesDialog());
headerPanel.add(manageBtn, BorderLayout.EAST);
} else if (title.contains("Activity")) {
JButton manageBtn = new JButton("Manage");
manageBtn.setFont(new Font("Segoe UI", Font.PLAIN, 12));
manageBtn.addActionListener(e -> showManageActivitiesDialog());
headerPanel.add(manageBtn, BorderLayout.EAST);
}
headerPanel.add(titleLabel, BorderLayout.WEST);
JPanel contentPanel = new JPanel(new BorderLayout());
contentPanel.setBackground(Color.WHITE);
contentPanel.setBorder(BorderFactory.createEmptyBorder(0, 25, 20, 25));
contentPanel.add(content, BorderLayout.CENTER);
card.add(headerPanel, BorderLayout.NORTH);
card.add(contentPanel, BorderLayout.CENTER);
return card;
}
private void showManageDeadlinesDialog() {
JDialog dialog = new JDialog(this, "Manage Deadlines", true);
dialog.setLayout(new BorderLayout());
DefaultListModel<String> listModel = new DefaultListModel<>();
for (Deadline deadline : deadlines) {
listModel.addElement(deadline.title + " - Due: " + deadline.dueDate);
}
JList<String> list = new JList<>(listModel);
JScrollPane scrollPane = new JScrollPane(list);
scrollPane.setPreferredSize(new Dimension(400, 300));
JPanel buttonPanel = new JPanel(new FlowLayout());
JButton deleteBtn = new JButton("Delete Selected");
deleteBtn.addActionListener(e -> {
int selectedIndex = list.getSelectedIndex();
if (selectedIndex >= 0) {
deadlines.remove(selectedIndex);
listModel.remove(selectedIndex);
saveDeadlines();
updateDashboardData();
refreshDeadlinesPanel();
}
});
buttonPanel.add(deleteBtn);
dialog.add(scrollPane, BorderLayout.CENTER);
dialog.add(buttonPanel, BorderLayout.SOUTH);
dialog.pack();
dialog.setLocationRelativeTo(this);
dialog.setVisible(true);
}
private void showManageActivitiesDialog() {
JDialog dialog = new JDialog(this, "Manage Activities", true);
dialog.setLayout(new BorderLayout());
DefaultListModel<String> listModel = new DefaultListModel<>();
for (Activity activity : activities) {
listModel.addElement(activity.description + " - " + activity.time);
}
JList<String> list = new JList<>(listModel);
JScrollPane scrollPane = new JScrollPane(list);
scrollPane.setPreferredSize(new Dimension(400, 300));
JPanel buttonPanel = new JPanel(new FlowLayout());
JButton deleteBtn = new JButton("Delete Selected");
deleteBtn.addActionListener(e -> {
int selectedIndex = list.getSelectedIndex();
if (selectedIndex >= 0) {
activities.remove(selectedIndex);
listModel.remove(selectedIndex);
saveActivities();
refreshActivityPanel();
}
});
buttonPanel.add(deleteBtn);
dialog.add(scrollPane, BorderLayout.CENTER);
dialog.add(buttonPanel, BorderLayout.SOUTH);
dialog.pack();
dialog.setLocationRelativeTo(this);
dialog.setVisible(true);
}
private JPanel createCoursesListPanel() {
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setBackground(Color.WHITE);
dashboardMyCoursesArea = new JTextArea();
dashboardMyCoursesArea.setFont(new Font("Segoe UI", Font.PLAIN, 14));
dashboardMyCoursesArea.setEditable(false);
dashboardMyCoursesArea.setBackground(Color.WHITE);
dashboardMyCoursesArea.setBorder(null);
JScrollPane scrollPane = new JScrollPane(dashboardMyCoursesArea);
scrollPane.setBorder(null);
scrollPane.setPreferredSize(new Dimension(0, 200));
scrollPane.setBackground(Color.WHITE);
panel.add(scrollPane);
return panel;
}
private JPanel createDeadlinesPanel() {
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setBackground(Color.WHITE);
deadlinesContentPanel = new JPanel();
deadlinesContentPanel.setLayout(new BoxLayout(deadlinesContentPanel, BoxLayout.Y_AXIS));
deadlinesContentPanel.setBackground(Color.WHITE);
JScrollPane scrollPane = new JScrollPane(deadlinesContentPanel);
scrollPane.setBorder(null);
scrollPane.setPreferredSize(new Dimension(0, 200));
scrollPane.setBackground(Color.WHITE);
panel.add(scrollPane);
refreshDeadlinesPanel();
return panel;
}
private void refreshDeadlinesPanel() {
if (deadlinesContentPanel != null) {
deadlinesContentPanel.removeAll();
if (deadlines.isEmpty()) {
JLabel noDeadlinesLabel = new JLabel("No upcoming deadlines");
noDeadlinesLabel.setFont(new Font("Segoe UI", Font.ITALIC, 14));
noDeadlinesLabel.setForeground(new Color(136, 136, 136));
deadlinesContentPanel.add(noDeadlinesLabel);
} else {
for (int i = 0; i < Math.min(deadlines.size(), 5); i++) { // Show only first 5
Deadline deadline = deadlines.get(i);
deadlinesContentPanel.add(createDeadlineItem(deadline.title, deadline.dueDate, deadline.type, deadline.urgent));
if (i < Math.min(deadlines.size(), 5) - 1) {
deadlinesContentPanel.add(Box.createRigidArea(new Dimension(0, 8)));
}
}
}
deadlinesContentPanel.revalidate();
deadlinesContentPanel.repaint();
}
}
private JPanel createDeadlineItem(String title, String dueDate, String type, boolean urgent) {
JPanel item = new JPanel(new BorderLayout());
item.setBackground(urgent ? new Color(255, 235, 238) : new Color(241, 248, 233));
// Set left border
item.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createMatteBorder(0, 4, 0, 0, urgent ? new Color(244, 67, 54) : new Color(76, 175, 80)),
BorderFactory.createEmptyBorder(12, 15, 12, 15)
));
JLabel titleLabel = new JLabel(title);
titleLabel.setFont(new Font("Segoe UI", Font.BOLD, 14));
titleLabel.setForeground(new Color(51, 51, 51));
JPanel metaPanel = new JPanel(new BorderLayout());
metaPanel.setBackground(item.getBackground());
JLabel dueDateLabel = new JLabel("Due: " + dueDate);
dueDateLabel.setFont(new Font("Segoe UI", Font.PLAIN, 12));
dueDateLabel.setForeground(new Color(102, 102, 102));
JLabel typeLabel = new JLabel(type);
typeLabel.setFont(new Font("Segoe UI Emoji", Font.PLAIN, 14));
metaPanel.add(dueDateLabel, BorderLayout.WEST);
metaPanel.add(typeLabel, BorderLayout.EAST);
JPanel contentPanel = new JPanel();
contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
contentPanel.setBackground(item.getBackground());
contentPanel.add(titleLabel);
contentPanel.add(Box.createRigidArea(new Dimension(0, 5)));
contentPanel.add(metaPanel);
item.add(contentPanel, BorderLayout.CENTER);
return item;
}
private JPanel createActivityPanel() {
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setBackground(Color.WHITE);
activityContentPanel = new JPanel();
activityContentPanel.setLayout(new BoxLayout(activityContentPanel, BoxLayout.Y_AXIS));
activityContentPanel.setBackground(Color.WHITE);
JScrollPane scrollPane = new JScrollPane(activityContentPanel);
scrollPane.setBorder(null);
scrollPane.setPreferredSize(new Dimension(0, 200));
scrollPane.setBackground(Color.WHITE);
panel.add(scrollPane);
refreshActivityPanel();
return panel;
}
private void refreshActivityPanel() {
if (activityContentPanel != null) {
activityContentPanel.removeAll();
if (activities.isEmpty()) {
JLabel noActivityLabel = new JLabel("No recent activities");
noActivityLabel.setFont(new Font("Segoe UI", Font.ITALIC, 14));
noActivityLabel.setForeground(new Color(136, 136, 136));
activityContentPanel.add(noActivityLabel);
} else {
for (int i = 0; i < Math.min(activities.size(), 6); i++) { // Show only first 6
Activity activity = activities.get(i);
String[] colorParts = activity.color.split(",");
Color iconColor = new Color(
Integer.parseInt(colorParts[0]),
Integer.parseInt(colorParts[1]),
Integer.parseInt(colorParts[2])
);
activityContentPanel.add(createActivityItem(activity.description, activity.time, activity.icon, iconColor));
if (i < Math.min(activities.size(), 6) - 1) {
activityContentPanel.add(Box.createRigidArea(new Dimension(0, 8)));
}
}
}
activityContentPanel.revalidate();
activityContentPanel.repaint();
}
}
private JPanel createActivityItem(String title, String time, String icon, Color iconColor) {
JPanel item = new JPanel(new BorderLayout());
item.setBackground(Color.WHITE);
item.setBorder(BorderFactory.createEmptyBorder(8, 0, 8, 0));
// Icon panel
JPanel iconPanel = new JPanel();
iconPanel.setBackground(iconColor);
iconPanel.setPreferredSize(new Dimension(35, 35));
iconPanel.setLayout(new BorderLayout());
iconPanel.setBorder(new RoundedBorder(17, iconColor));
JLabel iconLabel = new JLabel(icon, SwingConstants.CENTER);
iconLabel.setFont(new Font("Segoe UI", Font.BOLD, 12));
iconLabel.setForeground(Color.WHITE);
iconPanel.add(iconLabel, BorderLayout.CENTER);
// Content panel
JPanel contentPanel = new JPanel();
contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
contentPanel.setBackground(Color.WHITE);
contentPanel.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0));
JLabel titleLabel = new JLabel(title);