From 69e1bf4d3c5e46f901c6c521182aae06b3b0094d Mon Sep 17 00:00:00 2001 From: Denis Nutiu Date: Tue, 19 Nov 2024 21:58:28 +0200 Subject: [PATCH] implement image metadata display using a table --- img-ui/src/main/java/module-info.java | 2 +- .../dev/nuculabs/imagetagger/ui/MainPage.kt | 5 +- .../ui/controls/ImageTagsEntryControl.kt | 48 +++++++++---------- .../ui/controls/ImageTagsEntryModel.kt | 38 +++++++++++++++ .../ui/controls/image-tags-entry.fxml | 36 ++++++++------ 5 files changed, 85 insertions(+), 44 deletions(-) create mode 100644 img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/controls/ImageTagsEntryModel.kt diff --git a/img-ui/src/main/java/module-info.java b/img-ui/src/main/java/module-info.java index b3de0cf..c2e221a 100644 --- a/img-ui/src/main/java/module-info.java +++ b/img-ui/src/main/java/module-info.java @@ -18,7 +18,7 @@ module dev.nuculabs.imagetagger.ui { requires org.apache.commons.lang3; opens dev.nuculabs.imagetagger.ui to javafx.fxml, javafx.graphics; - opens dev.nuculabs.imagetagger.ui.controls to javafx.fxml, javafx.graphics; + opens dev.nuculabs.imagetagger.ui.controls to javafx.fxml, javafx.graphics, javafx.base; opens dev.nuculabs.imagetagger.ui.pages to javafx.fxml, javafx.graphics; exports dev.nuculabs.imagetagger.ui; } \ No newline at end of file diff --git a/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/MainPage.kt b/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/MainPage.kt index d28bfa0..19d4959 100644 --- a/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/MainPage.kt +++ b/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/MainPage.kt @@ -43,16 +43,13 @@ class MainPage : Application() { // Set up the stage. stage.title = "Image Tagger" stage.scene = scene - stage.minWidth = 640.0 + stage.minWidth = 960.0 stage.minHeight = 760.0 // Whe the main window is hidden we exit the application. stage.setOnHidden { Platform.exit() } - // Add menu bar - // (scene.root as BorderPane).children.add(ApplicationMenuBar(mainPageController)) - stage.show() } diff --git a/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/controls/ImageTagsEntryControl.kt b/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/controls/ImageTagsEntryControl.kt index c01ad62..6a0501d 100644 --- a/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/controls/ImageTagsEntryControl.kt +++ b/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/controls/ImageTagsEntryControl.kt @@ -2,11 +2,13 @@ package dev.nuculabs.imagetagger.ui.controls import dev.nuculabs.imagetagger.core.AnalyzedImage import dev.nuculabs.imagetagger.ui.alerts.ErrorAlert -import org.apache.commons.lang3.SystemUtils +import javafx.collections.FXCollections +import javafx.collections.ObservableList import javafx.fxml.FXML import javafx.fxml.FXMLLoader import javafx.scene.control.Button import javafx.scene.control.Label +import javafx.scene.control.TableView import javafx.scene.control.TextArea import javafx.scene.image.Image import javafx.scene.image.ImageView @@ -15,6 +17,7 @@ import javafx.scene.input.ClipboardContent import javafx.scene.input.MouseEvent import javafx.scene.layout.HBox import javafx.scene.layout.VBox +import org.apache.commons.lang3.SystemUtils import java.awt.Desktop import java.io.File import java.io.IOException @@ -43,7 +46,7 @@ class ImageTagsEntryControl(private val image: AnalyzedImage) : HBox() { /** * Holds the tags. */ - private var tags: List = ArrayList(); + private var tags: List = ArrayList() /** * Sets the default image tags display mode. @@ -69,22 +72,7 @@ class ImageTagsEntryControl(private val image: AnalyzedImage) : HBox() { private lateinit var metadataVbox: VBox @FXML - private lateinit var metadataAuthor: Label - - @FXML - private lateinit var metadataCamera: Label - - @FXML - private lateinit var metadataLens: Label - - @FXML - private lateinit var metadataISO: Label - - @FXML - private lateinit var metadataAperture: Label - - @FXML - private lateinit var metadataShutterSpeed: Label + private lateinit var metadataTableView: TableView init { val resource = ImageTagsEntryControl::class.java.getResource("image-tags-entry.fxml") @@ -171,12 +159,24 @@ class ImageTagsEntryControl(private val image: AnalyzedImage) : HBox() { */ private fun setMetadata() { val imageMetadata = image.metadata() - metadataAuthor.text = "Author: ${imageMetadata.artist}" - metadataCamera.text = "Camera: ${imageMetadata.cameraBrand} ${imageMetadata.cameraModel}" - metadataLens.text = "Lens: ${imageMetadata.lensModel}" - metadataISO.text = "ISO: ${imageMetadata.iso}" - metadataAperture.text = "Aperture: ${imageMetadata.aperture}" - metadataShutterSpeed.text = "Shutter Speed: ${imageMetadata.shutterSpeed}" + val metadataValues = listOf( + ImageTagsEntryModel("Author", imageMetadata.artist), + ImageTagsEntryModel("Brand", imageMetadata.cameraBrand), + ImageTagsEntryModel("Model", imageMetadata.cameraModel), + ImageTagsEntryModel("Lens", imageMetadata.lensModel), + ImageTagsEntryModel("ISO", imageMetadata.iso), + ImageTagsEntryModel("Aperture", imageMetadata.aperture), + ImageTagsEntryModel("Shutter Speed", imageMetadata.shutterSpeed), + ).filterNot { it.getValue() == "Unknown" } + val data: ObservableList = FXCollections.observableArrayList( + metadataValues + ) + if (data.size == 0) { + metadataVbox.isVisible = false + return + } + metadataTableView.items = data + } diff --git a/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/controls/ImageTagsEntryModel.kt b/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/controls/ImageTagsEntryModel.kt new file mode 100644 index 0000000..cb1cd51 --- /dev/null +++ b/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/controls/ImageTagsEntryModel.kt @@ -0,0 +1,38 @@ +@file:Suppress("unused") + +package dev.nuculabs.imagetagger.ui.controls + +import javafx.beans.property.SimpleStringProperty +import javafx.beans.property.StringProperty + +/** + * ImageTagsEntryModel represents a metadata and it's associated value. + */ +class ImageTagsEntryModel(metadata: String, value: String) { + private val metadata: StringProperty = SimpleStringProperty(metadata) + private val value: StringProperty = SimpleStringProperty(value) + + fun getMetadata(): String { + return metadata.get() + } + + fun setMetadata(metadata: String) { + this.metadata.set(metadata) + } + + fun metadataProperty(): StringProperty { + return metadata + } + + fun getValue(): String { + return value.get() + } + + fun setValue(value: String) { + this.value.set(value) + } + + fun valueProperty(): StringProperty { + return value + } +} \ No newline at end of file diff --git a/img-ui/src/main/resources/dev/nuculabs/imagetagger/ui/controls/image-tags-entry.fxml b/img-ui/src/main/resources/dev/nuculabs/imagetagger/ui/controls/image-tags-entry.fxml index 5c878ee..ae5d23e 100644 --- a/img-ui/src/main/resources/dev/nuculabs/imagetagger/ui/controls/image-tags-entry.fxml +++ b/img-ui/src/main/resources/dev/nuculabs/imagetagger/ui/controls/image-tags-entry.fxml @@ -6,11 +6,13 @@ - - + + + - + @@ -20,17 +22,6 @@