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 de0ece1..27b6b57 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 @@ -69,7 +69,7 @@ class MainPageController { /** * Controls how image tags are displayed on the screen. */ - private var tagsDisplayMode: ImageTagsDisplayMode = ImageTagsDisplayMode.CommaSeparated + private var tagsDisplayMode: ImageTagsDisplayMode = ImageTagsDisplayMode.Comma @FXML private lateinit var progressBar: ProgressBar @@ -102,10 +102,9 @@ class MainPageController { private fun initializeTagsDisplayMode() { // Tags display mode tagsDisplayModeSelection.items = FXCollections.observableArrayList( - ImageTagsDisplayMode.CommaSeparated.toString(), - ImageTagsDisplayMode.HashTags.toString() + ImageTagsDisplayMode.entries.map { it.toString() } ) - tagsDisplayModeSelection.value = ImageTagsDisplayMode.CommaSeparated.toString() + tagsDisplayModeSelection.value = ImageTagsDisplayMode.default().toString() tagsDisplayModeSelection.selectionModel.selectedItemProperty().addListener { _, oldValue, newValue -> if (oldValue != newValue && newValue != null) { 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 155be3c..3061b92 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,20 +4,31 @@ package dev.nuculabs.imagetagger.ui.controls * Determines how tags are displayed */ enum class ImageTagsDisplayMode { - CommaSeparated { - override fun toString(): String { - return "Comma Separated" - } - }, - HashTags; + Comma, + HashTags, + Space; companion object { + /** + * Builds the enum value from a given string. + * + * @param value - The string + * @throws IllegalArgumentException when an invalid value is provided. + */ fun fromString(value: String): ImageTagsDisplayMode { return when (value) { - CommaSeparated.toString() -> CommaSeparated + "Comma" -> Comma + "Space" -> Space "HashTags" -> HashTags else -> throw IllegalArgumentException("Invalid argument $value") } } + + /** + * Returns the default tags display mode. + */ + fun default(): ImageTagsDisplayMode { + return Comma + } } } \ No newline at end of file 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 dc59402..c01ad62 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 @@ -48,7 +48,7 @@ class ImageTagsEntryControl(private val image: AnalyzedImage) : HBox() { /** * Sets the default image tags display mode. */ - private var tagsDisplayMode: ImageTagsDisplayMode = ImageTagsDisplayMode.CommaSeparated + private var tagsDisplayMode: ImageTagsDisplayMode = ImageTagsDisplayMode.Comma /** * The file name label. @@ -152,7 +152,7 @@ class ImageTagsEntryControl(private val image: AnalyzedImage) : HBox() { */ private fun updateTags() { predictedImageTags.text = when (tagsDisplayMode) { - ImageTagsDisplayMode.CommaSeparated -> { + ImageTagsDisplayMode.Comma -> { tags.joinToString { it } } ImageTagsDisplayMode.HashTags -> { @@ -160,6 +160,9 @@ class ImageTagsEntryControl(private val image: AnalyzedImage) : HBox() { "#${it}" } } + ImageTagsDisplayMode.Space -> { + tags.joinToString(separator = " ") { it } + } } }