diff --git a/EpcQrCode/build.gradle.kts b/EpcQrCode/build.gradle.kts index 24e8475..1dd0425 100644 --- a/EpcQrCode/build.gradle.kts +++ b/EpcQrCode/build.gradle.kts @@ -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")) diff --git a/EpcQrCode/src/jvmMain/kotlin/net/codinux/banking/epcqrcode/QrCodeGenerator.kt b/EpcQrCode/src/jvmMain/kotlin/net/codinux/banking/epcqrcode/QrCodeGenerator.kt new file mode 100644 index 0000000..f97c02c --- /dev/null +++ b/EpcQrCode/src/jvmMain/kotlin/net/codinux/banking/epcqrcode/QrCodeGenerator.kt @@ -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() + + 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() + } + +} \ No newline at end of file diff --git a/EpcQrCodeJavaFxApp/build.gradle.kts b/EpcQrCodeJavaFxApp/build.gradle.kts index 54c52c3..b65d86b 100644 --- a/EpcQrCodeJavaFxApp/build.gradle.kts +++ b/EpcQrCodeJavaFxApp/build.gradle.kts @@ -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() { @@ -17,5 +27,34 @@ tasks.withType() { } application { - mainClassName = "MainKt" + mainClassName = mainClassName +} + + + +tasks.withType { + 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) } + }) } \ No newline at end of file diff --git a/EpcQrCodeJavaFxApp/src/main/kotlin/main.kt b/EpcQrCodeJavaFxApp/src/main/kotlin/main.kt deleted file mode 100644 index aade54c..0000000 --- a/EpcQrCodeJavaFxApp/src/main/kotlin/main.kt +++ /dev/null @@ -1,3 +0,0 @@ -fun main(args: Array) { - println("Hello World!") -} \ No newline at end of file diff --git a/EpcQrCodeJavaFxApp/src/main/kotlin/net/codinux/banking/epcqrcode/EpcQrCodeJavaFxApp.kt b/EpcQrCodeJavaFxApp/src/main/kotlin/net/codinux/banking/epcqrcode/EpcQrCodeJavaFxApp.kt new file mode 100644 index 0000000..63a75a4 --- /dev/null +++ b/EpcQrCodeJavaFxApp/src/main/kotlin/net/codinux/banking/epcqrcode/EpcQrCodeJavaFxApp.kt @@ -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) { + Application.launch(EpcQrCodeJavaFxApp::class.java, *args) +} \ No newline at end of file diff --git a/EpcQrCodeJavaFxApp/src/main/kotlin/net/codinux/banking/epcqrcode/windows/main/MainWindow.kt b/EpcQrCodeJavaFxApp/src/main/kotlin/net/codinux/banking/epcqrcode/windows/main/MainWindow.kt new file mode 100644 index 0000000..f7369c2 --- /dev/null +++ b/EpcQrCodeJavaFxApp/src/main/kotlin/net/codinux/banking/epcqrcode/windows/main/MainWindow.kt @@ -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(generateQrCode(MppTest().getTestEpcQrCodeContent())) + + + override val root = vbox { + imageview(qrCode) + } + + + private fun generateQrCode(informationToEncode: String): Image? { + val qrCodeBytes = qrCodeGenerator.generateQrCode(informationToEncode) + + return Image(ByteArrayInputStream(qrCodeBytes)) + } + +} \ No newline at end of file diff --git a/EpcQrCodeJavaFxApp/src/main/resources/Messages.properties b/EpcQrCodeJavaFxApp/src/main/resources/Messages.properties new file mode 100755 index 0000000..057c0e9 --- /dev/null +++ b/EpcQrCodeJavaFxApp/src/main/resources/Messages.properties @@ -0,0 +1,9 @@ +application.title=EPC QR Code + + +ok=OK +cancel=Cancel + + +main.window.menu.file=File +main.window.menu.file.quit=Quit \ No newline at end of file diff --git a/EpcQrCodeJavaFxApp/src/main/resources/Messages_de.properties b/EpcQrCodeJavaFxApp/src/main/resources/Messages_de.properties new file mode 100755 index 0000000..90377ab --- /dev/null +++ b/EpcQrCodeJavaFxApp/src/main/resources/Messages_de.properties @@ -0,0 +1,9 @@ +application.title=EPC QR Code + + +ok=OK +cancel=Abbrechen + + +main.window.menu.file=Datei +main.window.menu.file.quit=Beenden \ No newline at end of file