Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 44 additions & 17 deletions digitalCookBook/src/ui/admin/AdminPanel.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* File: AdminPanel.java
* Author: Angelina Binoy
* Date: 11 October 2025
* Description:
* This class creates the main Admin Panel GUI for the Recipe Manager application.
* It includes a top bar with project info, a side menu for navigation, and a
* main content area using CardLayout to switch between different admin views
* such as Chefs (UsersPanel) and Viewers. Logout functionality is also included.
*/

package ui.admin;

Expand All @@ -9,45 +19,53 @@
import java.awt.event.*;

public class AdminPanel {
private JFrame frame;
private JPanel mainContent;
private CardLayout cardLayout;
private boolean showDelete;
public User loggedInUser;

public AdminPanel(User loggedInUser) {
private JFrame frame; // Main frame for the admin panel
private JPanel mainContent; // Panel to hold different views using CardLayout
private CardLayout cardLayout; // Layout manager to switch between panels
private boolean showDelete; // Flag for showing delete options in UserListPanel
public User loggedInUser; // Currently logged-in admin user

// Constructor initializes the Admin Panel GUI
public AdminPanel(User loggedInUser) {
this.loggedInUser = loggedInUser;

// === Main JFrame setup ===
frame = new JFrame("Recipe Manager - Admin Dashboard");
frame.setSize(1000, 650);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setLocationRelativeTo(null); // Center on screen
frame.setLayout(new BorderLayout());

// === Top Bar ===
// === Top Bar (header) ===
JPanel topBar = createTopBar();
frame.add(topBar, BorderLayout.NORTH);

// === Side Menu ===
// === Side Menu (navigation) ===
JPanel sideMenu = createSideMenu();
frame.add(sideMenu, BorderLayout.WEST);

// === Main Content Area ===
cardLayout = new CardLayout();
mainContent = new JPanel(cardLayout);

// Add panels
boolean showDelete = true;
// Add panels to the CardLayout
boolean showDelete = true; // Option to show delete buttons in user panel
mainContent.add(new UserListpanel(cardLayout, mainContent, showDelete), "UsersPanel");
mainContent.add(new ViewerList(cardLayout, mainContent), "Viewers");

frame.add(mainContent, BorderLayout.CENTER);

// Show the frame
frame.setVisible(true);
}

/**
* Creates the top bar with project title and welcome message.
*/
private JPanel createTopBar() {
JPanel topBar = new JPanel(new BorderLayout());
topBar.setBackground(new Color(45, 110, 195));
topBar.setBackground(new Color(45, 110, 195)); // Blue background
topBar.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20));

JLabel projectLabel = new JLabel("🍴 Recipe Manager");
Expand All @@ -64,18 +82,22 @@ private JPanel createTopBar() {
return topBar;
}

/**
* Creates the side menu with navigation buttons: Chefs, Viewers, Logout.
*/
private JPanel createSideMenu() {
JPanel sideMenu = new JPanel();
sideMenu.setLayout(new BoxLayout(sideMenu, BoxLayout.Y_AXIS));
sideMenu.setBackground(new Color(245, 247, 250));
sideMenu.setPreferredSize(new Dimension(200, 0));
sideMenu.setBorder(BorderFactory.createEmptyBorder(20, 10, 10, 10));

// Menu buttons
JButton btnUsers = createMenuButton("Chefs");
JButton btnViewers = createMenuButton("Viewers");
JButton btnLogout = createMenuButton("Logout");

// === Traditional ActionListeners (no lambdas) ===
// Button actions (switch panels or logout)
btnUsers.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Expand All @@ -93,20 +115,24 @@ public void actionPerformed(ActionEvent e) {
btnLogout.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
LogoutAction.performLogout(frame);
LogoutAction.performLogout(frame); // Perform logout
}
});

// Add buttons to the side menu with spacing
sideMenu.add(Box.createVerticalStrut(10));
sideMenu.add(btnUsers);
sideMenu.add(Box.createVerticalStrut(10));
sideMenu.add(btnViewers);
sideMenu.add(Box.createVerticalGlue());
sideMenu.add(Box.createVerticalGlue()); // Push logout to bottom
sideMenu.add(btnLogout);

return sideMenu;
}

/**
* Helper method to create a styled side menu button with hover effects.
*/
private JButton createMenuButton(String text) {
JButton btn = new JButton(text);
btn.setMaximumSize(new Dimension(180, 45));
Expand All @@ -118,11 +144,12 @@ private JButton createMenuButton(String text) {
btn.setCursor(new Cursor(Cursor.HAND_CURSOR));
btn.setBorder(BorderFactory.createEmptyBorder(8, 12, 8, 12));

// Hover effect to lighten button color on mouse over
btn.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) { btn.setBackground(new Color(80, 140, 220)); }
public void mouseExited(MouseEvent e) { btn.setBackground(new Color(60, 120, 200)); }
});

