diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/model/App.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/model/App.java index ecc0e47..4b4d772 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/model/App.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/model/App.java @@ -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"); diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/view/Popup.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/view/Popup.java index cd542b5..3f74d0d 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/view/Popup.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/view/Popup.java @@ -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; @@ -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()); @@ -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()); @@ -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) { @@ -148,13 +127,14 @@ 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; }; @@ -162,7 +142,8 @@ private void loadStylesheets() { 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"); } @@ -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"); @@ -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(); @@ -257,4 +238,5 @@ public HBox getHeader() { public Button getCloseButton() { return closeButton; } + } \ No newline at end of file diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/view/apps/WeekendReportApp.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/view/apps/WeekendReportApp.java index 1e2e9a9..fc50860 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/view/apps/WeekendReportApp.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/view/apps/WeekendReportApp.java @@ -47,7 +47,7 @@ public class WeekendReportApp extends Popup { *

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()); diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/view/views/DesktopView.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/view/views/DesktopView.java index b731713..5832074 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/view/views/DesktopView.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/view/views/DesktopView.java @@ -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