
tornadofx.FX.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fx Show documentation
Show all versions of fx Show documentation
Lightweight JavaFX Framework for Kotlin
The newest version!
package tornadofx
import javafx.stage.Stage
import java.util.*
import kotlin.reflect.KClass
class FX {
companion object {
lateinit var primaryStage: Stage
lateinit var application: App
val stylesheets = ArrayList()
val components = HashMap, Component>()
val lock = Any()
}
}
fun importStylesheet(stylesheet: String) {
val css = FX::class.java.getResource(stylesheet)
FX.stylesheets.add(css.toExternalForm())
}
inline fun find(): T = find(T::class)
@Suppress("UNCHECKED_CAST")
fun find(type: KClass): T {
if (Fragment::class.java.isAssignableFrom(type.java))
return type.java.newInstance()
if (!FX.components.containsKey(type)) {
synchronized(FX.lock) {
if (!FX.components.containsKey(type))
FX.components[type] = type.java.newInstance()
}
}
return FX.components[type] as T
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy