Settings UI implemented.

This commit is contained in:
Asal Lotfi
2025-09-03 14:12:21 +03:30
parent cb63664701
commit cc9dcf2ac8
11 changed files with 617 additions and 37 deletions
@@ -46,7 +46,10 @@ public class EditProfileController {
overlayBackground.setOnMouseClicked(e -> closeEdit());
closeButton.setOnAction(e -> closeEdit());
backButton.setOnAction(e -> goBackToProfile());
backButton.setOnAction(e -> {
MainController.getInstance().goBack(overlayBackground);
});
// Load your camera icon image (white camera icon for visibility)
cameraIcon.setImage(new Image(
@@ -101,38 +104,6 @@ public class EditProfileController {
MainController.getInstance().closeOverlay(editCard.getParent());
}
@FXML
private void goBackToProfile() {
// Close edit overlay
MainController.getInstance().closeOverlay(editCard.getParent());
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource(
"/org/to/telegramfinalproject/Fxml/my_profile.fxml"));
Node profileOverlay = loader.load();
// Get the controller for the loaded MyProfile scene
MyProfileController controller = loader.getController();
// Pass updated data from edit fields
controller.setProfileData(
nameField.getText(),
"online",
bioField.getText(),
usernameField.getText(),
profileImageView.getImage() != null ?
profileImageView.getImage().getUrl() :
"/org/to/telegramfinalproject/Avatars/default_profile.png"
);
// Show updated MyProfile overlay
MainController.getInstance().showOverlay(profileOverlay);
} catch (IOException e) {
e.printStackTrace();
}
}
public void setProfileData(String name, String status, String bio, String userId, Image profileImage) {
profileStatus.setText(status);
profileName.setText(name);
@@ -61,6 +61,9 @@ public class MainController {
@FXML private ImageView menuIcon;
private SidebarMenuController sidebarController; //save sidebar controller
// === Overlay ===
@FXML private StackPane overlayLayer;
// === Time formatter for messages ===
private static final java.time.format.DateTimeFormatter FMT_HHMM =
java.time.format.DateTimeFormatter.ofPattern("HH:mm");
@@ -83,6 +86,9 @@ public class MainController {
public static MainController getInstance() {
return instance;
}
// Keep track of the scene user comes from
private final Deque<Node> navigationStack = new ArrayDeque<>();
private final Map<UUID, ChatItemController> itemControllers = new HashMap<>();
@@ -562,13 +568,30 @@ public class MainController {
// === Overlay Handling ===
public void showOverlay(Node overlayNode) {
mainRoot.getChildren().add(overlayNode);
if (!overlayLayer.getChildren().isEmpty()) {
Node current = overlayLayer.getChildren().get(overlayLayer.getChildren().size() - 1);
navigationStack.push(current);
overlayLayer.getChildren().remove(current);
}
overlayLayer.getChildren().add(overlayNode);
}
public void closeOverlay(Node overlayNode) {
mainRoot.getChildren().remove(overlayNode);
overlayLayer.getChildren().remove(overlayNode);
}
public void goBack(Pane currentOverlay) {
// Remove the current overlay
closeOverlay(currentOverlay);
if (!navigationStack.isEmpty()) {
Node previous = navigationStack.pop();
// Clear existing overlays before showing previous
overlayLayer.getChildren().clear();
overlayLayer.getChildren().add(previous);
}
}
// ===== Search UI state =====
private final java.util.List<SearchResult> searchBacking = new java.util.ArrayList<>();
@@ -0,0 +1,160 @@
package org.to.telegramfinalproject.UI;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Circle;
import java.io.IOException;
import java.net.URL;
public class SettingsController {
@FXML private VBox settingsCard;
@FXML private ImageView profileImage;
@FXML private Label profileName;
@FXML private Label profileId;
@FXML private MenuButton menuButton;
@FXML private MenuItem editProfileItem;
@FXML private MenuItem logoutItem;
@FXML private Button myAccountButton;
@FXML private Button privacyButton;
@FXML private Button faqButton;
@FXML private Button featuresButton;
@FXML private Pane overlayBackground;
@FXML private Button closeButton;
private static final String ICON_PATH = "/org/to/telegramfinalproject/Icons/";
@FXML
public void initialize() {
editProfileItem.setOnAction(e -> openEditProfile());
logoutItem.setOnAction(e -> System.out.println("Log Out clicked"));
// Example data load from DB or user session later
profileName.setText("Asal");
profileId.setText("@Whales_suicide");
profileImage.setImage(new Image(
getClass().getResourceAsStream("/org/to/telegramfinalproject/Avatars/default_user_profile.png")
));
// Make it circular
Circle clip = new Circle(48, 28, 38); // centerX, centerY, radius
profileImage.setClip(clip);
// Buttons
myAccountButton.setOnAction(e -> openEditProfile());
privacyButton.setOnAction(e -> System.out.println("Privacy and Security"));
faqButton.setOnAction(e -> System.out.println("Telegram Q&A"));
featuresButton.setOnAction(e -> System.out.println("Telegram Features"));
// Close overlay on background click
overlayBackground.setOnMouseClicked(e ->
MainController.getInstance().closeOverlay(settingsCard.getParent()));
closeButton.setOnAction(e ->
MainController.getInstance().closeOverlay(settingsCard.getParent())
);
// Register scene for ThemeManager → stylesheet swap will handle colors/icons
Platform.runLater(() -> {
if (settingsCard.getScene() != null) {
ThemeManager.getInstance().registerScene(settingsCard.getScene());
}
});
// Listener for theme change
ThemeManager.getInstance().darkModeProperty().addListener((obs, oldVal, newVal) -> {
updateEditIcon(newVal);
updateMoreIcon(newVal);
updateButtonsIcons(newVal);
});
// Set initial state
updateEditIcon(ThemeManager.getInstance().isDarkMode());
updateMoreIcon(ThemeManager.getInstance().isDarkMode());
updateButtonsIcons(ThemeManager.getInstance().isDarkMode());
}
private void openEditProfile() {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource(
"/org/to/telegramfinalproject/Fxml/edit_profile.fxml"));
Node editOverlay = loader.load();
EditProfileController controller = loader.getController();
controller.setProfileData(
profileName.getText(),
"online",
"Pass me that lovely little gun♡.",
"@Whales_suicide",
profileImage.getImage()
);
MainController.getInstance().showOverlay(editOverlay);
} catch (IOException ex) {
ex.printStackTrace();
}
}
private void updateEditIcon(boolean darkMode) {
String editPath = darkMode
? "/org/to/telegramfinalproject/Icons/edit_light.png"
: "/org/to/telegramfinalproject/Icons/edit_dark.png";
ImageView icon = new ImageView(new Image(getClass().getResourceAsStream(editPath)));
icon.setFitWidth(16);
icon.setFitHeight(16);
editProfileItem.setGraphic(icon);
}
private void updateMoreIcon(boolean darkMode) {
String morePath = darkMode
? "/org/to/telegramfinalproject/Icons/more_light.png"
: "/org/to/telegramfinalproject/Icons/more_dark.png";
ImageView icon = new ImageView(new Image(getClass().getResourceAsStream(morePath)));
icon.setFitWidth(16);
icon.setFitHeight(16);
menuButton.setGraphic(icon);
}
private void updateButtonsIcons(boolean darkMode) {
String suffix = darkMode ? "_light.png" : "_dark.png";
myAccountButton.setGraphic(makeIcon(ICON_PATH + "my_profile" + suffix));
privacyButton.setGraphic(makeIcon(ICON_PATH + "lock" + suffix));
faqButton.setGraphic(makeIcon(ICON_PATH + "telegram_features" + suffix));
featuresButton.setGraphic(makeIcon(ICON_PATH + "telegram_qna" + suffix));
}
// --- helpers -------------------------------------------------------------
private ImageView makeIcon(String path) {
ImageView iv = new ImageView();
Image img = loadImage(path);
if (img != null) {
iv.setImage(img);
iv.setFitWidth(22);
iv.setFitHeight(22);
iv.setPreserveRatio(true);
}
return iv;
}
private Image loadImage(String path) {
URL res = getClass().getResource(path);
if (res == null) {
System.err.println("Resource not found: " + path);
return null;
}
return new Image(res.toExternalForm());
}
}
@@ -239,7 +239,21 @@ public class SidebarMenuController {
}
private void openSavedMessages() { System.out.println("Opening Saved Messages..."); }
private void openSettings() { System.out.println("Opening Settings..."); }
private void openSettings() {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource(
"/org/to/telegramfinalproject/Fxml/settings.fxml"));
Node settingsOverlay = loader.load();
// Show overlay on top of everything
MainController.getInstance().showOverlay(settingsOverlay);
} catch (IOException e) {
e.printStackTrace();
}
}
private void openTelegramFeatures() { System.out.println("Opening Telegram Features..."); }
private void openTelegramQnA() { System.out.println("Opening Telegram Q&A..."); }
@@ -760,3 +760,141 @@
.channel-desc-area .content {
-fx-background-color: #1f2a36;
}
.settings-card {
-fx-background-color: #1f2a36;
-fx-background-radius: 8;
-fx-padding: 12;
}
.settings-avatar {
-fx-fit-width: 56px;
-fx-fit-height: 56px;
}
.settings-name {
-fx-font-size: 16px;
-fx-font-weight: bold;
-fx-text-fill: #ffffff;
}
.settings-id {
-fx-font-size: 13px;
-fx-text-fill: #aaaaaa;
}
.settings-option {
-fx-background-color: transparent;
-fx-text-fill: #ffffff;
-fx-font-size: 14px;
-fx-alignment: CENTER_LEFT;
}
.settings-option:hover {
-fx-background-color: #253544;
}
.settings-menu {
-fx-background-color: transparent;
-fx-font-size: 18px;
-fx-text-fill: #eeeeee;
}
.settings-header {
-fx-padding: 8 12;
-fx-border-color: -fx-box-border;
-fx-border-width: 0 0 1 0; /* bottom border only */
}
.settings-title {
-fx-font-size: 15px;
-fx-font-weight: bold;
-fx-text-fill: #fff;
}
.icon-button {
-fx-background-color: transparent;
-fx-padding: 0;
}
.icon-button:hover {
-fx-background-color: rgba(0,0,0,0.05);
-fx-background-radius: 50%;
}
/* Profile header */
.profile-header {
-fx-padding: 12 16;
}
.profile-avatar {
-fx-background-radius: 50%;
-fx-effect: dropshadow(gaussian, rgba(0,0,0,0.2), 4, 0.3, 0, 1);
}
.profile-name {
-fx-font-size: 14px;
-fx-font-weight: bold;
-fx-text-fill: #fff;
}
.profile-id {
-fx-font-size: 12px;
-fx-text-fill: #aaa;
}
/* Hide MenuButton text & arrow */
.icon-button > .label {
-fx-padding: 0;
-fx-text-fill: transparent;
}
.icon-button > .arrow-button,
.icon-button > .arrow {
-fx-padding: 0;
-fx-shape: null; /* removes arrow shape */
-fx-background-color: transparent;
-fx-opacity: 0;
}
.icon-image {
-fx-smooth: true; /* keeps scaling smooth */
-fx-opacity: 0.8; /* slightly dim until hover */
}
.icon-image:hover {
-fx-opacity: 1.0; /* brighten on hover */
}
/* Container for all settings buttons */
.settings-options {
-fx-background-color: transparent;
-fx-spacing: 4;
-fx-padding: 8 0 8 0;
-fx-border-color: #2a3b47;
-fx-border-width: 0 0 0 0; /* thin top border */
}
/* Settings action buttons */
.settings-option {
-fx-background-color: transparent;
-fx-text-fill: #ddd;
-fx-font-size: 14px;
-fx-alignment: CENTER_LEFT;
-fx-padding: 10 14;
-fx-background-radius: 6;
-fx-cursor: hand;
/* space between icon and text */
-fx-graphic-text-gap: 10px;
}
/* Hover effect */
.settings-option:hover {
-fx-background-color: #2c3e50;
}
/* Pressed effect */
.settings-option:pressed {
-fx-background-color: #1f2a36;
}
@@ -763,3 +763,141 @@
-fx-background-color: #fff;
}
.settings-card {
-fx-background-color: #ffffff;
-fx-background-radius: 8;
-fx-padding: 12;
}
.settings-avatar {
-fx-fit-width: 56px;
-fx-fit-height: 56px;
}
.settings-name {
-fx-font-size: 16px;
-fx-font-weight: bold;
-fx-text-fill: #000000;
}
.settings-id {
-fx-font-size: 13px;
-fx-text-fill: #666666;
}
.settings-option {
-fx-background-color: transparent;
-fx-text-fill: #000000;
-fx-font-size: 14px;
-fx-alignment: CENTER_LEFT;
}
.settings-option:hover {
-fx-background-color: #f1f1f1;
}
.settings-menu {
-fx-background-color: transparent;
-fx-font-size: 18px;
-fx-text-fill: #333333;
}
.settings-header {
-fx-padding: 8 12;
-fx-border-color: -fx-box-border;
-fx-border-width: 0 0 1 0; /* bottom border only */
}
.settings-title {
-fx-font-size: 15px;
-fx-font-weight: bold;
-fx-text-fill: -fx-text-base-color;
}
.icon-button {
-fx-background-color: transparent;
-fx-padding: 0;
}
.icon-button:hover {
-fx-background-color: rgba(0,0,0,0.05);
-fx-background-radius: 50%;
}
/* Profile header */
.profile-header {
-fx-padding: 12 16;
}
.profile-avatar {
-fx-background-radius: 50%;
-fx-effect: dropshadow(gaussian, rgba(0,0,0,0.2), 4, 0.3, 0, 1);
}
.profile-name {
-fx-font-size: 14px;
-fx-font-weight: bold;
-fx-text-fill: -fx-text-base-color;
}
.profile-id {
-fx-font-size: 12px;
-fx-text-fill: #888;
}
/* Hide MenuButton text & arrow */
.icon-button > .label {
-fx-padding: 0;
-fx-text-fill: transparent;
}
.icon-button > .arrow-button,
.icon-button > .arrow {
-fx-padding: 0;
-fx-shape: null; /* removes arrow shape */
-fx-background-color: transparent;
-fx-opacity: 0;
}
.icon-image {
-fx-smooth: true; /* keeps scaling smooth */
-fx-opacity: 0.8; /* slightly dim until hover */
}
.icon-image:hover {
-fx-opacity: 1.0; /* brighten on hover */
}
/* Container for all settings buttons */
.settings-options {
-fx-background-color: transparent;
-fx-spacing: 4;
-fx-padding: 8 0 8 0;
-fx-border-color: #e6e6e6;
-fx-border-width: 0 0 0 0; /* thin top border */
}
/* Settings action buttons */
.settings-option {
-fx-background-color: transparent;
-fx-text-fill: #222;
-fx-font-size: 14px;
-fx-alignment: CENTER_LEFT;
-fx-padding: 10 14;
-fx-background-radius: 6;
-fx-cursor: hand;
/* space between icon and text */
-fx-graphic-text-gap: 10px;
}
/* Hover effect */
.settings-option:hover {
-fx-background-color: #f2f2f2;
}
/* Pressed effect */
.settings-option:pressed {
-fx-background-color: #e0e0e0;
}
@@ -166,11 +166,15 @@
</items>
</SplitPane>
<!-- Overlay (for sidebar) -->
<!-- ===== Overlay background for sidebar only ===== -->
<Pane fx:id="overlay"
mouseTransparent="true"
onMouseClicked="#closeSidebar"
styleClass="overlay"
visible="false"/>
<!-- ===== Overlay layer for profile/settings/etc. ===== -->
<StackPane fx:id="overlayLayer"
pickOnBounds="false"/>
</children>
</StackPane>
@@ -0,0 +1,132 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.control.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.image.Image?>
<StackPane styleClass="overlay-root" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="org.to.telegramfinalproject.UI.SettingsController">
<children>
<!-- Dimmed background -->
<Pane fx:id="overlayBackground" styleClass="overlay-background" />
<!-- Settings Card -->
<VBox fx:id="settingsCard" maxHeight="470" maxWidth="350" prefHeight="470" prefWidth="350" spacing="12" styleClass="settings-card">
<children>
<!-- ===== Header ===== -->
<HBox alignment="CENTER_RIGHT" spacing="10" styleClass="settings-header">
<children>
<Label styleClass="settings-title" text="Settings" />
<Region HBox.hgrow="ALWAYS" /> <!-- pushes buttons to the right -->
<!-- 3-dots Menu -->
<MenuButton fx:id="menuButton" styleClass="icon-button">
<graphic>
<ImageView fitHeight="18" fitWidth="18" pickOnBounds="true" preserveRatio="true" styleClass="icon-image">
<image>
<Image url="@/org/to/telegramfinalproject/Icons/more_dark.png" />
</image>
</ImageView>
</graphic>
<items>
<MenuItem fx:id="editProfileItem" text="Edit Profile">
<graphic>
<ImageView fitHeight="14" fitWidth="14" preserveRatio="true">
<image>
<Image url="@/org/to/telegramfinalproject/Icons/edit_dark.png" />
</image>
</ImageView>
</graphic>
</MenuItem>
<MenuItem fx:id="logoutItem" text="Log Out">
<graphic>
<ImageView fitHeight="14" fitWidth="14" preserveRatio="true">
<image>
<Image url="@/org/to/telegramfinalproject/Icons/log_out.png" />
</image>
</ImageView>
</graphic>
</MenuItem>
</items>
</MenuButton>
<!-- Close Button -->
<Button fx:id="closeButton" styleClass="icon-button" text="✕" />
</children>
</HBox>
<!-- ===== Profile Info ===== -->
<HBox alignment="CENTER_LEFT" spacing="12" styleClass="profile-header">
<children>
<!-- Profile Picture -->
<ImageView fx:id="profileImage" fitHeight="92" fitWidth="92" preserveRatio="true" styleClass="profile-avatar" />
<!-- Name + ID -->
<VBox alignment="CENTER_LEFT" spacing="2">
<children>
<Label fx:id="profileName" styleClass="profile-name" text="User Name" />
<Label fx:id="profileId" styleClass="profile-id" />
</children>
</VBox>
</children>
</HBox>
<Separator />
<!-- ===== Options ===== -->
<VBox spacing="8" styleClass="settings-options">
<children>
<!-- My Account -->
<Button fx:id="myAccountButton" prefHeight="25.0" prefWidth="361.0" styleClass="settings-option" text="My Account">
<graphic>
<ImageView fitWidth="25" fitHeight="25" preserveRatio="true">
<image>
<Image url="@/org/to/telegramfinalproject/Icons/my_profile_dark.png"/>
</image>
</ImageView>
</graphic>
</Button>
<!-- Privacy and Security -->
<Button fx:id="privacyButton" prefHeight="25.0" prefWidth="376.0" styleClass="settings-option" text="Privacy and Security">
<graphic>
<ImageView fitWidth="25" fitHeight="25" preserveRatio="true">
<image>
<Image url="@/org/to/telegramfinalproject/Icons/lock_dark.png"/>
</image>
</ImageView>
</graphic>
</Button>
<!-- Telegram Q&A -->
<Button fx:id="faqButton" prefHeight="25.0" prefWidth="390.0" styleClass="settings-option" text="Telegram Q&amp;A">
<graphic>
<ImageView fitWidth="25" fitHeight="25" preserveRatio="true">
<image>
<Image url="@/org/to/telegramfinalproject/Icons/telegram_qna_dark.png"/>
</image>
</ImageView>
</graphic>
</Button>
<!-- Telegram Features -->
<Button fx:id="featuresButton" prefHeight="25.0" prefWidth="370.0" styleClass="settings-option" text="Telegram Features">
<graphic>
<ImageView fitWidth="25" fitHeight="25" preserveRatio="true">
<image>
<Image url="@/org/to/telegramfinalproject/Icons/telegram_features_dark.png"/>
</image>
</ImageView>
</graphic>
</Button>
</children>
</VBox>
</children>
</VBox>
</children>
</StackPane>
Binary file not shown.

After

Width:  |  Height:  |  Size: 305 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 260 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 553 B