implement tag display mode

This commit is contained in:
Denis-Cosmin Nutiu 2024-11-16 19:57:54 +02:00
parent 87737a5261
commit af578f09f4
4 changed files with 56 additions and 4 deletions

View file

@ -1 +0,0 @@
ImageTagger-Solution

View file

@ -1,6 +1,7 @@
package dev.nuculabs.imagetagger.ui
import dev.nuculabs.imagetagger.core.AnalyzedImage
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
@ -58,6 +59,8 @@ class MainPageController {
*/
private var isCurrentTagsOperationCancelled: Boolean = false
private var predictedImages: MutableList<ImageTagsEntryControl> = ArrayList()
@FXML
private lateinit var progressBar: ProgressBar
@ -148,7 +151,11 @@ class MainPageController {
fun addNewImagePredictionEntry(
analyzedImage: AnalyzedImage,
) {
verticalBox.children.add(ImageTagsEntryControl(analyzedImage))
val control = ImageTagsEntryControl(analyzedImage)
// TODO add default tag mode
control.setTagsDisplayMode(ImageTagsDisplayMode.CommaSeparated)
verticalBox.children.add(control)
predictedImages.add(control)
verticalBox.children.add(Separator())
}

View file

@ -0,0 +1,9 @@
package dev.nuculabs.imagetagger.ui.controls
/**
* Determines how tags are displayed
*/
enum class ImageTagsDisplayMode {
CommaSeparated,
HashTags
}

View file

@ -40,6 +40,16 @@ class ImageTagsEntryControl(private val image: AnalyzedImage) : HBox() {
@FXML
private lateinit var predictedImageTags: TextArea
/**
* Holds the tags.
*/
private var tags: List<String> = ArrayList();
/**
* Sets the default image tags display mode.
*/
private var tagsDisplayMode: ImageTagsDisplayMode = ImageTagsDisplayMode.CommaSeparated
/**
* The file name label.
*/
@ -122,8 +132,35 @@ class ImageTagsEntryControl(private val image: AnalyzedImage) : HBox() {
*
* @param predictions The prediction list.
*/
private fun setTags(predictions: List<String>) {
predictedImageTags.text = predictions.joinToString { it }
fun setTags(predictions: List<String>) {
tags = predictions
updateTags()
}
/**
* Sets the tags display mode.
*
* @param mode The image tags display mode.
*/
fun setTagsDisplayMode(mode: ImageTagsDisplayMode) {
tagsDisplayMode = mode
updateTags()
}
/**
* Updates the tags text.
*/
private fun updateTags() {
predictedImageTags.text = when (tagsDisplayMode) {
ImageTagsDisplayMode.CommaSeparated -> {
tags.joinToString { it }
}
ImageTagsDisplayMode.HashTags -> {
tags.joinToString(separator = " ") {
"#${it}"
}
}
}
}
/**