Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
peretr committed May 20, 2026
2 parents ccfcd3b + 7d64be0 commit b533803
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions src/main/java/edu/ntnu/idi/idatt2003/gruppe42/view/Popup.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
Expand Down Expand Up @@ -69,7 +71,28 @@ protected Popup(int width, int height, int x, int y, App type) {
scrollPane.getStyleClass().add("popup-scroll-pane");
scrollPane.setFitToWidth(true);
scrollPane.setFitToHeight(false);
scrollPane.setPrefSize(width, height);
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
content.heightProperty().addListener((obs, ov, nv) ->
scrollPane.setVbarPolicy(
nv.doubleValue() > scrollPane.getHeight()
? ScrollPane.ScrollBarPolicy.AS_NEEDED
: ScrollPane.ScrollBarPolicy.NEVER
)
);
scrollPane.heightProperty().addListener((obs, ov, nv) ->
scrollPane.setVbarPolicy(
content.getHeight() > nv.doubleValue()
? ScrollPane.ScrollBarPolicy.AS_NEEDED
: ScrollPane.ScrollBarPolicy.NEVER
)
);
if (width > 0) {
scrollPane.setPrefWidth(width);
}
if (height > 0) {
scrollPane.setPrefHeight(height);
}

closeButton = buildCloseButton();
header = buildHeader(closeButton, type.getDisplayName());
Expand All @@ -83,7 +106,6 @@ protected Popup(int width, int height, int x, int y, App type) {
Rectangle borderOverlay = buildBorderOverlay();

wrapper = new Pane(root, borderOverlay);
// Bind wrapper size to root's size so centering logic works
wrapper.prefWidthProperty().bind(root.widthProperty());
wrapper.prefHeightProperty().bind(root.heightProperty());
borderOverlay.widthProperty().bind(root.widthProperty());
Expand All @@ -96,7 +118,6 @@ protected Popup(int width, int height, int x, int y, App type) {
wrapper.addEventFilter(MouseEvent.MOUSE_PRESSED, e -> wrapper.toFront());

loadStylesheets();

}

private Rectangle buildClip(BorderPane target) {
Expand Down Expand Up @@ -127,7 +148,6 @@ private void loadStylesheets() {
sheets.add("/css/popup.css");
sheets.add("/css/components.css");

// Map App to CSS
String appCss = switch (type) {
case BANK -> "/css/bank.css";
case MAIL -> "/css/mail.css";
Expand All @@ -142,7 +162,6 @@ private void loadStylesheets() {
sheets.add(appCss);
}

// Some apps need receipt.css
if (type == App.STOCK || type == App.WEEKENDREPORT) {
sheets.add("/css/receipt.css");
}
Expand All @@ -169,11 +188,12 @@ private HBox buildHeader(Button closeButton, String title) {
Label titleLabel = new Label(title);
titleLabel.getStyleClass().add("popup-title");

HBox titleContainer = new HBox(titleLabel);
titleContainer.setAlignment(Pos.CENTER);
StackPane titleContainer = new StackPane(titleLabel);
StackPane.setAlignment(titleLabel, Pos.CENTER);
titleContainer.setMinHeight(Region.USE_PREF_SIZE);
HBox.setHgrow(titleContainer, Priority.ALWAYS);

HBox hbox = new HBox(10, closeButton, titleContainer);
HBox hbox = new HBox(closeButton, titleContainer);
hbox.setAlignment(Pos.CENTER_LEFT);
hbox.setPadding(new Insets(5, 10, 5, 10));
hbox.getStyleClass().add("popup-header");
Expand All @@ -192,11 +212,10 @@ private String resource(final String path) {
public void centerInParent() {
Runnable bind = () -> {
if (wrapper.getParent() instanceof Pane pane) {
// Use root.widthProperty/heightProperty for centering
wrapper.layoutXProperty().bind(
pane.widthProperty().subtract(root.widthProperty()).divide(2));
pane.widthProperty().subtract(wrapper.prefWidthProperty()).divide(2));
wrapper.layoutYProperty().bind(
pane.heightProperty().subtract(root.heightProperty()).divide(2));
pane.heightProperty().subtract(wrapper.prefHeightProperty()).divide(2));
}
};
bind.run();
Expand Down Expand Up @@ -238,5 +257,4 @@ public HBox getHeader() {
public Button getCloseButton() {
return closeButton;
}

}

0 comments on commit b533803

Please sign in to comment.