Skip to content

Commit

Permalink
added icons
Browse files Browse the repository at this point in the history
  • Loading branch information
peretr committed May 20, 2026
1 parent 86650cf commit d797543
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,26 @@
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.
*/
public record DesktopComponentFactory(
PopupsController popupsController, MailController mailController) {

private static final double BADGE_RADIUS = 10;

/**
* Constructs a DesktopComponentFactory.
*
Expand All @@ -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));

Expand All @@ -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(
Expand Down Expand Up @@ -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.
*
Expand Down
Binary file added src/main/resources/Images/bankApp_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/Images/hustlersApp_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/Images/mailApp_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/Images/stockApp_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.

0 comments on commit d797543

Please sign in to comment.