diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/AppControllers/BankAppController.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/AppControllers/BankAppController.java index c012783..09ac5a7 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/AppControllers/BankAppController.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/AppControllers/BankAppController.java @@ -7,19 +7,14 @@ * Controller for the {@link BankApp}. * Handles updating the player's financial status and portfolio view. */ -public final class BankAppController implements AppController { - private final Player player; - private final BankApp bankApp; - +public record BankAppController(BankApp bankApp, Player player) implements AppController { /** * Constructs a new BankAppController. * * @param bankApp the bank app view * @param player the player model */ - public BankAppController(final BankApp bankApp, final Player player) { - this.player = player; - this.bankApp = bankApp; + public BankAppController { } @Override diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/AppControllers/StockAppController.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/AppControllers/StockAppController.java index 4a252eb..60de256 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/AppControllers/StockAppController.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/AppControllers/StockAppController.java @@ -109,10 +109,10 @@ private void handleBuy(final Stock stock, final BigDecimal quantity) { } else { System.out.println("[DEBUG] Buy failed: transaction is null"); } - } catch (Exception e) { + } catch (Exception exception) { System.out.println("[DEBUG] Buy failed with exception: " - + e.getMessage()); - e.printStackTrace(); + + exception.getMessage()); + exception.printStackTrace(); } } diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/GameController.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/GameController.java index 66622b2..801486d 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/GameController.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/GameController.java @@ -12,11 +12,8 @@ * Controller for managing the game state and timing. */ public final class GameController { - /** The player model. */ private final Player player; - /** List of application controllers. */ private final List appControllers = new ArrayList<>(); - /** Timer for game ticks. */ private Timer timer; /** diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/MarketController.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/MarketController.java index 68b9f9c..b3b96bd 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/MarketController.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/MarketController.java @@ -4,10 +4,9 @@ import edu.ntnu.idi.idatt2003.gruppe42.Model.Stock; import edu.ntnu.idi.idatt2003.gruppe42.Model.StockFileHandler; import edu.ntnu.idi.idatt2003.gruppe42.View.Apps.StockApp; -import javafx.application.Platform; - import java.nio.file.Path; import java.util.List; +import java.util.Objects; /** * Controller for the stock market. @@ -25,14 +24,14 @@ public MarketController() { this.stockResolution = 50; try { - Path path = Path.of(getClass().getClassLoader() - .getResource("stocks.csv").toURI()); + Path path = Path.of(Objects.requireNonNull(getClass().getClassLoader() + .getResource("stocks.csv")).toURI()); exchange = new Exchange(StockFileHandler.readFromFile(path)); startMarket(); System.out.println("Market loaded"); - } catch (Exception e) { + } catch (Exception exception) { System.out.println("File not found"); } } diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/ViewControllers/DesktopViewController.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/ViewControllers/DesktopViewController.java index 6c5278e..7443f94 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/ViewControllers/DesktopViewController.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/ViewControllers/DesktopViewController.java @@ -49,23 +49,20 @@ public DesktopViewController( ) { List popups = new ArrayList<>(); - final int appWidth = 400; - final int appHeight = 300; - - AppStoreApp appStoreApp = new AppStoreApp(appWidth, appHeight, 100, 100); + AppStoreApp appStoreApp = new AppStoreApp(); gameController.addAppController(new AppStoreController(appStoreApp)); - HustlersApp hustlersApp = new HustlersApp(appWidth, appHeight, 140, 140); + HustlersApp hustlersApp = new HustlersApp(); - StockApp stockApp = new StockApp(appWidth, appHeight, 120, 120); + StockApp stockApp = new StockApp(); MarketController marketController = new MarketController(); gameController.addAppController( new StockAppController(stockApp, marketController, player) ); - MailApp mailApp = new MailApp(appWidth, appHeight, 160, 160); + MailApp mailApp = new MailApp(); - NewsApp newsApp = new NewsApp(appWidth, appHeight, 180, 180); + NewsApp newsApp = new NewsApp(); BankApp bankApp = new BankApp(); gameController.addAppController(new BankAppController(bankApp, player)); diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Calculator/PurchaseCalculator.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Calculator/PurchaseCalculator.java index cfc8c11..ca65050 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Calculator/PurchaseCalculator.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Calculator/PurchaseCalculator.java @@ -7,9 +7,7 @@ * Calculator for stock purchase transactions. */ public final class PurchaseCalculator implements TransactionCalculator { - /** The price per share at purchase. */ private final BigDecimal purchasePrice; - /** The number of shares bought. */ private final BigDecimal quantity; /** diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Calculator/SaleCalculator.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Calculator/SaleCalculator.java index 69ac0b5..1925e88 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Calculator/SaleCalculator.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Calculator/SaleCalculator.java @@ -7,11 +7,8 @@ * Calculator for stock sale transactions. */ public final class SaleCalculator implements TransactionCalculator { - /** The price per share at purchase. */ private final BigDecimal purchasePrice; - /** The current price per share at sale. */ private final BigDecimal salesPrice; - /** The number of shares sold. */ private final BigDecimal quantity; /** diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Exchange.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Exchange.java index f1706a1..682701b 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Exchange.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Exchange.java @@ -23,8 +23,7 @@ public class Exchange { private int week; /** Map of stock symbols to Stock objects. */ private final Map stockMap; - /** Random number generator for simulation events. */ - private final Random random; + /** * Constructs a new {@code Exchange} with a list of stocks. @@ -34,7 +33,6 @@ public class Exchange { public Exchange(final List stocks) { this.week = 0; this.stockMap = new HashMap(); - this.random = new Random(); for (Stock stock : stocks) { stockMap.put(stock.getSymbol(), stock); } diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Transaction/Transaction.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Transaction/Transaction.java index f3d8c09..9a95857 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Transaction/Transaction.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Transaction/Transaction.java @@ -8,13 +8,9 @@ * Abstract base class for financial transactions. */ public abstract class Transaction { - /** The share position involved in the transaction. */ private final Share share; - /** The week the transaction occurred. */ private final int week; - /** The calculator used for this transaction. */ private final TransactionCalculator calculator; - /** Whether the transaction has been committed. */ private boolean committed = false; /** diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Apps/AppStoreApp.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Apps/AppStoreApp.java index c37bcd8..9eeeaad 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Apps/AppStoreApp.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Apps/AppStoreApp.java @@ -4,21 +4,16 @@ import edu.ntnu.idi.idatt2003.gruppe42.View.Popup; /** - * A popup for the AppStore app. + * A popup for the app store app. */ public class AppStoreApp extends Popup { /** - * Constructs a new AppStore popup. - * - * @param width width of the popup - * @param height height of the popup - * @param x x-position of the popup - * @param y y-position of the popup + * Constructs a new app store popup. */ - public AppStoreApp(int width, int height, int x, int y) { - super(width, height, x, y, App.APPSTORE); - // Add AppStore specific content here + public AppStoreApp() { + super(400, 300, 100, 100, App.APPSTORE); + // Add App store specific content here } } diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Apps/BankApp.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Apps/BankApp.java index 4ffea33..f162ed7 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Apps/BankApp.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Apps/BankApp.java @@ -26,59 +26,41 @@ public class BankApp extends Popup { * Constructs a new Bank popup. */ public BankApp() { - super(400, 300, 120, 120, App.BANK); + super(400, 300, 220, 120, App.BANK); this.portfolioList = new ListView<>(); updateContent(); } private void updateContent() { GridPane statusPane = new GridPane(); + statusPane.add(netWorthLabel, 0, 0); + statusPane.add(growthPercentageLabel, 1, 0); + statusPane.add(unInvestedMoneyLabel, 0, 1); + statusPane.add(investedMoneyLabel, 1, 1); - final int col0 = 0; - final int col1 = 1; - final int row0 = 0; - final int row1 = 1; + portfolioList.setCellFactory(listView -> new ListCell() { + @Override + protected void updateItem(final Share share, final boolean empty) { + super.updateItem(share, empty); - statusPane.add(netWorthLabel, col0, row0); - statusPane.add(unInvestedMoneyLabel, col0, row1); - statusPane.add(investedMoneyLabel, col1, row1); - statusPane.add(growthPercentageLabel, col1, row0); + if (empty || share == null) { + setGraphic(null); + return; + } - portfolioList.setCellFactory( - lv -> - new ListCell() { - @Override - protected void updateItem(final Share share, final boolean empty) { - super.updateItem(share, empty); - if (empty || share == null) { - setGraphic(null); - } else { - GridPane sharePane = new GridPane(); - final int col0 = 0; - final int col1 = 1; - final int row0 = 0; - final int row1 = 1; - final int row2 = 2; - final int row3 = 3; - - sharePane.add(new Label(share.getStock().getCompany()), - col0, row0); - sharePane.add(new Label("Purchase"), col1, row0); - sharePane.add(new Label(share.getStock().getSymbol()), - col0, row1); - sharePane.add(new Label(share.getPurchasePrice().toString()), - col1, row1); - sharePane.add(new Label("Quantity"), col0, row2); - sharePane.add(new Label("Sale"), col1, row2); - sharePane.add(new Label(share.getQuantity().toString()), - col0, row3); - sharePane.add(new Label(share.getStock().getSalesPrice() - .toString()), col1, row3); - sharePane.setAlignment(Pos.CENTER_LEFT); - setGraphic(sharePane); - } - } - }); + GridPane sharePane = new GridPane(); + sharePane.setAlignment(Pos.CENTER_LEFT); + sharePane.add(new Label(share.getStock().getCompany()), 0, 0); + sharePane.add(new Label("Purchase"), 1, 0); + sharePane.add(new Label(share.getStock().getSymbol()), 0, 1); + sharePane.add(new Label(share.getPurchasePrice().toString()), 1, 1); + sharePane.add(new Label("Quantity"), 0, 2); + sharePane.add(new Label("Sale"), 1, 2); + sharePane.add(new Label(share.getQuantity().toString()), 0, 3); + sharePane.add(new Label(share.getStock().getSalesPrice().toString()), 1, 3); + setGraphic(sharePane); + } + }); content.getChildren().setAll(statusPane, portfolioList); } diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Apps/HustlersApp.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Apps/HustlersApp.java index 7467c1d..ec8981f 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Apps/HustlersApp.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Apps/HustlersApp.java @@ -10,14 +10,9 @@ public class HustlersApp extends Popup { /** * Constructs a new Hustlers popup. - * - * @param width width of the popup - * @param height height of the popup - * @param x x-position of the popup - * @param y y-position of the popup */ - public HustlersApp(int width, int height, int x, int y) { - super(width, height, x, y, App.HUSTLERS); + public HustlersApp() { + super(400, 300, 140, 140, App.HUSTLERS); // Add Hustlers specific content here } diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Apps/MailApp.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Apps/MailApp.java index 3b31ac3..74c44bc 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Apps/MailApp.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Apps/MailApp.java @@ -11,13 +11,9 @@ public class MailApp extends Popup { /** * Constructs a new Mail popup. * - * @param width width of the popup - * @param height height of the popup - * @param x x-position of the popup - * @param y y-position of the popup */ - public MailApp(int width, int height, int x, int y) { - super(width, height, x, y, App.MAIL); + public MailApp() { + super(400, 300, 140, 140, App.MAIL); // Add Mail specific content here } diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Apps/NewsApp.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Apps/NewsApp.java index ac57fe8..e8235d3 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Apps/NewsApp.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Apps/NewsApp.java @@ -10,14 +10,9 @@ public class NewsApp extends Popup { /** * Constructs a new News popup. - * - * @param width width of the popup - * @param height height of the popup - * @param x x-position of the popup - * @param y y-position of the popup */ - public NewsApp(int width, int height, int x, int y) { - super(width, height, x, y, App.NEWS); - // Add News specific content here + public NewsApp() { + super(400, 300, 180, 180, App.NEWS); + // Add news-specific content here } } diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Apps/StockApp.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Apps/StockApp.java index 680c0f7..f869efd 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Apps/StockApp.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Apps/StockApp.java @@ -27,18 +27,14 @@ public class StockApp extends Popup { /** * Constructs a new Stock popup. * - * @param width width of the popup - * @param height height of the popup - * @param x x-position of the popup - * @param y y-position of the popup */ - public StockApp(final int width, final int height, final int x, final int y) { - super(width, height, x, y, App.STOCK); + public StockApp() { + super(400, 300, 140, 140, App.STOCK); this.searchField = new TextField(); this.stockList = new ListView<>(); - final int minQuantity = -1000; - final int maxQuantity = 1000; + final int minQuantity = -10; + final int maxQuantity = 10; final int initialQuantity = 0; this.quantitySpinner = new Spinner<>( minQuantity, maxQuantity, initialQuantity 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 3553490..b1b0f3a 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,27 +15,17 @@ * Handles dragging, layout, and common components. */ public abstract class Popup { - /** Width of the popup. */ private final int width; - /** Height of the popup. */ private final int height; - /** X-offset for dragging. */ private double dx; - /** Y-offset for dragging. */ private double dy; - /** The app type of the popup. */ private final App type; /** Root layout node. */ private final BorderPane root; - /** Scrollable container for content. */ - private final ScrollPane scrollPane; - /** Header container. */ private final HBox header; - /** Close button. */ private final Button closeButton; - /** Content container. */ protected final VBox content; /** @@ -59,7 +49,7 @@ protected Popup( this.type = type; root = new BorderPane(); - scrollPane = new ScrollPane(); + ScrollPane scrollPane = new ScrollPane(); scrollPane.setStyle("-fx-hbar-policy: never; -fx-vbar-policy: AS_NEEDED; " + "-fx-background-insets: 0; -fx-padding: 0;"); @@ -92,18 +82,18 @@ private void setCloseButtonAction() { } private void setOnPressedAction() { - root.addEventFilter(MouseEvent.MOUSE_PRESSED, e -> root.toFront()); + root.addEventFilter(MouseEvent.MOUSE_PRESSED, mouseEvent -> root.toFront()); } private void makeDraggable() { - header.setOnMousePressed(e -> { - dx = e.getSceneX() - root.getLayoutX(); - dy = e.getSceneY() - root.getLayoutY(); + header.setOnMousePressed(mouseEvent -> { + dx = mouseEvent.getSceneX() - root.getLayoutX(); + dy = mouseEvent.getSceneY() - root.getLayoutY(); }); - header.setOnMouseDragged(e -> { - root.setLayoutX(e.getSceneX() - dx); - root.setLayoutY(e.getSceneY() - dy); + header.setOnMouseDragged(mouseEvent -> { + root.setLayoutX(mouseEvent.getSceneX() - dx); + root.setLayoutY(mouseEvent.getSceneY() - dy); keepInBounds(); }); } diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Views/Components/Receipt.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Views/Components/Receipt.java index 08578ee..4dfbe8f 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Views/Components/Receipt.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Views/Components/Receipt.java @@ -11,8 +11,6 @@ * Component for displaying a transaction receipt. */ public final class Receipt extends VBox { - private Stock stock; - private BigDecimal quantity; /** * Constructs a new Receipt. @@ -31,31 +29,25 @@ public Receipt(final Stock stock, final BigDecimal quantity) { * @param quantity the quantity */ public void update(final Stock stock, final BigDecimal quantity) { - this.stock = stock; - this.quantity = quantity; if (stock == null) { this.getChildren().clear(); return; } - GridPane receiptPane = new GridPane(); - final int col0 = 0; - final int col1 = 1; - final int row0 = 0; - final int row1 = 1; - final int row2 = 2; - final int row3 = 3; - - receiptPane.add(new Label(stock.getCompany()), col0, row0); - receiptPane.add(new Label("Quantity"), col1, row0); - receiptPane.add(new Label(stock.getSymbol()), col0, row1); - receiptPane.add(new Label(quantity.toString()), col1, row1); - receiptPane.add(new Label("Price"), col0, row2); - receiptPane.add(new Label("Amount"), col1, row2); - receiptPane.add(new Label(stock.getSalesPrice().toString()), col0, row3); - receiptPane.add(new Label((stock.getSalesPrice().multiply(quantity)) - .toString()), col1, row3); + GridPane receiptPane = new GridPane(); receiptPane.setAlignment(Pos.CENTER); + + BigDecimal totalAmount = stock.getSalesPrice().multiply(quantity); + + receiptPane.add(new Label(stock.getCompany()), 0, 0); + receiptPane.add(new Label("Quantity"), 1, 0); + receiptPane.add(new Label(stock.getSymbol()), 0, 1); + receiptPane.add(new Label(quantity.toString()), 1, 1); + receiptPane.add(new Label("Price"), 0, 2); + receiptPane.add(new Label("Amount"), 1, 2); + receiptPane.add(new Label(stock.getSalesPrice().toString()), 0, 3); + receiptPane.add(new Label(totalAmount.toString()), 1, 3); + this.getChildren().setAll(new Label("Receipt"), receiptPane); - } -} + } +} \ No newline at end of file diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Views/Components/StockGraph.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Views/Components/StockGraph.java index 40b88a8..b7a15d1 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Views/Components/StockGraph.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Views/Components/StockGraph.java @@ -16,7 +16,6 @@ public final class StockGraph extends VBox { private final LineChart lineChart; private boolean isVisible = false; - private final int stockResolution = 50; /** * Constructs a new StockGraph. @@ -33,8 +32,7 @@ public StockGraph() { yAxis.setAutoRanging(true); lineChart = new LineChart<>(xAxis, yAxis); - final int prefSize = 100; - lineChart.setPrefSize(prefSize, prefSize); + lineChart.setPrefSize(100, 100); lineChart.setCreateSymbols(false); lineChart.setLegendVisible(false); lineChart.setAnimated(false); @@ -59,6 +57,7 @@ public boolean update(final Stock stock) { return false; } + int stockResolution = 50; List latestHistory = history.subList( Math.max(history.size() - stockResolution, 0), history.size() 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 7a01c33..35fa3ee 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 @@ -2,7 +2,14 @@ import edu.ntnu.idi.idatt2003.gruppe42.Controller.ViewControllers.DesktopViewController; import edu.ntnu.idi.idatt2003.gruppe42.Model.App; +import java.util.Objects; import javafx.geometry.Pos; +import javafx.scene.image.Image; +import javafx.scene.layout.Background; +import javafx.scene.layout.BackgroundImage; +import javafx.scene.layout.BackgroundPosition; +import javafx.scene.layout.BackgroundRepeat; +import javafx.scene.layout.BackgroundSize; import javafx.scene.layout.BorderPane; import javafx.scene.layout.ColumnConstraints; import javafx.scene.layout.GridPane; @@ -15,13 +22,9 @@ * Displays a 6x4 grid of apps. */ public final class DesktopView { - /** Controller for the desktop. */ private final DesktopViewController desktopViewController; - /** Root layout node. */ private final BorderPane root; - /** Number of columns in the grid. */ private static final int COLS = 6; - /** Number of rows in the grid. */ private static final int ROWS = 4; /** @@ -42,6 +45,34 @@ public DesktopView(final DesktopViewController desktopViewController) { public BorderPane getRoot() { GridPane grid = createGrid(); root.setCenter(grid); + + // Load background image from resources + Image backgroundImage = new Image( + Objects.requireNonNull(getClass().getResourceAsStream("/Images/mac_home_background.jpg")), + 1920, 1080, + true, // preserve aspect ratio + true // smooth scaling + ); + + // Configure background to cover the full container without tiling + BackgroundSize backgroundSize = new BackgroundSize( + BackgroundSize.AUTO, BackgroundSize.AUTO, + false, + false, + false, + true + ); + + BackgroundImage background = new BackgroundImage( + backgroundImage, + BackgroundRepeat.NO_REPEAT, + BackgroundRepeat.NO_REPEAT, + BackgroundPosition.CENTER, + backgroundSize + ); + + root.setBackground(new Background(background)); + return root; } @@ -94,7 +125,6 @@ private GridPane createGrid() { */ private StackPane createCell() { StackPane cell = new StackPane(); - cell.setStyle("-fx-border-color: black; -fx-border-width: 1;"); desktopViewController.configureCellAsDropTarget(cell); return cell; } diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Views/StartView.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Views/StartView.java index 94924e6..17aceb1 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Views/StartView.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Views/StartView.java @@ -8,6 +8,11 @@ import javafx.scene.control.ToggleGroup; import javafx.scene.image.Image; import javafx.scene.image.ImageView; +import javafx.scene.layout.Background; +import javafx.scene.layout.BackgroundImage; +import javafx.scene.layout.BackgroundPosition; +import javafx.scene.layout.BackgroundRepeat; +import javafx.scene.layout.BackgroundSize; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; @@ -21,9 +26,19 @@ public class StartView { public StackPane getRoot() { - StackPane root = new StackPane(); + // Background image + Image backgroundImage = new Image(Objects.requireNonNull(getClass().getResourceAsStream("/Images/windows7_login_background.jpg")), 1920, 1080, true, true); + BackgroundImage background = new BackgroundImage( + backgroundImage, + BackgroundRepeat.NO_REPEAT, + BackgroundRepeat.NO_REPEAT, + BackgroundPosition.CENTER, + new BackgroundSize(BackgroundSize.AUTO, BackgroundSize.AUTO, false, false, true, true) + ); + root.setBackground(new Background(background)); + // Main content VBox content = new VBox(); content.setAlignment(Pos.CENTER); diff --git a/src/main/resources/Images/mac_home_background.jpg b/src/main/resources/Images/mac_home_background.jpg new file mode 100644 index 0000000..73d60c5 Binary files /dev/null and b/src/main/resources/Images/mac_home_background.jpg differ diff --git a/src/main/resources/Images/windows7_login_background.jpg b/src/main/resources/Images/windows7_login_background.jpg new file mode 100644 index 0000000..258f2df Binary files /dev/null and b/src/main/resources/Images/windows7_login_background.jpg differ