From a15095299033294fbff320fe586f23068a630714 Mon Sep 17 00:00:00 2001 From: Denis Nutiu Date: Sun, 17 Nov 2024 14:37:37 +0200 Subject: [PATCH] =?UTF-8?q?Implement=20settings=20for=20tags=20display=20m?= =?UTF-8?q?ode=20=F0=9F=93=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../imagetagger/ui/MainPageController.kt | 41 +++++++++++++++++-- .../ui/controls/ImageTagsDisplayMode.kt | 18 +++++++- .../imagetagger/ui/main-window-view.fxml | 8 +++- 3 files changed, 61 insertions(+), 6 deletions(-) diff --git a/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/MainPageController.kt b/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/MainPageController.kt index 8a12028..de0ece1 100644 --- a/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/MainPageController.kt +++ b/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/MainPageController.kt @@ -5,8 +5,10 @@ import dev.nuculabs.imagetagger.ui.controls.ImageTagsDisplayMode import dev.nuculabs.imagetagger.ui.controls.ImageTagsEntryControl import dev.nuculabs.imagetagger.ui.controls.ImageTagsSessionHeader import javafx.application.Platform +import javafx.collections.FXCollections import javafx.fxml.FXML import javafx.scene.control.Button +import javafx.scene.control.ChoiceBox import javafx.scene.control.ProgressBar import javafx.scene.control.Separator import javafx.scene.layout.HBox @@ -59,8 +61,16 @@ class MainPageController { */ private var isCurrentTagsOperationCancelled: Boolean = false + /** + * Holds a list of predicted images controls that are rendered in the view. + */ private var predictedImages: MutableList = ArrayList() + /** + * Controls how image tags are displayed on the screen. + */ + private var tagsDisplayMode: ImageTagsDisplayMode = ImageTagsDisplayMode.CommaSeparated + @FXML private lateinit var progressBar: ProgressBar @@ -71,7 +81,10 @@ class MainPageController { private lateinit var cancelButton: Button @FXML - lateinit var tagImagesButton: Button + private lateinit var tagImagesButton: Button + + @FXML + private lateinit var tagsDisplayModeSelection: ChoiceBox /** * Initializes the controller. Needs to be called after the dependencies have been injected. @@ -79,6 +92,29 @@ class MainPageController { fun initialize() { HBox.setHgrow(progressBar, Priority.ALWAYS) HBox.setHgrow(cancelButton, Priority.ALWAYS) + + initializeTagsDisplayMode() + } + + /** + * Initializes the tags display mode. + */ + private fun initializeTagsDisplayMode() { + // Tags display mode + tagsDisplayModeSelection.items = FXCollections.observableArrayList( + ImageTagsDisplayMode.CommaSeparated.toString(), + ImageTagsDisplayMode.HashTags.toString() + ) + tagsDisplayModeSelection.value = ImageTagsDisplayMode.CommaSeparated.toString() + + tagsDisplayModeSelection.selectionModel.selectedItemProperty().addListener { _, oldValue, newValue -> + if (oldValue != newValue && newValue != null) { + tagsDisplayMode = ImageTagsDisplayMode.fromString(newValue) + predictedImages.forEach { + it.setTagsDisplayMode(tagsDisplayMode) + } + } + } } /** @@ -152,8 +188,7 @@ class MainPageController { analyzedImage: AnalyzedImage, ) { val control = ImageTagsEntryControl(analyzedImage) - // TODO add default tag mode - control.setTagsDisplayMode(ImageTagsDisplayMode.CommaSeparated) + control.setTagsDisplayMode(tagsDisplayMode) verticalBox.children.add(control) predictedImages.add(control) verticalBox.children.add(Separator()) diff --git a/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/controls/ImageTagsDisplayMode.kt b/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/controls/ImageTagsDisplayMode.kt index e341477..155be3c 100644 --- a/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/controls/ImageTagsDisplayMode.kt +++ b/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/controls/ImageTagsDisplayMode.kt @@ -4,6 +4,20 @@ package dev.nuculabs.imagetagger.ui.controls * Determines how tags are displayed */ enum class ImageTagsDisplayMode { - CommaSeparated, - HashTags + CommaSeparated { + override fun toString(): String { + return "Comma Separated" + } + }, + HashTags; + + companion object { + fun fromString(value: String): ImageTagsDisplayMode { + return when (value) { + CommaSeparated.toString() -> CommaSeparated + "HashTags" -> HashTags + else -> throw IllegalArgumentException("Invalid argument $value") + } + } + } } \ No newline at end of file diff --git a/img-ui/src/main/resources/dev/nuculabs/imagetagger/ui/main-window-view.fxml b/img-ui/src/main/resources/dev/nuculabs/imagetagger/ui/main-window-view.fxml index 682c807..6b6576a 100644 --- a/img-ui/src/main/resources/dev/nuculabs/imagetagger/ui/main-window-view.fxml +++ b/img-ui/src/main/resources/dev/nuculabs/imagetagger/ui/main-window-view.fxml @@ -14,7 +14,7 @@ - + @@ -24,6 +24,12 @@ + + + + + +