mirror of
https://github.com/BalrajSinghGidda/Smart-College-Management-System.git
synced 2026-04-07 09:37:22 +00:00
Second draft
This commit is contained in:
BIN
college.db
BIN
college.db
Binary file not shown.
@@ -1,11 +1,13 @@
|
||||
package com.college.management;
|
||||
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.*;
|
||||
import javafx.stage.Stage;
|
||||
import java.sql.*;
|
||||
import java.util.List;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.control.cell.PropertyValueFactory;
|
||||
@@ -23,6 +25,7 @@ public class AdminDashboard {
|
||||
|
||||
public void show() {
|
||||
BorderPane root = new BorderPane();
|
||||
root.getStyleClass().add("dashboard-root");
|
||||
|
||||
// Sidebar
|
||||
VBox sidebar = new VBox(10);
|
||||
@@ -40,12 +43,15 @@ public class AdminDashboard {
|
||||
Button btnChat = createSidebarButton("Global Chat");
|
||||
Button btnPrivateChat = createSidebarButton("Private Chat");
|
||||
Button btnReports = createSidebarButton("Reports");
|
||||
Button btnSettings = createSidebarButton("Settings");
|
||||
Button btnLogout = createSidebarButton("Logout");
|
||||
|
||||
sidebar.getChildren().addAll(brand, new Separator(), btnUsers, btnNotices, btnTimetable, btnEvents, btnChat, btnPrivateChat, btnReports, btnLogout);
|
||||
sidebar.getChildren().addAll(brand, new Separator(), btnUsers, btnNotices, btnTimetable, btnEvents, btnChat, btnPrivateChat, btnReports, btnSettings, btnLogout);
|
||||
|
||||
root.setLeft(sidebar);
|
||||
|
||||
applyTheme(root);
|
||||
|
||||
// Default Content
|
||||
showUserManagement(root);
|
||||
|
||||
@@ -53,9 +59,10 @@ public class AdminDashboard {
|
||||
btnNotices.setOnAction(e -> showNoticeManagement(root));
|
||||
btnTimetable.setOnAction(e -> showTimetableManagement(root));
|
||||
btnEvents.setOnAction(e -> showEventManagement(root));
|
||||
btnChat.setOnAction(e -> showChat(root, "Admin"));
|
||||
btnChat.setOnAction(e -> showChat(root, username, userId));
|
||||
btnPrivateChat.setOnAction(e -> root.setCenter(new PrivateChatUI(userId).getView()));
|
||||
btnReports.setOnAction(e -> showReports(root));
|
||||
btnSettings.setOnAction(e -> root.setCenter(new SettingsUI(userId, () -> applyTheme(root)).getView()));
|
||||
btnLogout.setOnAction(e -> new App().start(stage));
|
||||
|
||||
Scene scene = new Scene(root, 900, 600);
|
||||
@@ -63,6 +70,16 @@ public class AdminDashboard {
|
||||
stage.setScene(scene);
|
||||
}
|
||||
|
||||
private void applyTheme(BorderPane root) {
|
||||
root.getStylesheets().clear();
|
||||
root.getStylesheets().add(getClass().getResource("/com/college/management/css/chat.css").toExternalForm());
|
||||
UserSettings settings = UserSettings.getSettings(userId);
|
||||
root.getStyleClass().remove("dark-theme");
|
||||
if ("DARK".equals(settings.getTheme())) {
|
||||
root.getStyleClass().add("dark-theme");
|
||||
}
|
||||
}
|
||||
|
||||
private void showTimetableManagement(BorderPane root) {
|
||||
VBox content = new VBox(15);
|
||||
content.setPadding(new Insets(20));
|
||||
@@ -127,34 +144,40 @@ public class AdminDashboard {
|
||||
root.setCenter(content);
|
||||
}
|
||||
|
||||
public static void showChat(BorderPane root, String senderName) {
|
||||
VBox content = new VBox(10);
|
||||
content.setPadding(new Insets(20));
|
||||
Label title = new Label("Global Chat / Announcements");
|
||||
title.setStyle("-fx-font-size: 24px; -fx-font-weight: bold;");
|
||||
public static void showChat(BorderPane root, String senderName, int viewerId) {
|
||||
VBox mainBox = new VBox();
|
||||
|
||||
TextArea chatArea = new TextArea();
|
||||
chatArea.setEditable(false);
|
||||
chatArea.setPrefHeight(400);
|
||||
Label title = new Label("Global Chat / Announcements");
|
||||
title.setPadding(new Insets(10));
|
||||
title.setStyle("-fx-font-size: 20px; -fx-font-weight: bold;");
|
||||
|
||||
ScrollPane scrollPane = new ScrollPane();
|
||||
VBox messageContainer = new VBox(15);
|
||||
messageContainer.setPadding(new Insets(20));
|
||||
messageContainer.getStyleClass().add("chat-container");
|
||||
|
||||
scrollPane.setContent(messageContainer);
|
||||
scrollPane.setFitToWidth(true);
|
||||
scrollPane.setVvalue(1.0);
|
||||
VBox.setVgrow(scrollPane, Priority.ALWAYS);
|
||||
|
||||
HBox inputArea = new HBox(10);
|
||||
inputArea.setPadding(new Insets(10));
|
||||
inputArea.setAlignment(Pos.CENTER);
|
||||
TextField txtMsg = new TextField();
|
||||
txtMsg.setPromptText("Type a message...");
|
||||
txtMsg.setPrefWidth(500);
|
||||
Button btnSend = new Button("Send");
|
||||
btnSend.setStyle("-fx-background-color: #128c7e; -fx-text-fill: white; -fx-font-weight: bold;");
|
||||
|
||||
Runnable refreshChat = () -> {
|
||||
try (Connection conn = DatabaseManager.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT sender, content, timestamp FROM messages ORDER BY id ASC")) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
while (rs.next()) {
|
||||
sb.append("[").append(rs.getString("timestamp")).append("] ")
|
||||
.append(rs.getString("sender")).append(": ")
|
||||
.append(rs.getString("content")).append("\n");
|
||||
}
|
||||
chatArea.setText(sb.toString());
|
||||
chatArea.setScrollTop(Double.MAX_VALUE);
|
||||
} catch (SQLException ex) { ex.printStackTrace(); }
|
||||
messageContainer.getChildren().clear();
|
||||
List<ChatMessage> messages = ChatService.getGlobalMessages();
|
||||
for (ChatMessage msg : messages) {
|
||||
boolean isMine = msg.getSenderName().equals(senderName);
|
||||
messageContainer.getChildren().add(PrivateChatUI.createBubble(msg, isMine, viewerId));
|
||||
}
|
||||
scrollPane.setVvalue(1.0);
|
||||
};
|
||||
|
||||
btnSend.setOnAction(e -> {
|
||||
@@ -171,8 +194,8 @@ public class AdminDashboard {
|
||||
|
||||
refreshChat.run();
|
||||
inputArea.getChildren().addAll(txtMsg, btnSend);
|
||||
content.getChildren().addAll(title, chatArea, inputArea);
|
||||
root.setCenter(content);
|
||||
mainBox.getChildren().addAll(title, scrollPane, inputArea);
|
||||
root.setCenter(mainBox);
|
||||
}
|
||||
|
||||
private void showReports(BorderPane root) {
|
||||
|
||||
22
src/main/java/com/college/management/ChatMessage.java
Normal file
22
src/main/java/com/college/management/ChatMessage.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package com.college.management;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class ChatMessage {
|
||||
private String senderName;
|
||||
private int senderId;
|
||||
private String content;
|
||||
private String timestamp;
|
||||
|
||||
public ChatMessage(String senderName, int senderId, String content, String timestamp) {
|
||||
this.senderName = senderName;
|
||||
this.senderId = senderId;
|
||||
this.content = content;
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public String getSenderName() { return senderName; }
|
||||
public int getSenderId() { return senderId; }
|
||||
public String getContent() { return content; }
|
||||
public String getTimestamp() { return timestamp; }
|
||||
}
|
||||
@@ -17,9 +17,9 @@ public class ChatService {
|
||||
} catch (SQLException e) { e.printStackTrace(); }
|
||||
}
|
||||
|
||||
public static List<String> getPrivateConversation(int user1, int user2) {
|
||||
List<String> messages = new ArrayList<>();
|
||||
String sql = "SELECT u.username as sender_name, pm.content, pm.timestamp " +
|
||||
public static List<ChatMessage> getPrivateConversation(int user1, int user2) {
|
||||
List<ChatMessage> messages = new ArrayList<>();
|
||||
String sql = "SELECT u.username as sender_name, pm.sender_id, pm.content, pm.timestamp " +
|
||||
"FROM private_messages pm " +
|
||||
"JOIN users u ON pm.sender_id = u.id " +
|
||||
"WHERE (pm.sender_id = ? AND pm.receiver_id = ?) " +
|
||||
@@ -33,8 +33,25 @@ public class ChatService {
|
||||
pstmt.setInt(4, user1);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
messages.add("[" + rs.getString("timestamp") + "] " +
|
||||
rs.getString("sender_name") + ": " + rs.getString("content"));
|
||||
messages.add(new ChatMessage(
|
||||
rs.getString("sender_name"),
|
||||
rs.getInt("sender_id"),
|
||||
rs.getString("content"),
|
||||
rs.getString("timestamp")
|
||||
));
|
||||
}
|
||||
} catch (SQLException e) { e.printStackTrace(); }
|
||||
return messages;
|
||||
}
|
||||
|
||||
public static List<ChatMessage> getGlobalMessages() {
|
||||
List<ChatMessage> messages = new ArrayList<>();
|
||||
String sql = "SELECT sender, content, timestamp FROM messages ORDER BY id ASC";
|
||||
try (Connection conn = DatabaseManager.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
ResultSet rs = stmt.executeQuery(sql)) {
|
||||
while (rs.next()) {
|
||||
messages.add(new ChatMessage(rs.getString("sender"), -1, rs.getString("content"), rs.getString("timestamp")));
|
||||
}
|
||||
} catch (SQLException e) { e.printStackTrace(); }
|
||||
return messages;
|
||||
|
||||
@@ -98,6 +98,15 @@ public class DatabaseManager {
|
||||
"FOREIGN KEY(receiver_id) REFERENCES users(id)" +
|
||||
")");
|
||||
|
||||
// User Settings
|
||||
stmt.execute("CREATE TABLE IF NOT EXISTS user_settings (" +
|
||||
"user_id INTEGER PRIMARY KEY," +
|
||||
"theme TEXT DEFAULT 'LIGHT'," +
|
||||
"bubble_color TEXT DEFAULT '#e1ffc7'," +
|
||||
"display_name TEXT," +
|
||||
"FOREIGN KEY(user_id) REFERENCES users(id)" +
|
||||
")");
|
||||
|
||||
// Insert default admin if not exists
|
||||
stmt.execute("INSERT OR IGNORE INTO users (username, password, role) VALUES ('admin', 'admin123', 'ADMIN')");
|
||||
|
||||
|
||||
@@ -39,19 +39,22 @@ public class FacultyDashboard {
|
||||
Button btnEvents = createSidebarButton("Events");
|
||||
Button btnChat = createSidebarButton("Global Chat");
|
||||
Button btnPrivateChat = createSidebarButton("Private Chat");
|
||||
Button btnSettings = createSidebarButton("Settings");
|
||||
Button btnLogout = createSidebarButton("Logout");
|
||||
|
||||
sidebar.getChildren().addAll(brand, new Separator(), btnAttendance, btnMarks, btnTimetable, btnEvents, btnChat, btnPrivateChat, btnLogout);
|
||||
sidebar.getChildren().addAll(brand, new Separator(), btnAttendance, btnMarks, btnTimetable, btnEvents, btnChat, btnPrivateChat, btnSettings, btnLogout);
|
||||
root.setLeft(sidebar);
|
||||
|
||||
applyTheme(root);
|
||||
showAttendanceManagement(root);
|
||||
|
||||
btnAttendance.setOnAction(e -> showAttendanceManagement(root));
|
||||
btnMarks.setOnAction(e -> showMarksEntry(root));
|
||||
btnTimetable.setOnAction(e -> showTimetable(root));
|
||||
btnEvents.setOnAction(e -> showEvents(root));
|
||||
btnChat.setOnAction(e -> AdminDashboard.showChat(root, username));
|
||||
btnChat.setOnAction(e -> AdminDashboard.showChat(root, username, userId));
|
||||
btnPrivateChat.setOnAction(e -> root.setCenter(new PrivateChatUI(userId).getView()));
|
||||
btnSettings.setOnAction(e -> root.setCenter(new SettingsUI(userId, () -> applyTheme(root)).getView()));
|
||||
btnLogout.setOnAction(e -> new App().start(stage));
|
||||
|
||||
Scene scene = new Scene(root, 900, 600);
|
||||
@@ -59,6 +62,16 @@ public class FacultyDashboard {
|
||||
stage.setScene(scene);
|
||||
}
|
||||
|
||||
private void applyTheme(BorderPane root) {
|
||||
root.getStylesheets().clear();
|
||||
root.getStylesheets().add(getClass().getResource("/com/college/management/css/chat.css").toExternalForm());
|
||||
UserSettings settings = UserSettings.getSettings(userId);
|
||||
root.getStyleClass().remove("dark-theme");
|
||||
if ("DARK".equals(settings.getTheme())) {
|
||||
root.getStyleClass().add("dark-theme");
|
||||
}
|
||||
}
|
||||
|
||||
private void showTimetable(BorderPane root) {
|
||||
VBox content = new VBox(15);
|
||||
content.setPadding(new Insets(20));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.college.management;
|
||||
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.*;
|
||||
import java.util.List;
|
||||
@@ -8,7 +9,8 @@ import java.util.List;
|
||||
public class PrivateChatUI {
|
||||
private int currentUserId;
|
||||
private User selectedUser;
|
||||
private TextArea chatArea;
|
||||
private VBox messageContainer;
|
||||
private ScrollPane scrollPane;
|
||||
private ListView<User> userList;
|
||||
|
||||
public PrivateChatUI(int currentUserId) {
|
||||
@@ -17,13 +19,14 @@ public class PrivateChatUI {
|
||||
|
||||
public Pane getView() {
|
||||
BorderPane layout = new BorderPane();
|
||||
|
||||
|
||||
// Left side: User List
|
||||
VBox leftPane = new VBox(10);
|
||||
leftPane.setPadding(new Insets(10));
|
||||
leftPane.setPrefWidth(200);
|
||||
leftPane.setStyle("-fx-background-color: #ffffff; -fx-border-color: #dcdcdc; -fx-border-width: 0 1 0 0;");
|
||||
Label userLbl = new Label("Contacts");
|
||||
userLbl.setStyle("-fx-font-weight: bold;");
|
||||
userLbl.setStyle("-fx-font-weight: bold; -fx-font-size: 16px;");
|
||||
|
||||
userList = new ListView<>();
|
||||
refreshUserList();
|
||||
@@ -41,22 +44,35 @@ public class PrivateChatUI {
|
||||
layout.setLeft(leftPane);
|
||||
|
||||
// Center: Chat Area
|
||||
VBox chatPane = new VBox(10);
|
||||
chatPane.setPadding(new Insets(10));
|
||||
VBox mainChatPane = new VBox();
|
||||
|
||||
chatArea = new TextArea();
|
||||
chatArea.setEditable(false);
|
||||
chatArea.setPrefHeight(400);
|
||||
chatArea.setWrapText(true);
|
||||
scrollPane = new ScrollPane();
|
||||
messageContainer = new VBox(15);
|
||||
messageContainer.setPadding(new Insets(20));
|
||||
messageContainer.getStyleClass().add("chat-container");
|
||||
messageContainer.setPrefWidth(550);
|
||||
|
||||
scrollPane.setContent(messageContainer);
|
||||
scrollPane.setFitToWidth(true);
|
||||
scrollPane.setVvalue(1.0);
|
||||
VBox.setVgrow(scrollPane, Priority.ALWAYS);
|
||||
|
||||
HBox inputPane = new HBox(10);
|
||||
inputPane.setPadding(new Insets(10));
|
||||
inputPane.setStyle("-fx-background-color: #f0f0f0;");
|
||||
inputPane.setAlignment(Pos.CENTER);
|
||||
|
||||
TextField txtMsg = new TextField();
|
||||
txtMsg.setPrefWidth(400);
|
||||
txtMsg.setPromptText("Type a message...");
|
||||
txtMsg.setPrefWidth(450);
|
||||
txtMsg.setStyle("-fx-background-radius: 20;");
|
||||
|
||||
Button btnSend = new Button("Send");
|
||||
btnSend.setStyle("-fx-background-color: #128c7e; -fx-text-fill: white; -fx-background-radius: 20; -fx-font-weight: bold;");
|
||||
inputPane.getChildren().addAll(txtMsg, btnSend);
|
||||
|
||||
chatPane.getChildren().addAll(new Label("Chat Window"), chatArea, inputPane);
|
||||
layout.setCenter(chatPane);
|
||||
mainChatPane.getChildren().addAll(scrollPane, inputPane);
|
||||
layout.setCenter(mainChatPane);
|
||||
|
||||
// Logic
|
||||
userList.getSelectionModel().selectedItemProperty().addListener((obs, oldVal, newVal) -> {
|
||||
@@ -81,16 +97,48 @@ public class PrivateChatUI {
|
||||
}
|
||||
|
||||
private void refreshMessages() {
|
||||
if (selectedUser == null) {
|
||||
chatArea.setText("Select a contact to start chatting.");
|
||||
return;
|
||||
messageContainer.getChildren().clear();
|
||||
if (selectedUser == null) return;
|
||||
|
||||
List<ChatMessage> history = ChatService.getPrivateConversation(currentUserId, selectedUser.getId());
|
||||
for (ChatMessage msg : history) {
|
||||
boolean isMine = msg.getSenderId() == currentUserId;
|
||||
messageContainer.getChildren().add(createBubble(msg, isMine, currentUserId));
|
||||
}
|
||||
List<String> history = ChatService.getPrivateConversation(currentUserId, selectedUser.getId());
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String msg : history) {
|
||||
sb.append(msg).append("\n");
|
||||
}
|
||||
chatArea.setText(sb.toString());
|
||||
chatArea.setScrollTop(Double.MAX_VALUE);
|
||||
scrollPane.setVvalue(1.0);
|
||||
}
|
||||
}
|
||||
|
||||
public static VBox createBubble(ChatMessage msg, boolean isMine, int viewerId) {
|
||||
VBox bubbleWrapper = new VBox(2);
|
||||
bubbleWrapper.setMaxWidth(Double.MAX_VALUE);
|
||||
bubbleWrapper.setAlignment(isMine ? Pos.CENTER_RIGHT : Pos.CENTER_LEFT);
|
||||
|
||||
VBox bubble = new VBox(3);
|
||||
bubble.setMaxWidth(350);
|
||||
bubble.getStyleClass().add(isMine ? "chat-bubble-left" : "chat-bubble-right");
|
||||
|
||||
if (isMine) {
|
||||
UserSettings settings = UserSettings.getSettings(viewerId);
|
||||
bubble.setStyle("-fx-bubble-color: " + settings.getBubbleColor() + ";");
|
||||
} else {
|
||||
bubble.setStyle("-fx-bubble-color: #ffffff;");
|
||||
}
|
||||
|
||||
if (!isMine) {
|
||||
Label sender = new Label(msg.getSenderName());
|
||||
sender.getStyleClass().add("chat-sender");
|
||||
bubble.getChildren().add(sender);
|
||||
}
|
||||
|
||||
Label content = new Label(msg.getContent());
|
||||
content.setWrapText(true);
|
||||
|
||||
Label time = new Label(msg.getTimestamp());
|
||||
time.getStyleClass().add("chat-time");
|
||||
|
||||
bubble.getChildren().addAll(content, time);
|
||||
bubbleWrapper.getChildren().add(bubble);
|
||||
|
||||
return bubbleWrapper;
|
||||
}
|
||||
}
|
||||
70
src/main/java/com/college/management/SettingsUI.java
Normal file
70
src/main/java/com/college/management/SettingsUI.java
Normal file
@@ -0,0 +1,70 @@
|
||||
package com.college.management;
|
||||
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.*;
|
||||
import javafx.scene.paint.Color;
|
||||
|
||||
public class SettingsUI {
|
||||
private int userId;
|
||||
private UserSettings settings;
|
||||
private Runnable onSaveCallback;
|
||||
|
||||
public SettingsUI(int userId, Runnable onSaveCallback) {
|
||||
this.userId = userId;
|
||||
this.settings = UserSettings.getSettings(userId);
|
||||
this.onSaveCallback = onSaveCallback;
|
||||
}
|
||||
|
||||
public Pane getView() {
|
||||
VBox layout = new VBox(20);
|
||||
layout.setPadding(new Insets(20));
|
||||
|
||||
Label title = new Label("User Settings");
|
||||
title.setStyle("-fx-font-size: 24px; -fx-font-weight: bold;");
|
||||
|
||||
// Display Name
|
||||
HBox nameBox = new HBox(10);
|
||||
Label nameLbl = new Label("Display Name:");
|
||||
TextField txtName = new TextField(settings.getDisplayName() == null ? "" : settings.getDisplayName());
|
||||
nameBox.getChildren().addAll(nameLbl, txtName);
|
||||
|
||||
// Theme Toggle
|
||||
HBox themeBox = new HBox(10);
|
||||
Label themeLbl = new Label("Theme:");
|
||||
ToggleButton themeBtn = new ToggleButton(settings.getTheme().equals("DARK") ? "Dark Mode" : "Light Mode");
|
||||
themeBtn.setSelected(settings.getTheme().equals("DARK"));
|
||||
themeBtn.setOnAction(e -> {
|
||||
themeBtn.setText(themeBtn.isSelected() ? "Dark Mode" : "Light Mode");
|
||||
});
|
||||
themeBox.getChildren().addAll(themeLbl, themeBtn);
|
||||
|
||||
// Bubble Color
|
||||
HBox colorBox = new HBox(10);
|
||||
Label colorLbl = new Label("My Chat Bubble Color:");
|
||||
ColorPicker colorPicker = new ColorPicker(Color.web(settings.getBubbleColor()));
|
||||
colorBox.getChildren().addAll(colorLbl, colorPicker);
|
||||
|
||||
Button btnSave = new Button("Save Settings");
|
||||
btnSave.setStyle("-fx-background-color: #128c7e; -fx-text-fill: white; -fx-font-weight: bold;");
|
||||
|
||||
btnSave.setOnAction(e -> {
|
||||
settings.setDisplayName(txtName.getText().isEmpty() ? null : txtName.getText());
|
||||
settings.setTheme(themeBtn.isSelected() ? "DARK" : "LIGHT");
|
||||
settings.setBubbleColor(toHexString(colorPicker.getValue()));
|
||||
settings.save();
|
||||
if (onSaveCallback != null) onSaveCallback.run();
|
||||
new Alert(Alert.AlertType.INFORMATION, "Settings Saved!").show();
|
||||
});
|
||||
|
||||
layout.getChildren().addAll(title, nameBox, themeBox, colorBox, btnSave);
|
||||
return layout;
|
||||
}
|
||||
|
||||
private String toHexString(Color color) {
|
||||
return String.format("#%02X%02X%02X",
|
||||
(int) (color.getRed() * 255),
|
||||
(int) (color.getGreen() * 255),
|
||||
(int) (color.getBlue() * 255));
|
||||
}
|
||||
}
|
||||
@@ -41,20 +41,23 @@ public class StudentDashboard {
|
||||
Button btnChat = createSidebarButton("Global Chat");
|
||||
Button btnPrivateChat = createSidebarButton("Private Chat");
|
||||
Button btnNotices = createSidebarButton("Notices");
|
||||
Button btnSettings = createSidebarButton("Settings");
|
||||
Button btnLogout = createSidebarButton("Logout");
|
||||
|
||||
sidebar.getChildren().addAll(brand, nameLbl, new Separator(), btnMarks, btnAttendance, btnTimetable, btnEvents, btnChat, btnPrivateChat, btnNotices, btnLogout);
|
||||
sidebar.getChildren().addAll(brand, nameLbl, new Separator(), btnMarks, btnAttendance, btnTimetable, btnEvents, btnChat, btnPrivateChat, btnNotices, btnSettings, btnLogout);
|
||||
root.setLeft(sidebar);
|
||||
|
||||
applyTheme(root);
|
||||
showMarks(root);
|
||||
|
||||
btnMarks.setOnAction(e -> showMarks(root));
|
||||
btnAttendance.setOnAction(e -> showAttendance(root));
|
||||
btnTimetable.setOnAction(e -> showTimetable(root));
|
||||
btnEvents.setOnAction(e -> showEvents(root));
|
||||
btnChat.setOnAction(e -> AdminDashboard.showChat(root, studentName));
|
||||
btnChat.setOnAction(e -> AdminDashboard.showChat(root, studentName, studentId));
|
||||
btnPrivateChat.setOnAction(e -> root.setCenter(new PrivateChatUI(studentId).getView()));
|
||||
btnNotices.setOnAction(e -> showNotices(root));
|
||||
btnSettings.setOnAction(e -> root.setCenter(new SettingsUI(studentId, () -> applyTheme(root)).getView()));
|
||||
btnLogout.setOnAction(e -> new App().start(stage));
|
||||
|
||||
Scene scene = new Scene(root, 900, 600);
|
||||
@@ -62,6 +65,16 @@ public class StudentDashboard {
|
||||
stage.setScene(scene);
|
||||
}
|
||||
|
||||
private void applyTheme(BorderPane root) {
|
||||
root.getStylesheets().clear();
|
||||
root.getStylesheets().add(getClass().getResource("/com/college/management/css/chat.css").toExternalForm());
|
||||
UserSettings settings = UserSettings.getSettings(studentId);
|
||||
root.getStyleClass().remove("dark-theme");
|
||||
if ("DARK".equals(settings.getTheme())) {
|
||||
root.getStyleClass().add("dark-theme");
|
||||
}
|
||||
}
|
||||
|
||||
private void showTimetable(BorderPane root) {
|
||||
VBox content = new VBox(15);
|
||||
content.setPadding(new Insets(20));
|
||||
|
||||
57
src/main/java/com/college/management/UserSettings.java
Normal file
57
src/main/java/com/college/management/UserSettings.java
Normal file
@@ -0,0 +1,57 @@
|
||||
package com.college.management;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
public class UserSettings {
|
||||
private int userId;
|
||||
private String theme;
|
||||
private String bubbleColor;
|
||||
private String displayName;
|
||||
|
||||
public UserSettings(int userId, String theme, String bubbleColor, String displayName) {
|
||||
this.userId = userId;
|
||||
this.theme = theme;
|
||||
this.bubbleColor = bubbleColor;
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
public static UserSettings getSettings(int userId) {
|
||||
try (Connection conn = DatabaseManager.getConnection();
|
||||
PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM user_settings WHERE user_id = ?")) {
|
||||
pstmt.setInt(1, userId);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
if (rs.next()) {
|
||||
return new UserSettings(userId, rs.getString("theme"), rs.getString("bubble_color"), rs.getString("display_name"));
|
||||
} else {
|
||||
// Default settings
|
||||
return new UserSettings(userId, "LIGHT", "#e1ffc7", null);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return new UserSettings(userId, "LIGHT", "#e1ffc7", null);
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
try (Connection conn = DatabaseManager.getConnection();
|
||||
PreparedStatement pstmt = conn.prepareStatement(
|
||||
"INSERT INTO user_settings (user_id, theme, bubble_color, display_name) VALUES (?, ?, ?, ?) " +
|
||||
"ON CONFLICT(user_id) DO UPDATE SET theme=excluded.theme, bubble_color=excluded.bubble_color, display_name=excluded.display_name")) {
|
||||
pstmt.setInt(1, userId);
|
||||
pstmt.setString(2, theme);
|
||||
pstmt.setString(3, bubbleColor);
|
||||
pstmt.setString(4, displayName);
|
||||
pstmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
public String getTheme() { return theme; }
|
||||
public void setTheme(String theme) { this.theme = theme; }
|
||||
public String getBubbleColor() { return bubbleColor; }
|
||||
public void setBubbleColor(String bubbleColor) { this.bubbleColor = bubbleColor; }
|
||||
public String getDisplayName() { return displayName; }
|
||||
public void setDisplayName(String displayName) { this.displayName = displayName; }
|
||||
}
|
||||
133
src/main/resources/com/college/management/css/chat.css
Normal file
133
src/main/resources/com/college/management/css/chat.css
Normal file
@@ -0,0 +1,133 @@
|
||||
/* Global Defaults */
|
||||
.root {
|
||||
-fx-font-family: "Segoe UI", Helvetica, Arial, sans-serif;
|
||||
}
|
||||
|
||||
/* Base Light Theme */
|
||||
.root {
|
||||
-fx-base-color: #f4f4f4;
|
||||
-fx-control-inner-background: #ffffff;
|
||||
-fx-background-color: #f4f4f4;
|
||||
}
|
||||
|
||||
/* Chat Bubbles */
|
||||
.chat-bubble-left {
|
||||
-fx-background-color: -fx-bubble-color;
|
||||
-fx-background-radius: 15 15 15 0;
|
||||
-fx-padding: 10;
|
||||
}
|
||||
|
||||
.chat-bubble-right {
|
||||
-fx-background-color: #ffffff;
|
||||
-fx-background-radius: 15 15 0 15;
|
||||
-fx-padding: 10;
|
||||
-fx-border-color: #dcdcdc;
|
||||
-fx-border-width: 1;
|
||||
-fx-border-radius: 15 15 0 15;
|
||||
}
|
||||
|
||||
.chat-container {
|
||||
-fx-background-color: transparent;
|
||||
}
|
||||
|
||||
/* DARK THEME - GLOBAL OVERRIDES */
|
||||
.dark-theme {
|
||||
-fx-base-color: #1e1e1e;
|
||||
-fx-background-color: #1e1e1e;
|
||||
-fx-control-inner-background: #2d2d2d;
|
||||
-fx-accent: #0078d4;
|
||||
-fx-focus-color: #0078d4;
|
||||
}
|
||||
|
||||
.dark-theme .label {
|
||||
-fx-text-fill: #e0e0e0;
|
||||
}
|
||||
|
||||
/* Sidebar Specific for Dark Theme */
|
||||
.dark-theme .vbox {
|
||||
/* If it's a sidebar, we might want it slightly different */
|
||||
}
|
||||
|
||||
/* Buttons in Dark Theme */
|
||||
.dark-theme .button {
|
||||
-fx-background-color: #333333;
|
||||
-fx-text-fill: #e0e0e0;
|
||||
-fx-border-color: #444444;
|
||||
}
|
||||
.dark-theme .button:hover {
|
||||
-fx-background-color: #444444;
|
||||
}
|
||||
|
||||
/* Inputs in Dark Theme */
|
||||
.dark-theme .text-field, .dark-theme .text-area, .dark-theme .password-field {
|
||||
-fx-background-color: #3c3c3c;
|
||||
-fx-text-fill: white;
|
||||
-fx-prompt-text-fill: #888888;
|
||||
-fx-border-color: #555555;
|
||||
}
|
||||
|
||||
/* Tables in Dark Theme */
|
||||
.dark-theme .table-view {
|
||||
-fx-background-color: #2d2d2d;
|
||||
-fx-border-color: #444444;
|
||||
}
|
||||
.dark-theme .table-view .column-header, .dark-theme .table-view .filler {
|
||||
-fx-background-color: #3c3c3c;
|
||||
}
|
||||
.dark-theme .table-view .column-header .label {
|
||||
-fx-text-fill: #ffffff;
|
||||
}
|
||||
.dark-theme .table-row-cell {
|
||||
-fx-background-color: #2d2d2d;
|
||||
-fx-text-fill: #e0e0e0;
|
||||
}
|
||||
.dark-theme .table-row-cell:odd {
|
||||
-fx-background-color: #333333;
|
||||
}
|
||||
.dark-theme .table-row-cell:selected {
|
||||
-fx-background-color: #0078d4;
|
||||
}
|
||||
|
||||
/* Lists in Dark Theme */
|
||||
.dark-theme .list-view {
|
||||
-fx-background-color: #2d2d2d;
|
||||
-fx-border-color: #444444;
|
||||
}
|
||||
.dark-theme .list-cell {
|
||||
-fx-background-color: #2d2d2d;
|
||||
-fx-text-fill: #e0e0e0;
|
||||
}
|
||||
.dark-theme .list-cell:selected {
|
||||
-fx-background-color: #0078d4;
|
||||
}
|
||||
|
||||
/* ScrollPane and ScrollBar */
|
||||
.dark-theme .scroll-pane {
|
||||
-fx-background-color: #1e1e1e;
|
||||
}
|
||||
.dark-theme .scroll-pane > .viewport {
|
||||
-fx-background-color: #1e1e1e;
|
||||
}
|
||||
|
||||
/* Separators */
|
||||
.dark-theme .separator .line {
|
||||
-fx-border-color: #444444;
|
||||
}
|
||||
|
||||
/* Chat bubble text in Dark Theme */
|
||||
.dark-theme .chat-bubble-right {
|
||||
-fx-background-color: #3c3c3c;
|
||||
-fx-border-color: #555555;
|
||||
-fx-text-fill: white;
|
||||
}
|
||||
.dark-theme .chat-bubble-right .label {
|
||||
-fx-text-fill: white;
|
||||
}
|
||||
|
||||
.dark-theme .chat-bubble-left .label {
|
||||
-fx-text-fill: black; /* Keep left bubble readable as it's usually light green */
|
||||
}
|
||||
|
||||
.dark-theme .chat-time {
|
||||
-fx-text-fill: #aaaaaa;
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
BIN
target/classes/com/college/management/ChatMessage.class
Normal file
BIN
target/classes/com/college/management/ChatMessage.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
target/classes/com/college/management/SettingsUI.class
Normal file
BIN
target/classes/com/college/management/SettingsUI.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
target/classes/com/college/management/UserSettings.class
Normal file
BIN
target/classes/com/college/management/UserSettings.class
Normal file
Binary file not shown.
133
target/classes/com/college/management/css/chat.css
Normal file
133
target/classes/com/college/management/css/chat.css
Normal file
@@ -0,0 +1,133 @@
|
||||
/* Global Defaults */
|
||||
.root {
|
||||
-fx-font-family: "Segoe UI", Helvetica, Arial, sans-serif;
|
||||
}
|
||||
|
||||
/* Base Light Theme */
|
||||
.root {
|
||||
-fx-base-color: #f4f4f4;
|
||||
-fx-control-inner-background: #ffffff;
|
||||
-fx-background-color: #f4f4f4;
|
||||
}
|
||||
|
||||
/* Chat Bubbles */
|
||||
.chat-bubble-left {
|
||||
-fx-background-color: -fx-bubble-color;
|
||||
-fx-background-radius: 15 15 15 0;
|
||||
-fx-padding: 10;
|
||||
}
|
||||
|
||||
.chat-bubble-right {
|
||||
-fx-background-color: #ffffff;
|
||||
-fx-background-radius: 15 15 0 15;
|
||||
-fx-padding: 10;
|
||||
-fx-border-color: #dcdcdc;
|
||||
-fx-border-width: 1;
|
||||
-fx-border-radius: 15 15 0 15;
|
||||
}
|
||||
|
||||
.chat-container {
|
||||
-fx-background-color: transparent;
|
||||
}
|
||||
|
||||
/* DARK THEME - GLOBAL OVERRIDES */
|
||||
.dark-theme {
|
||||
-fx-base-color: #1e1e1e;
|
||||
-fx-background-color: #1e1e1e;
|
||||
-fx-control-inner-background: #2d2d2d;
|
||||
-fx-accent: #0078d4;
|
||||
-fx-focus-color: #0078d4;
|
||||
}
|
||||
|
||||
.dark-theme .label {
|
||||
-fx-text-fill: #e0e0e0;
|
||||
}
|
||||
|
||||
/* Sidebar Specific for Dark Theme */
|
||||
.dark-theme .vbox {
|
||||
/* If it's a sidebar, we might want it slightly different */
|
||||
}
|
||||
|
||||
/* Buttons in Dark Theme */
|
||||
.dark-theme .button {
|
||||
-fx-background-color: #333333;
|
||||
-fx-text-fill: #e0e0e0;
|
||||
-fx-border-color: #444444;
|
||||
}
|
||||
.dark-theme .button:hover {
|
||||
-fx-background-color: #444444;
|
||||
}
|
||||
|
||||
/* Inputs in Dark Theme */
|
||||
.dark-theme .text-field, .dark-theme .text-area, .dark-theme .password-field {
|
||||
-fx-background-color: #3c3c3c;
|
||||
-fx-text-fill: white;
|
||||
-fx-prompt-text-fill: #888888;
|
||||
-fx-border-color: #555555;
|
||||
}
|
||||
|
||||
/* Tables in Dark Theme */
|
||||
.dark-theme .table-view {
|
||||
-fx-background-color: #2d2d2d;
|
||||
-fx-border-color: #444444;
|
||||
}
|
||||
.dark-theme .table-view .column-header, .dark-theme .table-view .filler {
|
||||
-fx-background-color: #3c3c3c;
|
||||
}
|
||||
.dark-theme .table-view .column-header .label {
|
||||
-fx-text-fill: #ffffff;
|
||||
}
|
||||
.dark-theme .table-row-cell {
|
||||
-fx-background-color: #2d2d2d;
|
||||
-fx-text-fill: #e0e0e0;
|
||||
}
|
||||
.dark-theme .table-row-cell:odd {
|
||||
-fx-background-color: #333333;
|
||||
}
|
||||
.dark-theme .table-row-cell:selected {
|
||||
-fx-background-color: #0078d4;
|
||||
}
|
||||
|
||||
/* Lists in Dark Theme */
|
||||
.dark-theme .list-view {
|
||||
-fx-background-color: #2d2d2d;
|
||||
-fx-border-color: #444444;
|
||||
}
|
||||
.dark-theme .list-cell {
|
||||
-fx-background-color: #2d2d2d;
|
||||
-fx-text-fill: #e0e0e0;
|
||||
}
|
||||
.dark-theme .list-cell:selected {
|
||||
-fx-background-color: #0078d4;
|
||||
}
|
||||
|
||||
/* ScrollPane and ScrollBar */
|
||||
.dark-theme .scroll-pane {
|
||||
-fx-background-color: #1e1e1e;
|
||||
}
|
||||
.dark-theme .scroll-pane > .viewport {
|
||||
-fx-background-color: #1e1e1e;
|
||||
}
|
||||
|
||||
/* Separators */
|
||||
.dark-theme .separator .line {
|
||||
-fx-border-color: #444444;
|
||||
}
|
||||
|
||||
/* Chat bubble text in Dark Theme */
|
||||
.dark-theme .chat-bubble-right {
|
||||
-fx-background-color: #3c3c3c;
|
||||
-fx-border-color: #555555;
|
||||
-fx-text-fill: white;
|
||||
}
|
||||
.dark-theme .chat-bubble-right .label {
|
||||
-fx-text-fill: white;
|
||||
}
|
||||
|
||||
.dark-theme .chat-bubble-left .label {
|
||||
-fx-text-fill: black; /* Keep left bubble readable as it's usually light green */
|
||||
}
|
||||
|
||||
.dark-theme .chat-time {
|
||||
-fx-text-fill: #aaaaaa;
|
||||
}
|
||||
@@ -2,7 +2,9 @@ com/college/management/StudentDashboard.class
|
||||
com/college/management/FacultyDashboard.class
|
||||
com/college/management/ReportGenerator.class
|
||||
com/college/management/PrivateChatUI.class
|
||||
com/college/management/SettingsUI.class
|
||||
com/college/management/DatabaseManager.class
|
||||
com/college/management/UserSettings.class
|
||||
com/college/management/AdminDashboard$TableValue.class
|
||||
com/college/management/App.class
|
||||
com/college/management/PrivateChatUI$1.class
|
||||
@@ -10,4 +12,5 @@ com/college/management/ChatService.class
|
||||
com/college/management/User.class
|
||||
com/college/management/FacultyDashboard$TimetableEntry.class
|
||||
com/college/management/StudentDashboard$MarkRecord.class
|
||||
com/college/management/ChatMessage.class
|
||||
com/college/management/AdminDashboard.class
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
/home/balraj/Work/Smart College Management System/src/main/java/com/college/management/DatabaseManager.java
|
||||
/home/balraj/Work/Smart College Management System/src/main/java/com/college/management/SettingsUI.java
|
||||
/home/balraj/Work/Smart College Management System/src/main/java/com/college/management/ChatMessage.java
|
||||
/home/balraj/Work/Smart College Management System/src/main/java/com/college/management/App.java
|
||||
/home/balraj/Work/Smart College Management System/src/main/java/com/college/management/ChatService.java
|
||||
/home/balraj/Work/Smart College Management System/src/main/java/com/college/management/ReportGenerator.java
|
||||
/home/balraj/Work/Smart College Management System/src/main/java/com/college/management/PrivateChatUI.java
|
||||
/home/balraj/Work/Smart College Management System/src/main/java/com/college/management/UserSettings.java
|
||||
/home/balraj/Work/Smart College Management System/src/main/java/com/college/management/AdminDashboard.java
|
||||
/home/balraj/Work/Smart College Management System/src/main/java/com/college/management/FacultyDashboard.java
|
||||
/home/balraj/Work/Smart College Management System/src/main/java/com/college/management/StudentDashboard.java
|
||||
|
||||
Reference in New Issue
Block a user