Implemented JavaFx app, but could not test if it works

This commit is contained in:
dankito 2020-11-12 22:59:33 +01:00
parent 807228f869
commit f88070181d
8 changed files with 135 additions and 6 deletions

View File

@ -58,7 +58,11 @@ kotlin {
}
}
val jvmMain by getting
val jvmMain by getting {
dependencies {
implementation("com.google.zxing:javase:3.4.1")
}
}
val jvmTest by getting {
dependencies {
implementation(kotlin("test-junit"))

View File

@ -0,0 +1,26 @@
package net.codinux.banking.epcqrcode
import com.google.zxing.BarcodeFormat
import com.google.zxing.EncodeHintType
import com.google.zxing.client.j2se.MatrixToImageWriter
import com.google.zxing.qrcode.QRCodeWriter
import java.io.ByteArrayOutputStream
class QrCodeGenerator {
fun generateQrCode(informationToEncode: String, config: EncodeToQrCodeConfig = EncodeToQrCodeConfig()): ByteArray {
val hints = mutableMapOf<EncodeHintType, Any>()
hints[EncodeHintType.CHARACTER_SET] = config.encoding.name
val bitMatrix = QRCodeWriter().encode(informationToEncode, BarcodeFormat.QR_CODE, config.width, config.height, hints)
val outputStream = ByteArrayOutputStream()
MatrixToImageWriter.writeToStream(bitMatrix, config.format.name, outputStream)
outputStream.flush()
return outputStream.toByteArray()
}
}

View File

@ -7,9 +7,19 @@ plugins {
group = "net.codinux.banking.epcqrcode.javafx"
val mainClassName = "net.codinux.banking.epcqrcode.EpcQrCodeJavaFxAppKt"
dependencies {
testImplementation(kotlin("test-junit"))
implementation(project(":EpcQrCode"))
implementation("net.dankito.utils:java-fx-utils:1.0.8")
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
tasks.withType<KotlinCompile>() {
@ -17,5 +27,34 @@ tasks.withType<KotlinCompile>() {
}
application {
mainClassName = "MainKt"
mainClassName = mainClassName
}
tasks.withType<Jar> {
isZip64 = true
// If one of the source JARs is signed, merging it into one fat jar destroys the signature -> remove signatures
// (but may runs into problems with jars that require a valid signature like BouncyCastle, see
// https://stackoverflow.com/questions/51455197/gradle-fatjar-could-not-find-or-load-main-class)
exclude("META-INF/*.RSA", "META-INF/*.SF", "META-INF/*.DSA")
manifest {
attributes(mapOf(
"Main-Class" to mainClassName,
"Implementation-Title" to "EPC QR Code",
"Implementation-Version" to "1.0.0-SNAPSHOT"
))
}
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
// To add all of the dependencies
from(sourceSets.main.get().output)
dependsOn(configurations.runtimeClasspath)
from({
configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) }
})
}

View File

@ -1,3 +0,0 @@
fun main(args: Array<String>) {
println("Hello World!")
}

View File

@ -0,0 +1,16 @@
package net.codinux.banking.epcqrcode
import javafx.application.Application
import net.codinux.banking.epcqrcode.windows.main.MainWindow
import net.dankito.utils.javafx.ui.Utf8App
class EpcQrCodeJavaFxApp : Utf8App("Messages", MainWindow::class) {
}
fun main(args: Array<String>) {
Application.launch(EpcQrCodeJavaFxApp::class.java, *args)
}

View File

@ -0,0 +1,29 @@
package net.codinux.banking.epcqrcode.windows.main
import javafx.beans.property.SimpleObjectProperty
import javafx.scene.image.Image
import tornadofx.*
import java.io.ByteArrayInputStream
import net.codinux.banking.epcqrcode.MppTest
import net.codinux.banking.epcqrcode.QrCodeGenerator
class MainWindow : View(FX.messages["application.title"]) {
private val qrCodeGenerator = QrCodeGenerator()
private val qrCode = SimpleObjectProperty<Image>(generateQrCode(MppTest().getTestEpcQrCodeContent()))
override val root = vbox {
imageview(qrCode)
}
private fun generateQrCode(informationToEncode: String): Image? {
val qrCodeBytes = qrCodeGenerator.generateQrCode(informationToEncode)
return Image(ByteArrayInputStream(qrCodeBytes))
}
}

View File

@ -0,0 +1,9 @@
application.title=EPC QR Code
ok=OK
cancel=Cancel
main.window.menu.file=File
main.window.menu.file.quit=Quit

View File

@ -0,0 +1,9 @@
application.title=EPC QR Code
ok=OK
cancel=Abbrechen
main.window.menu.file=Datei
main.window.menu.file.quit=Beenden