All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tornadofx.FX.kt Maven / Gradle / Ivy

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