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 d797543 + 2704375 commit ccfcd3b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public enum App {
BANK("Bank"),
SETTINGS("Settings"),
FILEPICKER("File Picker"),
WEEKENDRAPPORT("Weekend Rapport"),
WEEKENDREPORT("Weekend Report"),
WARNING("Warning"),
GAMEOVER("Game Over");

Expand Down
46 changes: 14 additions & 32 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,8 +15,6 @@
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 @@ -71,28 +69,7 @@ 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.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);
}
scrollPane.setPrefSize(width, height);

closeButton = buildCloseButton();
header = buildHeader(closeButton, type.getDisplayName());
Expand All @@ -106,6 +83,7 @@ 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 @@ -118,6 +96,7 @@ 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 @@ -148,21 +127,23 @@ 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";
case SETTINGS -> "/css/settings.css";
case STOCK -> "/css/stock.css";
case FILEPICKER -> "/css/filepicker.css";
case WEEKENDRAPPORT -> "/css/rapport.css";
case WEEKENDREPORT -> "/css/rapport.css";
case WARNING, GAMEOVER -> "/css/warning.css";
default -> null;
};
if (appCss != null) {
sheets.add(appCss);
}

if (type == App.STOCK || type == App.WEEKENDRAPPORT) {
// Some apps need receipt.css
if (type == App.STOCK || type == App.WEEKENDREPORT) {
sheets.add("/css/receipt.css");
}

Expand All @@ -188,12 +169,11 @@ private HBox buildHeader(Button closeButton, String title) {
Label titleLabel = new Label(title);
titleLabel.getStyleClass().add("popup-title");

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

HBox hbox = new HBox(closeButton, titleContainer);
HBox hbox = new HBox(10, closeButton, titleContainer);
hbox.setAlignment(Pos.CENTER_LEFT);
hbox.setPadding(new Insets(5, 10, 5, 10));
hbox.getStyleClass().add("popup-header");
Expand All @@ -212,10 +192,11 @@ 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(wrapper.prefWidthProperty()).divide(2));
pane.widthProperty().subtract(root.widthProperty()).divide(2));
wrapper.layoutYProperty().bind(
pane.heightProperty().subtract(wrapper.prefHeightProperty()).divide(2));
pane.heightProperty().subtract(root.heightProperty()).divide(2));
}
};
bind.run();
Expand Down Expand Up @@ -257,4 +238,5 @@ public HBox getHeader() {
public Button getCloseButton() {
return closeButton;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class WeekendReportApp extends Popup {
* <p>Initializes the layout and binds the continue button to close/advance the report.
*/
public WeekendReportApp() {
super(740, 620, 0, 0, App.WEEKENDRAPPORT);
super(740, 620, 0, 0, App.WEEKENDREPORT);

getCloseButton().setOnAction(event -> continueButton.fire());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ private GridPane createGrid() {
}

private static boolean isDesktopApp(final App app) {
return app != App.WEEKENDRAPPORT
return app != App.WEEKENDREPORT
&& app != App.WARNING
&& app != App.GAMEOVER
&& app != App.SETTINGS
Expand Down

0 comments on commit ccfcd3b

Please sign in to comment.