add application menu bar

This commit is contained in:
Denis-Cosmin NUTIU 2024-04-06 17:20:19 +03:00
parent 30bee0db25
commit cbd104ae9d
4 changed files with 67 additions and 1 deletions

View file

@ -1,10 +1,12 @@
package dev.nuculabs.imagetagger.ui
import dev.nuculabs.imagetagger.ai.ImageTagsPrediction
import dev.nuculabs.imagetagger.ui.controls.ApplicationMenuBar
import javafx.application.Application
import javafx.fxml.FXMLLoader
import javafx.scene.Scene
import javafx.scene.image.Image
import javafx.scene.layout.BorderPane
import javafx.stage.Stage
import java.awt.Taskbar
import java.awt.Toolkit
@ -30,7 +32,8 @@ class MainPage : Application() {
val scene = Scene(fxmlLoader.load(), 640.0, 760.0)
// Initialize the controller.
fxmlLoader.getController<MainPageController>().initialize()
val mainPageController = fxmlLoader.getController<MainPageController>()
mainPageController.initialize()
// Set up the stage.
stage.title = "Image Tagger"
@ -38,6 +41,9 @@ class MainPage : Application() {
stage.minWidth = 640.0
stage.minHeight = 760.0
// Add menu bar
(scene.root as BorderPane).children.add(ApplicationMenuBar(mainPageController))
stage.show()
}

View file

@ -75,6 +75,7 @@ class MainPageController {
HBox.setHgrow(progressBar, Priority.ALWAYS)
HBox.setHgrow(cancelButton, Priority.ALWAYS)
}
/**
* Prompts the user to select files then predicts tags for the selected image files.
*/

View file

@ -0,0 +1,21 @@
package dev.nuculabs.imagetagger.ui.alerts
import javafx.scene.control.Alert
import javafx.scene.layout.Region
/**
* Represents the alert shown when the user clicks on About.
*/
class AboutAlert : Alert(AlertType.INFORMATION) {
init {
title = "About ImageTagger"
headerText = ""
contentText = "Image Tagger is an application that predicts an image's tags using deep-learning. " +
"It is useful for photographers who want to improve their workflow by auto-tagging images.\n\n" +
"Author: Denis-Cosmin Nutiu\n\n" +
"Website: blog.nuculabs.dev\n" +
"Github: https://github.com/dnutiu/ImageTagger"
dialogPane.minHeight = Region.USE_PREF_SIZE
show()
}
}

View file

@ -0,0 +1,38 @@
package dev.nuculabs.imagetagger.ui.controls
import dev.nuculabs.imagetagger.ui.MainPageController
import dev.nuculabs.imagetagger.ui.alerts.AboutAlert
import javafx.scene.control.Menu
import javafx.scene.control.MenuBar
import javafx.scene.control.MenuItem
/**
* Used as the application menu bar.
*/
class ApplicationMenuBar(private val mainPageController: MainPageController) : MenuBar() {
private val fileMenu = Menu("File")
private val aboutMenu = Menu("About")
init {
useSystemMenuBarProperty().set(true)
menus.addAll(fileMenu, aboutMenu)
setupFileMenu()
setupAboutMenu()
}
private fun setupAboutMenu() {
val aboutMenuItem = MenuItem("About")
aboutMenuItem.setOnAction {
AboutAlert()
}
aboutMenu.items.add(aboutMenuItem)
}
private fun setupFileMenu() {
val tagImagesMenuItem = MenuItem("Tag Images")
tagImagesMenuItem.setOnAction {
mainPageController.onTagImagesButtonClick()
}
fileMenu.items.add(tagImagesMenuItem)
}
}