From d31b70ebc3d19063a5621b880026940792cb7d15 Mon Sep 17 00:00:00 2001 From: yostane <1958676+yostane@users.noreply.github.com> Date: Thu, 21 Nov 2024 13:18:54 +0100 Subject: [PATCH 1/6] Add JavaFX demo applications and .gitignore files for jbang and kts --- material/scripting/jbang/.gitignore | 1 + material/scripting/jbang/jfxdemo.kt | 44 +++++++++++++++++++ material/scripting/kts/.gitignore | 1 + .../scripting/kts/compiler-options.main.kts | 18 ++++++++ material/scripting/kts/jfxdemo.main.kts | 40 +++++++++++++++++ 5 files changed, 104 insertions(+) create mode 100644 material/scripting/jbang/.gitignore create mode 100644 material/scripting/jbang/jfxdemo.kt create mode 100644 material/scripting/kts/.gitignore create mode 100644 material/scripting/kts/compiler-options.main.kts create mode 100644 material/scripting/kts/jfxdemo.main.kts diff --git a/material/scripting/jbang/.gitignore b/material/scripting/jbang/.gitignore new file mode 100644 index 0000000..62c8935 --- /dev/null +++ b/material/scripting/jbang/.gitignore @@ -0,0 +1 @@ +.idea/ \ No newline at end of file diff --git a/material/scripting/jbang/jfxdemo.kt b/material/scripting/jbang/jfxdemo.kt new file mode 100644 index 0000000..cf8c481 --- /dev/null +++ b/material/scripting/jbang/jfxdemo.kt @@ -0,0 +1,44 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? + +//DEPS org.openjfx:javafx-controls:23 +//DEPS org.openjfx:javafx-graphics:23:${os.detected.jfxname} +//DEPS org.openjfx:javafx-fxml:23 + +import javafx.application.Application +import javafx.geometry.Pos +import javafx.scene.Scene +import javafx.scene.control.Label +import javafx.scene.layout.VBox +import javafx.stage.Stage + +class HelloJFXApp : Application() { + private var scene: Scene? = null + + override fun start(stage: Stage) { + val javaInfoString = String.format( + "Java: %s, %s , %s", + System.getProperty("java.version"), + System.getProperty("java.vendor"), + System.getProperty("java.vm.version") + ) + val jfxInfoString = String.format("JavaFX: %s", System.getProperty("javafx.version")) + + val holder = VBox() + holder.isFillWidth = true + holder.alignment = Pos.TOP_CENTER + holder.spacing = 5.0 + holder.children.addAll( + Label(javaInfoString), + Label(jfxInfoString), + ) + + scene = Scene(holder, 400.0, 300.0) + stage.title = "JavaFX Demo" + stage.scene = scene + stage.show() + } +} + +fun main() { + Application.launch(HelloJFXApp::class.java) +} \ No newline at end of file diff --git a/material/scripting/kts/.gitignore b/material/scripting/kts/.gitignore new file mode 100644 index 0000000..62c8935 --- /dev/null +++ b/material/scripting/kts/.gitignore @@ -0,0 +1 @@ +.idea/ \ No newline at end of file diff --git a/material/scripting/kts/compiler-options.main.kts b/material/scripting/kts/compiler-options.main.kts new file mode 100644 index 0000000..feb19ec --- /dev/null +++ b/material/scripting/kts/compiler-options.main.kts @@ -0,0 +1,18 @@ +@file:CompilerOptions("-jvm-target", "1.8", "-Xabi-stability=unstable") + +interface Test { + fun print() + fun printSuper() = println("Hi from super") +} + +class TestImpl : Test { + override fun print() = println("Hi from sub") +} + +fun printRandom() = println("Hi from random") + +TestImpl().run { + print() + printSuper() + printRandom() +} \ No newline at end of file diff --git a/material/scripting/kts/jfxdemo.main.kts b/material/scripting/kts/jfxdemo.main.kts new file mode 100644 index 0000000..a0ba082 --- /dev/null +++ b/material/scripting/kts/jfxdemo.main.kts @@ -0,0 +1,40 @@ +@file:DependsOn("org.openjfx:javafx-controls:23") +@file:DependsOn("org.openjfx:javafx-graphics:23") + +import javafx.application.Application +import javafx.geometry.Pos +import javafx.scene.Scene +import javafx.scene.control.Label +import javafx.scene.layout.VBox +import javafx.stage.Stage + + +class HelloJFXApp : Application() { + private var scene: Scene? = null + + override fun start(stage: Stage) { + val javaInfoString = String.format( + "Java: %s, %s , %s", + System.getProperty("java.version"), + System.getProperty("java.vendor"), + System.getProperty("java.vm.version") + ) + val jfxInfoString = String.format("JavaFX: %s", System.getProperty("javafx.version")) + + val holder = VBox() + holder.isFillWidth = true + holder.alignment = Pos.TOP_CENTER + holder.spacing = 5.0 + holder.children.addAll( + Label(javaInfoString), + Label(jfxInfoString), + ) + + scene = Scene(holder, 400.0, 300.0) + stage.title = "JavaFX Demo" + stage.scene = scene + stage.show() + } +} + +Application.launch(HelloJFXApp::class.java) \ No newline at end of file From 2ca1a9a98df30e9cd52116176fee0b5b5aa976d3 Mon Sep 17 00:00:00 2001 From: yostane <1958676+yostane@users.noreply.github.com> Date: Sat, 30 Nov 2024 17:49:31 +0100 Subject: [PATCH 2/6] Some JBang templates and scripts --- jbang-catalog.json | 25 +++++++++++++ material/scripting/jbang/jfxdemo.qute | 44 +++++++++++++++++++++++ material/scripting/jbang/testjfx.kt | 44 +++++++++++++++++++++++ material/scripting/jbang/testjfx2.kt | 44 +++++++++++++++++++++++ material/scripting/kts/ktor-demo.main.kts | 0 5 files changed, 157 insertions(+) create mode 100644 jbang-catalog.json create mode 100644 material/scripting/jbang/jfxdemo.qute create mode 100644 material/scripting/jbang/testjfx.kt create mode 100644 material/scripting/jbang/testjfx2.kt create mode 100644 material/scripting/kts/ktor-demo.main.kts diff --git a/jbang-catalog.json b/jbang-catalog.json new file mode 100644 index 0000000..612e08e --- /dev/null +++ b/jbang-catalog.json @@ -0,0 +1,25 @@ +{ + "catalogs": {}, + "aliases": { + "jfxapp": { + "script-ref": "/material/scripting/jbang/jfxdemo.kt", + "description": "Single file JavaFX application that defined the UI with code (no fxml)" + }, + }, + "templates": { + "jfxkt-legacy": { + "file-refs": { + "{basename}.kt": "/material/scripting/jbang/jfxdemo.kt", + "description": "Single file JavaFX application that defined the UI with code (no fxml)" + }, + "properties": {} + }, + "jfxkt": { + "file-refs": { + "{basename}.kt": "/material/scripting/jbang/jfxdemo.qute", + "description": "Single file JavaFX application that defined the UI with code (no fxml)" + }, + "properties": {} + } + } +} \ No newline at end of file diff --git a/material/scripting/jbang/jfxdemo.qute b/material/scripting/jbang/jfxdemo.qute new file mode 100644 index 0000000..4e6935d --- /dev/null +++ b/material/scripting/jbang/jfxdemo.qute @@ -0,0 +1,44 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? + +//DEPS org.openjfx:javafx-controls:23 +//DEPS org.openjfx:javafx-graphics:23:${os.detected.jfxname} +//DEPS org.openjfx:javafx-fxml:23 + +import javafx.application.Application +import javafx.geometry.Pos +import javafx.scene.Scene +import javafx.scene.control.Label +import javafx.scene.layout.VBox +import javafx.stage.Stage + +class {baseName} : Application() { + private var scene: Scene? = null + + override fun start(stage: Stage) { + val javaInfoString = String.format( + "Java: %s, %s , %s", + System.getProperty("java.version"), + System.getProperty("java.vendor"), + System.getProperty("java.vm.version") + ) + val jfxInfoString = String.format("JavaFX: %s", System.getProperty("javafx.version")) + + val holder = VBox() + holder.isFillWidth = true + holder.alignment = Pos.TOP_CENTER + holder.spacing = 5.0 + holder.children.addAll( + Label(javaInfoString), + Label(jfxInfoString), + ) + + scene = Scene(holder, 400.0, 300.0) + stage.title = "JavaFX Demo" + stage.scene = scene + stage.show() + } +} + +fun main() { + Application.launch(HelloJFXApp::class.java) +} \ No newline at end of file diff --git a/material/scripting/jbang/testjfx.kt b/material/scripting/jbang/testjfx.kt new file mode 100644 index 0000000..cf8c481 --- /dev/null +++ b/material/scripting/jbang/testjfx.kt @@ -0,0 +1,44 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? + +//DEPS org.openjfx:javafx-controls:23 +//DEPS org.openjfx:javafx-graphics:23:${os.detected.jfxname} +//DEPS org.openjfx:javafx-fxml:23 + +import javafx.application.Application +import javafx.geometry.Pos +import javafx.scene.Scene +import javafx.scene.control.Label +import javafx.scene.layout.VBox +import javafx.stage.Stage + +class HelloJFXApp : Application() { + private var scene: Scene? = null + + override fun start(stage: Stage) { + val javaInfoString = String.format( + "Java: %s, %s , %s", + System.getProperty("java.version"), + System.getProperty("java.vendor"), + System.getProperty("java.vm.version") + ) + val jfxInfoString = String.format("JavaFX: %s", System.getProperty("javafx.version")) + + val holder = VBox() + holder.isFillWidth = true + holder.alignment = Pos.TOP_CENTER + holder.spacing = 5.0 + holder.children.addAll( + Label(javaInfoString), + Label(jfxInfoString), + ) + + scene = Scene(holder, 400.0, 300.0) + stage.title = "JavaFX Demo" + stage.scene = scene + stage.show() + } +} + +fun main() { + Application.launch(HelloJFXApp::class.java) +} \ No newline at end of file diff --git a/material/scripting/jbang/testjfx2.kt b/material/scripting/jbang/testjfx2.kt new file mode 100644 index 0000000..34599d9 --- /dev/null +++ b/material/scripting/jbang/testjfx2.kt @@ -0,0 +1,44 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? + +//DEPS org.openjfx:javafx-controls:23 +//DEPS org.openjfx:javafx-graphics:23:$NOT_FOUND +//DEPS org.openjfx:javafx-fxml:23 + +import javafx.application.Application +import javafx.geometry.Pos +import javafx.scene.Scene +import javafx.scene.control.Label +import javafx.scene.layout.VBox +import javafx.stage.Stage + +class testjfx2 : Application() { + private var scene: Scene? = null + + override fun start(stage: Stage) { + val javaInfoString = String.format( + "Java: %s, %s , %s", + System.getProperty("java.version"), + System.getProperty("java.vendor"), + System.getProperty("java.vm.version") + ) + val jfxInfoString = String.format("JavaFX: %s", System.getProperty("javafx.version")) + + val holder = VBox() + holder.isFillWidth = true + holder.alignment = Pos.TOP_CENTER + holder.spacing = 5.0 + holder.children.addAll( + Label(javaInfoString), + Label(jfxInfoString), + ) + + scene = Scene(holder, 400.0, 300.0) + stage.title = "JavaFX Demo" + stage.scene = scene + stage.show() + } +} + +fun main() { + Application.launch(HelloJFXApp::class.java) +} \ No newline at end of file diff --git a/material/scripting/kts/ktor-demo.main.kts b/material/scripting/kts/ktor-demo.main.kts new file mode 100644 index 0000000..e69de29 From ff5373441729860e536380c2ec8be09b92849bca Mon Sep 17 00:00:00 2001 From: Yassine Benabbas <1958676+yostane@users.noreply.github.com> Date: Sat, 30 Nov 2024 17:55:51 +0100 Subject: [PATCH 3/6] Update jbang-catalog.json --- jbang-catalog.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jbang-catalog.json b/jbang-catalog.json index 612e08e..52a7941 100644 --- a/jbang-catalog.json +++ b/jbang-catalog.json @@ -4,7 +4,7 @@ "jfxapp": { "script-ref": "/material/scripting/jbang/jfxdemo.kt", "description": "Single file JavaFX application that defined the UI with code (no fxml)" - }, + } }, "templates": { "jfxkt-legacy": { @@ -22,4 +22,4 @@ "properties": {} } } -} \ No newline at end of file +} From c0e7b7d055513a7d0af94be6424bf3dc3121d66a Mon Sep 17 00:00:00 2001 From: Yassine Benabbas <1958676+yostane@users.noreply.github.com> Date: Sat, 30 Nov 2024 17:57:49 +0100 Subject: [PATCH 4/6] some catalog fixes --- jbang-catalog.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jbang-catalog.json b/jbang-catalog.json index 52a7941..d7c8e93 100644 --- a/jbang-catalog.json +++ b/jbang-catalog.json @@ -2,21 +2,21 @@ "catalogs": {}, "aliases": { "jfxapp": { - "script-ref": "/material/scripting/jbang/jfxdemo.kt", + "script-ref": "material/scripting/jbang/jfxdemo.kt", "description": "Single file JavaFX application that defined the UI with code (no fxml)" } }, "templates": { "jfxkt-legacy": { "file-refs": { - "{basename}.kt": "/material/scripting/jbang/jfxdemo.kt", + "{basename}.kt": "material/scripting/jbang/jfxdemo.kt", "description": "Single file JavaFX application that defined the UI with code (no fxml)" }, "properties": {} }, "jfxkt": { "file-refs": { - "{basename}.kt": "/material/scripting/jbang/jfxdemo.qute", + "{basename}.kt": "material/scripting/jbang/jfxdemo.qute", "description": "Single file JavaFX application that defined the UI with code (no fxml)" }, "properties": {} From e4769b74709cebb722fa788231c774dbf2e28940 Mon Sep 17 00:00:00 2001 From: Yassine Benabbas <1958676+yostane@users.noreply.github.com> Date: Sat, 30 Nov 2024 18:04:22 +0100 Subject: [PATCH 5/6] some catalog fixes --- jbang-catalog.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/jbang-catalog.json b/jbang-catalog.json index d7c8e93..a447246 100644 --- a/jbang-catalog.json +++ b/jbang-catalog.json @@ -9,15 +9,13 @@ "templates": { "jfxkt-legacy": { "file-refs": { - "{basename}.kt": "material/scripting/jbang/jfxdemo.kt", - "description": "Single file JavaFX application that defined the UI with code (no fxml)" + "{basename}.kt": "material/scripting/jbang/jfxdemo.kt" }, "properties": {} }, "jfxkt": { "file-refs": { - "{basename}.kt": "material/scripting/jbang/jfxdemo.qute", - "description": "Single file JavaFX application that defined the UI with code (no fxml)" + "{basename}.kt": "material/scripting/jbang/jfxdemo.qute" }, "properties": {} } From eabc4e0472a693e3bca011c237450fd2321c817f Mon Sep 17 00:00:00 2001 From: Yassine Benabbas <1958676+yostane@users.noreply.github.com> Date: Sat, 30 Nov 2024 18:34:49 +0100 Subject: [PATCH 6/6] some catalog fixes --- jbang-catalog.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jbang-catalog.json b/jbang-catalog.json index a447246..0b4983a 100644 --- a/jbang-catalog.json +++ b/jbang-catalog.json @@ -11,12 +11,14 @@ "file-refs": { "{basename}.kt": "material/scripting/jbang/jfxdemo.kt" }, + "description": "Single file JavaFX application", "properties": {} }, "jfxkt": { "file-refs": { "{basename}.kt": "material/scripting/jbang/jfxdemo.qute" }, + "description": "Single file JavaFX application that defined the UI with code (no fxml)", "properties": {} } }