From 14d7f910b58abaa71c01be57cee39f3e8410db1a Mon Sep 17 00:00:00 2001 From: TodorovicSrdjan Date: Sun, 18 Sep 2022 20:18:13 +0200 Subject: [PATCH] chore: include resources in jar Loads images as project resources instead of loading them as files. This makes it possible to include them in jar file. Doing so will solve problem with absent images (previously they weren't found in the runtime) --- .../main/resources}/images/alt-logo.png | Bin {resources => src/main/resources}/images/arrows.png | Bin {resources => src/main/resources}/images/logo.png | Bin src/main/scala/gui/Gui.scala | 8 ++++---- 4 files changed, 4 insertions(+), 4 deletions(-) rename {resources => src/main/resources}/images/alt-logo.png (100%) rename {resources => src/main/resources}/images/arrows.png (100%) rename {resources => src/main/resources}/images/logo.png (100%) diff --git a/resources/images/alt-logo.png b/src/main/resources/images/alt-logo.png similarity index 100% rename from resources/images/alt-logo.png rename to src/main/resources/images/alt-logo.png diff --git a/resources/images/arrows.png b/src/main/resources/images/arrows.png similarity index 100% rename from resources/images/arrows.png rename to src/main/resources/images/arrows.png diff --git a/resources/images/logo.png b/src/main/resources/images/logo.png similarity index 100% rename from resources/images/logo.png rename to src/main/resources/images/logo.png diff --git a/src/main/scala/gui/Gui.scala b/src/main/scala/gui/Gui.scala index b88fd38..71215e6 100644 --- a/src/main/scala/gui/Gui.scala +++ b/src/main/scala/gui/Gui.scala @@ -61,8 +61,8 @@ class Gui(app: JFXApp3, engine: Engine, appName: String, numOfBlocks: Int = 4) { private val LabelGridGap = 25 private val LabelMaxChars = 6 private val ChoiceGroupsOpacity = 0.35 - private val ArrowsImagePath = "resources/images/arrows.png" - private val LogoImagePath = "resources/images/logo.png" + private val ArrowsImagePath = "/images/arrows.png" + private val LogoImagePath = "/images/logo.png" private var BlockList: IndexedSeq[Node] = null private var MainButton: Circle = null @@ -82,7 +82,7 @@ class Gui(app: JFXApp3, engine: Engine, appName: String, numOfBlocks: Int = 4) { alwaysOnTop = true } app.stage.centerOnScreen() - app.stage.icons += new Image(new File(LogoImagePath).toURI.toString) + app.stage.icons += new Image(classOf[Gui].getResourceAsStream(LogoImagePath)) //new Image(new File(LogoImagePath).toURI.toString) } private def createScene(): Scene = { @@ -143,7 +143,7 @@ class Gui(app: JFXApp3, engine: Engine, appName: String, numOfBlocks: Int = 4) { selectedChoicesGrid.setMouseTransparent(true) // Create layer for direction indicators - ArrowsImage = Option(new ImageView(new Image(new File(ArrowsImagePath).toURI.toString))) + ArrowsImage = Option(new ImageView(new Image(classOf[Gui].getResourceAsStream(ArrowsImagePath)))) ArrowsImage.get.setMouseTransparent(true) ArrowsImage.get.visible = false