Skip to content

Commit

Permalink
#149: adds build information to about screen
Browse files Browse the repository at this point in the history
  • Loading branch information
rladstaetter committed Sep 3, 2023
1 parent 5d50957 commit a0ba8ed
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 20 deletions.
4 changes: 4 additions & 0 deletions app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
Expand Down
18 changes: 1 addition & 17 deletions app/src/main/scala/app/logorrr/util/CpResource.scala
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
package app.logorrr.util

import java.io.InputStream

abstract class CpResource(value: String) {

/**
* returns a inputstream handle to this classpath address
*
* @param clazz class whose classloader is used to load the resource
* @return
*/
def inputStream(clazz: Class[_]): InputStream = {
val r = clazz.getResourceAsStream(value)
require(Option(r).isDefined, s"'$value' does not exist.")
r
}

}
abstract class CpResource(value: String)
18 changes: 18 additions & 0 deletions app/src/main/scala/app/logorrr/util/ImageCp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@ package app.logorrr.util

import javafx.scene.image.{Image, ImageView}

import java.util.Properties


case class PropsCp(classPathResource : String) extends CpResource(classPathResource) {

def asProperties(clazz: Class[_]): Properties = {
val properties = new Properties()
val is = clazz.getResourceAsStream(classPathResource)
try {
properties.load(is)
} finally {
Option(is).foreach(_.close)
}
properties
}

}

case class ImageCp(value: String, width: Int, height: Int) extends CpResource(value) {
def imageView(): ImageView =
new ImageView(new Image(value, width, height, true, true, true))
Expand Down
31 changes: 29 additions & 2 deletions app/src/main/scala/app/logorrr/views/about/AboutScreen.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package app.logorrr.views.about

import app.logorrr.meta.AppMeta
import app.logorrr.util.{HLink, ImageCp, LogoRRRFonts}
import app.logorrr.util.{HLink, ImageCp, LogoRRRFonts, PropsCp}
import javafx.geometry.{Insets, Pos}
import javafx.scene.control._
import javafx.scene.image.ImageView
import javafx.scene.layout.{BorderPane, VBox}
import javafx.scene.layout.{BorderPane, HBox, VBox}

import java.time.format.DateTimeFormatter
import java.time.{Instant, ZoneId}


object AboutScreen {
Expand Down Expand Up @@ -34,6 +37,26 @@ object AboutScreen {
}


object BuildProps {

lazy val Instance = new BuildProps
}

class BuildProps {
lazy val buildProps = PropsCp("/build.properties").asProperties(getClass)

lazy val githash = buildProps.getProperty("revision")

lazy val timestamp: String = {
val PATTERN_FORMAT = "dd.MM.yyyy"
val formatter = DateTimeFormatter.ofPattern(PATTERN_FORMAT)
.withZone(ZoneId.systemDefault());
val i = Instant.ofEpochMilli(buildProps.getProperty("timestamp").toLong)
formatter.format(i)
}

}

class AboutScreen extends BorderPane {

private def mkLogo(): ImageView = AboutScreen.logo.imageView()
Expand All @@ -44,5 +67,9 @@ class AboutScreen extends BorderPane {
setTop(mkHeader())
setLeft(mkLogo())
setRight(new AboutScreen.HLinkView(AboutScreen.links))
val hBox = new HBox()
hBox.setAlignment(Pos.CENTER_LEFT)
hBox.getChildren.add(new Label(BuildProps.Instance.timestamp + " " + BuildProps.Instance.githash))
setBottom(hBox)

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object HelpMenu {
val stage = new Stage()
stage.initModality(Modality.APPLICATION_MODAL)
stage.setTitle(s"About ${AppMeta.fullAppNameWithVersion}")
val scene = new Scene(new AboutScreen, 440, 210)
val scene = new Scene(new AboutScreen, 440, 250)
stage.setScene(scene)
stage.setOnCloseRequest(_ => stage.close())
stage.showAndWait()
Expand Down
1 change: 1 addition & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
</dependencies>
<build>
<plugins>

<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
Expand Down
22 changes: 22 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
<jdk.jpackage.binary>${jdk.home}/bin/jpackage</jdk.jpackage.binary>
</properties>

<scm>
<connection>scm:git:https://github.com/rladstaetter/LogoRRR.git</connection>
<developerConnection>scm:git:https://github.com/rladstaetter/LogoRRR.git</developerConnection>
<tag>HEAD</tag>
</scm>

<profiles>
<profile>
<id>OS.windows</id>
Expand Down Expand Up @@ -234,6 +240,22 @@
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>create-metadata</goal>
</goals>
<configuration>
<addOutputDirectoryToResources>true</addOutputDirectoryToResources>
</configuration>
</execution>
</executions>
</plugin>
<!-- to make intellij idea happy -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down

0 comments on commit a0ba8ed

Please sign in to comment.