From 525a25769b0ac4866cf98706290379afbb2c5493 Mon Sep 17 00:00:00 2001 From: Denis-Cosmin NUTIU Date: Sun, 7 Apr 2024 17:40:45 +0300 Subject: [PATCH] make about dialog a page --- img-ui/src/main/java/module-info.java | 1 + .../dev/nuculabs/imagetagger/ui/MainPage.kt | 5 ++ .../imagetagger/ui/alerts/AboutAlert.kt | 22 --------- .../programatic/ApplicationMenuBar.kt | 4 +- .../imagetagger/ui/pages/AboutPage.kt | 35 ++++++++++++++ .../imagetagger/ui/pages/about-page.css | 4 ++ .../imagetagger/ui/pages/about-page.fxml | 47 +++++++++++++++++++ 7 files changed, 94 insertions(+), 24 deletions(-) delete mode 100644 img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/alerts/AboutAlert.kt create mode 100644 img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/pages/AboutPage.kt create mode 100644 img-ui/src/main/resources/dev/nuculabs/imagetagger/ui/pages/about-page.css create mode 100644 img-ui/src/main/resources/dev/nuculabs/imagetagger/ui/pages/about-page.fxml diff --git a/img-ui/src/main/java/module-info.java b/img-ui/src/main/java/module-info.java index 7f07c0b..0dd6bab 100644 --- a/img-ui/src/main/java/module-info.java +++ b/img-ui/src/main/java/module-info.java @@ -17,5 +17,6 @@ module dev.nuculabs.imagetagger.ui { opens dev.nuculabs.imagetagger.ui to javafx.fxml, javafx.graphics; opens dev.nuculabs.imagetagger.ui.controls to javafx.fxml, javafx.graphics; + opens dev.nuculabs.imagetagger.ui.pages to javafx.fxml, javafx.graphics; exports dev.nuculabs.imagetagger.ui; } \ No newline at end of file diff --git a/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/MainPage.kt b/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/MainPage.kt index ea23b55..fcb77c8 100644 --- a/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/MainPage.kt +++ b/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/MainPage.kt @@ -3,6 +3,7 @@ package dev.nuculabs.imagetagger.ui 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 @@ -40,6 +41,10 @@ class MainPage : Application() { stage.scene = scene stage.minWidth = 640.0 stage.minHeight = 760.0 + // Whe the main window is hidden we exit the application. + stage.setOnHidden { + Platform.exit() + } // Add menu bar (scene.root as BorderPane).children.add(ApplicationMenuBar(mainPageController)) diff --git a/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/alerts/AboutAlert.kt b/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/alerts/AboutAlert.kt deleted file mode 100644 index 3a6594a..0000000 --- a/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/alerts/AboutAlert.kt +++ /dev/null @@ -1,22 +0,0 @@ -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. - * // TODO: Move this into a panel to make links clickable. - */ -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() - } -} \ No newline at end of file diff --git a/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/controls/programatic/ApplicationMenuBar.kt b/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/controls/programatic/ApplicationMenuBar.kt index d145e71..1f34571 100644 --- a/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/controls/programatic/ApplicationMenuBar.kt +++ b/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/controls/programatic/ApplicationMenuBar.kt @@ -1,7 +1,7 @@ package dev.nuculabs.imagetagger.ui.controls.programatic import dev.nuculabs.imagetagger.ui.MainPageController -import dev.nuculabs.imagetagger.ui.alerts.AboutAlert +import dev.nuculabs.imagetagger.ui.pages.AboutPage import javafx.scene.control.Menu import javafx.scene.control.MenuBar import javafx.scene.control.MenuItem @@ -23,7 +23,7 @@ class ApplicationMenuBar(private val mainPageController: MainPageController) : M private fun setupAboutMenu() { val aboutMenuItem = MenuItem("About") aboutMenuItem.setOnAction { - AboutAlert() + AboutPage.show() } aboutMenu.items.add(aboutMenuItem) } diff --git a/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/pages/AboutPage.kt b/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/pages/AboutPage.kt new file mode 100644 index 0000000..56789ed --- /dev/null +++ b/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/pages/AboutPage.kt @@ -0,0 +1,35 @@ +package dev.nuculabs.imagetagger.ui.pages + +import javafx.fxml.FXML +import javafx.fxml.FXMLLoader +import javafx.scene.Parent +import javafx.scene.Scene +import javafx.stage.Stage +import java.awt.Desktop +import java.net.URL + + +class AboutPage { + + @FXML + fun openBlog() { + Desktop.getDesktop().browse(URL("https://blog.nuculabs.dev").toURI()); + } + + @FXML + fun openGithub() { + Desktop.getDesktop().browse(URL("https://github.com/dnutiu/ImageTagger").toURI()); + } + + companion object { + fun show() { + val fxmlLoader = FXMLLoader(AboutPage::class.java.getResource("about-page.fxml")) + val root = fxmlLoader.load() as Parent + val newStage = Stage() + newStage.title = "About ImageTagger" + newStage.scene = Scene(root) + newStage.isResizable = false + newStage.show() + } + } +} \ No newline at end of file diff --git a/img-ui/src/main/resources/dev/nuculabs/imagetagger/ui/pages/about-page.css b/img-ui/src/main/resources/dev/nuculabs/imagetagger/ui/pages/about-page.css new file mode 100644 index 0000000..4f95d10 --- /dev/null +++ b/img-ui/src/main/resources/dev/nuculabs/imagetagger/ui/pages/about-page.css @@ -0,0 +1,4 @@ +.hyperlink { + -fx-underline: false; + -fx-border-color: transparent; +} \ No newline at end of file diff --git a/img-ui/src/main/resources/dev/nuculabs/imagetagger/ui/pages/about-page.fxml b/img-ui/src/main/resources/dev/nuculabs/imagetagger/ui/pages/about-page.fxml new file mode 100644 index 0000000..b619e5a --- /dev/null +++ b/img-ui/src/main/resources/dev/nuculabs/imagetagger/ui/pages/about-page.fxml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +