diff --git a/src/main/java/com/andrewlalis/perfin/view/component/AttachmentPreview.java b/src/main/java/com/andrewlalis/perfin/view/component/AttachmentPreview.java index 3e97082..7b29a96 100644 --- a/src/main/java/com/andrewlalis/perfin/view/component/AttachmentPreview.java +++ b/src/main/java/com/andrewlalis/perfin/view/component/AttachmentPreview.java @@ -4,8 +4,7 @@ import com.andrewlalis.perfin.model.TransactionAttachment; import javafx.scene.control.Label; import javafx.scene.image.Image; import javafx.scene.image.ImageView; -import javafx.scene.layout.BorderPane; -import javafx.scene.layout.VBox; +import javafx.scene.layout.*; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; @@ -23,27 +22,42 @@ public class AttachmentPreview extends BorderPane { public static final double HEIGHT = IMAGE_SIZE + LABEL_SIZE; public AttachmentPreview(TransactionAttachment attachment) { + BorderPane contentContainer = new BorderPane(); Label nameLabel = new Label(attachment.getFilename()); nameLabel.setStyle("-fx-font-size: small;"); VBox nameContainer = new VBox(nameLabel); nameContainer.setPrefHeight(LABEL_SIZE); nameContainer.setMaxHeight(LABEL_SIZE); nameContainer.setMinHeight(LABEL_SIZE); - setBottom(nameContainer); + contentContainer.setBottom(nameContainer); Rectangle placeholder = new Rectangle(IMAGE_SIZE, IMAGE_SIZE); placeholder.setFill(Color.WHITE); - setCenter(placeholder); + contentContainer.setCenter(placeholder); Set imageTypes = Set.of("image/png", "image/jpeg", "image/gif", "image/bmp"); if (imageTypes.contains(attachment.getContentType())) { try (var in = Files.newInputStream(attachment.getPath())) { Image img = new Image(in, IMAGE_SIZE, IMAGE_SIZE, true, true); - setCenter(new ImageView(img)); + contentContainer.setCenter(new ImageView(img)); } catch (IOException e) { e.printStackTrace(); } } + BorderPane hoverIndicatorPane = new BorderPane(); + hoverIndicatorPane.prefWidthProperty().bind(contentContainer.widthProperty()); + hoverIndicatorPane.prefHeightProperty().bind(contentContainer.heightProperty()); + hoverIndicatorPane.setBackground(new Background(new BackgroundFill(Color.rgb(186, 210, 255, 0.5), null, null))); + hoverIndicatorPane.visibleProperty().bind(this.hoverProperty()); + + StackPane stackPane = new StackPane(contentContainer, hoverIndicatorPane); + + this.setCenter(stackPane); + this.setOnMouseClicked(event -> { + if (this.isHover()) { + System.out.println("Opening attachment: " + attachment.getFilename()); + } + }); } }