diff --git a/src/main/kotlin/com/nuculabs/dev/imagetagger/ui/MainPageController.kt b/src/main/kotlin/com/nuculabs/dev/imagetagger/ui/MainPageController.kt index 2be521e..14c14ee 100644 --- a/src/main/kotlin/com/nuculabs/dev/imagetagger/ui/MainPageController.kt +++ b/src/main/kotlin/com/nuculabs/dev/imagetagger/ui/MainPageController.kt @@ -5,22 +5,25 @@ import com.nuculabs.dev.imagetagger.ui.controls.ImageTagsEntryControl import javafx.application.Platform import javafx.fxml.FXML import javafx.scene.control.Label +import javafx.scene.control.ProgressBar import javafx.scene.control.Separator import javafx.scene.layout.VBox import javafx.stage.FileChooser import java.io.File import java.util.logging.Logger import javax.imageio.ImageIO +import kotlin.math.log class MainPageController { + private val logger: Logger = Logger.getLogger("MainPageController") @FXML - private lateinit var verticalBox: VBox + private lateinit var progressBar: ProgressBar @FXML - private lateinit var statusLabel: Label + private lateinit var verticalBox: VBox /** * Prompts the user to select files then predicts tags for the selected image files. @@ -33,12 +36,15 @@ class MainPageController { fileChooser.title = "Choose images" val filePaths = fileChooser.showOpenMultipleDialog(null) ?: return - statusLabel.isVisible = true + progressBar.isVisible = true + progressBar.progress = 0.0; // Create a new thread to predict the images. val thread = Thread { - try { - for (filePath in filePaths) { + val filePathsTotal = filePaths.count() + logger.info("Analyzing $filePathsTotal files") + filePaths.forEachIndexed { index, filePath -> + try { // Get predictions for the image. val imageFile = ImageIO.read(File(filePath.absolutePath)) val tags: List = imageTagsPrediction.predictTags(imageFile) @@ -46,13 +52,15 @@ class MainPageController { // Add image and prediction to the view. verticalBox.children.add(ImageTagsEntryControl(filePath.absolutePath, tags)) verticalBox.children.add(Separator()) + progressBar.progress = (((index + 1) * 100) / filePathsTotal).toDouble() / 100.0 + logger.info("Progress ${progressBar.progress}") } + } catch (e: Exception) { + logger.warning("Error while predicting images $e") } - Platform.runLater { - statusLabel.isVisible = false - } - } catch (e: Exception) { - logger.warning("Error while predicting images $e") + } + Platform.runLater { + progressBar.isVisible = false } } thread.start() diff --git a/src/main/resources/com/nuculabs/dev/imagetagger/ui/main-window-view.fxml b/src/main/resources/com/nuculabs/dev/imagetagger/ui/main-window-view.fxml index 39a2c8e..e96ddcb 100644 --- a/src/main/resources/com/nuculabs/dev/imagetagger/ui/main-window-view.fxml +++ b/src/main/resources/com/nuculabs/dev/imagetagger/ui/main-window-view.fxml @@ -25,6 +25,6 @@ - \ No newline at end of file