Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
# TornadoFX v2 (Gradle)
# TornadoFX v2

A JavaFX framework for Kotlin (Java 11+)

This (experimental) branch is gradle based.
Current state: TODO

* Kotlin & Java target is Java 11.0.2
* JavaFX version is 15.0.1
* JUnit5 with additional vintage engine for unit testing
* Tests running on classpath ignoring javas module system
* no support for OSGI bundle
Current state: [![Build Status](https://travis-ci.com/confinitum/tornadofx2.svg)](https://travis-ci.com/confinitum/tornadofx2)

## Features

Expand All @@ -25,9 +18,8 @@ Current state: TODO

## Requirements

* JDK 11+
* [Kotlin 1.3+](https://kotlinlang.org/)
* [JavaFX 13+](https://openjfx.io/)
* [Kotlin 1.4+](https://kotlinlang.org/)
* [JavaFX 15+](https://openjfx.io/)

## Feature Requests and Bugs

Expand All @@ -37,3 +29,11 @@ Please use the GitHub [issues](https://github.com/edvin/tornadofx2/issues) for a

* [Edvin Syse](https://github.com/edvin)
* [GoToTags](https://gototags.com/) / [Craig Tadlock](https://www.linkedin.com/in/ctadlock/)

## Developer Info

* Kotlin & Java target is Java 11
* JUnit5 plus vintage engine for unit testing
* Tests running on classpath ignoring javas module system
* no support for OSGI bundle

4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
* Gradle version 6.6.1
*/
plugins {
kotlin("jvm") version "1.3.61"
kotlin("jvm") version "1.4.32"
`java-library`
id("org.openjfx.javafxplugin") version "0.0.9"
`maven-publish`
Expand All @@ -25,7 +25,7 @@ val hamcrest_version: String by project
val fontawesomefx_version: String by project

group = "no.tornado"
version = "2.0.0-SNAPSHOT"
version = tornado_version
description = "JavaFX Framework for Kotlin"

extra["isReleaseVersion"] = !version.toString().endsWith("SNAPSHOT")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ kotlin.code.style=official
org.gradle.daemon=false
org.gradle.jvmargs=-Xmx1024m
#deps
kotlin_version=1.3.61
kotlin_version=1.4.32
tornado_version=2.0.0-SNAPSHOT
dokka_version=1.4.20
json_version=1.1.2
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/tornadofx/FX.kt
Original file line number Diff line number Diff line change
Expand Up @@ -516,12 +516,11 @@ fun EventTarget.addChildIfPossible(node: Node, index: Int? = null) {
if (FX.childInterceptors.dropWhile { !it(this, node, index) }.isNotEmpty()) return

if (FX.ignoreParentBuilder != FX.IgnoreParentBuilder.No) return
if (this is Node) {

if (this is Node && builderTarget != null) {
val target = builderTarget
if (target != null) {
// Trick to get around the disallowed use of invoke on out projected types
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
target!!(this).value = node
target(this).value = node
return
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/tornadofx/Layouts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ fun EventTarget.tilepane(op: TilePane.() -> Unit = {}) = opcr(this, TilePane(),
fun EventTarget.borderpane(op: BorderPane.() -> Unit = {}) = opcr(this, BorderPane(), op)

@Suppress("UNCHECKED_CAST")
var Node.builderTarget: KFunction1<*, ObjectProperty<Node>>?
get() = properties["tornadofx.builderTarget"] as KFunction1<Any, ObjectProperty<Node>>?
var Node.builderTarget: ((Any) -> ObjectProperty<Node>)?
get() = properties["tornadofx.builderTarget"] as ((Any) -> ObjectProperty<Node>)?
set(value) {
properties["tornadofx.builderTarget"] = value
}
Expand All @@ -176,8 +176,10 @@ fun BorderPane.bottom(op: BorderPane.() -> Unit) = region(BorderPane::bottomProp
fun BorderPane.left(op: BorderPane.() -> Unit) = region(BorderPane::leftProperty, op)
fun BorderPane.right(op: BorderPane.() -> Unit) = region(BorderPane::rightProperty, op)
fun BorderPane.center(op: BorderPane.() -> Unit) = region(BorderPane::centerProperty, op)
internal fun BorderPane.region(region: KFunction1<BorderPane, ObjectProperty<Node>>?, op: BorderPane.() -> Unit) {
builderTarget = region

internal fun BorderPane.region(region: ((BorderPane) -> ObjectProperty<Node>)?, op: BorderPane.() -> Unit) {
@Suppress("UNCHECKED_CAST")
builderTarget = region as ((Any) -> ObjectProperty<Node>)?
op()
builderTarget = null
}
Expand Down
60 changes: 60 additions & 0 deletions src/test/kotlin/tornadofx/tests/BorderPaneTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package tornadofx.tests

import javafx.scene.Scene
import javafx.scene.control.Label
import javafx.scene.layout.BorderPane
import javafx.scene.layout.HBox
import javafx.scene.layout.StackPane
import javafx.stage.Stage
import org.assertj.core.api.Assertions
import org.junit.jupiter.api.Test
import org.testfx.api.FxAssert
import org.testfx.api.FxService
import org.testfx.api.FxToolkit
import org.testfx.matcher.base.NodeMatchers
import tornadofx.*

class BorderPaneTest {
val primaryStage: Stage = FxToolkit.registerPrimaryStage()

@Test
fun borderPaneBasicTest() {
FxToolkit.setupFixture {
val root = StackPane().apply {
borderpane {
styleClass.add("my-border=pane")
// Direct access
top = label("Top")
// Builder target
center {
hbox {
label("Center") {
}
}
}
bottom {
label("Bottom")
}
}
setPrefSize(150.0, 150.0)
}
primaryStage.scene = Scene(root)
primaryStage.show()
}
//precheck
val borderpane = FxService.serviceContext().nodeFinder.lookup(".my-border=pane").query<BorderPane>()
FxAssert.verifyThat(borderpane, NodeMatchers.isNotNull())

//expect no cell with teststyle
Assertions.assertThat(borderpane.top)
.`as`("top should be a Label")
.isInstanceOf(Label::class.java)
Assertions.assertThat(borderpane.center)
.`as`("center should be a HBox")
.isInstanceOf(HBox::class.java)
Assertions.assertThat((borderpane.center as HBox).children)
.`as`("center should contain only 1 child")
.hasSize(1)
}

}
6 changes: 3 additions & 3 deletions src/test/kotlin/tornadofx/tests/PropertiesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2819,9 +2819,9 @@ class PropertiesTest {
}

@Test fun propertyFromMapKey() {
val map = mutableMapOf("hello" to "world", "number" to 42)
val helloProperty = map.toProperty("hello") { SimpleStringProperty(it as String?) }
val numberProperty = map.toProperty("number") { SimpleIntegerProperty(it as Int) }
val map: MutableMap<String, Any> = mutableMapOf("hello" to "world", "number" to 42)
val helloProperty: Property<String> = map.toProperty("hello") { SimpleStringProperty(it as String?) }
val numberProperty: Property<Number> = map.toProperty("number") { SimpleIntegerProperty(it as Int) }
helloProperty.value = "there"
numberProperty.value = 43
Assert.assertEquals("there", map["hello"])
Expand Down
17 changes: 9 additions & 8 deletions src/test/kotlin/tornadofx/tests/ViewModelTest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tornadofx.tests

import javafx.beans.property.ObjectProperty
import javafx.beans.property.Property
import javafx.beans.property.SimpleObjectProperty
import javafx.beans.property.SimpleStringProperty
Expand Down Expand Up @@ -223,24 +224,24 @@ class PersonAutoModel(var person: Person? = null) : ViewModel() {

// JavaFX Property
open class PersonModel(person: Person? = null) : ItemViewModel<Person>(person) {
val name = bind { item?.nameProperty() }
val age = bind { item?.ageProperty() }
val phone = bind { item?.phoneProperty() }
val email = bind { item?.emailProperty() }
val name: Property<String> = bind { item?.nameProperty() }
val age: Property<Int> = bind { item?.ageProperty() }
val phone: Property<String> = bind { item?.phoneProperty() }
val email: Property<String> = bind { item?.emailProperty() }
}

// Java POJO getter/setter property
class JavaPersonModel(person: JavaPerson) : ViewModel() {
val name = bind { person.observable(JavaPerson::getName, JavaPerson::setName) }
val name: Property<String> = bind { person.observable(JavaPerson::getName, JavaPerson::setName) }
}

// Kotlin var property
class PersonVarModel(person: Person) : ViewModel() {
val name = bind { person.observable(Person::name) }
val name: Property<String> = bind { person.observable(Person::name) }
}

//Kotlin nullable and non-nullable property in ItemViewModel
class PersonPokoModel(item : PersonPoko): ItemViewModel<PersonPoko>(item) {
val name = bind(PersonPoko::name)
val phone = bind(PersonPoko::phone)
val name: Property<String> = bind(PersonPoko::name)
val phone: Property<String> = bind(PersonPoko::phone)
}