diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/controller/viewcontrollers/DesktopComponentFactory.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/controller/viewcontrollers/DesktopComponentFactory.java index b166456..631ccca 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/controller/viewcontrollers/DesktopComponentFactory.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/controller/viewcontrollers/DesktopComponentFactory.java @@ -3,22 +3,19 @@ import edu.ntnu.idi.idatt2003.gruppe42.controller.PopupsController; import edu.ntnu.idi.idatt2003.gruppe42.controller.appcontrollers.MailController; import edu.ntnu.idi.idatt2003.gruppe42.model.App; +import java.util.Objects; import javafx.beans.binding.Bindings; -import javafx.geometry.Pos; import javafx.scene.Node; import javafx.scene.SnapshotParameters; import javafx.scene.control.Button; -import javafx.scene.control.Label; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; import javafx.scene.input.ClipboardContent; import javafx.scene.input.Dragboard; import javafx.scene.input.TransferMode; -import javafx.scene.layout.Pane; import javafx.scene.layout.Region; import javafx.scene.layout.StackPane; import javafx.scene.paint.Color; -import javafx.scene.shape.Circle; -import javafx.scene.text.Font; -import javafx.scene.text.FontWeight; /** * Factory class for creating desktop user interface components. @@ -26,8 +23,6 @@ public record DesktopComponentFactory( PopupsController popupsController, MailController mailController) { - private static final double BADGE_RADIUS = 10; - /** * Constructs a DesktopComponentFactory. * @@ -44,10 +39,36 @@ public record DesktopComponentFactory( * @return the created application button node */ public Node createAppButton(final App type) { - Button button = new Button(type.getDisplayName()); - button.getStyleClass().add("app-button"); + Button button = new Button(); + button.setStyle( + "-fx-background-color: transparent; -fx-padding: 0; -fx-border-color: transparent;" + ); button.setMinSize(0, 0); + try { + String path = iconPath(type); + Image img = new javafx.scene.image.Image( + Objects.requireNonNull(getClass().getResourceAsStream(Objects.requireNonNull(path)))); + + ImageView icon = new javafx.scene.image.ImageView(img); + icon.setPreserveRatio(false); + icon.fitWidthProperty().bind(button.prefWidthProperty()); + icon.fitHeightProperty().bind(button.prefHeightProperty()); + + button.setGraphic(icon); + button.setPadding(javafx.geometry.Insets.EMPTY); + + button.prefWidthProperty().addListener(( + obs, ov, nv) -> + applyIconClip(icon, nv.doubleValue(), button.getPrefHeight())); + button.prefHeightProperty().addListener(( + obs, ov, nv) -> + applyIconClip(icon, button.getPrefWidth(), nv.doubleValue())); + button.setGraphic(icon); + } catch (Exception e) { + button.setText(type.getDisplayName()); + } + button.parentProperty().addListener((obs, oldParent, newParent) -> bindButtonSize(button, newParent)); @@ -56,6 +77,16 @@ public Node createAppButton(final App type) { return button; } + private String iconPath(final App type) { + return switch (type) { + case MAIL -> "/Images/mailApp_icon.png"; + case BANK -> "/Images/bankApp_icon.png"; + case STOCK -> "/Images/stockApp_icon.png"; + case HUSTLERS -> "/Images/hustlersApp_icon.png"; + default -> null; + }; + } + private void bindButtonSize(final Button button, final Object parent) { if (parent instanceof Region region) { button.prefWidthProperty().bind( @@ -86,6 +117,19 @@ private void setupDrag(final Button button) { }); } + private void applyIconClip( + final javafx.scene.image.ImageView icon, + final double w, + final double h) { + if (w <= 0 || h <= 0) { + return; + } + javafx.scene.shape.Rectangle clip = new javafx.scene.shape.Rectangle(w, h); + clip.setArcWidth(w * 0.45); + clip.setArcHeight(h * 0.45); + icon.setClip(clip); + } + /** * Configures a stack pane to accept dragged application buttons. * diff --git a/src/main/resources/Images/bankApp_icon.png b/src/main/resources/Images/bankApp_icon.png new file mode 100644 index 0000000..642b9a4 Binary files /dev/null and b/src/main/resources/Images/bankApp_icon.png differ diff --git a/src/main/resources/Images/hustlersApp_icon.png b/src/main/resources/Images/hustlersApp_icon.png new file mode 100644 index 0000000..30d19ee Binary files /dev/null and b/src/main/resources/Images/hustlersApp_icon.png differ diff --git a/src/main/resources/Images/mailApp_icon.png b/src/main/resources/Images/mailApp_icon.png new file mode 100644 index 0000000..e1be4fd Binary files /dev/null and b/src/main/resources/Images/mailApp_icon.png differ diff --git a/src/main/resources/Images/stockApp_icon.png b/src/main/resources/Images/stockApp_icon.png new file mode 100644 index 0000000..093366a Binary files /dev/null and b/src/main/resources/Images/stockApp_icon.png differ diff --git a/src/main/resources/Images/windows7_login_background.jpg b/src/main/resources/Images/windows7_login_background.jpg deleted file mode 100644 index 258f2df..0000000 Binary files a/src/main/resources/Images/windows7_login_background.jpg and /dev/null differ