implement ImageTagsSessionHeader feature

This commit is contained in:
Denis-Cosmin NUTIU 2024-04-10 00:17:01 +03:00
parent 13696d3c54
commit 87339f853e
4 changed files with 85 additions and 4 deletions

View file

@ -1,6 +1,7 @@
package dev.nuculabs.imagetagger.ui
import dev.nuculabs.imagetagger.ui.controls.ImageTagsEntryControl
import dev.nuculabs.imagetagger.ui.controls.ImageTagsSessionHeader
import javafx.application.Platform
import javafx.fxml.FXML
import javafx.scene.control.Button
@ -93,6 +94,11 @@ class MainPageController {
// Create a new thread to predict the image tags.
Thread {
logger.info("Analyzing $imageFilesTotal files")
if (filePaths.isNotEmpty()) {
Platform.runLater {
addNewImagePredictionHeader(imageFilesTotal, filePaths.first().parent)
}
}
filePaths.forEach { filePath ->
if (isCurrentTagsOperationCancelled) {
logger.info("Cancelling current prediction operation.")
@ -171,6 +177,16 @@ class MainPageController {
verticalBox.children.add(Separator())
}
/**
* Display the image prediction session header on the UI.
*/
fun addNewImagePredictionHeader(totalImages: Int, directoryPath: String) {
val imageSessionHeader = ImageTagsSessionHeader()
imageSessionHeader.updateHeader(totalImages, directoryPath)
verticalBox.children.add(imageSessionHeader)
verticalBox.children.add(Separator())
}
/**
* Updates the progress bar of the UI.
*/

View file

@ -1,10 +1,37 @@
package dev.nuculabs.imagetagger.ui.controls
import dev.nuculabs.imagetagger.ui.alerts.ErrorAlert
import dev.nuculabs.imagetagger.ui.utils.date.DateTimeProvider
import dev.nuculabs.imagetagger.ui.utils.date.IDateTimeProvider
import javafx.fxml.FXML
import javafx.fxml.FXMLLoader
import javafx.scene.control.Button
import javafx.scene.control.Label
import javafx.scene.layout.HBox
import java.awt.Desktop
import java.io.File
import java.io.IOException
import java.util.logging.Logger
class ImageTagsSessionHeader : HBox() {
private val logger: Logger = Logger.getLogger("ImageTagsSessionHeader")
/**
* Is a provider for providing the date-time data for setting the title's header.
*/
var dateTimeProvider: IDateTimeProvider = DateTimeProvider()
/**
* Is the path that will be opened when the open directory button is clicked.
*/
private var directoryPath: String? = null
@FXML
private lateinit var title: Label
@FXML
private lateinit var openDirectoryButton: Button
init {
val fxmlLoader = FXMLLoader(
ImageTagsSessionHeader::class.java.getResource("image-tags-session-header.fxml")
@ -16,5 +43,44 @@ class ImageTagsSessionHeader : HBox() {
} catch (exception: IOException) {
throw RuntimeException(exception)
}
updateHeader(0)
}
/**
* Updates the header with the number of images and the directory path.
*/
fun updateHeader(numberOfImages: Int, directoryPath: String? = null) {
// set directory path and button visibility
this.directoryPath = directoryPath
if (this.directoryPath == null) {
this.openDirectoryButton.isVisible = false
} else {
this.openDirectoryButton.isVisible = true
}
// update header title
val shortDate = dateTimeProvider.getTodayShortDate()
this.title.text = "$shortDate ($numberOfImages Images)"
}
/**
* Opens the directory in the user's Desktop.
*/
fun openDirectory() {
this.directoryPath?.let {
if (Desktop.isDesktopSupported()) {
val desktop = Desktop.getDesktop()
if (desktop.isSupported(Desktop.Action.OPEN)) {
desktop.open(File(it))
} else {
logger.severe("Cannot open image directory $it. Desktop action not supported!")
ErrorAlert("Can't open file: $it\nOperation is not supported!")
}
} else {
logger.severe("Cannot open image directory $it. Desktop action not supported!")
ErrorAlert("Can't open file: $it\nOperation is not supported!")
}
}
}
}

View file

@ -1,4 +1,4 @@
.sessionTitle {
-fx-font-size: 32;
-fx-font-size: 24;
}

View file

@ -10,9 +10,9 @@
<padding>
<Insets left="10" right="10"/>
</padding>
<Label text="9 Apr. 2024" styleClass="sessionTitle"/>
<Label fx:id="title" text="9 Apr. 2024" styleClass="sessionTitle"/>
<Pane HBox.hgrow="ALWAYS"/>
<Button text="Open Directory">
<Button fx:id="openDirectoryButton" onAction="#openDirectory" text="Open Directory">
<tooltip>
<Tooltip text="Open directory of the images"/>
</tooltip>
@ -20,5 +20,4 @@
<FontIcon iconLiteral="far-folder-open" iconSize="16"/>
</graphic>
</Button>
<Separator/>
</fx:root>