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 08902c1..502d86d 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
@@ -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.
*/
diff --git a/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/controls/ImageTagsSessionHeader.kt b/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/controls/ImageTagsSessionHeader.kt
index 6da8dff..feb8603 100644
--- a/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/controls/ImageTagsSessionHeader.kt
+++ b/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/controls/ImageTagsSessionHeader.kt
@@ -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!")
+ }
+ }
}
}
\ No newline at end of file
diff --git a/img-ui/src/main/resources/dev/nuculabs/imagetagger/ui/controls/image-tags-session-header.css b/img-ui/src/main/resources/dev/nuculabs/imagetagger/ui/controls/image-tags-session-header.css
index e3234fa..161176f 100644
--- a/img-ui/src/main/resources/dev/nuculabs/imagetagger/ui/controls/image-tags-session-header.css
+++ b/img-ui/src/main/resources/dev/nuculabs/imagetagger/ui/controls/image-tags-session-header.css
@@ -1,4 +1,4 @@
.sessionTitle {
- -fx-font-size: 32;
+ -fx-font-size: 24;
}
\ No newline at end of file
diff --git a/img-ui/src/main/resources/dev/nuculabs/imagetagger/ui/controls/image-tags-session-header.fxml b/img-ui/src/main/resources/dev/nuculabs/imagetagger/ui/controls/image-tags-session-header.fxml
index 96541e2..bc5ecfd 100644
--- a/img-ui/src/main/resources/dev/nuculabs/imagetagger/ui/controls/image-tags-session-header.fxml
+++ b/img-ui/src/main/resources/dev/nuculabs/imagetagger/ui/controls/image-tags-session-header.fxml
@@ -10,9 +10,9 @@
-
+
-