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 98d9631..4409e8a 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 @@ -8,6 +8,7 @@ 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; @@ -15,6 +16,7 @@ import javafx.scene.input.TransferMode; import javafx.scene.layout.Region; import javafx.scene.layout.StackPane; +import javafx.scene.layout.VBox; import javafx.scene.paint.Color; /** @@ -38,7 +40,8 @@ public record DesktopComponentFactory( * @param type the application type * @return the created application button node */ - public Node createAppButton(final App type) { + public VBox createAppButton(final App type) { + final VBox buttonContainer = new VBox(); Button button = new Button(); button.setStyle( "-fx-background-color: transparent; -fx-padding: 0; -fx-border-color: transparent;" @@ -73,8 +76,15 @@ public Node createAppButton(final App type) { bindButtonSize(button, newParent)); popupsController.bindOpenButton(button, type); - setupDrag(button); - return button; + setupDrag(button, buttonContainer); + + Label appName = new Label(type.getDisplayName()); + appName.setStyle( + "-fx-font-size: 12px; -fx-font-weight: bold; -fx-text-fill: white; -fx-wrap-text: true;"); + buttonContainer.setAlignment(javafx.geometry.Pos.CENTER); + buttonContainer.setSpacing(5); + buttonContainer.getChildren().addAll(button, appName); + return buttonContainer; } private String iconPath(final App type) { @@ -102,12 +112,12 @@ private void bindButtonSize(final Button button, final Object parent) { } } - private void setupDrag(final Button button) { + private void setupDrag(final Button button, final VBox container) { button.setOnDragDetected(event -> { - Dragboard dragboard = button.startDragAndDrop(TransferMode.MOVE); + Dragboard dragboard = container.startDragAndDrop(TransferMode.MOVE); SnapshotParameters params = new SnapshotParameters(); params.setFill(Color.TRANSPARENT); - dragboard.setDragView(button.snapshot(params, null)); + dragboard.setDragView(container.snapshot(params, null)); dragboard.setDragViewOffsetX(event.getX()); dragboard.setDragViewOffsetY(event.getY()); ClipboardContent content = new ClipboardContent(); @@ -119,14 +129,14 @@ 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) { + final double width, + final double height) { + if (width <= 0 || height <= 0) { return; } - javafx.scene.shape.Rectangle clip = new javafx.scene.shape.Rectangle(w, h); - clip.setArcWidth(w * 0.45); - clip.setArcHeight(h * 0.45); + javafx.scene.shape.Rectangle clip = new javafx.scene.shape.Rectangle(width, height); + clip.setArcWidth(width * 0.45); + clip.setArcHeight(height * 0.45); icon.setClip(clip); } @@ -137,7 +147,7 @@ private void applyIconClip( */ public void configureCellAsDropTarget(final StackPane cell) { cell.setOnDragOver(event -> { - if (event.getGestureSource() instanceof Button && cell.getChildren().isEmpty()) { + if (event.getGestureSource() instanceof VBox && cell.getChildren().isEmpty()) { event.acceptTransferModes(TransferMode.MOVE); } event.consume(); @@ -145,9 +155,10 @@ public void configureCellAsDropTarget(final StackPane cell) { cell.setOnDragDropped(event -> { boolean success = false; - if (event.getGestureSource() instanceof Button button) { - ((StackPane) button.getParent()).getChildren().remove(button); - cell.getChildren().add(button); + if (event.getGestureSource() instanceof VBox container) { + StackPane source = (StackPane) container.getParent(); + source.getChildren().remove(container); + cell.getChildren().add(container); success = true; } event.setDropCompleted(success);