return btn;
}
}

}
51 changes: 40 additions & 11 deletions digitalCookBook/src/ui/admin/UserListpanel.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* File: UserListpanel.java
* Author: Angelina Binoy
* Date: 12 October 2025
* Description:
* This class represents the panel displaying a list of registered chefs (users)
* in the Admin Dashboard. Each chef is displayed in a card with options to
* view their profile or delete them (if admin permission is granted).
* The panel uses a scrollable layout to handle large numbers of users.
*/

package ui.admin;

Expand All @@ -13,56 +23,65 @@

public class UserListpanel extends JPanel {

/**
* Constructor to create the User List Panel
*
* @param cardLayout CardLayout from parent panel for switching views
* @param mainContent Main content panel containing all views
* @param showDelete Flag to indicate if delete buttons should be shown
*/
public UserListpanel(CardLayout cardLayout, JPanel mainContent, boolean showDelete) {
setLayout(new BorderLayout());
setBackground(Color.WHITE);

// 🔹 Header
// 🔹 Header label
JLabel header = new JLabel("Registered Chefs", SwingConstants.CENTER);
header.setFont(new Font("Segoe UI", Font.BOLD, 22));
header.setBorder(new EmptyBorder(20, 0, 10, 0));
add(header, BorderLayout.NORTH);

// 🔹 User list panel
// 🔹 Panel to hold individual user cards
JPanel userListPanel = new JPanel();
userListPanel.setLayout(new BoxLayout(userListPanel, BoxLayout.Y_AXIS));
userListPanel.setBackground(Color.WHITE);
userListPanel.setBorder(new EmptyBorder(20, 30, 20, 30));

try {
UserDAO dao = new UserDAO();
List<User> chefs = dao.getChefs();
List<User> chefs = dao.getChefs(); // Fetch all registered chefs

for (User user : chefs) {
// 🔹 Card panel for each user
JPanel card = new JPanel(new BorderLayout());
card.setBackground(new Color(250, 250, 250));
card.setBorder(new CompoundBorder(
new LineBorder(new Color(220, 220, 220), 1, true),
new EmptyBorder(10, 15, 10, 15)
));

// 🔹 Username label with chef emoji
JLabel name = new JLabel("👨‍🍳 " + user.getUsername());
name.setFont(new Font("Segoe UI", Font.PLAIN, 16));

// 🔹 Panel for action buttons (View, Delete)
JPanel btnPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 0));
btnPanel.setOpaque(false);

// 🔹 View button
// 🔹 View profile button
JButton viewBtn = new JButton("View");
styleActionButton(viewBtn, new Color(46, 204, 113));

styleActionButton(viewBtn, new Color(46, 204, 113)); // Green button
viewBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ev) {
new ChefProfile(user);
new ChefProfile(user); // Open Chef Profile window
}
});
btnPanel.add(viewBtn);

// 🔹 Delete button for admin
// 🔹 Delete button (only if showDelete is true)
if (showDelete) {
JButton deleteBtn = new JButton("Delete");
styleActionButton(deleteBtn, new Color(231, 76, 60));
styleActionButton(deleteBtn, new Color(231, 76, 60)); // Red button

deleteBtn.addActionListener(new ActionListener() {
@Override
Expand All @@ -84,6 +103,7 @@ public void actionPerformed(ActionEvent ev) {
"User deleted successfully!"
);

// Remove card from panel and refresh UI
userListPanel.remove(card);
userListPanel.revalidate();
userListPanel.repaint();
Expand All @@ -101,10 +121,12 @@ public void actionPerformed(ActionEvent ev) {
btnPanel.add(deleteBtn);
}

// Add name and button panel to card
card.add(name, BorderLayout.WEST);
card.add(btnPanel, BorderLayout.EAST);
card.setMaximumSize(new Dimension(Integer.MAX_VALUE, 55));
card.setMaximumSize(new Dimension(Integer.MAX_VALUE, 55)); // Fixed height

// Add card to user list panel with spacing
userListPanel.add(card);
userListPanel.add(Box.createVerticalStrut(10));
}
Expand All @@ -113,11 +135,18 @@ public void actionPerformed(ActionEvent ev) {
JOptionPane.showMessageDialog(this, "❌ Error loading users: " + e.getMessage());
}

// Add scroll pane for the user list
JScrollPane scrollPane = new JScrollPane(userListPanel);
scrollPane.setBorder(null);
add(scrollPane, BorderLayout.CENTER);
}

/**
* Helper method to style action buttons consistently
*
* @param btn JButton to style
* @param bgColor Background color of the button
*/
private void styleActionButton(JButton btn, Color bgColor) {
btn.setBackground(bgColor);
btn.setForeground(Color.WHITE);
Expand All @@ -126,6 +155,7 @@ private void styleActionButton(JButton btn, Color bgColor) {
btn.setCursor(new Cursor(Cursor.HAND_CURSOR));
btn.setBorder(new EmptyBorder(6, 10, 6, 10));

// Hover effect: darken background on mouse over
btn.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseEntered(java.awt.event.MouseEvent e) {
btn.setBackground(bgColor.darker());
Expand All @@ -137,4 +167,3 @@ public void mouseExited(java.awt.event.MouseEvent e) {
});
}
}

Loading