-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibrarianDashboard.java
More file actions
306 lines (269 loc) · 11 KB
/
LibrarianDashboard.java
File metadata and controls
306 lines (269 loc) · 11 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
import javax.swing.*;
import java.awt.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class LibrarianDashboard extends JFrame {
private int userId;
private JPanel contentPanel;
private boolean isDarkMode = false;
private Color darkBackground = new Color(33, 33, 33);
private Color lightBackground = new Color(242, 242, 242);
private Color darkMenuBackground = new Color(50, 50, 50);
private Color lightMenuBackground = new Color(230, 230, 230);
private Color primaryColor = new Color(70, 130, 180);
private JPanel menuPanel;
public LibrarianDashboard(int userId) {
this.userId = userId;
setTitle("Library Management System - Librarian Dashboard");
setSize(1200, 800);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
// Create split pane
JSplitPane splitPane = new JSplitPane();
splitPane.setBorder(null);
// Create menu panel
menuPanel = createMenuPanel();
contentPanel = new JPanel();
contentPanel.setLayout(new BorderLayout());
showWelcomeMessage();
splitPane.setLeftComponent(menuPanel);
splitPane.setRightComponent(contentPanel);
splitPane.setDividerLocation(250);
splitPane.setDividerSize(1);
add(splitPane);
applyTheme();
}
private JPanel createMenuPanel() {
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
// Add profile section
JPanel profilePanel = new JPanel(new BorderLayout());
profilePanel.setOpaque(false);
JLabel userLabel = new JLabel("Librarian Dashboard");
userLabel.setFont(new Font("Segoe UI", Font.BOLD, 20));
profilePanel.add(userLabel, BorderLayout.CENTER);
panel.add(profilePanel);
panel.add(Box.createRigidArea(new Dimension(0, 30)));
String[] menuItems = {
"Manage Books",
"Issue Books",
"View Issued Books",
"Return Books",
"Student Records",
"Notifications",
"Toggle Theme",
"Logout"
};
for (String item : menuItems) {
JButton button = createMenuButton(item);
panel.add(button);
panel.add(Box.createRigidArea(new Dimension(0, 10)));
}
return panel;
}
private JButton createMenuButton(String text) {
JButton button = new JButton(text);
button.setFont(new Font("Segoe UI", Font.PLAIN, 14));
button.setAlignmentX(Component.CENTER_ALIGNMENT);
button.setMaximumSize(new Dimension(200, 40));
button.setFocusPainted(false);
button.setBorderPainted(false);
button.addActionListener(e -> handleMenuClick(text));
return button;
}
private void handleMenuClick(String menuItem) {
switch(menuItem) {
case "Manage Books":
showBookManagement();
break;
case "Issue Books":
showIssueBooks();
break;
case "View Issued Books":
showIssuedBooks();
break;
case "Return Books":
showReturnBooks();
break;
case "Student Records":
showStudentRecords();
break;
case "Notifications":
showNotifications();
break;
case "Toggle Theme":
isDarkMode = !isDarkMode;
applyTheme();
break;
case "Logout":
handleLogout();
break;
}
}
private void applyTheme() {
menuPanel.setBackground(isDarkMode ? darkMenuBackground : lightMenuBackground);
contentPanel.setBackground(isDarkMode ? darkBackground : lightBackground);
for (Component c : menuPanel.getComponents()) {
if (c instanceof JButton) {
JButton button = (JButton) c;
button.setBackground(isDarkMode ? new Color(70, 70, 70) : primaryColor);
button.setForeground(Color.WHITE);
} else if (c instanceof JPanel) {
JPanel panel = (JPanel) c;
panel.setBackground(isDarkMode ? darkMenuBackground : lightMenuBackground);
for (Component comp : panel.getComponents()) {
if (comp instanceof JLabel) {
((JLabel) comp).setForeground(isDarkMode ? Color.WHITE : Color.BLACK);
}
}
}
}
SwingUtilities.updateComponentTreeUI(this);
}
private void showWelcomeMessage() {
contentPanel.removeAll();
JPanel welcomePanel = new JPanel(new GridBagLayout());
welcomePanel.setBackground(isDarkMode ? darkBackground : lightBackground);
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.anchor = GridBagConstraints.CENTER;
gbc.insets = new Insets(10, 10, 10, 10);
// Welcome message
JLabel welcomeLabel = new JLabel("Welcome to Librarian Dashboard");
welcomeLabel.setFont(new Font("Segoe UI", Font.BOLD, 24));
welcomeLabel.setForeground(isDarkMode ? Color.WHITE : Color.BLACK);
welcomePanel.add(welcomeLabel, gbc);
// Add librarian name if available
try {
Connection conn = DatabaseConnection.getConnection();
PreparedStatement stmt = conn.prepareStatement(
"SELECT full_name FROM users WHERE user_id = ?"
);
stmt.setInt(1, userId);
ResultSet rs = stmt.executeQuery();
if (rs.next()) {
JLabel nameLabel = new JLabel("Welcome, " + rs.getString("full_name"));
nameLabel.setFont(new Font("Segoe UI", Font.PLAIN, 18));
nameLabel.setForeground(isDarkMode ? Color.WHITE : Color.BLACK);
gbc.insets = new Insets(10, 10, 20, 10);
welcomePanel.add(nameLabel, gbc);
}
// Get some statistics
stmt = conn.prepareStatement(
"SELECT COUNT(*) FROM book_borrowings WHERE status = 'BORROWED'"
);
rs = stmt.executeQuery();
if (rs.next()) {
JLabel statsLabel = new JLabel("Total Books Currently Issued: " + rs.getInt(1));
statsLabel.setFont(new Font("Segoe UI", Font.PLAIN, 16));
statsLabel.setForeground(isDarkMode ? Color.WHITE : Color.BLACK);
gbc.insets = new Insets(20, 10, 10, 10);
welcomePanel.add(statsLabel, gbc);
}
} catch (SQLException ex) {
ex.printStackTrace();
showErrorMessage("Error loading statistics: " + ex.getMessage());
}
contentPanel.add(welcomePanel);
contentPanel.revalidate();
contentPanel.repaint();
}
private void showBookManagement() {
contentPanel.removeAll();
try {
BookManagementPanel bookPanel = new BookManagementPanel(userId , isDarkMode);
contentPanel.add(bookPanel);
} catch (Exception ex) {
showErrorMessage("Error loading book management panel: " + ex.getMessage());
ex.printStackTrace();
}
contentPanel.revalidate();
contentPanel.repaint();
}
private void showIssueBooks() {
contentPanel.removeAll();
try {
IssueBooksPanel issuePanel = new IssueBooksPanel(userId, isDarkMode);
contentPanel.add(issuePanel);
} catch (Exception ex) {
showErrorMessage("Error loading issue books panel: " + ex.getMessage());
ex.printStackTrace();
}
contentPanel.revalidate();
contentPanel.repaint();
}
private void showIssuedBooks() {
contentPanel.removeAll();
try {
IssuedBooksPanel issuedBooksPanel = new IssuedBooksPanel(userId, isDarkMode);
contentPanel.add(issuedBooksPanel);
} catch (Exception ex) {
showErrorMessage("Error loading issued books panel: " + ex.getMessage());
ex.printStackTrace();
}
contentPanel.revalidate();
contentPanel.repaint();
}
private void showReturnBooks() {
contentPanel.removeAll();
try {
ReturnBooksPanel returnPanel = new ReturnBooksPanel(userId, isDarkMode);
contentPanel.add(returnPanel);
} catch (Exception ex) {
showErrorMessage("Error loading return books panel: " + ex.getMessage());
ex.printStackTrace();
}
contentPanel.revalidate();
contentPanel.repaint();
}
private void showStudentRecords() {
contentPanel.removeAll();
try {
StudentRecordsPanel studentPanel = new StudentRecordsPanel(userId, isDarkMode);
contentPanel.add(studentPanel);
} catch (Exception ex) {
showErrorMessage("Error loading student records panel: " + ex.getMessage());
ex.printStackTrace();
}
contentPanel.revalidate();
contentPanel.repaint();
}
private void showNotifications() {
contentPanel.removeAll();
try {
NotificationPanel notificationPanel = new NotificationPanel(userId, isDarkMode);
contentPanel.add(notificationPanel);
} catch (Exception ex) {
showErrorMessage("Error loading notifications panel: " + ex.getMessage());
ex.printStackTrace();
}
contentPanel.revalidate();
contentPanel.repaint();
}
private void showErrorMessage(String message) {
JPanel errorPanel = new JPanel(new GridBagLayout());
errorPanel.setBackground(isDarkMode ? darkBackground : lightBackground);
JLabel errorLabel = new JLabel(message);
errorLabel.setForeground(Color.RED);
errorLabel.setFont(new Font("Segoe UI", Font.PLAIN, 14));
errorPanel.add(errorLabel);
contentPanel.add(errorPanel);
contentPanel.revalidate();
contentPanel.repaint();
}
private void handleLogout() {
int confirm = JOptionPane.showConfirmDialog(
this,
"Are you sure you want to logout?",
"Confirm Logout",
JOptionPane.YES_NO_OPTION
);
if (confirm == JOptionPane.YES_OPTION) {
this.dispose();
new LoginScreen().setVisible(true);
}
}
}