make ApplicationMenuBar work on Windows

This commit is contained in:
Denis-Cosmin Nutiu 2024-04-13 17:10:08 +03:00
parent 9ffe3d844f
commit 6a710da083
6 changed files with 52 additions and 21 deletions

View file

@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="FrameworkDetectionExcludesConfiguration">

View file

@ -10,6 +10,7 @@ import dev.nuculabs.imagetagger.ai.IImageTagsPrediction
*/
class BasicServiceLocator private constructor() {
internal lateinit var imageTagsPrediction: IImageTagsPrediction
internal lateinit var mainPageController: MainPageController
// Singleton Pattern
companion object {

View file

@ -2,13 +2,11 @@ package dev.nuculabs.imagetagger.ui
import dev.nuculabs.imagetagger.ai.IImageTagsPrediction
import dev.nuculabs.imagetagger.ai.ImageTagsPrediction
import dev.nuculabs.imagetagger.ui.controls.programatic.ApplicationMenuBar
import javafx.application.Application
import javafx.application.Platform
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
@ -39,6 +37,8 @@ class MainPage : Application() {
// Initialize the controller.
val mainPageController = fxmlLoader.getController<MainPageController>()
mainPageController.initialize()
// Set MainPage controller.
serviceLocator.mainPageController = fxmlLoader.getController()
// Set up the stage.
stage.title = "Image Tagger"
@ -51,7 +51,7 @@ class MainPage : Application() {
}
// Add menu bar
(scene.root as BorderPane).children.add(ApplicationMenuBar(mainPageController))
// (scene.root as BorderPane).children.add(ApplicationMenuBar(mainPageController))
stage.show()
}

View file

@ -1,20 +1,42 @@
package dev.nuculabs.imagetagger.ui.controls.programatic
package dev.nuculabs.imagetagger.ui.controls
import dev.nuculabs.imagetagger.ui.BasicServiceLocator
import dev.nuculabs.imagetagger.ui.MainPageController
import dev.nuculabs.imagetagger.ui.pages.AboutPage
import javafx.fxml.FXMLLoader
import javafx.scene.control.Menu
import javafx.scene.control.MenuBar
import javafx.scene.control.MenuItem
import java.io.IOException
/**
* Used as the application menu bar.
*/
class ApplicationMenuBar(private val mainPageController: MainPageController) : MenuBar() {
class ApplicationMenuBar : MenuBar() {
private val fileMenu = Menu("File")
private val aboutMenu = Menu("About")
private val mainPageController: MainPageController by lazy {
BasicServiceLocator.getInstance().mainPageController
}
init {
useSystemMenuBarProperty().set(true)
// Load component
val fxmlLoader = FXMLLoader(
ImageTagsSessionHeader::class.java.getResource("application-menu-bar.fxml")
)
fxmlLoader.setRoot(this)
fxmlLoader.setController(this)
try {
fxmlLoader.load()
} catch (exception: IOException) {
throw RuntimeException(exception)
}
initialize()
}
private fun initialize() {
useSystemMenuBarProperty().set(false)
menus.addAll(fileMenu, aboutMenu)
setupFileMenu()
setupAboutMenu()

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<fx:root type="javafx.scene.control.MenuBar" xmlns:fx="http://javafx.com/fxml">
</fx:root>

View file

@ -5,31 +5,35 @@
<?import javafx.scene.layout.*?>
<?import org.kordamp.ikonli.javafx.FontIcon?>
<?import dev.nuculabs.imagetagger.ui.controls.ApplicationMenuBar?>
<BorderPane prefHeight="537.0" prefWidth="725.0"
xmlns:fx="http://javafx.com/fxml/1"
xmlns="http://javafx.com/javafx/17.0.2-ea"
fx:controller="dev.nuculabs.imagetagger.ui.MainPageController"
stylesheets="@main-window-view.css"
>
<padding>
<Insets bottom="20.0" left="30.0" right="30.0" top="20.0"/>
</padding>
<top>
<HBox alignment="CENTER_LEFT">
<padding>
<Insets bottom="5" left="5" right="5"/>
</padding>
<Button onAction="#onTagImagesButtonClick" text="Tag Images">
<graphic>
<FontIcon iconLiteral="far-images" iconSize="16"/>
</graphic>
</Button>
<Separator orientation="VERTICAL" style="-fx-padding: 10px"/>
</HBox>
<VBox>
<ApplicationMenuBar/>
<HBox alignment="CENTER_LEFT">
<padding>
<Insets bottom="5" left="5" right="5"/>
</padding>
<Button onAction="#onTagImagesButtonClick" text="Tag Images">
<graphic>
<FontIcon iconLiteral="far-images" iconSize="16"/>
</graphic>
</Button>
<Separator orientation="VERTICAL" style="-fx-padding: 10px"/>
</HBox>
</VBox>
</top>
<center>
<ScrollPane fitToWidth="true" fitToHeight="true">
<VBox fx:id="verticalBox">
<padding>
<Insets left="10" right="10"/>
</padding>
</VBox>
</ScrollPane>
</center>